Re: completion routine and waiting (revised)

ok. I’ve revised my query to be more specific. I’ve
checked OSRs archive, and still have not been able to
come up with an answer.

I have an intermediate filter to my class driver
in this the I have a completion routine that goes as
follows
Please note Points A & B

NTSTATUS cmpltrn (PDEVICE_OBJECT fido, PIRP Irp, PVOID
Context)
{
/* Boiler Plate */
if (Irp->PendingReturned)
IoMarkIrpPending(Irp);


MyIoAllocateWorkItem(…) ;
/* Point A */
//note: my own customized function.
//I have my own threads which do the work

return STATUS_MORE_PROCESSING REQUIRED ;
} /*Point B */

VOID mythredfn (PVOID Context)
{
/* pick up IRP from a queue */
/* Do some work
Note: I have not modified the IRP in anyway
*/
IoCompleteRequest(Irp) ;
}

What confuses me is that how can I be sure threadfn
does not call IoCompleteRequest BEFORE completion
routine has moved from Point A To B. I could insert a
sleep in my thread to prevent this problem, but it
brings down performance

Rajeev


Everything you always wanted to know about cars and bikes,now
at: http://in.autos.yahoo.com/cricket/tracker.html

You don’t care. In most cases the completion routine will be running at
DISPATCH_LEVEL so the worker thread can’t be scheduled until that routine
completes.

----- Original Message -----
From: “Rajeev Rao”
To: “NT Developers Interest List”
Sent: Thursday, May 30, 2002 3:10 PM
Subject: [ntdev] Re: completion routine and waiting (revised)

> ok. I’ve revised my query to be more specific. I’ve
> checked OSRs archive, and still have not been able to
> come up with an answer.
>
> I have an intermediate filter to my class driver
> in this the I have a completion routine that goes as
> follows
> Please note Points A & B
>
> NTSTATUS cmpltrn (PDEVICE_OBJECT fido, PIRP Irp, PVOID
> Context)
> {
> /* Boiler Plate /
> if (Irp->PendingReturned)
> IoMarkIrpPending(Irp);
>
> …
> MyIoAllocateWorkItem(…) ;
> /
Point A */
> //note: my own customized function.
> //I have my own threads which do the work
>
> return STATUS_MORE_PROCESSING REQUIRED ;
> } /*Point B /
>
> VOID mythredfn (PVOID Context)
> {
> /
pick up IRP from a queue /
> /
Do some work
> Note: I have not modified the IRP in anyway
> */
> IoCompleteRequest(Irp) ;
> }
>
>
> What confuses me is that how can I be sure threadfn
> does not call IoCompleteRequest BEFORE completion
> routine has moved from Point A To B. I could insert a
> sleep in my thread to prevent this problem, but it
> brings down performance
>
> Rajeev
>
>
>
> ________________________________________________________________________
> Everything you always wanted to know about cars and bikes,now
> at: http://in.autos.yahoo.com/cricket/tracker.html
>
> —
> You are currently subscribed to ntdev as: xxxxx@yoshimuni.com
> To unsubscribe send a blank email to %%email.unsub%%

the answer (I believe) is that you don’t. As long as your completion
routine returns STATUS_MORE_PROCESSING_REQUIRED and doesn’t do anything
else with the IRP after queueing the work item then you’re safe.

however if, in between A & B, you use the IRP or any part of the i/o
request (the MDL, the buffers, the status block, etc…) then you will
need to come up with some sort of synchronization. You could easily use
an event for this, creating it unsignalled in the completion routine
(but not on the stack) and then signalling it when you’re ready for your
work item to start up. However it seems simpler to just start the work
item once you’re done with the IRP.

-p

-----Original Message-----
From: Rajeev Rao [mailto:xxxxx@yahoo.co.in]
Sent: Thursday, May 30, 2002 12:10 PM
To: NT Developers Interest List
Subject: [ntdev] Re: completion routine and waiting (revised)

ok. I’ve revised my query to be more specific. I’ve
checked OSRs archive, and still have not been able to
come up with an answer.

I have an intermediate filter to my class driver
in this the I have a completion routine that goes as
follows
Please note Points A & B

NTSTATUS cmpltrn (PDEVICE_OBJECT fido, PIRP Irp, PVOID
Context)
{
/* Boiler Plate */
if (Irp->PendingReturned)
IoMarkIrpPending(Irp);


MyIoAllocateWorkItem(…) ;
/* Point A */
//note: my own customized function.
//I have my own threads which do the work

return STATUS_MORE_PROCESSING REQUIRED ;
} /*Point B */

VOID mythredfn (PVOID Context)
{
/* pick up IRP from a queue */
/* Do some work
Note: I have not modified the IRP in anyway
*/
IoCompleteRequest(Irp) ;
}

What confuses me is that how can I be sure threadfn
does not call IoCompleteRequest BEFORE completion
routine has moved from Point A To B. I could insert a
sleep in my thread to prevent this problem, but it
brings down performance

Rajeev


Everything you always wanted to know about cars and bikes,now
at: http://in.autos.yahoo.com/cricket/tracker.html


You are currently subscribed to ntdev as: xxxxx@microsoft.com To
unsubscribe send a blank email to %%email.unsub%%

the worker thread could easily be scheduled on another processor while
your completion routine is running. It could also be scheduled on the
same processor if that “most cases” doesn’t hold up.

-p

-----Original Message-----
From: David J. Craig [mailto:xxxxx@yoshimuni.com]
Sent: Thursday, May 30, 2002 12:40 PM
To: NT Developers Interest List
Subject: [ntdev] Re: completion routine and waiting (revised)

You don’t care. In most cases the completion routine will be running at
DISPATCH_LEVEL so the worker thread can’t be scheduled until that
routine completes.

----- Original Message -----
From: “Rajeev Rao”
To: “NT Developers Interest List”
Sent: Thursday, May 30, 2002 3:10 PM
Subject: [ntdev] Re: completion routine and waiting (revised)

> ok. I’ve revised my query to be more specific. I’ve
> checked OSRs archive, and still have not been able to
> come up with an answer.
>
> I have an intermediate filter to my class driver
> in this the I have a completion routine that goes as
> follows
> Please note Points A & B
>
> NTSTATUS cmpltrn (PDEVICE_OBJECT fido, PIRP Irp, PVOID
> Context)
> {
> /* Boiler Plate /
> if (Irp->PendingReturned)
> IoMarkIrpPending(Irp);
>
> …
> MyIoAllocateWorkItem(…) ;
> /
Point A */
> //note: my own customized function.
> //I have my own threads which do the work
>
> return STATUS_MORE_PROCESSING REQUIRED ;
> } /*Point B /
>
> VOID mythredfn (PVOID Context)
> {
> /
pick up IRP from a queue /
> /
Do some work
> Note: I have not modified the IRP in anyway
> */
> IoCompleteRequest(Irp) ;
> }
>
>
> What confuses me is that how can I be sure threadfn
> does not call IoCompleteRequest BEFORE completion
> routine has moved from Point A To B. I could insert a
> sleep in my thread to prevent this problem, but it
> brings down performance
>
> Rajeev
>
>
>
> ____________________________________________________________________
>

> Everything you always wanted to know about cars and bikes,now
> at: http://in.autos.yahoo.com/cricket/tracker.html
>
> —
> You are currently subscribed to ntdev as: xxxxx@yoshimuni.com To
> unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@microsoft.com To
unsubscribe send a blank email to %%email.unsub%%

> What confuses me is that how can I be sure threadfn

does not call IoCompleteRequest BEFORE completion
routine has moved from Point A To B.

This is not necessary. Just do not touch the IRP after you call
ExQueueWorkItem.

Max

I think you should have some kind of synchronization between your thread
function and completion routine . Pass the same event between the completion
routine and thread function , set the event before returning from completion
routine and wait for the event in thread function before completing the IRP.

-----Original Message-----
From: Rajeev Rao [mailto:xxxxx@yahoo.co.in]
Sent: Thursday, May 30, 2002 12:10 PM
To: NT Developers Interest List
Subject: [ntdev] Re: completion routine and waiting (revised)

ok. I’ve revised my query to be more specific. I’ve
checked OSRs archive, and still have not been able to
come up with an answer.

I have an intermediate filter to my class driver
in this the I have a completion routine that goes as
follows
Please note Points A & B

NTSTATUS cmpltrn (PDEVICE_OBJECT fido, PIRP Irp, PVOID
Context)
{
/* Boiler Plate */
if (Irp->PendingReturned)
IoMarkIrpPending(Irp);


MyIoAllocateWorkItem(…) ;
/* Point A */
//note: my own customized function.
//I have my own threads which do the work

return STATUS_MORE_PROCESSING REQUIRED ;
} /*Point B */

VOID mythredfn (PVOID Context)
{
/* pick up IRP from a queue */
/* Do some work
Note: I have not modified the IRP in anyway
*/
IoCompleteRequest(Irp) ;
}

What confuses me is that how can I be sure threadfn
does not call IoCompleteRequest BEFORE completion
routine has moved from Point A To B. I could insert a
sleep in my thread to prevent this problem, but it
brings down performance

Rajeev


Everything you always wanted to know about cars and bikes,now
at: http://in.autos.yahoo.com/cricket/tracker.html


You are currently subscribed to ntdev as: xxxxx@microtune.com
To unsubscribe send a blank email to %%email.unsub%%