Pavel, when you say “executive spinlocks” I’m not sure what you mean. I’ll
mentally insert “dispatcher objects” in my mind and answer your question.
All dispatcher objects (which are the PASSIVE_LEVEL synchronization objects,
more or less, in NT) involve at least an interlocked compare/exchange
operation, and if there’s any lock contention, a couple of changes of IRQL
and some more interlocked operations. In total, I suspect that they’re
higher in overhead than spinlocks.
Executive objects (like the Fast Mutex) also involve an IRQL change, even
when there’s no contention.
In summary, don’t pick your synchronization mechanism for its perceived
overhead. Pick it for its semantics.
Jake Oshins
Hyper-V I/O Architect
Windows Kernel Group
This post implies no warranties and confers no rights.
“Pavel A.” wrote in message news:xxxxx@ntdev…
wrote in message news:xxxxx@ntdev…
> So… Let’s summarize, shall we?
>
> 1) The WDK Docs that say “NEVER call KeAcquireSpinLock from code that is
> running at IRQL =
> DISPATCH_LEVEL” is, at best, misleading. Other, similar, guidance has
> appeared in the DDK docs since NT V3.1 but never in such strong words. The
> docs need changed to reflect that they are referring to a performance
> optimization not a logic error.
>
> 2) It may or may not be expensive to query/set the IRQL on any given
> processor on which your driver runs. On certain x86 systems IRQL
> management is mostly done in software (and was historically done this way
> on particular processor configurations).
>
> 3) The IRQL functions on AMD64 are inlined, thereby demonstrating the
> underlying evil of inlining basic support functions (or, worse, making
> them macros – the IRP stack manipulation macros come quickly to mind) and
> proving that Cutler is not omniscient.
>
> 4) It’s incredibly helpful to have folks like Doron and Jake, who actually
> have insight into how the code works, answer questions on this forum…
> otherwise we could be in the midst of a long “what’s wrong with those
> people, they could just cache the IRQL, they are soooo stooopid” thread.
>
> Peter
> OSR
>
Does (2) also mean that executive spinlocks (all kinds of them)
are expensive and should be avoided whenever possible?
Especially, using spinlocks to sync threads running at PASSIVE,
just in case if a DISPATCH code path may be added later,
is waste of performance; instead, passive-only locks should be used?
Re. “underlying evil of inlining basic support functions” - IMHO
this is inherent weakness of
native code vs. JIT code generation, optimized for specific target system.
This sort of evil could not been avoided then. Now it may be viewed as
preliminary optimization.
Regards,
– pa