spinlocks

Will a spinlock for a uni-processor really do busy waiting? I was told
there’s a new spin lock function for XP and beyond. Can anyone comment on
that?

Thanks

Ta H.


Check out the coupons and bargains on MSN Offers!
http://shopping.msn.com/softcontent/softcontent.aspx?scmId=1418

Spin locks with the uniprocessor kernel never did a busy wait, they just
raised IRQL to DISPATCH_LEVEL which prohibited scheduling another thread.
There are new spinlock functions for XP, they provide a queued spin lock
which is more efficient for multiprocessors by reducing the bus contention.

Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

----- Original Message -----
From: “Ta H.”
To: “Windows System Software Devs Interest List”
Sent: Thursday, January 22, 2004 5:35 PM
Subject: [ntdev] spinlocks

> Will a spinlock for a uni-processor really do busy waiting? I was told
> there’s a new spin lock function for XP and beyond. Can anyone comment on
> that?
>
> Thanks
>
> Ta H.
>
> _________________________________________________________________
> Check out the coupons and bargains on MSN Offers!
> http://shopping.msn.com/softcontent/softcontent.aspx?scmId=1418
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@acm.org
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

Thanks.

Does it also apply to ISR spin locks? (No busy waiting…)

Ta H.

From: “Don Burn”
>Reply-To: “Windows System Software Devs Interest List”
>
>To: “Windows System Software Devs Interest List”
>Subject: Re: [ntdev] spinlocks
>Date: Thu, 22 Jan 2004 17:47:14 -0500
>
>Spin locks with the uniprocessor kernel never did a busy wait, they just
>raised IRQL to DISPATCH_LEVEL which prohibited scheduling another thread.
>There are new spinlock functions for XP, they provide a queued spin lock
>which is more efficient for multiprocessors by reducing the bus contention.
>
>Don Burn (MVP, Windows DDK)
>Windows 2k/XP/2k3 Filesystem and Driver Consulting
>
>----- Original Message -----
>From: “Ta H.”
>To: “Windows System Software Devs Interest List”
>Sent: Thursday, January 22, 2004 5:35 PM
>Subject: [ntdev] spinlocks
>
>
> > Will a spinlock for a uni-processor really do busy waiting? I was told
> > there’s a new spin lock function for XP and beyond. Can anyone comment
>on
> > that?
> >
> > Thanks
> >
> > Ta H.
> >
> >
> > Check out the coupons and bargains on MSN Offers!
> > http://shopping.msn.com/softcontent/softcontent.aspx?scmId=1418
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@acm.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@hotmail.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com


Let the new MSN Premium Internet Software make the most of your high-speed
experience. http://join.msn.com/?pgmarket=en-us&page=byoa/prem&ST=1

If it didn’t, then you’d end up waiting forever to acquire the lock, since
there is no other processor to release it in a 1-processor machine.


Jake Oshins
Windows Base Kernel Team

This posting is provided “AS IS” with no warranties, and confers no rights.

“Ta H.” wrote in message news:xxxxx@ntdev…
> Thanks.
>
> Does it also apply to ISR spin locks? (No busy waiting…)
>
> Ta H.
>
>
> >From: “Don Burn”
> >Reply-To: “Windows System Software Devs Interest List”
> >
> >To: “Windows System Software Devs Interest List”
> >Subject: Re: [ntdev] spinlocks
> >Date: Thu, 22 Jan 2004 17:47:14 -0500
> >
> >Spin locks with the uniprocessor kernel never did a busy wait, they just
> >raised IRQL to DISPATCH_LEVEL which prohibited scheduling another thread.
> >There are new spinlock functions for XP, they provide a queued spin lock
> >which is more efficient for multiprocessors by reducing the bus
contention.
> >
> >Don Burn (MVP, Windows DDK)
> >Windows 2k/XP/2k3 Filesystem and Driver Consulting
> >
> >----- Original Message -----
> >From: “Ta H.”
> >To: “Windows System Software Devs Interest List”
> >Sent: Thursday, January 22, 2004 5:35 PM
> >Subject: [ntdev] spinlocks
> >
> >
> > > Will a spinlock for a uni-processor really do busy waiting? I was
told
> > > there’s a new spin lock function for XP and beyond. Can anyone
comment
> >on
> > > that?
> > >
> > > Thanks
> > >
> > > Ta H.
> > >
> > >
> > > Check out the coupons and bargains on MSN Offers!
> > > http://shopping.msn.com/softcontent/softcontent.aspx?scmId=1418
> > >
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> >http://www.osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as: xxxxx@acm.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@hotmail.com
> >To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>

> Let the new MSN Premium Internet Software make the most of your high-speed
> experience. http://join.msn.com/?pgmarket=en-us&page=byoa/prem&ST=1
>
>

> Thanks.

Does it also apply to ISR spin locks? (No busy waiting…)

Yes, but you’d also busy wait in the spin-lock IF it’s on a MP system
(including HT).

Busy-waiting in ISR’s is a BAD thing, even if there’s another processor that
could take the next interrupt. First of all, you don’t know if the
architecture of the system allows this.

So, if you’re calling spin-locks in the ISR, you’re presumably trying to
cope with MP systems, and the questions are just to cover you in the UP
case?

Well, that would be BAD design… Try to find a different way of dealing
with the problem, like start off a DPC or something that can block and let
the rest of the system run…


Mats

Ta H.

>From: “Don Burn”
> >Reply-To: “Windows System Software Devs Interest List”
> >
> >To: “Windows System Software Devs Interest List”
>
> >Subject: Re: [ntdev] spinlocks
> >Date: Thu, 22 Jan 2004 17:47:14 -0500
> >
> >Spin locks with the uniprocessor kernel never did a busy
> wait, they just
> >raised IRQL to DISPATCH_LEVEL which prohibited scheduling
> another thread.
> >There are new spinlock functions for XP, they provide a
> queued spin lock
> >which is more efficient for multiprocessors by reducing the
> bus contention.
> >
> >Don Burn (MVP, Windows DDK)
> >Windows 2k/XP/2k3 Filesystem and Driver Consulting
> >
> >----- Original Message -----
> >From: “Ta H.”
> >To: “Windows System Software Devs Interest List”
>
> >Sent: Thursday, January 22, 2004 5:35 PM
> >Subject: [ntdev] spinlocks
> >
> >
> > > Will a spinlock for a uni-processor really do busy
> waiting? I was told
> > > there’s a new spin lock function for XP and beyond. Can
> anyone comment
> >on
> > > that?
> > >
> > > Thanks
> > >
> > > Ta H.
> > >
> > >
> > > Check out the coupons and bargains on MSN Offers!
> > > http://shopping.msn.com/softcontent/softcontent.aspx?scmId=1418
> > >
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> >http://www.osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as: xxxxx@acm.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@hotmail.com
> >To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>

> Let the new MSN Premium Internet Software make the most of
> your high-speed
> experience. http://join.msn.com/?pgmarket=en-us&page=byoa/prem&ST=1
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@3dlabs.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

FYI, Microsoft just released some white papers concerning
synchronization.

. Read the "Locks, Deadlocks, and Synchronization" white paper at:
http://www.microsoft.com/whdc/hwdev/driver/LOCKS.mspx
. Read the companion white paper, "Scheduling, Thread Context, and IRQL" at:
http://www.microsoft.com/whdc/hwdev/driver/IRQL.mspx
. Take into account multiprocessor issues when you design and test drivers.
. Design drivers to minimize the need for locks.
. Follow the best practices for driver synchronization described in the white
papers.

Norbert.

"A Puritan is someone who is deathly afraid that someone somewhere is
having fun."
---- snip ----

No, spinlocks on uniprocessor are macro-expanded to KeRaiseIrql.

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

----- Original Message -----
From: “Ta H.”
To: “Windows System Software Devs Interest List”
Sent: Friday, January 23, 2004 1:35 AM
Subject: [ntdev] spinlocks

> Will a spinlock for a uni-processor really do busy waiting? I was told
> there’s a new spin lock function for XP and beyond. Can anyone comment on
> that?
>
> Thanks
>
> Ta H.
>
> _________________________________________________________________
> Check out the coupons and bargains on MSN Offers!
> http://shopping.msn.com/softcontent/softcontent.aspx?scmId=1418
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

Yes. They just KeRaiseIrql to the ISR’s level and not to DISPATCH, and such
a KeRaiseIrql will do the necessary things with the APIC’s interrupt mask.

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

----- Original Message -----
From: “Ta H.”
To: “Windows System Software Devs Interest List”
Sent: Friday, January 23, 2004 2:37 AM
Subject: Re: [ntdev] spinlocks

> Thanks.
>
> Does it also apply to ISR spin locks? (No busy waiting…)
>
> Ta H.
>
>
> >From: “Don Burn”
> >Reply-To: “Windows System Software Devs Interest List”
> >
> >To: “Windows System Software Devs Interest List”
> >Subject: Re: [ntdev] spinlocks
> >Date: Thu, 22 Jan 2004 17:47:14 -0500
> >
> >Spin locks with the uniprocessor kernel never did a busy wait, they just
> >raised IRQL to DISPATCH_LEVEL which prohibited scheduling another thread.
> >There are new spinlock functions for XP, they provide a queued spin lock
> >which is more efficient for multiprocessors by reducing the bus contention.
> >
> >Don Burn (MVP, Windows DDK)
> >Windows 2k/XP/2k3 Filesystem and Driver Consulting
> >
> >----- Original Message -----
> >From: “Ta H.”
> >To: “Windows System Software Devs Interest List”
> >Sent: Thursday, January 22, 2004 5:35 PM
> >Subject: [ntdev] spinlocks
> >
> >
> > > Will a spinlock for a uni-processor really do busy waiting? I was told
> > > there’s a new spin lock function for XP and beyond. Can anyone comment
> >on
> > > that?
> > >
> > > Thanks
> > >
> > > Ta H.
> > >
> > >
> > > Check out the coupons and bargains on MSN Offers!
> > > http://shopping.msn.com/softcontent/softcontent.aspx?scmId=1418
> > >
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> >http://www.osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as: xxxxx@acm.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@hotmail.com
> >To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>

> Let the new MSN Premium Internet Software make the most of your high-speed
> experience. http://join.msn.com/?pgmarket=en-us&page=byoa/prem&ST=1
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

It’s a bit of a misnomer, no ? They should rather be called “mutexes” in
single processors, just like that MS white paper does. A spinlock should
resolve to a noop in a single processor, and it should spin with interrupts
disabled on a multiprocessor, so that it’s orthogonal to IRQLs.

Alberto.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Maxim S. Shatskih
Sent: Friday, January 23, 2004 1:23 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] spinlocks

No, spinlocks on uniprocessor are macro-expanded to KeRaiseIrql.

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

----- Original Message -----
From: “Ta H.”
To: “Windows System Software Devs Interest List”
Sent: Friday, January 23, 2004 1:35 AM
Subject: [ntdev] spinlocks

> Will a spinlock for a uni-processor really do busy waiting? I was told
> there’s a new spin lock function for XP and beyond. Can anyone comment on
> that?
>
> Thanks
>
> Ta H.
>
> _________________________________________________________________
> Check out the coupons and bargains on MSN Offers!
> http://shopping.msn.com/softcontent/softcontent.aspx?scmId=1418
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.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@compuware.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it.

> single processors, just like that MS white paper does. A spinlock should

resolve to a noop in a single processor

It should disable thread preemption at least.

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

I strongly recommend these papers, by the way. I think that they’re one of
the better discussions of the topic that I’ve seen. (The previous best was
OSR’s paper on locking, which was also very good.)


Jake Oshins
Windows Base Kernel Team

This posting is provided “AS IS” with no warranties, and confers no rights.

“Norbert Kawulski” wrote in message news:xxxxx@ntdev…
> FYI, Microsoft just released some white papers concerning
> synchronization.
>
>
> . Read the “Locks, Deadlocks, and Synchronization” white paper at:
> http://www.microsoft.com/whdc/hwdev/driver/LOCKS.mspx
> . Read the companion white paper, “Scheduling, Thread Context, and
IRQL” at:
> http://www.microsoft.com/whdc/hwdev/driver/IRQL.mspx
> . Take into account multiprocessor issues when you design and test
drivers.
> . Design drivers to minimize the need for locks.
> . Follow the best practices for driver synchronization described in
the white
> papers.
>
> Norbert.
> --------
> “A Puritan is someone who is deathly afraid that someone somewhere is
> having fun.”
> ---- snip ----
>
>
>

Jake Oshins wrote:

I strongly recommend these papers, by the way. I think that they’re one of
the better discussions of the topic that I’ve seen. (The previous best was
OSR’s paper on locking, which was also very good.)

> http://www.microsoft.com/whdc/hwdev/driver/IRQL.mspx
>> http://www.microsoft.com/whdc/hwdev/driver/LOCKS.mspx

I also *highly* recommend these papers. They contain the clearest,
fundamental description of these topics that I’ve seen.

(and no, I didn’t write either of them :slight_smile:

P