Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

KeAcquireSpinLock or KeAcquireSpinLickAtDpc?

0 views
Skip to first unread message

Raj

unread,
Mar 26, 2008, 8:11:00 PM3/26/08
to
I have a function that uses KeAcquireSpinLock(). This function will be called
for each packet in a data stream at DISPATCH_LEVEL and I was interested to
tune the performance. Then I read documentation that KeAcquireSpinLockAtDpc()
will improve performance. I also want to use this function in few places
where it rarely be called at " less than DISPATCH Irql".

I am thinking of using KeGetCurrentIrql() to decide whether I use
KeAcquireSpinLock() or KeAcquireSpinLockAtDpc(). I am not sure if I should
bother to do this or simply always use KeAcquireSpinLock(). Is the
performance be considerable to use conditional KeAcquireSpinLockAtDpc() ?

Thanks,
Raj

PCAUSA

unread,
Mar 26, 2008, 8:53:05 PM3/26/08
to

It would be really unlikely that changes from KeAcquireSpinLock to
KeGetCurrentIrql/KeAcquireSpinLock|KeAcquireSpinLockAtDpc would have
any performance improvement. Likely the call to KeGetCurrentIrql is as
expensive as calling KeAcquireSpinLock when actually at dispatch.

Use KeAcquireSpinLockAtDpc when you _know_ you are being called at
dispatch by the callback definition.

Thomas F. Divine
http://www.pcausa.com

Alexander Grigoriev

unread,
Mar 26, 2008, 11:24:08 PM3/26/08
to
You may get some performance gain in Windows 2003, if you simply use
KeAcquireSpinLockAtDpc(), AND if you can be sure you're at DISPATCH_LEVEL.
KeGetCurrentIrql() in Win2003 may be as expensive as KeRaiseIrql(), though
not much.

In Win2008, KeRaiseIrql and KeGetCurrentIrql() are very inexpensive. You're
not likely to get much performance gain.

"Raj" <R...@discussions.microsoft.com> wrote in message
news:8611CC23-B6C0-42BC...@microsoft.com...

Uv

unread,
Mar 27, 2008, 11:06:20 AM3/27/08
to

Optimizations such as the one you are proposing will affect the total
throughput only if the code path is under high contention.
Otherwise, the general rule is to improve the design to get better
performance and not depend on micro-optimizations.

Regards,
UV

Don Burn

unread,
Mar 27, 2008, 11:13:20 AM3/27/08
to
Actually, IIRC KeGetCurrentIrql() is expensive enough that it will probably
decrease performance.


--
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

"Uv" <yuv...@gmail.com> wrote in message
news:70050799-892a-4bfd...@h11g2000prf.googlegroups.com...

Maxim S. Shatskih

unread,
Mar 27, 2008, 1:17:38 PM3/27/08
to
>Then I read documentation that KeAcquireSpinLockAtDpc()
> will improve performance. I also want to use this function in few places
> where it rarely be called at " less than DISPATCH Irql".

In these places, use KeRaiseIrql and the KeAcquireSpinLockAtDpcLevel.

In usual places, use KeAcquireSpinLockAtDpcLevel alone.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
ma...@storagecraft.com
http://www.storagecraft.com

Doron Holan [MSFT]

unread,
Mar 27, 2008, 2:24:25 PM3/27/08
to
it comes down to a simple litmus test

1) if you know you are at dispatch level, the AtDpc version will be faster
b/c there is no IRQL get and possible set.
2) otherwise, if you do no not know for sure, just call KeAcquireSpinLock.
internally it will call KeGetCurrentIrql to know if it needs to raise to
dispatch level, so if you check for current irql first and you are at
passive level, you get worse performance b/c KeGetCurrentIrql is called
twice

d

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


"Raj" <R...@discussions.microsoft.com> wrote in message
news:8611CC23-B6C0-42BC...@microsoft.com...

0 new messages