Hello,

I write experimental drivers, and have never worked on SMP systems yet.
I need to upgrade to an IBM T60 but I am worried about the dual-core
Intel processor engine. I have the following questions:

- It seems the dual-core provides 2 pipelines and 2 caches to 2 cores
on a single die. This sounds like a SMP system. Will my drivers have to
worry about SMP stuff?

- Can I configured Windows XP SP2/BIOS to completely disable/ignore one
of the cores when I write my drivers? Will there be a major performance
impact if I did this? I read that Windows installs a different HAL when
it sees an SMP... so it sounds like I cant do this at boot time each
time.. it has to be a one-time decision during installation?

Basically, I want to know if I can write non-SMP aware drivers in
someway on a IBM T60 that has a core2duo processor engine.

Thanks!

Re: WinXPSP2, Intel Core2Duo, Kernel drivers by Don

Don
Wed Sep 06 20:27:34 CDT 2006

Yes uyou drivers will have to be SMP aware for a dual core, or a hyper
threaded, or a SMP system. Of course, your driver should be SMP aware
anyway since you need to deal with most of the synchronization issues even
ou a uni-processor they just are less likely (but not impossible) to happen.

No, you can do this at boot time, use the /KERNEL=ntkrnlup.exe
/HAL=halup.DLL /numproc=1 to indicate you want to treat the computer as a
uni-processor. You will find on the XPSP2 CD ntoskrnl.exe which is the
uni-processor version, rename it to something like ntkrnlup.exe, likewise
the hal.dll on the XPSP2 CD rename to halup.DLL put them both in the
system32 directory and you have a uni-processor system by choosing that
boot.ini line.



--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply

<on3lonestar@gmail.com> wrote in message
news:1157590558.092218.40890@i42g2000cwa.googlegroups.com...
> Hello,
>
> I write experimental drivers, and have never worked on SMP systems yet.
> I need to upgrade to an IBM T60 but I am worried about the dual-core
> Intel processor engine. I have the following questions:
>
> - It seems the dual-core provides 2 pipelines and 2 caches to 2 cores
> on a single die. This sounds like a SMP system. Will my drivers have to
> worry about SMP stuff?
>
> - Can I configured Windows XP SP2/BIOS to completely disable/ignore one
> of the cores when I write my drivers? Will there be a major performance
> impact if I did this? I read that Windows installs a different HAL when
> it sees an SMP... so it sounds like I cant do this at boot time each
> time.. it has to be a one-time decision during installation?
>
> Basically, I want to know if I can write non-SMP aware drivers in
> someway on a IBM T60 that has a core2duo processor engine.
>
> Thanks!
>



Re: WinXPSP2, Intel Core2Duo, Kernel drivers by soviet_bloke

soviet_bloke
Wed Sep 06 22:33:58 CDT 2006

Hi Don

> No, you can do this at boot time, use the /KERNEL=ntkrnlup.exe
> /HAL=halup.DLL /numproc=1 to indicate you want to treat the computer as a
> uni-processor. You will find on the XPSP2 CD ntoskrnl.exe which is the
> uni-processor version, rename it to something like ntkrnlup.exe, likewise
> the hal.dll on the XPSP2 CD rename to halup.DLL put them both in the
> system32 directory and you have a uni-processor system by choosing that
> boot.ini line.
>

In fact, it just does not make sense to write "non-SMP aware" drivers,
in the first place - once the driver works fine on SMP machine, it
automatically implies it will work fine on UP one as well. It is
understandable that the reverse is not true....

Anton Bassov

Don Burn wrote:
> Yes uyou drivers will have to be SMP aware for a dual core, or a hyper
> threaded, or a SMP system. Of course, your driver should be SMP aware
> anyway since you need to deal with most of the synchronization issues even
> ou a uni-processor they just are less likely (but not impossible) to happen.
>
> No, you can do this at boot time, use the /KERNEL=ntkrnlup.exe
> /HAL=halup.DLL /numproc=1 to indicate you want to treat the computer as a
> uni-processor. You will find on the XPSP2 CD ntoskrnl.exe which is the
> uni-processor version, rename it to something like ntkrnlup.exe, likewise
> the hal.dll on the XPSP2 CD rename to halup.DLL put them both in the
> system32 directory and you have a uni-processor system by choosing that
> boot.ini line.
>
>
>
> --
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> http://www.windrvr.com
> Remove StopSpam from the email to reply
>
> <on3lonestar@gmail.com> wrote in message
> news:1157590558.092218.40890@i42g2000cwa.googlegroups.com...
> > Hello,
> >
> > I write experimental drivers, and have never worked on SMP systems yet.
> > I need to upgrade to an IBM T60 but I am worried about the dual-core
> > Intel processor engine. I have the following questions:
> >
> > - It seems the dual-core provides 2 pipelines and 2 caches to 2 cores
> > on a single die. This sounds like a SMP system. Will my drivers have to
> > worry about SMP stuff?
> >
> > - Can I configured Windows XP SP2/BIOS to completely disable/ignore one
> > of the cores when I write my drivers? Will there be a major performance
> > impact if I did this? I read that Windows installs a different HAL when
> > it sees an SMP... so it sounds like I cant do this at boot time each
> > time.. it has to be a one-time decision during installation?
> >
> > Basically, I want to know if I can write non-SMP aware drivers in
> > someway on a IBM T60 that has a core2duo processor engine.
> >
> > Thanks!
> >


Re: WinXPSP2, Intel Core2Duo, Kernel drivers by Calvin

Calvin
Wed Sep 06 23:23:30 CDT 2006

<soviet_bloke@hotmail.com> wrote in message
news:1157600038.483526.248840@p79g2000cwp.googlegroups.com...
> In fact, it just does not make sense to write "non-SMP aware" drivers,
> in the first place

well said.

> once the driver works fine on SMP machine, it
> automatically implies it will work fine on UP one as well.

Believe it or not, this is not true.

--
Calvin Guan (DDK MVP)
Sr. Staff Engineer
NetXtreme Vista/Longhorn Server Miniport
Broadcom Corporation
Connecting Everything(r)



Re: WinXPSP2, Intel Core2Duo, Kernel drivers by Tim

Tim
Wed Sep 06 23:27:14 CDT 2006

on3lonestar@gmail.com wrote:
>
>I write experimental drivers, and have never worked on SMP systems yet.
>I need to upgrade to an IBM T60 but I am worried about the dual-core
>Intel processor engine. I have the following questions:
>
>- It seems the dual-core provides 2 pipelines and 2 caches to 2 cores
>on a single die. This sounds like a SMP system. Will my drivers have to
>worry about SMP stuff?

Your drivers should ALWAYS ALWAYS ALWAYS worry about SMP stuff. An
SMP-unaware driver is a disaster just waiting to happen. It's also good
practice; many SMP-triggering conditions can also be triggered in a
uniprocessor, system because of multithreading.
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Re: WinXPSP2, Intel Core2Duo, Kernel drivers by soviet_bloke

soviet_bloke
Thu Sep 07 00:02:19 CDT 2006

Hi Calvin

> > once the driver works fine on SMP machine, it
> > automatically implies it will work fine on UP one as well.
>
> Believe it or not, this is not true.

My statement is based upon the "bold" assumption that the driver in
question relies only upon the "supported" stuff. Certainly, if it, say,
uses SYNCH_LEVEL directly (i.e. does something that drivers are not
supposed to do), then it may work fine on MP kernel and fail on UP one
- on UP kernel SYNCH_LEVEL equals DISPATCH_LEVEL, although on MP one it
equals CLOCK2_LEVEL. Similarly, if it uses KeQueryPerformanceCounter()
in order to measure the elapsed time(again, something drivers are not
supposed to do), implications may be quite different for UP and MP
kernels. However, as long as it plays by the rules, my statement
holds....



Anton Bassov

Calvin Guan wrote:
> <soviet_bloke@hotmail.com> wrote in message
> news:1157600038.483526.248840@p79g2000cwp.googlegroups.com...
> > In fact, it just does not make sense to write "non-SMP aware" drivers,
> > in the first place
>
> well said.
>
> > once the driver works fine on SMP machine, it
> > automatically implies it will work fine on UP one as well.
>
> Believe it or not, this is not true.
>
> --
> Calvin Guan (DDK MVP)
> Sr. Staff Engineer
> NetXtreme Vista/Longhorn Server Miniport
> Broadcom Corporation
> Connecting Everything(r)


Re: WinXPSP2, Intel Core2Duo, Kernel drivers by Calvin

Calvin
Thu Sep 07 00:58:58 CDT 2006

It has little to do with whether it's supported or unsupported. Human beings
are extremely creative when it comes to making bugs. I figure it's because
we are not being fully debugged.

Testing driver on UP thoroughly is a must IMO.

--
Calvin Guan (DDK MVP)
Sr. Staff Engineer
NetXtreme Vista/Longhorn Server Miniport
Broadcom Corporation
Connecting Everything(r)

<soviet_bloke@hotmail.com> wrote in message
news:1157605339.245398.35080@m79g2000cwm.googlegroups.com...
> Hi Calvin
>
>> > once the driver works fine on SMP machine, it
>> > automatically implies it will work fine on UP one as well.
>>
>> Believe it or not, this is not true.
>
> My statement is based upon the "bold" assumption that the driver in
> question relies only upon the "supported" stuff. Certainly, if it, say,
> uses SYNCH_LEVEL directly (i.e. does something that drivers are not
> supposed to do), then it may work fine on MP kernel and fail on UP one
> - on UP kernel SYNCH_LEVEL equals DISPATCH_LEVEL, although on MP one it
> equals CLOCK2_LEVEL. Similarly, if it uses KeQueryPerformanceCounter()
> in order to measure the elapsed time(again, something drivers are not
> supposed to do), implications may be quite different for UP and MP
> kernels. However, as long as it plays by the rules, my statement
> holds....
>
>
>
> Anton Bassov
>
> Calvin Guan wrote:
>> <soviet_bloke@hotmail.com> wrote in message
>> news:1157600038.483526.248840@p79g2000cwp.googlegroups.com...
>> > In fact, it just does not make sense to write "non-SMP aware" drivers,
>> > in the first place
>>
>> well said.
>>
>> > once the driver works fine on SMP machine, it
>> > automatically implies it will work fine on UP one as well.
>>
>> Believe it or not, this is not true.
>>
>> --
>> Calvin Guan (DDK MVP)
>> Sr. Staff Engineer
>> NetXtreme Vista/Longhorn Server Miniport
>> Broadcom Corporation
>> Connecting Everything(r)
>



Re: WinXPSP2, Intel Core2Duo, Kernel drivers by soviet_bloke

soviet_bloke
Thu Sep 07 06:16:59 CDT 2006

Hi Calvin

> It has little to do with whether it's supported or unsupported. Human beings
> are extremely creative when it comes to making bugs. I figure it's because
> we are not being fully debugged.

Well, you can think of my examples as of ones of the bugs if you wish -
no matter how you call them, these are the examples of doing something
you are not supposed to do, which may have undesirable effects (unless
you are 100% sure you know what you are doing)


> Testing driver on UP thoroughly is a must IMO.

Certainly, the more thorougly your driver is tested, the better it is
for you. However, it does not mean that your driver has to be "non-SMP
aware" one. In actuality, the very fact that driver is "non-SMP aware"
one somehow implies that it does something it is not supposed to...


Anton Bassov

Calvin Guan wrote:
> It has little to do with whether it's supported or unsupported. Human beings
> are extremely creative when it comes to making bugs. I figure it's because
> we are not being fully debugged.
>
> Testing driver on UP thoroughly is a must IMO.
>
> --
> Calvin Guan (DDK MVP)
> Sr. Staff Engineer
> NetXtreme Vista/Longhorn Server Miniport
> Broadcom Corporation
> Connecting Everything(r)
>
> <soviet_bloke@hotmail.com> wrote in message
> news:1157605339.245398.35080@m79g2000cwm.googlegroups.com...
> > Hi Calvin
> >
> >> > once the driver works fine on SMP machine, it
> >> > automatically implies it will work fine on UP one as well.
> >>
> >> Believe it or not, this is not true.
> >
> > My statement is based upon the "bold" assumption that the driver in
> > question relies only upon the "supported" stuff. Certainly, if it, say,
> > uses SYNCH_LEVEL directly (i.e. does something that drivers are not
> > supposed to do), then it may work fine on MP kernel and fail on UP one
> > - on UP kernel SYNCH_LEVEL equals DISPATCH_LEVEL, although on MP one it
> > equals CLOCK2_LEVEL. Similarly, if it uses KeQueryPerformanceCounter()
> > in order to measure the elapsed time(again, something drivers are not
> > supposed to do), implications may be quite different for UP and MP
> > kernels. However, as long as it plays by the rules, my statement
> > holds....
> >
> >
> >
> > Anton Bassov
> >
> > Calvin Guan wrote:
> >> <soviet_bloke@hotmail.com> wrote in message
> >> news:1157600038.483526.248840@p79g2000cwp.googlegroups.com...
> >> > In fact, it just does not make sense to write "non-SMP aware" drivers,
> >> > in the first place
> >>
> >> well said.
> >>
> >> > once the driver works fine on SMP machine, it
> >> > automatically implies it will work fine on UP one as well.
> >>
> >> Believe it or not, this is not true.
> >>
> >> --
> >> Calvin Guan (DDK MVP)
> >> Sr. Staff Engineer
> >> NetXtreme Vista/Longhorn Server Miniport
> >> Broadcom Corporation
> >> Connecting Everything(r)
> >


Re: WinXPSP2, Intel Core2Duo, Kernel drivers by Don

Don
Thu Sep 07 07:16:51 CDT 2006


<soviet_bloke@hotmail.com> wrote in message
> Well, you can think of my examples as of ones of the bugs if you wish -
> no matter how you call them, these are the examples of doing something
> you are not supposed to do, which may have undesirable effects (unless
> you are 100% sure you know what you are doing)
>
Yes they are doing something you are not supposed to do, that is a pretty
good definition of a bug. For instance, if you forget that a routine uses
spinlocks and then accidently call it from your ISR, it may very well work
on an SMP system because the spinlock is an actual test and set, but it has
terrible consequences on a UP system where it becomes a NOP since the IRQL
is above DISPATCH_LEVEL.



--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply




Re: WinXPSP2, Intel Core2Duo, Kernel drivers by soviet_bloke

soviet_bloke
Thu Sep 07 09:44:47 CDT 2006

Hi Don

> For instance, if you forget that a routine uses
> spinlocks and then accidently call it from your ISR, it may very well work
> on an SMP system because the spinlock is an actual test and set, but it has
> terrible consequences on a UP system where it becomes a NOP since the IRQL
> is above DISPATCH_LEVEL.

Trying to call the routine that uses spinlocks from ISR is not going to
work fine on
MP system either. Let's look at how MP HAL obtains spinlocks - the code
below is implementation of KeAcquireSpinLock() from halmacpi.dll


80012830: mov edx,dword ptr ds:[FFFE0080h]
80012836: mov dword ptr ds:[FFFE0080h],41h
80012840: shr edx,4
80012843: movzx eax,byte ptr [edx+8001D218h]

8001284A: lock bts dword ptr [ecx],0
8001284F: jb 80012854
80012851: ret

As you can see, the very first step KeAcquireSpinLock() does is
UNCONDITIONALLY(!!!)writing 0x41 to the Task Priority Register, i.e.
setting IRQL to DISPATCH_LEVEL, and then proceeds to set and test.
KeAcquireQueuedSpinLock() behaves in similar fashion. Therefore,
calling these functions at IRQL>DISPATCH_LEVEL is quite unwise thing to
do - even on MP HAL.

Anton Bassov




Don Burn wrote:
> <soviet_bloke@hotmail.com> wrote in message
> > Well, you can think of my examples as of ones of the bugs if you wish -
> > no matter how you call them, these are the examples of doing something
> > you are not supposed to do, which may have undesirable effects (unless
> > you are 100% sure you know what you are doing)
> >
> Yes they are doing something you are not supposed to do, that is a pretty
> good definition of a bug. For instance, if you forget that a routine uses
> spinlocks and then accidently call it from your ISR, it may very well work
> on an SMP system because the spinlock is an actual test and set, but it has
> terrible consequences on a UP system where it becomes a NOP since the IRQL
> is above DISPATCH_LEVEL.
>
>
>
> --
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> http://www.windrvr.com
> Remove StopSpam from the email to reply


Re: WinXPSP2, Intel Core2Duo, Kernel drivers by Don

Don
Thu Sep 07 09:50:09 CDT 2006

Sorry, it was early the instance I was thinking of was
KeAcquireSpinLockAtDpc. This code was done by a very good developer who is
now a respected member of the Windows driver community (and not me).


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply


<soviet_bloke@hotmail.com> wrote in message
news:1157640287.046142.16480@i42g2000cwa.googlegroups.com...
> Hi Don
>
>> For instance, if you forget that a routine uses
>> spinlocks and then accidently call it from your ISR, it may very well
>> work
>> on an SMP system because the spinlock is an actual test and set, but it
>> has
>> terrible consequences on a UP system where it becomes a NOP since the
>> IRQL
>> is above DISPATCH_LEVEL.
>
> Trying to call the routine that uses spinlocks from ISR is not going to
> work fine on
> MP system either. Let's look at how MP HAL obtains spinlocks - the code
> below is implementation of KeAcquireSpinLock() from halmacpi.dll
>
>
> 80012830: mov edx,dword ptr ds:[FFFE0080h]
> 80012836: mov dword ptr ds:[FFFE0080h],41h
> 80012840: shr edx,4
> 80012843: movzx eax,byte ptr [edx+8001D218h]
>
> 8001284A: lock bts dword ptr [ecx],0
> 8001284F: jb 80012854
> 80012851: ret
>
> As you can see, the very first step KeAcquireSpinLock() does is
> UNCONDITIONALLY(!!!)writing 0x41 to the Task Priority Register, i.e.
> setting IRQL to DISPATCH_LEVEL, and then proceeds to set and test.
> KeAcquireQueuedSpinLock() behaves in similar fashion. Therefore,
> calling these functions at IRQL>DISPATCH_LEVEL is quite unwise thing to
> do - even on MP HAL.
>
> Anton Bassov
>
>
>
>
> Don Burn wrote:
>> <soviet_bloke@hotmail.com> wrote in message
>> > Well, you can think of my examples as of ones of the bugs if you wish -
>> > no matter how you call them, these are the examples of doing something
>> > you are not supposed to do, which may have undesirable effects (unless
>> > you are 100% sure you know what you are doing)
>> >
>> Yes they are doing something you are not supposed to do, that is a pretty
>> good definition of a bug. For instance, if you forget that a routine
>> uses
>> spinlocks and then accidently call it from your ISR, it may very well
>> work
>> on an SMP system because the spinlock is an actual test and set, but it
>> has
>> terrible consequences on a UP system where it becomes a NOP since the
>> IRQL
>> is above DISPATCH_LEVEL.
>>
>>
>>
>> --
>> Don Burn (MVP, Windows DDK)
>> Windows 2k/XP/2k3 Filesystem and Driver Consulting
>> http://www.windrvr.com
>> Remove StopSpam from the email to reply
>



Re: WinXPSP2, Intel Core2Duo, Kernel drivers by soviet_bloke

soviet_bloke
Thu Sep 07 15:07:03 CDT 2006

Hi Don

> Sorry, it was early the instance I was thinking of was
> KeAcquireSpinLockAtDpc.

But why should KeAcquireSpinLockAtDpcLevel() pose problems???? After
all, it does not try to modify IRQL

Anton Bassov


Don Burn wrote:
> Sorry, it was early the instance I was thinking of was
> KeAcquireSpinLockAtDpc. This code was done by a very good developer who is
> now a respected member of the Windows driver community (and not me).
>
>
> --
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> http://www.windrvr.com
> Remove StopSpam from the email to reply
>
>
> <soviet_bloke@hotmail.com> wrote in message
> news:1157640287.046142.16480@i42g2000cwa.googlegroups.com...
> > Hi Don
> >
> >> For instance, if you forget that a routine uses
> >> spinlocks and then accidently call it from your ISR, it may very well
> >> work
> >> on an SMP system because the spinlock is an actual test and set, but it
> >> has
> >> terrible consequences on a UP system where it becomes a NOP since the
> >> IRQL
> >> is above DISPATCH_LEVEL.
> >
> > Trying to call the routine that uses spinlocks from ISR is not going to
> > work fine on
> > MP system either. Let's look at how MP HAL obtains spinlocks - the code
> > below is implementation of KeAcquireSpinLock() from halmacpi.dll
> >
> >
> > 80012830: mov edx,dword ptr ds:[FFFE0080h]
> > 80012836: mov dword ptr ds:[FFFE0080h],41h
> > 80012840: shr edx,4
> > 80012843: movzx eax,byte ptr [edx+8001D218h]
> >
> > 8001284A: lock bts dword ptr [ecx],0
> > 8001284F: jb 80012854
> > 80012851: ret
> >
> > As you can see, the very first step KeAcquireSpinLock() does is
> > UNCONDITIONALLY(!!!)writing 0x41 to the Task Priority Register, i.e.
> > setting IRQL to DISPATCH_LEVEL, and then proceeds to set and test.
> > KeAcquireQueuedSpinLock() behaves in similar fashion. Therefore,
> > calling these functions at IRQL>DISPATCH_LEVEL is quite unwise thing to
> > do - even on MP HAL.
> >
> > Anton Bassov
> >
> >
> >
> >
> > Don Burn wrote:
> >> <soviet_bloke@hotmail.com> wrote in message
> >> > Well, you can think of my examples as of ones of the bugs if you wish -
> >> > no matter how you call them, these are the examples of doing something
> >> > you are not supposed to do, which may have undesirable effects (unless
> >> > you are 100% sure you know what you are doing)
> >> >
> >> Yes they are doing something you are not supposed to do, that is a pretty
> >> good definition of a bug. For instance, if you forget that a routine
> >> uses
> >> spinlocks and then accidently call it from your ISR, it may very well
> >> work
> >> on an SMP system because the spinlock is an actual test and set, but it
> >> has
> >> terrible consequences on a UP system where it becomes a NOP since the
> >> IRQL
> >> is above DISPATCH_LEVEL.
> >>
> >>
> >>
> >> --
> >> Don Burn (MVP, Windows DDK)
> >> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> >> http://www.windrvr.com
> >> Remove StopSpam from the email to reply
> >


Re: WinXPSP2, Intel Core2Duo, Kernel drivers by Don

Don
Thu Sep 07 15:17:52 CDT 2006

Because on an SMP machine CPU 1 will get the lock, then an interrupt occurs
on CPU 2 and it will spin when it calls the routine until CPU 1 is finished,
but if this is a uni-processor, the lock is taken, the interupt occurs, the
interupt executes through the code, and then the returns with the processor
finishing the code under the lock. If this is for instance a lock to
protect insertion into a linked list, you can have a totally messed up list
with the forward link of A pointing to B whose back link points to C.

This is because KeAcquireSpinLockAtDpcLevel on a uni-processor is a NOP.


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply



<soviet_bloke@hotmail.com> wrote in message
news:1157659623.530224.278180@m73g2000cwd.googlegroups.com...
> Hi Don
>
>> Sorry, it was early the instance I was thinking of was
>> KeAcquireSpinLockAtDpc.
>
> But why should KeAcquireSpinLockAtDpcLevel() pose problems???? After
> all, it does not try to modify IRQL
>
> Anton Bassov
>
>
> Don Burn wrote:
>> Sorry, it was early the instance I was thinking of was
>> KeAcquireSpinLockAtDpc. This code was done by a very good developer who
>> is
>> now a respected member of the Windows driver community (and not me).
>>
>>
>> --
>> Don Burn (MVP, Windows DDK)
>> Windows 2k/XP/2k3 Filesystem and Driver Consulting
>> http://www.windrvr.com
>> Remove StopSpam from the email to reply
>>
>>
>> <soviet_bloke@hotmail.com> wrote in message
>> news:1157640287.046142.16480@i42g2000cwa.googlegroups.com...
>> > Hi Don
>> >
>> >> For instance, if you forget that a routine uses
>> >> spinlocks and then accidently call it from your ISR, it may very well
>> >> work
>> >> on an SMP system because the spinlock is an actual test and set, but
>> >> it
>> >> has
>> >> terrible consequences on a UP system where it becomes a NOP since the
>> >> IRQL
>> >> is above DISPATCH_LEVEL.
>> >
>> > Trying to call the routine that uses spinlocks from ISR is not going to
>> > work fine on
>> > MP system either. Let's look at how MP HAL obtains spinlocks - the code
>> > below is implementation of KeAcquireSpinLock() from halmacpi.dll
>> >
>> >
>> > 80012830: mov edx,dword ptr ds:[FFFE0080h]
>> > 80012836: mov dword ptr ds:[FFFE0080h],41h
>> > 80012840: shr edx,4
>> > 80012843: movzx eax,byte ptr [edx+8001D218h]
>> >
>> > 8001284A: lock bts dword ptr [ecx],0
>> > 8001284F: jb 80012854
>> > 80012851: ret
>> >
>> > As you can see, the very first step KeAcquireSpinLock() does is
>> > UNCONDITIONALLY(!!!)writing 0x41 to the Task Priority Register, i.e.
>> > setting IRQL to DISPATCH_LEVEL, and then proceeds to set and test.
>> > KeAcquireQueuedSpinLock() behaves in similar fashion. Therefore,
>> > calling these functions at IRQL>DISPATCH_LEVEL is quite unwise thing to
>> > do - even on MP HAL.
>> >
>> > Anton Bassov
>> >
>> >
>> >
>> >
>> > Don Burn wrote:
>> >> <soviet_bloke@hotmail.com> wrote in message
>> >> > Well, you can think of my examples as of ones of the bugs if you
>> >> > wish -
>> >> > no matter how you call them, these are the examples of doing
>> >> > something
>> >> > you are not supposed to do, which may have undesirable effects
>> >> > (unless
>> >> > you are 100% sure you know what you are doing)
>> >> >
>> >> Yes they are doing something you are not supposed to do, that is a
>> >> pretty
>> >> good definition of a bug. For instance, if you forget that a routine
>> >> uses
>> >> spinlocks and then accidently call it from your ISR, it may very well
>> >> work
>> >> on an SMP system because the spinlock is an actual test and set, but
>> >> it
>> >> has
>> >> terrible consequences on a UP system where it becomes a NOP since the
>> >> IRQL
>> >> is above DISPATCH_LEVEL.
>> >>
>> >>
>> >>
>> >> --
>> >> Don Burn (MVP, Windows DDK)
>> >> Windows 2k/XP/2k3 Filesystem and Driver Consulting
>> >> http://www.windrvr.com
>> >> Remove StopSpam from the email to reply
>> >
>



Re: WinXPSP2, Intel Core2Duo, Kernel drivers by soviet_bloke

soviet_bloke
Thu Sep 07 17:23:18 CDT 2006

Hi Don

In fact, I thought we were speaking about accidentally forgetting that
the routine, called by ISR, deals with spinlocks. However, what you
have mentioned in your latest post is already from the totally
different field - you mentioned the scenario of synchronizing some
routine with ISR by means of spinlock, rather than of
KeSynchronizeExecution(). This is the classical example of intentional
improper design, rather than of accidental bug .

However, I made it clear that my statement does not cover intentional
"unsupported" strategies - after all, if you intentionally go for
something "unsupported" you have to know what you are doing (and, at
this point, you may ask yourself whether you really want to do it). In
this particular case, the routine that you want to synchronize with ISR
has to check how many CPUs are there, i.e. do something like

if(*KeNumberOfProcessors==1) KeRaiseIrql (IRQL >=the one ISR runs
at,...);
else KeAcquireSpinlock(...);

If you do it it this way, your code will be able to run on SMP machine,
UP one plus UP machine with MP HAL installed. Certainly, this is still
improper design (after all, you make code that runs at DIRQL "wait" for
the one that runs at DISPATCH_LEVEL, which is just stupid thing to do),
but it will work

Anton Bassov



Don Burn wrote:
> Because on an SMP machine CPU 1 will get the lock, then an interrupt occurs
> on CPU 2 and it will spin when it calls the routine until CPU 1 is finished,
> but if this is a uni-processor, the lock is taken, the interupt occurs, the
> interupt executes through the code, and then the returns with the processor
> finishing the code under the lock. If this is for instance a lock to
> protect insertion into a linked list, you can have a totally messed up list
> with the forward link of A pointing to B whose back link points to C.
>
> This is because KeAcquireSpinLockAtDpcLevel on a uni-processor is a NOP.
>
>
> --
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> http://www.windrvr.com
> Remove StopSpam from the email to reply
>
>
>
> <soviet_bloke@hotmail.com> wrote in message
> news:1157659623.530224.278180@m73g2000cwd.googlegroups.com...
> > Hi Don
> >
> >> Sorry, it was early the instance I was thinking of was
> >> KeAcquireSpinLockAtDpc.
> >
> > But why should KeAcquireSpinLockAtDpcLevel() pose problems???? After
> > all, it does not try to modify IRQL
> >
> > Anton Bassov
> >
> >
> > Don Burn wrote:
> >> Sorry, it was early the instance I was thinking of was
> >> KeAcquireSpinLockAtDpc. This code was done by a very good developer who
> >> is
> >> now a respected member of the Windows driver community (and not me).
> >>
> >>
> >> --
> >> Don Burn (MVP, Windows DDK)
> >> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> >> http://www.windrvr.com
> >> Remove StopSpam from the email to reply
> >>
> >>
> >> <soviet_bloke@hotmail.com> wrote in message
> >> news:1157640287.046142.16480@i42g2000cwa.googlegroups.com...
> >> > Hi Don
> >> >
> >> >> For instance, if you forget that a routine uses
> >> >> spinlocks and then accidently call it from your ISR, it may very well
> >> >> work
> >> >> on an SMP system because the spinlock is an actual test and set, but
> >> >> it
> >> >> has
> >> >> terrible consequences on a UP system where it becomes a NOP since the
> >> >> IRQL
> >> >> is above DISPATCH_LEVEL.
> >> >
> >> > Trying to call the routine that uses spinlocks from ISR is not going to
> >> > work fine on
> >> > MP system either. Let's look at how MP HAL obtains spinlocks - the code
> >> > below is implementation of KeAcquireSpinLock() from halmacpi.dll
> >> >
> >> >
> >> > 80012830: mov edx,dword ptr ds:[FFFE0080h]
> >> > 80012836: mov dword ptr ds:[FFFE0080h],41h
> >> > 80012840: shr edx,4
> >> > 80012843: movzx eax,byte ptr [edx+8001D218h]
> >> >
> >> > 8001284A: lock bts dword ptr [ecx],0
> >> > 8001284F: jb 80012854
> >> > 80012851: ret
> >> >
> >> > As you can see, the very first step KeAcquireSpinLock() does is
> >> > UNCONDITIONALLY(!!!)writing 0x41 to the Task Priority Register, i.e.
> >> > setting IRQL to DISPATCH_LEVEL, and then proceeds to set and test.
> >> > KeAcquireQueuedSpinLock() behaves in similar fashion. Therefore,
> >> > calling these functions at IRQL>DISPATCH_LEVEL is quite unwise thing to
> >> > do - even on MP HAL.
> >> >
> >> > Anton Bassov
> >> >
> >> >
> >> >
> >> >
> >> > Don Burn wrote:
> >> >> <soviet_bloke@hotmail.com> wrote in message
> >> >> > Well, you can think of my examples as of ones of the bugs if you
> >> >> > wish -
> >> >> > no matter how you call them, these are the examples of doing
> >> >> > something
> >> >> > you are not supposed to do, which may have undesirable effects
> >> >> > (unless
> >> >> > you are 100% sure you know what you are doing)
> >> >> >
> >> >> Yes they are doing something you are not supposed to do, that is a
> >> >> pretty
> >> >> good definition of a bug. For instance, if you forget that a routine
> >> >> uses
> >> >> spinlocks and then accidently call it from your ISR, it may very well
> >> >> work
> >> >> on an SMP system because the spinlock is an actual test and set, but
> >> >> it
> >> >> has
> >> >> terrible consequences on a UP system where it becomes a NOP since the
> >> >> IRQL
> >> >> is above DISPATCH_LEVEL.
> >> >>
> >> >>
> >> >>
> >> >> --
> >> >> Don Burn (MVP, Windows DDK)
> >> >> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> >> >> http://www.windrvr.com
> >> >> Remove StopSpam from the email to reply
> >> >
> >


Re: WinXPSP2, Intel Core2Duo, Kernel drivers by Don

Don
Thu Sep 07 17:27:27 CDT 2006

No, I am referring to a routine normally called at DISPATCH_LEVEL that takes
a lock, and which an individual forgot was for DISPATCH and called from his
ISR. This was a purely unitentional mistake, that happened to work just
fine on an SMP, but not on a uni-processor.


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply



<soviet_bloke@hotmail.com> wrote in message
news:1157667798.504670.23420@i42g2000cwa.googlegroups.com...
> Hi Don
>
> In fact, I thought we were speaking about accidentally forgetting that
> the routine, called by ISR, deals with spinlocks. However, what you
> have mentioned in your latest post is already from the totally
> different field - you mentioned the scenario of synchronizing some
> routine with ISR by means of spinlock, rather than of
> KeSynchronizeExecution(). This is the classical example of intentional
> improper design, rather than of accidental bug .
>
> However, I made it clear that my statement does not cover intentional
> "unsupported" strategies - after all, if you intentionally go for
> something "unsupported" you have to know what you are doing (and, at
> this point, you may ask yourself whether you really want to do it). In
> this particular case, the routine that you want to synchronize with ISR
> has to check how many CPUs are there, i.e. do something like
>
> if(*KeNumberOfProcessors==1) KeRaiseIrql (IRQL >=the one ISR runs
> at,...);
> else KeAcquireSpinlock(...);
>
> If you do it it this way, your code will be able to run on SMP machine,
> UP one plus UP machine with MP HAL installed. Certainly, this is still
> improper design (after all, you make code that runs at DIRQL "wait" for
> the one that runs at DISPATCH_LEVEL, which is just stupid thing to do),
> but it will work
>
> Anton Bassov
>
>
>
> Don Burn wrote:
>> Because on an SMP machine CPU 1 will get the lock, then an interrupt
>> occurs
>> on CPU 2 and it will spin when it calls the routine until CPU 1 is
>> finished,
>> but if this is a uni-processor, the lock is taken, the interupt occurs,
>> the
>> interupt executes through the code, and then the returns with the
>> processor
>> finishing the code under the lock. If this is for instance a lock to
>> protect insertion into a linked list, you can have a totally messed up
>> list
>> with the forward link of A pointing to B whose back link points to C.
>>
>> This is because KeAcquireSpinLockAtDpcLevel on a uni-processor is a NOP.
>>
>>
>> --
>> Don Burn (MVP, Windows DDK)
>> Windows 2k/XP/2k3 Filesystem and Driver Consulting
>> http://www.windrvr.com
>> Remove StopSpam from the email to reply
>>
>>
>>
>> <soviet_bloke@hotmail.com> wrote in message
>> news:1157659623.530224.278180@m73g2000cwd.googlegroups.com...
>> > Hi Don
>> >
>> >> Sorry, it was early the instance I was thinking of was
>> >> KeAcquireSpinLockAtDpc.
>> >
>> > But why should KeAcquireSpinLockAtDpcLevel() pose problems???? After
>> > all, it does not try to modify IRQL
>> >
>> > Anton Bassov
>> >
>> >
>> > Don Burn wrote:
>> >> Sorry, it was early the instance I was thinking of was
>> >> KeAcquireSpinLockAtDpc. This code was done by a very good developer
>> >> who
>> >> is
>> >> now a respected member of the Windows driver community (and not me).
>> >>
>> >>
>> >> --
>> >> Don Burn (MVP, Windows DDK)
>> >> Windows 2k/XP/2k3 Filesystem and Driver Consulting
>> >> http://www.windrvr.com
>> >> Remove StopSpam from the email to reply
>> >>
>> >>
>> >> <soviet_bloke@hotmail.com> wrote in message
>> >> news:1157640287.046142.16480@i42g2000cwa.googlegroups.com...
>> >> > Hi Don
>> >> >
>> >> >> For instance, if you forget that a routine uses
>> >> >> spinlocks and then accidently call it from your ISR, it may very
>> >> >> well
>> >> >> work
>> >> >> on an SMP system because the spinlock is an actual test and set,
>> >> >> but
>> >> >> it
>> >> >> has
>> >> >> terrible consequences on a UP system where it becomes a NOP since
>> >> >> the
>> >> >> IRQL
>> >> >> is above DISPATCH_LEVEL.
>> >> >
>> >> > Trying to call the routine that uses spinlocks from ISR is not going
>> >> > to
>> >> > work fine on
>> >> > MP system either. Let's look at how MP HAL obtains spinlocks - the
>> >> > code
>> >> > below is implementation of KeAcquireSpinLock() from halmacpi.dll
>> >> >
>> >> >
>> >> > 80012830: mov edx,dword ptr ds:[FFFE0080h]
>> >> > 80012836: mov dword ptr ds:[FFFE0080h],41h
>> >> > 80012840: shr edx,4
>> >> > 80012843: movzx eax,byte ptr [edx+8001D218h]
>> >> >
>> >> > 8001284A: lock bts dword ptr [ecx],0
>> >> > 8001284F: jb 80012854
>> >> > 80012851: ret
>> >> >
>> >> > As you can see, the very first step KeAcquireSpinLock() does is
>> >> > UNCONDITIONALLY(!!!)writing 0x41 to the Task Priority Register, i.e.
>> >> > setting IRQL to DISPATCH_LEVEL, and then proceeds to set and test.
>> >> > KeAcquireQueuedSpinLock() behaves in similar fashion. Therefore,
>> >> > calling these functions at IRQL>DISPATCH_LEVEL is quite unwise thing
>> >> > to
>> >> > do - even on MP HAL.
>> >> >
>> >> > Anton Bassov
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > Don Burn wrote:
>> >> >> <soviet_bloke@hotmail.com> wrote in message
>> >> >> > Well, you can think of my examples as of ones of the bugs if you
>> >> >> > wish -
>> >> >> > no matter how you call them, these are the examples of doing
>> >> >> > something
>> >> >> > you are not supposed to do, which may have undesirable effects
>> >> >> > (unless
>> >> >> > you are 100% sure you know what you are doing)
>> >> >> >
>> >> >> Yes they are doing something you are not supposed to do, that is a
>> >> >> pretty
>> >> >> good definition of a bug. For instance, if you forget that a
>> >> >> routine
>> >> >> uses
>> >> >> spinlocks and then accidently call it from your ISR, it may very
>> >> >> well
>> >> >> work
>> >> >> on an SMP system because the spinlock is an actual test and set,
>> >> >> but
>> >> >> it
>> >> >> has
>> >> >> terrible consequences on a UP system where it becomes a NOP since
>> >> >> the
>> >> >> IRQL
>> >> >> is above DISPATCH_LEVEL.
>> >> >>
>> >> >>
>> >> >>
>> >> >> --
>> >> >> Don Burn (MVP, Windows DDK)
>> >> >> Windows 2k/XP/2k3 Filesystem and Driver Consulting
>> >> >> http://www.windrvr.com
>> >> >> Remove StopSpam from the email to reply
>> >> >
>> >
>



Re: WinXPSP2, Intel Core2Duo, Kernel drivers by soviet_bloke

soviet_bloke
Thu Sep 07 17:39:07 CDT 2006

Hi Don

In fact, this bug has a chance to reveal itself on the MP system as
well (after a bit of thinking I realized that your example is not
so-well suited for MP machines either, although it is not so obvious at
the very first glance). Consider the following scenario:

1. CPU1 obtains a spinlock
2. Interrupt occurs, and gets dispensed to CPU1, rather than CPU2

What is going to happen if the above scenario occurs???? ISR that runs
on CPU1 will try to acquire the spinlock that CPU1 has already
acquired. As a result, CPU1 starts spinning in infinite loop at DIRQL,
and there is nothing that can terminate this loop

To be honest, I cannot tell you how the system will react, but I
believe BSOD is due pretty shortly.....

Anton Bassov



Don Burn wrote:
> Because on an SMP machine CPU 1 will get the lock, then an interrupt occurs
> on CPU 2 and it will spin when it calls the routine until CPU 1 is finished,
> but if this is a uni-processor, the lock is taken, the interupt occurs, the
> interupt executes through the code, and then the returns with the processor
> finishing the code under the lock. If this is for instance a lock to
> protect insertion into a linked list, you can have a totally messed up list
> with the forward link of A pointing to B whose back link points to C.
>
> This is because KeAcquireSpinLockAtDpcLevel on a uni-processor is a NOP.
>
>
> --
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> http://www.windrvr.com
> Remove StopSpam from the email to reply
>
>
>
> <soviet_bloke@hotmail.com> wrote in message
> news:1157659623.530224.278180@m73g2000cwd.googlegroups.com...
> > Hi Don
> >
> >> Sorry, it was early the instance I was thinking of was
> >> KeAcquireSpinLockAtDpc.
> >
> > But why should KeAcquireSpinLockAtDpcLevel() pose problems???? After
> > all, it does not try to modify IRQL
> >
> > Anton Bassov
> >
> >
> > Don Burn wrote:
> >> Sorry, it was early the instance I was thinking of was
> >> KeAcquireSpinLockAtDpc. This code was done by a very good developer who
> >> is
> >> now a respected member of the Windows driver community (and not me).
> >>
> >>
> >> --
> >> Don Burn (MVP, Windows DDK)
> >> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> >> http://www.windrvr.com
> >> Remove StopSpam from the email to reply
> >>
> >>
> >> <soviet_bloke@hotmail.com> wrote in message
> >> news:1157640287.046142.16480@i42g2000cwa.googlegroups.com...
> >> > Hi Don
> >> >
> >> >> For instance, if you forget that a routine uses
> >> >> spinlocks and then accidently call it from your ISR, it may very well
> >> >> work
> >&g