Reading through Windows Internals 6th Edition, page 12, I see...
The I/O manager serializes IRPs for a driver by ensuring that the driver processes only one IRP at a time.
Drivers can process multiple IRPs concurrently, but serialization is usually required for most devices because they cannot concurrently handle multiple I/O requests.
And on page 38-39...
Drivers must synchronize their access to global driver data and hardware registers for two reasons:
- The execution of a driver can be preempted by higher-priority threads and time-slice (or quantum) expiration or can be interrupted by higher IRQL interrupts.
- __On multiprocessor systems, Windows can run driver code simultaneously on more than one processor.
I understand how the I/O manager can have multiple IRPs going on at the same time, even from the same File and the same calling thread if asynchronous I/O is being used. But the meaning of "processes only one IRP at a time" is unclear. When is the driver "processing" an IRP, and does this prevent the driver from processing multiple IRPs at the same time in different threads?
What I believe this means is as follows, and you gurus please confirm or correct. I'd like to have this post be useful to future driver writers with similar concerns.
Now, if the driver can process multiple IRPs concurrently, then what does "processes only one IRP at a time" mean, and what difference does this make to the driver code (i.e., what synchronizations are unnecessary as a result?
So assuming I have to protect my driver code from being preemted by a higher priority thread, both of which are in a critical section, it seems that at a minimum, I would need a spinlock, because that raises the first thread to DISPATCH_LEVEL and assures that it will complete quickly. Simply using an interlocked exchange guard to protect the critical section wouldn't work because the second thread would keep waiting for the guard to be released. The spinlock also locks other processors out of the critical section.
It looks like you're new here. If you want to get involved, click one of these buttons!
|Upcoming OSR Seminars|
|Writing WDF Drivers||25 Feb 2019||OSR Seminar Space|
|Developing Minifilters||8 April 2019||OSR Seminar Space|