Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


KeTryToAcquireSpinLock

Matt_WuMatt_Wu Member Posts: 72
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

Comments

  • Matt_WuMatt_Wu Member Posts: 72
    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
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    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" <[email protected]>
    Newsgroups: ntdev
    To: "Windows System Software Devs Interest List" <[email protected]>
    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: [email protected]
    > To unsubscribe send a blank email to [email protected]
    >
    > __________ NOD32 1.1030 (20050319) Information __________
    >
    > This message was checked by NOD32 antivirus system.
    > http://www.nod32.com
    >
    >
  • Mark_RoddyMark_Roddy Member - All Emails Posts: 4,374
    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: [email protected]
    > [mailto:[email protected]] 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" <[email protected]>
    > Newsgroups: ntdev
    > To: "Windows System Software Devs Interest List" <[email protected]>
    > 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: [email protected]
    > > To unsubscribe send a blank email to [email protected]
    > >
    > > __________ 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: [email protected]
    > To unsubscribe send a blank email to [email protected]
    >
  • Matt_WuMatt_Wu Member Posts: 72
    I just got that this way was only for traced spinlock :-(
    So it's no use at all to identify MP or UP system.

    "Matt" wrote:[email protected]
    > 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.
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    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: [email protected]
    > [mailto:[email protected]] 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: [email protected]
    > > [mailto:[email protected]] 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" <[email protected]>
    > > Newsgroups: ntdev
    > > To: "Windows System Software Devs Interest List"
    > <[email protected]>
    > > 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: [email protected] To
    > unsubscribe
    > > > send a blank email to [email protected]
    > > >
    > > > __________ 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: [email protected] To
    > > unsubscribe send a blank email to [email protected]
    > >
    >
    >
    >
    >
    > ---
    > Questions? First check the Kernel Driver FAQ at
    > http://www.osronline.com/article.cfm?id=256
    >
    > You are currently subscribed to ntdev as:
    > [email protected] To unsubscribe send a blank
    > email to [email protected]
    >
  • Ray_TrentRay_Trent Member Posts: 398
    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: [email protected]
    >>[mailto:[email protected]] 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" <[email protected]>
    >>Newsgroups: ntdev
    >>To: "Windows System Software Devs Interest List" <[email protected]>
    >>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: [email protected]
    >>>To unsubscribe send a blank email to [email protected]
    >>>
    >>>__________ 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: [email protected]
    >>To unsubscribe send a blank email to [email protected]
    >>
    >
    >
    >
    >
    >

    --
    ../ray\..

    Please remove ".spamblock" from my email address if you need to contact
    me outside the newsgroup.
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    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" <[email protected]> wrote in message
    news:[email protected]
    > 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: [email protected]
    >>>[mailto:[email protected]] 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" <[email protected]>
    >>>Newsgroups: ntdev
    >>>To: "Windows System Software Devs Interest List"
    >>><[email protected]>
    >>>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_TrentRay_Trent Member Posts: 398
    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" <[email protected]> wrote in message
    > news:[email protected]
    >
    >> 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: [email protected]
    >>>> [mailto:[email protected]] 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" <[email protected]>
    >>>> Newsgroups: ntdev
    >>>> To: "Windows System Software Devs Interest List" <[email protected]>
    >>>> 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.
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    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" <[email protected]>
    Newsgroups: ntdev
    To: "Windows System Software Devs Interest List"
    <[email protected]>
    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" <[email protected]> wrote in message
    >> news:[email protected]
    >>
    >>> 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: [email protected]
    >>>>> [mailto:[email protected]] 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" <[email protected]>
    >>>>> Newsgroups: ntdev
    >>>>> To: "Windows System Software Devs Interest List"
    >>>>> <[email protected]>
    >>>>> 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: [email protected]
    > To unsubscribe send a blank email to
    > [email protected]
  • Don_Burn_1Don_Burn_1 Member Posts: 4,311
    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:[email protected]
    > 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:[email protected]
    >>>
    >>>> 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: [email protected]
    >>>>>> [mailto:[email protected]] 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: [email protected]
    >> To unsubscribe send a blank email to [email protected]
    >
    >
  • Maxim_S._ShatskihMaxim_S._Shatskih Member Posts: 10,396
    > 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
    [email protected]
    http://www.storagecraft.com
  • Maxim_S._ShatskihMaxim_S._Shatskih Member Posts: 10,396
    > 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
    [email protected]
    http://www.storagecraft.com
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    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" <[email protected]>
    Newsgroups: ntdev
    To: "Windows System Software Devs Interest List"
    <[email protected]>
    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" <[email protected]> wrote in message
    > news:[email protected]
    >> 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" <[email protected]>
    >> Newsgroups: ntdev
    >> To: "Windows System Software Devs Interest List"
    >> <[email protected]>
    >> 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" <[email protected]> wrote in message
    >>>> news:[email protected]
    >>>>
    >>>>> 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: [email protected]
    >>>>>>> [mailto:[email protected]] 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" <[email protected]>
    >>>>>>> Newsgroups: ntdev
    >>>>>>> To: "Windows System Software Devs Interest List"
    >>>>>>> <[email protected]>
    >>>>>>> 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: [email protected]
    >>> To unsubscribe send a blank email to
    >>> [email protected]
    >>
    >>
    >
    >
    >
    > ---
    > Questions? First check the Kernel Driver FAQ at
    > http://www.osronline.com/article.cfm?id=256
    >
    > You are currently subscribed to ntdev as: [email protected]
    > To unsubscribe send a blank email to
    > [email protected]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Writing WDF Drivers 7 Dec 2020 LIVE ONLINE
Internals & Software Drivers 25 Jan 2021 LIVE ONLINE
Developing Minifilters 8 March 2021 LIVE ONLINE