X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/2d21ac55c334faf3a56e5634905ed6987fc787d4..04b8595b18b1b41ac7a206e4b3d51a635f8413d7:/iokit/Kernel/IOCommandGate.cpp diff --git a/iokit/Kernel/IOCommandGate.cpp b/iokit/Kernel/IOCommandGate.cpp index f276ebc22..9b19d70ee 100644 --- a/iokit/Kernel/IOCommandGate.cpp +++ b/iokit/Kernel/IOCommandGate.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1998-2000, 2009-2010 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -31,11 +31,16 @@ #include #include #include +#include #define super IOEventSource OSDefineMetaClassAndStructors(IOCommandGate, IOEventSource) +#if __LP64__ OSMetaClassDefineReservedUnused(IOCommandGate, 0); +#else +OSMetaClassDefineReservedUsed(IOCommandGate, 0); +#endif OSMetaClassDefineReservedUnused(IOCommandGate, 1); OSMetaClassDefineReservedUnused(IOCommandGate, 2); OSMetaClassDefineReservedUnused(IOCommandGate, 3); @@ -44,11 +49,33 @@ OSMetaClassDefineReservedUnused(IOCommandGate, 5); OSMetaClassDefineReservedUnused(IOCommandGate, 6); OSMetaClassDefineReservedUnused(IOCommandGate, 7); -bool IOCommandGate::checkForWork() { return false; } +#if IOKITSTATS + +#define IOStatisticsInitializeCounter() \ +do { \ + IOStatistics::setCounterType(IOEventSource::reserved->counter, kIOStatisticsCommandGateCounter); \ +} while (0) + +#define IOStatisticsActionCall() \ +do { \ + IOStatistics::countCommandGateActionCall(IOEventSource::reserved->counter); \ +} while (0) + +#else + +#define IOStatisticsInitializeCounter() +#define IOStatisticsActionCall() + +#endif /* IOKITSTATS */ bool IOCommandGate::init(OSObject *inOwner, Action inAction) { - return super::init(inOwner, (IOEventSource::Action) inAction); + bool res = super::init(inOwner, (IOEventSource::Action) inAction); + if (res) { + IOStatisticsInitializeCounter(); + } + + return res; } IOCommandGate * @@ -125,9 +152,6 @@ IOReturn IOCommandGate::runAction(Action inAction, if (!inAction) return kIOReturnBadArgument; - IOTimeStampConstant(IODBG_CMDQ(IOCMDQ_ACTION), - (unsigned int) inAction, (unsigned int) owner); - // closeGate is recursive needn't worry if we already hold the lock. closeGate(); @@ -154,10 +178,23 @@ IOReturn IOCommandGate::runAction(Action inAction, } } + bool trace = ( gIOKitTrace & kIOTraceCommandGates ) ? true : false; + + if (trace) + IOTimeStampStartConstant(IODBG_CMDQ(IOCMDQ_ACTION), + VM_KERNEL_UNSLIDE(inAction), (uintptr_t) owner); + + IOStatisticsActionCall(); + // Must be gated and on the work loop or enabled res = (*inAction)(owner, arg0, arg1, arg2, arg3); + + if (trace) + IOTimeStampEndConstant(IODBG_CMDQ(IOCMDQ_ACTION), + VM_KERNEL_UNSLIDE(inAction), (uintptr_t) owner); + openGate(); - + return res; } @@ -178,10 +215,20 @@ IOReturn IOCommandGate::attemptAction(Action inAction, if (!workLoop->onThread() && !enabled) res = kIOReturnNotPermitted; else { - IOTimeStampConstant(IODBG_CMDQ(IOCMDQ_ACTION), - (unsigned int) inAction, (unsigned int) owner); - - res = (*inAction)(owner, arg0, arg1, arg2, arg3); + + bool trace = ( gIOKitTrace & kIOTraceCommandGates ) ? true : false; + + if (trace) + IOTimeStampStartConstant(IODBG_CMDQ(IOCMDQ_ACTION), + VM_KERNEL_UNSLIDE(inAction), (uintptr_t) owner); + + IOStatisticsActionCall(); + + res = (*inAction)(owner, arg0, arg1, arg2, arg3); + + if (trace) + IOTimeStampEndConstant(IODBG_CMDQ(IOCMDQ_ACTION), + VM_KERNEL_UNSLIDE(inAction), (uintptr_t) owner); } openGate(); @@ -197,6 +244,14 @@ IOReturn IOCommandGate::commandSleep(void *event, UInt32 interruptible) return sleepGate(event, interruptible); } +IOReturn IOCommandGate::commandSleep(void *event, AbsoluteTime deadline, UInt32 interruptible) +{ + if (!workLoop->inGate()) + return kIOReturnNotPermitted; + + return sleepGate(event, deadline, interruptible); +} + void IOCommandGate::commandWakeup(void *event, bool oneThread) { wakeupGate(event, oneThread);