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

Re: KeAcquireSpinLock or KeAcquireSpinLickAtDpc? by PCAUSA

PCAUSA
Wed Mar 26 19:53:05 CDT 2008

On Mar 26, 8:11=A0pm, Raj <R...@discussions.microsoft.com> wrote:
> I have a function that uses KeAcquireSpinLock(). This function will be cal=
led
> for each packet in a data stream at DISPATCH_LEVEL and I was interested to=

> tune the performance. Then I read documentation that KeAcquireSpinLockAtDp=
c()
> 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

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

Re: KeAcquireSpinLock or KeAcquireSpinLickAtDpc? by Alexander

Alexander
Wed Mar 26 22:24:08 CDT 2008

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" <Raj@discussions.microsoft.com> wrote in message
news:8611CC23-B6C0-42BC-91DE-EC0AAA411FC0@microsoft.com...
>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



Re: KeAcquireSpinLock or KeAcquireSpinLickAtDpc? by Uv

Uv
Thu Mar 27 10:06:20 CDT 2008

On Mar 26, 5:11 pm, Raj <R...@discussions.microsoft.com> wrote:
> 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

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

Re: KeAcquireSpinLock or KeAcquireSpinLickAtDpc? by Don

Don
Thu Mar 27 10:13:20 CDT 2008

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" <yuvraaj@gmail.com> wrote in message
news:70050799-892a-4bfd-bb6d-466b21945007@h11g2000prf.googlegroups.com...
> On Mar 26, 5:11 pm, Raj <R...@discussions.microsoft.com> wrote:
>> 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
>
> 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



Re: KeAcquireSpinLock or KeAcquireSpinLickAtDpc? by Maxim

Maxim
Thu Mar 27 12:17:38 CDT 2008

>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
maxim@storagecraft.com
http://www.storagecraft.com


Re: KeAcquireSpinLock or KeAcquireSpinLickAtDpc? by Doron

Doron
Thu Mar 27 13:24:25 CDT 2008

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" <Raj@discussions.microsoft.com> wrote in message
news:8611CC23-B6C0-42BC-91DE-EC0AAA411FC0@microsoft.com...
>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