Can I call KeAcquireSpinLockAtDpcLevel at DISPATCH_LEVEL?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Can I call KeAcquireSpinLockAtDpcLevel at DISPATCH_LEVEL?

While this question may sound silly (since the function name suggests
that it is made exactly for acquiring a spinlock at DISPATCH_LEVEL),
you will shortly find out why I am asking it:

In the book that I am using to learn the art of writing WDM device
drivers (by Chris Cant, published by R&D books), the section on Spin
Locks reads:

"Only one instance of a piece of code can acquire a spin lock at the
same time. Other attempts to acquire the spin lock will "spin" until
the resource becomes available. "Spinning" means that
KeAcquireSpinLock keeps looking continuously. ... If you are certain
that your code is working at DISPATCH_LEVEL, you can use
KeAcquireSpinLockAtDpcLevel ... for better performance."

However, in Microsoft's list of "Tips for Windows NT Driver Developers
-- Things to Avoid":

http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q186775&;

tips #6 and #7 read:

6. Never wait on a kernel dispatcher object for a nonzero interval at
IRQL >= DISPATCH_LEVEL. It is a fatal error.

7. Never call any function that causes the calling thread to wait
directly or indirectly while executing at IRQL >= DISPATCH_LEVEL. It
is a fatal error.

Now I am confused: is a SpinLock considered a "kernel dispatcher
object"? If so, which piece of information (of the two brought above)
is correct?

If SpinLocks are not considered "kernel dispatcher objects", could you
please explain the difference? What is considered to be a "kernel
dispatcher object"? After all, a piece of code attempting to acquire a
spinlock will wait indefinitely until it is release, right? (I know
about the 25 microsecond max acquisition rule).

To further deepen my confusion, Microsoft's MSVAD sample (tested
working perfectly in a multi-processor system) definitely calls
KeAcquireSpinLockAtDpcLevel inside a TimerNotify DPC (see
CSaveData::WriteData):

http://msdn2.microsoft.com/en-us/library/ms790032.aspx

So it seems that either tips #6 and #7 are incorrect/inaccurate or...
a spinlock is not a "kernel dispatcher objects"?

If the latter, what makes the wait on spinlock so different from a
wait on a "kernel dispatcher objects" that makes it suitable for
DISPATCH_LEVEL?

Could someone clarify this issue(s) please?

Thanks,
Don

.



Relevant Pages

  • Re: WinXPSP2, Intel Core2Duo, Kernel drivers
    ... CPU1 obtains a spinlock ... This is because KeAcquireSpinLockAtDpcLevel on a uni-processor is a NOP. ... Don Burn ... Windows 2k/XP/2k3 Filesystem and Driver Consulting ...
    (microsoft.public.development.device.drivers)
  • Re: Can I call KeAcquireSpinLockAtDpcLevel at DISPATCH_LEVEL?
    ... that it is made exactly for acquiring a spinlock at DISPATCH_LEVEL), ... in Microsoft's list of "Tips for Windows NT Driver Developers ... If SpinLocks are not considered "kernel dispatcher objects", ... A spin lock is a low level primative, in fact kernel dispatcher objects use ...
    (microsoft.public.development.device.drivers)
  • Re: Can I call KeAcquireSpinLockAtDpcLevel at DISPATCH_LEVEL?
    ... More so - DISPATCH_LEVEL is a must for KeAcquireSpinLockAtDpcLevel. ... interrupt spinlock is the only chance. ... Spinlock is not a dispatcher object. ... Waiting on a spinlock stalls the CPU in a dead loop. ...
    (microsoft.public.development.device.drivers)