how to ensure atomic code in a kernel mode driver

I’m learning to write kernel mode drivers using “Driver Works - SoftICE”.
I have to ensure that 2 statements are executed atomically (without
interrupts) to make an IO writing operation correctly. Can I use assembler
code (CLI) to disable all interrupts from my ANSI C code?

No, first using assembler period is a bad idea, and you should never use CLI
in a driver. The kernel provides a synchronization mechanism between your
interrupts and the rest of your driver, I’m sure DriverStudio provides a
wrapper for this mechanism.

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

----- Original Message -----
From: “Agustin”
To: “Windows System Software Devs Interest List”
Sent: Wednesday, December 03, 2003 10:00 AM
Subject: [ntdev] how to ensure atomic code in a kernel mode driver

> I’m learning to write kernel mode drivers using “Driver Works - SoftICE”.
> I have to ensure that 2 statements are executed atomically (without
> interrupts) to make an IO writing operation correctly. Can I use assembler
> code (CLI) to disable all interrupts from my ANSI C code?
>
> —
> 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

CLI is per processor, if I could recall, so that might not be the right
thing, if your driver runs on multiprocessor or hyperthreaded machine !!!.

Look for the documentations on spin locks, if you need to sync with your
ISR, then need to use interrupt spin lock.

You will find lot of discussion by looking at the FAQ on this osr site.

-prokash
----- Original Message -----
From: “Agustin”
To: “Windows System Software Devs Interest List”
Sent: Wednesday, December 03, 2003 7:00 AM
Subject: [ntdev] how to ensure atomic code in a kernel mode driver

> I’m learning to write kernel mode drivers using “Driver Works - SoftICE”.
> I have to ensure that 2 statements are executed atomically (without
> interrupts) to make an IO writing operation correctly. Can I use assembler
> code (CLI) to disable all interrupts from my ANSI C code?
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@garlic.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>

Use KeSynchronizeExecution or KeAcquireInterruptSpinLock (XP and later) to
synchronize the sequence of 2 writes with your own ISR.

No ways of synchronizing with the other ISRs, and more so - this is not
needed.

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

----- Original Message -----
From: “Agustin”
To: “Windows System Software Devs Interest List”
Sent: Wednesday, December 03, 2003 6:00 PM
Subject: [ntdev] how to ensure atomic code in a kernel mode driver

> I’m learning to write kernel mode drivers using “Driver Works - SoftICE”.
> I have to ensure that 2 statements are executed atomically (without
> interrupts) to make an IO writing operation correctly. Can I use assembler
> code (CLI) to disable all interrupts from my ANSI C code?
>
> —
> 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

> I’m learning to write kernel mode drivers using “Driver Works - SoftICE”.

I have to ensure that 2 statements are executed atomically (without
interrupts) to make an IO writing operation correctly. Can I use assembler
code (CLI) to disable all interrupts from my ANSI C code?

The underlying mechanism in the system is to use KeSynchronizeExecution.
You provide a callback function that will be executed at the IRQL of the
interrupt and with the interrupt spin lock held. This is so the ISR will
not execute at the same time.

Refer to the IntrDemo sample in DriverWorks. It demonstrates how to
synchronize execution with an ISR. It makes use of
KDevice::SynchronizeInterrupt method (a wrapper around
KeSynchronizeExecution system call) to perform atomic operations with an
ISR.

You can declare the callback function with DriverWorks using the
DEVMEMBER_SYNCHCRITSECTION macro

Steve Smith
Compuware
DriverStudio

If all you’re trying to do is to learn, machine code’s no big deal, in fact,
by all means try it because you’re going to learn a fair amount in the
process.

But cli won’t work because it only stops interrupts on one processor. If the
only place you access that i/o location is your ISR, you can roll up your
own barrier using a lock bts or lock btc, or lock compare and replace, or
lock exchange and add. There are Intel tutorials on the P4 that teach you
how to do that kind of thing, go to http://developer.intel.com and look
around, you’ll eventually get to a file ht_intro.zip that has a nice
tutorial on hyperthreading, which among other things teaches you how to
write spinlocks to Intel processors. Greg Andrews’s book also has good
material on this.

Note however that in doing that you totally give up any pretension of
portability, so, you may be better off using the DriverWorks synchronization
wrappers. The tradeoff is, they’re just there, so you just use them, and you
don’t learn much about what it takes to achieve the synchronization to begin
with !

Alberto.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Agustin
Sent: Wednesday, December 03, 2003 10:01 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] how to ensure atomic code in a kernel mode driver

I’m learning to write kernel mode drivers using “Driver Works - SoftICE”.
I have to ensure that 2 statements are executed atomically (without
interrupts) to make an IO writing operation correctly. Can I use assembler
code (CLI) to disable all interrupts from my ANSI C code?


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.

I would take the liberty to mention another book. To me it is one of the
ultimate due to its clarity, and preciseness

Unix Systems for Modern Architecture (Symmetric multiprocessing and caching
for kernel programmer) by
Curt Schimmel… IT MIGHT HAVE A NEW VERSION, and that might even cover
NUMA in detail.

Dont be fooled by the name Unix. Majority of it applies to all MP os.

-prokash
----- Original Message -----
From: “Moreira, Alberto”
To: “Windows System Software Devs Interest List”
Sent: Wednesday, December 03, 2003 9:28 AM
Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver

> If all you’re trying to do is to learn, machine code’s no big deal, in
fact,
> by all means try it because you’re going to learn a fair amount in the
> process.
>
> But cli won’t work because it only stops interrupts on one processor. If
the
> only place you access that i/o location is your ISR, you can roll up your
> own barrier using a lock bts or lock btc, or lock compare and replace, or
> lock exchange and add. There are Intel tutorials on the P4 that teach you
> how to do that kind of thing, go to http://developer.intel.com and look
> around, you’ll eventually get to a file ht_intro.zip that has a nice
> tutorial on hyperthreading, which among other things teaches you how to
> write spinlocks to Intel processors. Greg Andrews’s book also has good
> material on this.
>
> Note however that in doing that you totally give up any pretension of
> portability, so, you may be better off using the DriverWorks
synchronization
> wrappers. The tradeoff is, they’re just there, so you just use them, and
you
> don’t learn much about what it takes to achieve the synchronization to
begin
> with !
>
>
> Alberto.
>
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com]On Behalf Of Agustin
> Sent: Wednesday, December 03, 2003 10:01 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] how to ensure atomic code in a kernel mode driver
>
>
> I’m learning to write kernel mode drivers using “Driver Works - SoftICE”.
> I have to ensure that 2 statements are executed atomically (without
> interrupts) to make an IO writing operation correctly. Can I use assembler
> code (CLI) to disable all interrupts from my ANSI C code?
>
> —
> 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.
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@garlic.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>

> own barrier using a lock bts or lock btc, or lock compare and replace, or

Which is already there as KeAcquireSpinLock.

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

Cool, Prokash, I should take a look ! It might help in my course.

Alberto.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Prokash Sinha
Sent: Wednesday, December 03, 2003 12:48 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver

I would take the liberty to mention another book. To me it is one of the
ultimate due to its clarity, and preciseness

Unix Systems for Modern Architecture (Symmetric multiprocessing and caching
for kernel programmer) by
Curt Schimmel… IT MIGHT HAVE A NEW VERSION, and that might even cover
NUMA in detail.

Dont be fooled by the name Unix. Majority of it applies to all MP os.

-prokash
----- Original Message -----
From: “Moreira, Alberto”
To: “Windows System Software Devs Interest List”
Sent: Wednesday, December 03, 2003 9:28 AM
Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver

> If all you’re trying to do is to learn, machine code’s no big deal, in
fact,
> by all means try it because you’re going to learn a fair amount in the
> process.
>
> But cli won’t work because it only stops interrupts on one processor. If
the
> only place you access that i/o location is your ISR, you can roll up your
> own barrier using a lock bts or lock btc, or lock compare and replace, or
> lock exchange and add. There are Intel tutorials on the P4 that teach you
> how to do that kind of thing, go to http://developer.intel.com and look
> around, you’ll eventually get to a file ht_intro.zip that has a nice
> tutorial on hyperthreading, which among other things teaches you how to
> write spinlocks to Intel processors. Greg Andrews’s book also has good
> material on this.
>
> Note however that in doing that you totally give up any pretension of
> portability, so, you may be better off using the DriverWorks
synchronization
> wrappers. The tradeoff is, they’re just there, so you just use them, and
you
> don’t learn much about what it takes to achieve the synchronization to
begin
> with !
>
>
> Alberto.
>
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com]On Behalf Of Agustin
> Sent: Wednesday, December 03, 2003 10:01 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] how to ensure atomic code in a kernel mode driver
>
>
> I’m learning to write kernel mode drivers using “Driver Works - SoftICE”.
> I have to ensure that 2 statements are executed atomically (without
> interrupts) to make an IO writing operation correctly. Can I use assembler
> code (CLI) to disable all interrupts from my ANSI C code?
>
> —
> 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.
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@garlic.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.

I’m sure U and all others would love to take a look at it. Lot of other
books and discussion(s) just tells how to do it, and when I (personally)
look at those, ALL OF HAIRS BECOMES MUTULLAY ORTHOGONAL, but this one is
one of a kind, if beauty and elegance has anything to do with this *kernel*
subject, this book shows its muscles off. It tells what goes on …

I’m also contemplating to offer some course here in county college, that
might be sometime next year, and I would definitely try to use this book.
The exercise, the explanation, the whole sequel is just enormous. Thousand
times I’ve read articles, and books that does not define the objective,
legends, definitions of terms, and gradual approach, and that clearly tells
the author’s *thought process*. Often one has to jump back and forth (
remember the perils of non-local goto stmt) to get read the mind of the
author. This one is different.

Enjoy it !

-prokash
----- Original Message -----
From: “Moreira, Alberto”
To: “Windows System Software Devs Interest List”
Sent: Wednesday, December 03, 2003 12:23 PM
Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver

> Cool, Prokash, I should take a look ! It might help in my course.
>
> Alberto.
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com]On Behalf Of Prokash Sinha
> Sent: Wednesday, December 03, 2003 12:48 PM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver
>
>
> I would take the liberty to mention another book. To me it is one of the
> ultimate due to its clarity, and preciseness
>
> Unix Systems for Modern Architecture (Symmetric multiprocessing and
caching
> for kernel programmer) by
> Curt Schimmel… IT MIGHT HAVE A NEW VERSION, and that might even cover
> NUMA in detail.
>
> Dont be fooled by the name Unix. Majority of it applies to all MP os.
>
> -prokash
> ----- Original Message -----
> From: “Moreira, Alberto”
> To: “Windows System Software Devs Interest List”
> Sent: Wednesday, December 03, 2003 9:28 AM
> Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver
>
>
> > If all you’re trying to do is to learn, machine code’s no big deal, in
> fact,
> > by all means try it because you’re going to learn a fair amount in the
> > process.
> >
> > But cli won’t work because it only stops interrupts on one processor. If
> the
> > only place you access that i/o location is your ISR, you can roll up
your
> > own barrier using a lock bts or lock btc, or lock compare and replace,
or
> > lock exchange and add. There are Intel tutorials on the P4 that teach
you
> > how to do that kind of thing, go to http://developer.intel.com and look
> > around, you’ll eventually get to a file ht_intro.zip that has a nice
> > tutorial on hyperthreading, which among other things teaches you how to
> > write spinlocks to Intel processors. Greg Andrews’s book also has good
> > material on this.
> >
> > Note however that in doing that you totally give up any pretension of
> > portability, so, you may be better off using the DriverWorks
> synchronization
> > wrappers. The tradeoff is, they’re just there, so you just use them, and
> you
> > don’t learn much about what it takes to achieve the synchronization to
> begin
> > with !
> >
> >
> > Alberto.
> >
> >
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com]On Behalf Of Agustin
> > Sent: Wednesday, December 03, 2003 10:01 AM
> > To: Windows System Software Devs Interest List
> > Subject: [ntdev] how to ensure atomic code in a kernel mode driver
> >
> >
> > I’m learning to write kernel mode drivers using “Driver Works -
SoftICE”.
> > I have to ensure that 2 statements are executed atomically (without
> > interrupts) to make an IO writing operation correctly. Can I use
assembler
> > code (CLI) to disable all interrupts from my ANSI C code?
> >
> > —
> > 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.
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@garlic.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.
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@garlic.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

Yes, Max, but the guy is a beginner. One can use KeAcquireSpinlock and still
have no clue of what a spinlock is all about. Do it at machine level, and
knowledge will seep in - first time he uses the calls, he knows what’s going
on underneath ! And the insights on computer architecture by trying to
implement a spinlock loop with or without pause instructions, or the
difference between btc/bts and compare replace or exchange add, again, those
cannot be acquired by using the kernel call. Maybe it’s the professor in me
speaking, but I believe that every one of us kernel devs should do a fair
amount of machine code development, if nothing else as a scratching pole.

Alberto.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Maxim S. Shatskih
Sent: Wednesday, December 03, 2003 3:08 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver

own barrier using a lock bts or lock btc, or lock compare and replace, or

Which is already there as KeAcquireSpinLock.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.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.

If you go teaching, I know it’s a pain, but try to put up a web site ! It’s
nice to be able to refer to other courses given by other people, and see the
different approaches they have to teach OS and kernel development.

Alberto.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Prokash Sinha
Sent: Wednesday, December 03, 2003 3:46 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver

I’m sure U and all others would love to take a look at it. Lot of other
books and discussion(s) just tells how to do it, and when I (personally)
look at those, ALL OF HAIRS BECOMES MUTULLAY ORTHOGONAL, but this one is
one of a kind, if beauty and elegance has anything to do with this *kernel*
subject, this book shows its muscles off. It tells what goes on …

I’m also contemplating to offer some course here in county college, that
might be sometime next year, and I would definitely try to use this book.
The exercise, the explanation, the whole sequel is just enormous. Thousand
times I’ve read articles, and books that does not define the objective,
legends, definitions of terms, and gradual approach, and that clearly tells
the author’s *thought process*. Often one has to jump back and forth (
remember the perils of non-local goto stmt) to get read the mind of the
author. This one is different.

Enjoy it !

-prokash
----- Original Message -----
From: “Moreira, Alberto”
To: “Windows System Software Devs Interest List”
Sent: Wednesday, December 03, 2003 12:23 PM
Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver

> Cool, Prokash, I should take a look ! It might help in my course.
>
> Alberto.
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com]On Behalf Of Prokash Sinha
> Sent: Wednesday, December 03, 2003 12:48 PM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver
>
>
> I would take the liberty to mention another book. To me it is one of the
> ultimate due to its clarity, and preciseness
>
> Unix Systems for Modern Architecture (Symmetric multiprocessing and
caching
> for kernel programmer) by
> Curt Schimmel… IT MIGHT HAVE A NEW VERSION, and that might even cover
> NUMA in detail.
>
> Dont be fooled by the name Unix. Majority of it applies to all MP os.
>
> -prokash
> ----- Original Message -----
> From: “Moreira, Alberto”
> To: “Windows System Software Devs Interest List”
> Sent: Wednesday, December 03, 2003 9:28 AM
> Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver
>
>
> > If all you’re trying to do is to learn, machine code’s no big deal, in
> fact,
> > by all means try it because you’re going to learn a fair amount in the
> > process.
> >
> > But cli won’t work because it only stops interrupts on one processor. If
> the
> > only place you access that i/o location is your ISR, you can roll up
your
> > own barrier using a lock bts or lock btc, or lock compare and replace,
or
> > lock exchange and add. There are Intel tutorials on the P4 that teach
you
> > how to do that kind of thing, go to http://developer.intel.com and look
> > around, you’ll eventually get to a file ht_intro.zip that has a nice
> > tutorial on hyperthreading, which among other things teaches you how to
> > write spinlocks to Intel processors. Greg Andrews’s book also has good
> > material on this.
> >
> > Note however that in doing that you totally give up any pretension of
> > portability, so, you may be better off using the DriverWorks
> synchronization
> > wrappers. The tradeoff is, they’re just there, so you just use them, and
> you
> > don’t learn much about what it takes to achieve the synchronization to
> begin
> > with !
> >
> >
> > Alberto.
> >
> >
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com]On Behalf Of Agustin
> > Sent: Wednesday, December 03, 2003 10:01 AM
> > To: Windows System Software Devs Interest List
> > Subject: [ntdev] how to ensure atomic code in a kernel mode driver
> >
> >
> > I’m learning to write kernel mode drivers using “Driver Works -
SoftICE”.
> > I have to ensure that 2 statements are executed atomically (without
> > interrupts) to make an IO writing operation correctly. Can I use
assembler
> > code (CLI) to disable all interrupts from my ANSI C code?
> >
> > —
> > 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.
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@garlic.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.
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@garlic.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.

Alberto,

I dunno, but the thought of a beginner munging an OS such as Windows 2000+
by indiscriminately using low level control ops like “CLI/STI” kinda makes
me faint of heart. One does not learn proper weapons handling by walking out
to the local firing range packing a 90 mm howitzer. Seems those experiments
are best carried out in a limited OS such as DOS. However, great
enlightenment can be had by simply de-compiling the ExInterlockedXxxx
functions as well as studying the multi-processor HAL IO synchronization
function calls.


Gary G. Little
Seagate Technologies, LLC

“Moreira, Alberto” wrote in message
news:xxxxx@ntdev…
>
> Yes, Max, but the guy is a beginner. One can use KeAcquireSpinlock and
still
> have no clue of what a spinlock is all about. Do it at machine level, and
> knowledge will seep in - first time he uses the calls, he knows what’s
going
> on underneath ! And the insights on computer architecture by trying to
> implement a spinlock loop with or without pause instructions, or the
> difference between btc/bts and compare replace or exchange add, again,
those
> cannot be acquired by using the kernel call. Maybe it’s the professor in
me
> speaking, but I believe that every one of us kernel devs should do a fair
> amount of machine code development, if nothing else as a scratching pole.
>
> Alberto.
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com]On Behalf Of Maxim S. Shatskih
> Sent: Wednesday, December 03, 2003 3:08 PM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver
>
>
> > own barrier using a lock bts or lock btc, or lock compare and replace,
or
>
> Which is already there as KeAcquireSpinLock.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.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.
>
>
>

Thanx for the suggestion, I do have a site, I will update soon. Yes I know
it is a pain to teach, but I have to take it up on parttime basis, and
really not expecting much in terms of income …

-prokash
----- Original Message -----
From: “Moreira, Alberto”
To: “Windows System Software Devs Interest List”
Sent: Wednesday, December 03, 2003 12:55 PM
Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver

> If you go teaching, I know it’s a pain, but try to put up a web site !
It’s
> nice to be able to refer to other courses given by other people, and see
the
> different approaches they have to teach OS and kernel development.
>
> Alberto.
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com]On Behalf Of Prokash Sinha
> Sent: Wednesday, December 03, 2003 3:46 PM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver
>
>
> I’m sure U and all others would love to take a look at it. Lot of other
> books and discussion(s) just tells how to do it, and when I (personally)
> look at those, ALL OF HAIRS BECOMES MUTULLAY ORTHOGONAL, but this one is
> one of a kind, if beauty and elegance has anything to do with this
kernel
> subject, this book shows its muscles off. It tells what goes on …
>
> I’m also contemplating to offer some course here in county college, that
> might be sometime next year, and I would definitely try to use this book.
> The exercise, the explanation, the whole sequel is just enormous. Thousand
> times I’ve read articles, and books that does not define the objective,
> legends, definitions of terms, and gradual approach, and that clearly
tells
> the author’s thought process. Often one has to jump back and forth (
> remember the perils of non-local goto stmt) to get read the mind of the
> author. This one is different.
>
> Enjoy it !
>
> -prokash
> ----- Original Message -----
> From: “Moreira, Alberto”
> To: “Windows System Software Devs Interest List”
> Sent: Wednesday, December 03, 2003 12:23 PM
> Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver
>
>
> > Cool, Prokash, I should take a look ! It might help in my course.
> >
> > Alberto.
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com]On Behalf Of Prokash Sinha
> > Sent: Wednesday, December 03, 2003 12:48 PM
> > To: Windows System Software Devs Interest List
> > Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver
> >
> >
> > I would take the liberty to mention another book. To me it is one of the
> > ultimate due to its clarity, and preciseness
> >
> > Unix Systems for Modern Architecture (Symmetric multiprocessing and
> caching
> > for kernel programmer) by
> > Curt Schimmel… IT MIGHT HAVE A NEW VERSION, and that might even cover
> > NUMA in detail.
> >
> > Dont be fooled by the name Unix. Majority of it applies to all MP os.
> >
> > -prokash
> > ----- Original Message -----
> > From: “Moreira, Alberto”
> > To: “Windows System Software Devs Interest List”
> > Sent: Wednesday, December 03, 2003 9:28 AM
> > Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver
> >
> >
> > > If all you’re trying to do is to learn, machine code’s no big deal, in
> > fact,
> > > by all means try it because you’re going to learn a fair amount in the
> > > process.
> > >
> > > But cli won’t work because it only stops interrupts on one processor.
If
> > the
> > > only place you access that i/o location is your ISR, you can roll up
> your
> > > own barrier using a lock bts or lock btc, or lock compare and replace,
> or
> > > lock exchange and add. There are Intel tutorials on the P4 that teach
> you
> > > how to do that kind of thing, go to http://developer.intel.com and
look
> > > around, you’ll eventually get to a file ht_intro.zip that has a nice
> > > tutorial on hyperthreading, which among other things teaches you how
to
> > > write spinlocks to Intel processors. Greg Andrews’s book also has good
> > > material on this.
> > >
> > > Note however that in doing that you totally give up any pretension of
> > > portability, so, you may be better off using the DriverWorks
> > synchronization
> > > wrappers. The tradeoff is, they’re just there, so you just use them,
and
> > you
> > > don’t learn much about what it takes to achieve the synchronization to
> > begin
> > > with !
> > >
> > >
> > > Alberto.
> > >
> > >
> > >
> > > -----Original Message-----
> > > From: xxxxx@lists.osr.com
> > > [mailto:xxxxx@lists.osr.com]On Behalf Of Agustin
> > > Sent: Wednesday, December 03, 2003 10:01 AM
> > > To: Windows System Software Devs Interest List
> > > Subject: [ntdev] how to ensure atomic code in a kernel mode driver
> > >
> > >
> > > I’m learning to write kernel mode drivers using “Driver Works -
> SoftICE”.
> > > I have to ensure that 2 statements are executed atomically (without
> > > interrupts) to make an IO writing operation correctly. Can I use
> assembler
> > > code (CLI) to disable all interrupts from my ANSI C code?
> > >
> > > —
> > > 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.
> > >
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as: xxxxx@garlic.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.
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@garlic.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.
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@garlic.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>

Absolutely agreed. However, it’s important that new driver developers
know that it is no longer appropriate, in general, to roll your own
assembly in NT drivers. I know I’m preaching to the choir here, but
I’ve had to deal with too much crappy, needlessly-inconsistent code to
have much tolerance for it anymore.

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Moreira, Alberto
Sent: Wednesday, December 03, 2003 3:54 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver

Yes, Max, but the guy is a beginner. One can use KeAcquireSpinlock and
still have no clue of what a spinlock is all about. Do it at machine
level, and knowledge will seep in - first time he uses the calls, he
knows what’s going on underneath ! And the insights on computer
architecture by trying to implement a spinlock loop with or without
pause instructions, or the difference between btc/bts and compare
replace or exchange add, again, those cannot be acquired by using the
kernel call. Maybe it’s the professor in me speaking, but I believe that
every one of us kernel devs should do a fair amount of machine code
development, if nothing else as a scratching pole.

Alberto.

Yeah. 99.9% of all synchronization techniques can (and should!!) be
learned in user-mode, before being attempted in kernel-mode…

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gary G. Little
Sent: Wednesday, December 03, 2003 4:11 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Re: how to ensure atomic code in a kernel mode driver

Alberto,

I dunno, but the thought of a beginner munging an OS such as Windows
2000+ by indiscriminately using low level control ops like “CLI/STI”
kinda makes me faint of heart. One does not learn proper weapons
handling by walking out to the local firing range packing a 90 mm
howitzer. Seems those experiments are best carried out in a limited OS
such as DOS. However, great enlightenment can be had by simply
de-compiling the ExInterlockedXxxx functions as well as studying the
multi-processor HAL IO synchronization function calls.


Gary G. Little
Seagate Technologies, LLC

I know a lot of things that people do as a matter of fact that are way less
appropriate than talking directly to the hardware. In fact, I’d rather talk
to the hardware than to a Byzantine kernel layer, there’s much less
probability of making mistakes and screwing things up. The best low level
code isn’t the one that sticks to the OS rules, but the one that works
independent of what OS is running. And if machine level code was
automatically crappy or inconsistent, neither SoftICE nor any of our tools
would be feasible.

Alberto.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Arlie Davis
Sent: Wednesday, December 03, 2003 4:45 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver

Absolutely agreed. However, it’s important that new driver developers
know that it is no longer appropriate, in general, to roll your own
assembly in NT drivers. I know I’m preaching to the choir here, but
I’ve had to deal with too much crappy, needlessly-inconsistent code to
have much tolerance for it anymore.

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Moreira, Alberto
Sent: Wednesday, December 03, 2003 3:54 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver

Yes, Max, but the guy is a beginner. One can use KeAcquireSpinlock and
still have no clue of what a spinlock is all about. Do it at machine
level, and knowledge will seep in - first time he uses the calls, he
knows what’s going on underneath ! And the insights on computer
architecture by trying to implement a spinlock loop with or without
pause instructions, or the difference between btc/bts and compare
replace or exchange add, again, those cannot be acquired by using the
kernel call. Maybe it’s the professor in me speaking, but I believe that
every one of us kernel devs should do a fair amount of machine code
development, if nothing else as a scratching pole.

Alberto.


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.

Never said it was automatically crappy. But, empirically, in the code I
have had to directly deal with, code that relied on assembly for
anything but very specific performance-critical reasons has been, on the
whole, crappier than code that has not. Obviously, our experiences may
differ.

Tools like SoftICE, and other low-level debugger tools, are exceptions.
They can ONLY achieve their goals through low-level machine twiddling.
That’s their entire purpose. I assumed that this discussion was
initially focusing on “general” device drivers – either pure-software
drivers like file system drivers, or physical drivers. These are an
entirely different species than SoftICE, profilers, etc. Unless you are
doing something arch-specific, like using SIMD, or processor-specific
registers (debugging, performance, etc.), there is little to no reason
to use assembly.

Arguing for using assembly for context neutrality is… odd. I thought
we hashed out the whole C-vs-assembly thing a long time ago.

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Moreira, Alberto
Sent: Wednesday, December 03, 2003 4:57 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver

I know a lot of things that people do as a matter of fact that are way
less appropriate than talking directly to the hardware. In fact, I’d
rather talk to the hardware than to a Byzantine kernel layer, there’s
much less probability of making mistakes and screwing things up. The
best low level code isn’t the one that sticks to the OS rules, but the
one that works independent of what OS is running. And if machine level
code was automatically crappy or inconsistent, neither SoftICE nor any
of our tools would be feasible.

Alberto.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Arlie Davis
Sent: Wednesday, December 03, 2003 4:45 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver

Absolutely agreed. However, it’s important that new driver developers
know that it is no longer appropriate, in general, to roll your own
assembly in NT drivers. I know I’m preaching to the choir here, but
I’ve had to deal with too much crappy, needlessly-inconsistent code to
have much tolerance for it anymore.

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Moreira, Alberto
Sent: Wednesday, December 03, 2003 3:54 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver

Yes, Max, but the guy is a beginner. One can use KeAcquireSpinlock and
still have no clue of what a spinlock is all about. Do it at machine
level, and knowledge will seep in - first time he uses the calls, he
knows what’s going on underneath ! And the insights on computer
architecture by trying to implement a spinlock loop with or without
pause instructions, or the difference between btc/bts and compare
replace or exchange add, again, those cannot be acquired by using the
kernel call. Maybe it’s the professor in me speaking, but I believe that
every one of us kernel devs should do a fair amount of machine code
development, if nothing else as a scratching pole.

Alberto.


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.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@sublinear.org To
unsubscribe send a blank email to xxxxx@lists.osr.com

BULLSHIT, almost every piece of code as you describe that has been my
misfortune to encounter in the last 30+ years of systems level programming
has violated the operating system principles and in general messed up the
system.

Your arguments about spin locks are a case in point, if you do not know what
you are doing it is easy to mess up a multi-processor with a poor spinlock
implementation.

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

----- Original Message -----
From: “Moreira, Alberto”
To: “Windows System Software Devs Interest List”
Sent: Wednesday, December 03, 2003 4:57 PM
Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver

> I know a lot of things that people do as a matter of fact that are way
less
> appropriate than talking directly to the hardware. In fact, I’d rather
talk
> to the hardware than to a Byzantine kernel layer, there’s much less
> probability of making mistakes and screwing things up. The best low level
> code isn’t the one that sticks to the OS rules, but the one that works
> independent of what OS is running. And if machine level code was
> automatically crappy or inconsistent, neither SoftICE nor any of our tools
> would be feasible.
>
> Alberto.
>

You mean something like the system-wide cancel spinlock? You can do worse
and I have seen it from no spinlocks to grabbing several for almost the
entire duration of processing each request.

“Don Burn” wrote in message news:xxxxx@ntdev…
>
> BULLSHIT, almost every piece of code as you describe that has been my
> misfortune to encounter in the last 30+ years of systems level programming
> has violated the operating system principles and in general messed up the
> system.
>
> Your arguments about spin locks are a case in point, if you do not know
what
> you are doing it is easy to mess up a multi-processor with a poor spinlock
> implementation.
>
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
>
> ----- Original Message -----
> From: “Moreira, Alberto”
> To: “Windows System Software Devs Interest List”
> Sent: Wednesday, December 03, 2003 4:57 PM
> Subject: [ntdev] RE: how to ensure atomic code in a kernel mode driver
>
>
> > I know a lot of things that people do as a matter of fact that are way
> less
> > appropriate than talking directly to the hardware. In fact, I’d rather
> talk
> > to the hardware than to a Byzantine kernel layer, there’s much less
> > probability of making mistakes and screwing things up. The best low
level
> > code isn’t the one that sticks to the OS rules, but the one that works
> > independent of what OS is running. And if machine level code was
> > automatically crappy or inconsistent, neither SoftICE nor any of our
tools
> > would be feasible.
> >
> > Alberto.
> >
>
>
>