KeTryToAcquireSpinLock

I noticed that nt kenrel has such a routine: KeTryToOAcquireSpinLock.
Are there any ways to use it ?

PS: Anybody knows how to identify it’s a MP built or UP build system ? Nt kernel does not
seem to provide the corresponding functions.

Best wishes,

Matt

Here’s a a way I got to identify it’s UP or MP system:

For a MP system, the spinlock will be realized and it will points to a system defined (the
real spin_lock) structrure, certainly it’s not a NULL pointer and it must bigger than >
0x8000000

For a UP system, the spinlock is not used at all (IRQL is used instead to control it). So
the
KSPIN_LOCK must contain the NULL value.

Matt

I too have noticed that this documented kernel function is not exported;
well, under NT 4.0 build environment it is not. My filter drivers are done
under NT 4.0 DDK and IFS kit to maintain support for NT 4.0 users.

I have not tried this kernel routine under 2K or XP.

Jamey

----- Original Message -----
From: “Matt Wu”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Tuesday, March 22, 2005 8:23 PM
Subject: [ntdev] KeTryToAcquireSpinLock

>I noticed that nt kenrel has such a routine: KeTryToOAcquireSpinLock.
> Are there any ways to use it ?
>
> PS: Anybody knows how to identify it’s a MP built or UP build system ? Nt
> kernel does not seem to provide the corresponding functions.
>
>
> Best wishes,
>
> Matt
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@tfb.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
> NOD32 1.1030 (20050319) Information
>
> This message was checked by NOD32 antivirus system.
> http://www.nod32.com
>
>

I’ve always wondered why anybody thought this routine would be useful.

=====================
Mark Roddy
Windows .NET/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jamey Kirby
Sent: Tuesday, March 22, 2005 11:40 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] KeTryToAcquireSpinLock

I too have noticed that this documented kernel function is
not exported; well, under NT 4.0 build environment it is not.
My filter drivers are done under NT 4.0 DDK and IFS kit to
maintain support for NT 4.0 users.

I have not tried this kernel routine under 2K or XP.

Jamey

----- Original Message -----
From: “Matt Wu”
> Newsgroups: ntdev
> To: “Windows System Software Devs Interest List”
> Sent: Tuesday, March 22, 2005 8:23 PM
> Subject: [ntdev] KeTryToAcquireSpinLock
>
>
> >I noticed that nt kenrel has such a routine: KeTryToOAcquireSpinLock.
> > Are there any ways to use it ?
> >
> > PS: Anybody knows how to identify it’s a MP built or UP
> build system ? Nt
> > kernel does not seem to provide the corresponding functions.
> >
> >
> > Best wishes,
> >
> > Matt
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@tfb.com
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> > NOD32 1.1030 (20050319) Information
> >
> > This message was checked by NOD32 antivirus system.
> > http://www.nod32.com
> >
> >
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@hollistech.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

I just got that this way was only for traced spinlock :frowning:
So it’s no use at all to identify MP or UP system.

“Matt” wrote:xxxxx@ntdev…

Here’s a a way I got to identify it’s UP or MP system:

For a MP system, the spinlock will be realized and it will points to a system defined
(the real spin_lock) structrure, certainly it’s not a NULL pointer and it must bigger
than > 0x8000000

For a UP system, the spinlock is not used at all (IRQL is used instead to control it).
So the
KSPIN_LOCK must contain the NULL value.

it’s a little odd. I suppose you could use it to split up DPCs and let
some other run if you had deferrable work that still needed a spinlock.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
Sent: Wednesday, March 23, 2005 3:58 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] KeTryToAcquireSpinLock

I’ve always wondered why anybody thought this routine would be useful.

=====================
Mark Roddy
Windows .NET/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032 www.hollistech.com

> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Jamey Kirby
> Sent: Tuesday, March 22, 2005 11:40 PM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] KeTryToAcquireSpinLock
>
> I too have noticed that this documented kernel function is not
> exported; well, under NT 4.0 build environment it is not.
> My filter drivers are done under NT 4.0 DDK and IFS kit to maintain
> support for NT 4.0 users.
>
> I have not tried this kernel routine under 2K or XP.
>
> Jamey
>
> ----- Original Message -----
> From: “Matt Wu”
> > Newsgroups: ntdev
> > To: “Windows System Software Devs Interest List”
>
> > Sent: Tuesday, March 22, 2005 8:23 PM
> > Subject: [ntdev] KeTryToAcquireSpinLock
> >
> >
> > >I noticed that nt kenrel has such a routine:
> KeTryToOAcquireSpinLock.
> > > Are there any ways to use it ?
> > >
> > > PS: Anybody knows how to identify it’s a MP built or UP
> > build system ? Nt
> > > kernel does not seem to provide the corresponding functions.
> > >
> > >
> > > Best wishes,
> > >
> > > Matt
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> > > http://www.osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as: xxxxx@tfb.com To
> unsubscribe
> > > send a blank email to xxxxx@lists.osr.com
> > >
> > > NOD32 1.1030 (20050319) Information
> > >
> > > This message was checked by NOD32 antivirus system.
> > > http://www.nod32.com
> > >
> > >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@hollistech.com To
> > unsubscribe send a blank email to xxxxx@lists.osr.com
> >
>
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@windows.microsoft.com To unsubscribe send a blank
> email to xxxxx@lists.osr.com
>

The only reason I can think of is if you’re doing some non-critical
function in a bottleneck region of code, and you only want to do it if
you probably won’t have to incur a blocked spinlock.

Errr… hard to think of real examples, but suppose you had a network
activity LED on your card that the driver had to blink. You probably
wouldn’t want to bother doing that on the current packet if you probably
can’t grab the spinlock… assuming it’ll probably happen on the next
packet anyway.

Now all I have to explain is why a non-critical resource like this would
really need to be protected by a spinlock, but I’ll leave that as an
exercise for the reader :-).

Mark Roddy wrote:

I’ve always wondered why anybody thought this routine would be useful.

=====================
Mark Roddy
Windows .NET/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

>-----Original Message-----
>From: xxxxx@lists.osr.com
>[mailto:xxxxx@lists.osr.com] On Behalf Of Jamey Kirby
>Sent: Tuesday, March 22, 2005 11:40 PM
>To: Windows System Software Devs Interest List
>Subject: Re: [ntdev] KeTryToAcquireSpinLock
>
>I too have noticed that this documented kernel function is
>not exported; well, under NT 4.0 build environment it is not.
>My filter drivers are done under NT 4.0 DDK and IFS kit to
>maintain support for NT 4.0 users.
>
>I have not tried this kernel routine under 2K or XP.
>
>Jamey
>
>----- Original Message -----
>From: “Matt Wu”
>>Newsgroups: ntdev
>>To: “Windows System Software Devs Interest List”
>>Sent: Tuesday, March 22, 2005 8:23 PM
>>Subject: [ntdev] KeTryToAcquireSpinLock
>>
>>
>>
>>>I noticed that nt kenrel has such a routine: KeTryToOAcquireSpinLock.
>>>Are there any ways to use it ?
>>>
>>>PS: Anybody knows how to identify it’s a MP built or UP
>>
>>build system ? Nt
>>
>>>kernel does not seem to provide the corresponding functions.
>>>
>>>
>>>Best wishes,
>>>
>>>Matt
>>>
>>>—
>>>Questions? First check the Kernel Driver FAQ at
>>>http://www.osronline.com/article.cfm?id=256
>>>
>>>You are currently subscribed to ntdev as: xxxxx@tfb.com
>>>To unsubscribe send a blank email to xxxxx@lists.osr.com
>>>
>>>NOD32 1.1030 (20050319) Information
>>>
>>>This message was checked by NOD32 antivirus system.
>>>http://www.nod32.com
>>>
>>>
>>
>>
>>—
>>Questions? First check the Kernel Driver FAQ at
>>http://www.osronline.com/article.cfm?id=256
>>
>>You are currently subscribed to ntdev as: xxxxx@hollistech.com
>>To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>
>
>
>
>


…/ray..

Please remove “.spamblock” from my email address if you need to contact
me outside the newsgroup.

I don’t know the semantics of the call, but it could be
something in the direction of test-test-and-set. A Test and Set
can generate a fair amount of traffic on the Front-Side Bus, so,
one could code like this:

while (NotSignaled(lock));
while (failto(KeTryToAcquireSpinLock(lock))
{
while (NotSignaled(lock));
}

You can see that much of the wait is done in the first while,
which doesn’t go anywhere beyond the cache. Once the first loop
detects the lock being in a Signaled state, it tries to grab it,
and if it fails, it goes back looping on the cache copy of the
lock. Only the second while loop generates traffic on the
Front-Side Bus, and even then, only once in a blue moon.

This is explained in Gregory Andrew’s OS book, page 100, and it
should make a difference in SMP performance.

Alberto.

“Ray Trent” wrote in message
news:xxxxx@hormel9.ieee.org
> The only reason I can think of is if you’re doing some
> non-critical
> function in a bottleneck region of code, and you only want to
> do it if
> you probably won’t have to incur a blocked spinlock.
>
> Errr… hard to think of real examples, but suppose you had a
> network
> activity LED on your card that the driver had to blink. You
> probably
> wouldn’t want to bother doing that on the current packet if
> you probably
> can’t grab the spinlock… assuming it’ll probably happen on
> the next
> packet anyway.
>
> Now all I have to explain is why a non-critical resource like
> this would
> really need to be protected by a spinlock, but I’ll leave that
> as an
> exercise for the reader :-).
>
> Mark Roddy wrote:
>> I’ve always wondered why anybody thought this routine would
>> be useful.
>>
>> =====================
>> Mark Roddy
>> Windows .NET/XP/2000 Consulting
>> Hollis Technology Solutions 603-321-1032
>> www.hollistech.com
>>
>>
>>>-----Original Message-----
>>>From: xxxxx@lists.osr.com
>>>[mailto:xxxxx@lists.osr.com] On Behalf Of Jamey
>>>Kirby
>>>Sent: Tuesday, March 22, 2005 11:40 PM
>>>To: Windows System Software Devs Interest List
>>>Subject: Re: [ntdev] KeTryToAcquireSpinLock
>>>
>>>I too have noticed that this documented kernel function is
>>>not exported; well, under NT 4.0 build environment it is not.
>>>My filter drivers are done under NT 4.0 DDK and IFS kit to
>>>maintain support for NT 4.0 users.
>>>
>>>I have not tried this kernel routine under 2K or XP.
>>>
>>>Jamey
>>>
>>>----- Original Message -----
>>>From: “Matt Wu”
>>>Newsgroups: ntdev
>>>To: “Windows System Software Devs Interest List”
>>>
>>>Sent: Tuesday, March 22, 2005 8:23 PM
>>>Subject: [ntdev] KeTryToAcquireSpinLock
>>>
>>>
>>>
>>>>I noticed that nt kenrel has such a routine:
>>>>KeTryToOAcquireSpinLock.
>>>>Are there any ways to use it ?
>>>>
>>>>PS: Anybody knows how to identify it’s a MP built or UP
>>>
>>>build system ? Nt
>>>
>>>>kernel does not seem to provide the corresponding functions.
>>>>
>>>>
>>>>Best wishes,
>>>>
>>>>Matt
>>>>

The last time this topic came up, I’m pretty sure the general conclusion
from people that looked was that KeAcquireSpinLock *already* does
test-test-and-set. If so, that would tend to limit the usefulness of
this function call to cases where you don’t care if you can’t get the lock.

Alberto Moreira wrote:

I don’t know the semantics of the call, but it could be something in the
direction of test-test-and-set. A Test and Set can generate a fair
amount of traffic on the Front-Side Bus, so, one could code like this:

while (NotSignaled(lock));
while (failto(KeTryToAcquireSpinLock(lock))
{
while (NotSignaled(lock));
}

You can see that much of the wait is done in the first while, which
doesn’t go anywhere beyond the cache. Once the first loop detects the
lock being in a Signaled state, it tries to grab it, and if it fails, it
goes back looping on the cache copy of the lock. Only the second while
loop generates traffic on the Front-Side Bus, and even then, only once
in a blue moon.

This is explained in Gregory Andrew’s OS book, page 100, and it should
make a difference in SMP performance.

Alberto.

“Ray Trent” wrote in message
> news:xxxxx@hormel9.ieee.org
>
>> The only reason I can think of is if you’re doing some non-critical
>> function in a bottleneck region of code, and you only want to do it if
>> you probably won’t have to incur a blocked spinlock.
>>
>> Errr… hard to think of real examples, but suppose you had a network
>> activity LED on your card that the driver had to blink. You probably
>> wouldn’t want to bother doing that on the current packet if you probably
>> can’t grab the spinlock… assuming it’ll probably happen on the next
>> packet anyway.
>>
>> Now all I have to explain is why a non-critical resource like this would
>> really need to be protected by a spinlock, but I’ll leave that as an
>> exercise for the reader :-).
>>
>> Mark Roddy wrote:
>>
>>> I’ve always wondered why anybody thought this routine would be useful.
>>>
>>> =====================
>>> Mark Roddy
>>> Windows .NET/XP/2000 Consulting
>>> Hollis Technology Solutions 603-321-1032
>>> www.hollistech.com
>>>
>>>
>>>> -----Original Message-----
>>>> From: xxxxx@lists.osr.com
>>>> [mailto:xxxxx@lists.osr.com] On Behalf Of Jamey Kirby
>>>> Sent: Tuesday, March 22, 2005 11:40 PM
>>>> To: Windows System Software Devs Interest List
>>>> Subject: Re: [ntdev] KeTryToAcquireSpinLock
>>>>
>>>> I too have noticed that this documented kernel function is
>>>> not exported; well, under NT 4.0 build environment it is not.
>>>> My filter drivers are done under NT 4.0 DDK and IFS kit to
>>>> maintain support for NT 4.0 users.
>>>>
>>>> I have not tried this kernel routine under 2K or XP.
>>>>
>>>> Jamey
>>>>
>>>> ----- Original Message -----
>>>> From: “Matt Wu”
>>>> Newsgroups: ntdev
>>>> To: “Windows System Software Devs Interest List”
>>>> Sent: Tuesday, March 22, 2005 8:23 PM
>>>> Subject: [ntdev] KeTryToAcquireSpinLock
>>>>
>>>>
>>>>
>>>>> I noticed that nt kenrel has such a routine: KeTryToOAcquireSpinLock.
>>>>> Are there any ways to use it ?
>>>>>
>>>>> PS: Anybody knows how to identify it’s a MP built or UP
>>>>
>>>>
>>>> build system ? Nt
>>>>
>>>>> kernel does not seem to provide the corresponding functions.
>>>>>
>>>>>
>>>>> Best wishes,
>>>>>
>>>>> Matt
>>>>>
>
>


…/ray..

Please remove “.spamblock” from my email address if you need to contact
me outside the newsgroup.

Actually, if I remember correctly, the word was that only Queued
Spinlocks were implemented that way. But I may be wrong, and I
didn’t look at the actual implementation in Ntoskrnl. In any
case, KeTryToAcquireSpinLock could turn out to be a nice
building block for someone who wants to implement his/her own
synchronization primitive. For example, I can see Alberto
potentially using that call to implement an MPI-like OS-level
generalized queuing facility!

Alberto.

----- Original Message -----
From: “Ray Trent”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”

Sent: Wednesday, March 23, 2005 7:55 PM
Subject: Re:[ntdev] KeTryToAcquireSpinLock

> The last time this topic came up, I’m pretty sure the general
> conclusion from people that looked was that KeAcquireSpinLock
> already does test-test-and-set. If so, that would tend to
> limit the usefulness of this function call to cases where you
> don’t care if you can’t get the lock.
>
> Alberto Moreira wrote:
>> I don’t know the semantics of the call, but it could be
>> something in the direction of test-test-and-set. A Test and
>> Set can generate a fair amount of traffic on the Front-Side
>> Bus, so, one could code like this:
>>
>> while (NotSignaled(lock));
>> while (failto(KeTryToAcquireSpinLock(lock))
>> {
>> while (NotSignaled(lock));
>> }
>>
>> You can see that much of the wait is done in the first while,
>> which doesn’t go anywhere beyond the cache. Once the first
>> loop detects the lock being in a Signaled state, it tries to
>> grab it, and if it fails, it goes back looping on the cache
>> copy of the lock. Only the second while loop generates
>> traffic on the Front-Side Bus, and even then, only once in a
>> blue moon.
>>
>> This is explained in Gregory Andrew’s OS book, page 100, and
>> it should make a difference in SMP performance.
>>
>> Alberto.
>>
>>
>> “Ray Trent” wrote in message
>> news:xxxxx@hormel9.ieee.org
>>
>>> The only reason I can think of is if you’re doing some
>>> non-critical
>>> function in a bottleneck region of code, and you only want
>>> to do it if
>>> you probably won’t have to incur a blocked spinlock.
>>>
>>> Errr… hard to think of real examples, but suppose you had
>>> a network
>>> activity LED on your card that the driver had to blink. You
>>> probably
>>> wouldn’t want to bother doing that on the current packet if
>>> you probably
>>> can’t grab the spinlock… assuming it’ll probably happen on
>>> the next
>>> packet anyway.
>>>
>>> Now all I have to explain is why a non-critical resource
>>> like this would
>>> really need to be protected by a spinlock, but I’ll leave
>>> that as an
>>> exercise for the reader :-).
>>>
>>> Mark Roddy wrote:
>>>
>>>> I’ve always wondered why anybody thought this routine would
>>>> be useful.
>>>>
>>>> =====================
>>>> Mark Roddy
>>>> Windows .NET/XP/2000 Consulting
>>>> Hollis Technology Solutions 603-321-1032
>>>> www.hollistech.com
>>>>
>>>>
>>>>> -----Original Message-----
>>>>> From: xxxxx@lists.osr.com
>>>>> [mailto:xxxxx@lists.osr.com] On Behalf Of
>>>>> Jamey Kirby
>>>>> Sent: Tuesday, March 22, 2005 11:40 PM
>>>>> To: Windows System Software Devs Interest List
>>>>> Subject: Re: [ntdev] KeTryToAcquireSpinLock
>>>>>
>>>>> I too have noticed that this documented kernel function is
>>>>> not exported; well, under NT 4.0 build environment it is
>>>>> not.
>>>>> My filter drivers are done under NT 4.0 DDK and IFS kit to
>>>>> maintain support for NT 4.0 users.
>>>>>
>>>>> I have not tried this kernel routine under 2K or XP.
>>>>>
>>>>> Jamey
>>>>>
>>>>> ----- Original Message -----
>>>>> From: “Matt Wu”
>>>>> Newsgroups: ntdev
>>>>> To: “Windows System Software Devs Interest List”
>>>>>
>>>>> Sent: Tuesday, March 22, 2005 8:23 PM
>>>>> Subject: [ntdev] KeTryToAcquireSpinLock
>>>>>
>>>>>
>>>>>
>>>>>> I noticed that nt kenrel has such a routine:
>>>>>> KeTryToOAcquireSpinLock.
>>>>>> Are there any ways to use it ?
>>>>>>
>>>>>> PS: Anybody knows how to identify it’s a MP built or UP
>>>>>
>>>>>
>>>>> build system ? Nt
>>>>>
>>>>>> kernel does not seem to provide the corresponding
>>>>>> functions.
>>>>>>
>>>>>>
>>>>>> Best wishes,
>>>>>>
>>>>>> Matt
>>>>>>
>>
>>
>
> –
> …/ray..
>
> Please remove “.spamblock” from my email address if you need
> to contact me outside the newsgroup.
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@ieee.org
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com

Sorry, Alberto it was for all of them since at least 3.5.1 and in those
sources it looked like it was from NT/OS2 days. We have been here before
you aren’t listening. Please choose a new OS as you threaten to earlier
this evening.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply

“Alberto Moreira” wrote in message news:xxxxx@ntdev…
> Actually, if I remember correctly, the word was that only Queued Spinlocks
> were implemented that way. But I may be wrong, and I didn’t look at the
> actual implementation in Ntoskrnl. In any case, KeTryToAcquireSpinLock
> could turn out to be a nice building block for someone who wants to
> implement his/her own synchronization primitive. For example, I can see
> Alberto potentially using that call to implement an MPI-like OS-level
> generalized queuing facility!
>
> Alberto.
>
>
> ----- Original Message -----
> From: “Ray Trent”
> Newsgroups: ntdev
> To: “Windows System Software Devs Interest List”
> Sent: Wednesday, March 23, 2005 7:55 PM
> Subject: Re:[ntdev] KeTryToAcquireSpinLock
>
>
>> The last time this topic came up, I’m pretty sure the general conclusion
>> from people that looked was that KeAcquireSpinLock already does
>> test-test-and-set. If so, that would tend to limit the usefulness of this
>> function call to cases where you don’t care if you can’t get the lock.
>>
>> Alberto Moreira wrote:
>>> I don’t know the semantics of the call, but it could be something in the
>>> direction of test-test-and-set. A Test and Set can generate a fair
>>> amount of traffic on the Front-Side Bus, so, one could code like this:
>>>
>>> while (NotSignaled(lock));
>>> while (failto(KeTryToAcquireSpinLock(lock))
>>> {
>>> while (NotSignaled(lock));
>>> }
>>>
>>> You can see that much of the wait is done in the first while, which
>>> doesn’t go anywhere beyond the cache. Once the first loop detects the
>>> lock being in a Signaled state, it tries to grab it, and if it fails, it
>>> goes back looping on the cache copy of the lock. Only the second while
>>> loop generates traffic on the Front-Side Bus, and even then, only once
>>> in a blue moon.
>>>
>>> This is explained in Gregory Andrew’s OS book, page 100, and it should
>>> make a difference in SMP performance.
>>>
>>> Alberto.
>>>
>>>
>>> “Ray Trent” wrote in message
>>> news:xxxxx@hormel9.ieee.org
>>>
>>>> The only reason I can think of is if you’re doing some non-critical
>>>> function in a bottleneck region of code, and you only want to do it if
>>>> you probably won’t have to incur a blocked spinlock.
>>>>
>>>> Errr… hard to think of real examples, but suppose you had a network
>>>> activity LED on your card that the driver had to blink. You probably
>>>> wouldn’t want to bother doing that on the current packet if you
>>>> probably
>>>> can’t grab the spinlock… assuming it’ll probably happen on the next
>>>> packet anyway.
>>>>
>>>> Now all I have to explain is why a non-critical resource like this
>>>> would
>>>> really need to be protected by a spinlock, but I’ll leave that as an
>>>> exercise for the reader :-).
>>>>
>>>> Mark Roddy wrote:
>>>>
>>>>> I’ve always wondered why anybody thought this routine would be useful.
>>>>>
>>>>> =====================
>>>>> Mark Roddy
>>>>> Windows .NET/XP/2000 Consulting
>>>>> Hollis Technology Solutions 603-321-1032
>>>>> www.hollistech.com
>>>>>
>>>>>
>>>>>> -----Original Message-----
>>>>>> From: xxxxx@lists.osr.com
>>>>>> [mailto:xxxxx@lists.osr.com] On Behalf Of Jamey Kirby
>>>>>> Sent: Tuesday, March 22, 2005 11:40 PM
>>>>>> To: Windows System Software Devs Interest List
>>>>>> Subject: Re: [ntdev] KeTryToAcquireSpinLock
>>>>>>
>>>>>> I too have noticed that this documented kernel function is
>>>>>> not exported; well, under NT 4.0 build environment it is not.
>>>>>> My filter drivers are done under NT 4.0 DDK and IFS kit to
>>>>>> maintain support for NT 4.0 users.
>>>>>>
>>>>>> I have not tried this kernel routine under 2K or XP.
>>>>>>
>>>>>> Jamey
>>>>>>
>>>>>> ----- Original Message -----
>>>>>> From: “Matt Wu”
>>>>>> Newsgroups: ntdev
>>>>>> To: “Windows System Software Devs Interest List”
>>>>>>
>>>>>> Sent: Tuesday, March 22, 2005 8:23 PM
>>>>>> Subject: [ntdev] KeTryToAcquireSpinLock
>>>>>>
>>>>>>
>>>>>>
>>>>>>> I noticed that nt kenrel has such a routine:
>>>>>>> KeTryToOAcquireSpinLock.
>>>>>>> Are there any ways to use it ?
>>>>>>>
>>>>>>> PS: Anybody knows how to identify it’s a MP built or UP
>>>>>>
>>>>>>
>>>>>> build system ? Nt
>>>>>>
>>>>>>> kernel does not seem to provide the corresponding functions.
>>>>>>>
>>>>>>>
>>>>>>> Best wishes,
>>>>>>>
>>>>>>> Matt
>>>>>>>
>>>
>>>
>>
>> –
>> …/ray..
>>
>> Please remove “.spamblock” from my email address if you need to contact
>> me outside the newsgroup.
>>
>> —
>> Questions? First check the Kernel Driver FAQ at
>> http://www.osronline.com/article.cfm?id=256
>>
>> You are currently subscribed to ntdev as: xxxxx@ieee.org
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>

> The last time this topic came up, I’m pretty sure the general conclusion

from people that looked was that KeAcquireSpinLock *already* does
test-test-and-set. If so, that would tend to limit the usefulness of

Exactly.

With ERESOURCE, TryToAcquire is valuable, so you can queue a work item to
process the IRP and return STATUS_PENDING.

But with a spinlock?

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

> Actually, if I remember correctly, the word was that only Queued

Spinlocks were implemented that way.

No, usual spinlocks too.

Queued spinlocks are better since a) each CPU busy-loops on its local variable
b) fairness is guaranteed - the first stalled waiter is guaranteed to be the
first to be awakened c) lesser number of atomic operations on acquire/release.

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

You know, I could dig the actual interchange but I’m too lazy
and it doesn’t matter anyway. The point still is, that specific
function could be a nice building block to achieve further
functionality that’s not present in the current OS. And don’t
come with this worn out and tattered excuse that “this or that
function already does something like that hence I don’t need
it” - I don’t buy that kind of nonsense, find a better excuse.

Alberto.

----- Original Message -----
From: “Don Burn”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”

Sent: Wednesday, March 23, 2005 8:42 PM
Subject: Re:[ntdev] Re:KeTryToAcquireSpinLock

> Sorry, Alberto it was for all of them since at least 3.5.1 and
> in those sources it looked like it was from NT/OS2 days. We
> have been here before you aren’t listening. Please choose a
> new OS as you threaten to earlier this evening.
>
>
> –
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> Remove StopSpam from the email to reply
>
>
> “Alberto Moreira” wrote in message
> news:xxxxx@ntdev…
>> Actually, if I remember correctly, the word was that only
>> Queued Spinlocks were implemented that way. But I may be
>> wrong, and I didn’t look at the actual implementation in
>> Ntoskrnl. In any case, KeTryToAcquireSpinLock could turn out
>> to be a nice building block for someone who wants to
>> implement his/her own synchronization primitive. For example,
>> I can see Alberto potentially using that call to implement an
>> MPI-like OS-level generalized queuing facility!
>>
>> Alberto.
>>
>>
>> ----- Original Message -----
>> From: “Ray Trent”
>> Newsgroups: ntdev
>> To: “Windows System Software Devs Interest List”
>>
>> Sent: Wednesday, March 23, 2005 7:55 PM
>> Subject: Re:[ntdev] KeTryToAcquireSpinLock
>>
>>
>>> The last time this topic came up, I’m pretty sure the
>>> general conclusion from people that looked was that
>>> KeAcquireSpinLock already does test-test-and-set. If so,
>>> that would tend to limit the usefulness of this function
>>> call to cases where you don’t care if you can’t get the
>>> lock.
>>>
>>> Alberto Moreira wrote:
>>>> I don’t know the semantics of the call, but it could be
>>>> something in the direction of test-test-and-set. A Test and
>>>> Set can generate a fair amount of traffic on the Front-Side
>>>> Bus, so, one could code like this:
>>>>
>>>> while (NotSignaled(lock));
>>>> while (failto(KeTryToAcquireSpinLock(lock))
>>>> {
>>>> while (NotSignaled(lock));
>>>> }
>>>>
>>>> You can see that much of the wait is done in the first
>>>> while, which doesn’t go anywhere beyond the cache. Once the
>>>> first loop detects the lock being in a Signaled state, it
>>>> tries to grab it, and if it fails, it goes back looping on
>>>> the cache copy of the lock. Only the second while loop
>>>> generates traffic on the Front-Side Bus, and even then,
>>>> only once in a blue moon.
>>>>
>>>> This is explained in Gregory Andrew’s OS book, page 100,
>>>> and it should make a difference in SMP performance.
>>>>
>>>> Alberto.
>>>>
>>>>
>>>> “Ray Trent” wrote in message
>>>> news:xxxxx@hormel9.ieee.org
>>>>
>>>>> The only reason I can think of is if you’re doing some
>>>>> non-critical
>>>>> function in a bottleneck region of code, and you only want
>>>>> to do it if
>>>>> you probably won’t have to incur a blocked spinlock.
>>>>>
>>>>> Errr… hard to think of real examples, but suppose you
>>>>> had a network
>>>>> activity LED on your card that the driver had to blink.
>>>>> You probably
>>>>> wouldn’t want to bother doing that on the current packet
>>>>> if you probably
>>>>> can’t grab the spinlock… assuming it’ll probably happen
>>>>> on the next
>>>>> packet anyway.
>>>>>
>>>>> Now all I have to explain is why a non-critical resource
>>>>> like this would
>>>>> really need to be protected by a spinlock, but I’ll leave
>>>>> that as an
>>>>> exercise for the reader :-).
>>>>>
>>>>> Mark Roddy wrote:
>>>>>
>>>>>> I’ve always wondered why anybody thought this routine
>>>>>> would be useful.
>>>>>>
>>>>>> =====================
>>>>>> Mark Roddy
>>>>>> Windows .NET/XP/2000 Consulting
>>>>>> Hollis Technology Solutions 603-321-1032
>>>>>> www.hollistech.com
>>>>>>
>>>>>>
>>>>>>> -----Original Message-----
>>>>>>> From: xxxxx@lists.osr.com
>>>>>>> [mailto:xxxxx@lists.osr.com] On Behalf Of
>>>>>>> Jamey Kirby
>>>>>>> Sent: Tuesday, March 22, 2005 11:40 PM
>>>>>>> To: Windows System Software Devs Interest List
>>>>>>> Subject: Re: [ntdev] KeTryToAcquireSpinLock
>>>>>>>
>>>>>>> I too have noticed that this documented kernel function
>>>>>>> is
>>>>>>> not exported; well, under NT 4.0 build environment it is
>>>>>>> not.
>>>>>>> My filter drivers are done under NT 4.0 DDK and IFS kit
>>>>>>> to
>>>>>>> maintain support for NT 4.0 users.
>>>>>>>
>>>>>>> I have not tried this kernel routine under 2K or XP.
>>>>>>>
>>>>>>> Jamey
>>>>>>>
>>>>>>> ----- Original Message -----
>>>>>>> From: “Matt Wu”
>>>>>>> Newsgroups: ntdev
>>>>>>> To: “Windows System Software Devs Interest List”
>>>>>>>
>>>>>>> Sent: Tuesday, March 22, 2005 8:23 PM
>>>>>>> Subject: [ntdev] KeTryToAcquireSpinLock
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>> I noticed that nt kenrel has such a routine:
>>>>>>>> KeTryToOAcquireSpinLock.
>>>>>>>> Are there any ways to use it ?
>>>>>>>>
>>>>>>>> PS: Anybody knows how to identify it’s a MP built or
>>>>>>>> UP
>>>>>>>
>>>>>>>
>>>>>>> build system ? Nt
>>>>>>>
>>>>>>>> kernel does not seem to provide the corresponding
>>>>>>>> functions.
>>>>>>>>
>>>>>>>>
>>>>>>>> Best wishes,
>>>>>>>>
>>>>>>>> Matt
>>>>>>>>
>>>>
>>>>
>>>
>>> –
>>> …/ray..
>>>
>>> Please remove “.spamblock” from my email address if you need
>>> to contact me outside the newsgroup.
>>>
>>> —
>>> Questions? First check the Kernel Driver FAQ at
>>> http://www.osronline.com/article.cfm?id=256
>>>
>>> You are currently subscribed to ntdev as: xxxxx@ieee.org
>>> To unsubscribe send a blank email to
>>> xxxxx@lists.osr.com
>>
>>
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@ieee.org
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com