Re: Can I call KeAcquireSpinLockAtDpcLevel at DISPATCH_LEVEL?

Tech-Archive recommends: Speed Up your PC by fixing your registry



Comments inline:

<0dbell@xxxxxxxxx> wrote in message
news:1181502206.494425.224140@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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:

One reviewer of Chris Cant's book described it as the biggest waste of
paper ever. Personally, I consider the reviewer way too kind. Do not
refer to the book, but you can keep it for a game, let it fall open to a
pair of pages and see how many errors you can find on that pair (the number
in many cases is multiple digits).

"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).

Spin locks are not kernel dispatcher objects, those are things like
KMUTEX'es, TIMERS, EVENT's etc.

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?

A spin lock is a low level primative, in fact kernel dispatcher objects use
spin locks as part of their implementation.


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply


.



Relevant Pages

  • Can I call KeAcquireSpinLockAtDpcLevel at DISPATCH_LEVEL?
    ... Can I call KeAcquireSpinLockAtDpcLevel at DISPATCH_LEVEL? ... that it is made exactly for acquiring a spinlock at DISPATCH_LEVEL), ... Never wait on a kernel dispatcher object for a nonzero interval at ... If SpinLocks are not considered "kernel dispatcher objects", ...
    (microsoft.public.development.device.drivers)
  • Re: Hyperthread issue
    ... I am calling NdisMEthIndicateReceive while holding the spinlock. ... while you are holding a spin lock. ... If you are facing problems writing an NDIS miniport driver that is ...
    (microsoft.public.development.device.drivers)
  • Re: KeWaitForSingleObject and SMP machines
    ... > However, in order to be SMP safe, it must internally use a spinlock. ... > your title you seem to work for MS, so you could possibly check the source> real quick and let us know whether it is internally using a spin lock or> bus ... >> Don Burn (MVP, Windows DDK) ...
    (microsoft.public.development.device.drivers)
  • Re: KMDF DPC Synchronization
    ... I confirmed my problem is a multiple claiming of a single spin lock. ... the same time as a serial port IO request. ... My spin lock is being claimed by the DPC then processing the DMA data. ... A spinlock will 'spin' until the spinlock is released. ...
    (microsoft.public.development.device.drivers)
  • Re: Righ use of spin lock
    ... essentially just wrappers around the standard nt spinlock calls. ... Have you tried running your driver against the checked os and/or driver ... > and by MiniportSend which runs on PASSIVE_LEVEL. ... > I see in debuger that acquiring spin lock in MiniportSend raises IRQL ...
    (microsoft.public.development.device.drivers)