From: Jamie Hanrahan [jeh@cmkrnl.com] Sent: Tuesday, August 31, 1999 7:47 AM To: ntdev@atria.com Subject: RE: [ntdev] StartIo LIFO > [ ... scenario where IoStartNextPacket, and hence Startio, > is called from StartIo routine ...] > This is recursive calls... Yes, it is. However, for most drivers this is not a problem, because if you are completing IRPs from your start IO routine (i.e. before you return to caller and get called back), there is not going to be much time for many IRPs (usually not any) to build up on the queue. > PS. This code path is worked as FIFO only if > IoCompleteRequest is called in > another thread context, i.e. in DpcForIsr, or in > driver(etc) dedicated Thread. And this suggests one solution: Just queue a DPC from your StartIo and let the DPC routine call IoCR and IoSNP. Another solution is to drain the queue yourself *within* a single instance of your StartIo routine. Something like: while( DvcObj->CurrentIrp != NULL && IrpCanBeCompletedImmediately( DvcObj->CurrentIrp)) { perform the function indicated by the IRP; IoCompleteRequest( DvcObj->CurrentIrp); newIrpQueueEntry = KeRemoveDeviceQueue( dvcObj->DeviceQueue); if (newIrpQueueEntry == 0) DvcObj->CurrentIrp = NULL; else DvcObj->CurrentIrp = CONTAINING_RECORD( newIrpQueueEntry, IRP, Tail.Overlay.DeviceQueueEntry); } Declaration of locals, casts, cancel processing, etc., is left as an exercise for the reader. Finally, if ALL of your IRPs can be completed immediately in your start IO routine, there is no need for a queue at all! Just grab a spinlock in your dispatch routine, do the operation, drop the spinlock, and call IoCompleteRequest. If you're sure your upper levels will never invoke you at DISPATCH_LEVEL, you can easily use a mutex (and really wait on it) instead. > Lets there higher-level driver above us, and it set > CompletionRoutine. > Then, from the point of view of this higher-level drivers > this is LIFO model > - i.e. their CompletionRoutines will be called in reverse > order - and they > will see last IRPs as first in CompletioRoutines. Is it?.. Yes. They're not supposed to care, ever. In fact they are not supposed to expect the IRPs to come back in any particular order. You see, even if IRPs are always completed "normally" in a DPC routine, it is possible on an MP system for upper layers (or requesters) to see IO completion reports in a different sequence than that in which IoCompleteRequest got called. --- Jamie Hanrahan, Kernel Mode Systems ( http://www.cmkrnl.com/ ) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ To unsubscribe, send email to ntdev-request@atria.com with body UNSUBSCRIBE (the subject is ignored). ]