Re: Can I call KeAcquireSpinLockAtDpcLevel at DISPATCH_LEVEL?
- From: "Don Burn" <burn@xxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 10 Jun 2007 15:13:21 -0400
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
.
- Follow-Ups:
- Re: Can I call KeAcquireSpinLockAtDpcLevel at DISPATCH_LEVEL?
- From: Anton Bassov
- Re: Can I call KeAcquireSpinLockAtDpcLevel at DISPATCH_LEVEL?
- From: 0dbell
- Re: Can I call KeAcquireSpinLockAtDpcLevel at DISPATCH_LEVEL?
- References:
- Prev by Date: Can I call KeAcquireSpinLockAtDpcLevel at DISPATCH_LEVEL?
- Next by Date: Re: Can I call KeAcquireSpinLockAtDpcLevel at DISPATCH_LEVEL?
- Previous by thread: Can I call KeAcquireSpinLockAtDpcLevel at DISPATCH_LEVEL?
- Next by thread: Re: Can I call KeAcquireSpinLockAtDpcLevel at DISPATCH_LEVEL?
- Index(es):
Relevant Pages
|