Discussion:
DeviceIoControl and Timeout
(too old to reply)
Dennis Burns
2004-08-04 12:40:25 UTC
Permalink
How do I specify a timeout when doing overlapped IO, and calling
DeviceIoControl?

What does the driver have to do to implement this?

How does the User mode code know when the timeout occurs?

Thanks in advance for the help,
Dennis
Don Burn
2004-08-04 14:28:18 UTC
Permalink
You either are handling a timeout independant of overlapped I/O or
independant of the driver. In the first model, a driver check a request for
the amount of time it has been waiting for data and complete the IRP with an
error if more time than desired has passed. The timeout value is either
fixed or passed in to the driver by another deviceiocontrol before the
request of the type with a timeout is issued.

With the second approack, you issue an overlapped I/O with an event then
wait on the event with a timeout, if the timeout occurs cancel the I/O.
There are many variations on these themes but these are the basic ones.
--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply
Post by Dennis Burns
How do I specify a timeout when doing overlapped IO, and calling
DeviceIoControl?
What does the driver have to do to implement this?
How does the User mode code know when the timeout occurs?
Thanks in advance for the help,
Dennis
Dennis Burns
2004-08-04 15:11:44 UTC
Permalink
Hi Don,
Thanks for the help.
Would you please clarify the second approach?
Does the user mode code cancel the request?
If I'm not using a queue for the Irp, do I have to do anything special
in the driver to support the cancellation?

FYI: I find all of this driver stuff very complex. It's hard to get my mind
around the whole process.
Thanks again,
Dennis
Post by Don Burn
You either are handling a timeout independant of overlapped I/O or
independant of the driver. In the first model, a driver check a request for
the amount of time it has been waiting for data and complete the IRP with an
error if more time than desired has passed. The timeout value is either
fixed or passed in to the driver by another deviceiocontrol before the
request of the type with a timeout is issued.
With the second approack, you issue an overlapped I/O with an event then
wait on the event with a timeout, if the timeout occurs cancel the I/O.
There are many variations on these themes but these are the basic ones.
--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply
Post by Dennis Burns
How do I specify a timeout when doing overlapped IO, and calling
DeviceIoControl?
What does the driver have to do to implement this?
How does the User mode code know when the timeout occurs?
Thanks in advance for the help,
Dennis
Don Burn
2004-08-04 15:30:51 UTC
Permalink
Yes the user mode code cancels the IRP. In your driver what are you doing
with the IRP if you don't put it in a queue (even a one slot queue, ie a
pointer)? If you want overlapped I/O to work, you need to return
STATUS_PENDING from the DeviceIoControl call to the driver and complete the
IRP later, so that implies some sort of queue. To cancel the IRP you need
to set the cancel routine, complete the IRP on the cancel, removing it from
your queue.
--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply
Post by Dennis Burns
Hi Don,
Thanks for the help.
Would you please clarify the second approach?
Does the user mode code cancel the request?
If I'm not using a queue for the Irp, do I have to do anything special
in the driver to support the cancellation?
FYI: I find all of this driver stuff very complex. It's hard to get my mind
around the whole process.
Thanks again,
Dennis
Post by Don Burn
You either are handling a timeout independant of overlapped I/O or
independant of the driver. In the first model, a driver check a request
for
Post by Don Burn
the amount of time it has been waiting for data and complete the IRP
with
Post by Dennis Burns
an
Post by Don Burn
error if more time than desired has passed. The timeout value is either
fixed or passed in to the driver by another deviceiocontrol before the
request of the type with a timeout is issued.
With the second approack, you issue an overlapped I/O with an event then
wait on the event with a timeout, if the timeout occurs cancel the I/O.
There are many variations on these themes but these are the basic ones.
--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply
Post by Dennis Burns
How do I specify a timeout when doing overlapped IO, and calling
DeviceIoControl?
What does the driver have to do to implement this?
How does the User mode code know when the timeout occurs?
Thanks in advance for the help,
Dennis
Dennis Burns
2004-08-04 16:51:05 UTC
Permalink
Hi Don,
Yes, I do have a pointer to the Irp.
I set a completion routine, as you suggest. I'm using the general approach
in Oney's book, pg 282-3.
The only issue I seem to have now is the location of my completion routine
(paged vs non-paged), and the IRQL level it can be called at. I need to
study this closely.
Thank again,
Dennis
Post by Don Burn
Yes the user mode code cancels the IRP. In your driver what are you doing
with the IRP if you don't put it in a queue (even a one slot queue, ie a
pointer)? If you want overlapped I/O to work, you need to return
STATUS_PENDING from the DeviceIoControl call to the driver and complete the
IRP later, so that implies some sort of queue. To cancel the IRP you need
to set the cancel routine, complete the IRP on the cancel, removing it from
your queue.
--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply
Post by Dennis Burns
Hi Don,
Thanks for the help.
Would you please clarify the second approach?
Does the user mode code cancel the request?
If I'm not using a queue for the Irp, do I have to do anything special
in the driver to support the cancellation?
FYI: I find all of this driver stuff very complex. It's hard to get my
mind
Post by Dennis Burns
around the whole process.
Thanks again,
Dennis
Post by Don Burn
You either are handling a timeout independant of overlapped I/O or
independant of the driver. In the first model, a driver check a request
for
Post by Don Burn
the amount of time it has been waiting for data and complete the IRP
with
Post by Dennis Burns
an
Post by Don Burn
error if more time than desired has passed. The timeout value is either
fixed or passed in to the driver by another deviceiocontrol before the
request of the type with a timeout is issued.
With the second approack, you issue an overlapped I/O with an event then
wait on the event with a timeout, if the timeout occurs cancel the I/O.
There are many variations on these themes but these are the basic ones.
--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply
Post by Dennis Burns
How do I specify a timeout when doing overlapped IO, and calling
DeviceIoControl?
What does the driver have to do to implement this?
How does the User mode code know when the timeout occurs?
Thanks in advance for the help,
Dennis
thedirtyduck
2004-08-05 11:58:16 UTC
Permalink
Hi guys,

Just to jump on the bandwagon here, as this is the same problem I'm
having at the moment....

. how can I implement a timeout in a non-overlapped DeviceIoControl call?
Don, you mentioned implementing "a timeout independant of overlapped I/O"
- how do I do this in the driver?

Thanks!

- Colm.
Don Burn
2004-08-05 12:35:28 UTC
Permalink
First, unless you are able to complete the request immediately, you should
return status pending so there isn't in that sense a non-overlapped call.
The general approach here is to timestamp when the request reaches the
driver, and then through a timer mechanism complete the IRP with an error
such as STATUS_IO_TIMEOUT. For simple cases this can be create a timer
callback for the request, cancel the timer if the IRP completes, or complete
the IRP in the timer callback if not. For cases where many requests could
be queued a smarted model is desirable.
--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply
Post by thedirtyduck
Hi guys,
Just to jump on the bandwagon here, as this is the same problem I'm
having at the moment....
. how can I implement a timeout in a non-overlapped DeviceIoControl call?
Don, you mentioned implementing "a timeout independant of overlapped I/O"
- how do I do this in the driver?
Thanks!
- Colm.
thedirtyduck
2004-08-05 14:00:38 UTC
Permalink
Thanks Don, that sounds like a good approach alright. But (unfortunately!)
B-( leads me to ask two other questions:

- how to get a timestamp in the driver code ? GetTickCount and
GetSystemTime are windows calls ?

- how to create a timer callback from the driver to my application?

Thanks again!

- Colm.
Don Burn
2004-08-05 14:07:55 UTC
Permalink
Post by thedirtyduck
Thanks Don, that sounds like a good approach alright. But (unfortunately!)
- how to get a timestamp in the driver code ? GetTickCount and
GetSystemTime are windows calls ?
KeQueryTickCount or KeQuerySystemTime
Post by thedirtyduck
- how to create a timer callback from the driver to my application?
Don't try to callback to the application, use KeSetTimeEx and KeCancelTimer
to handle this in the driver, then complete the pending IRP with an
appropriate status to indicate a timeout.
--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply
thedirtyduck
2004-08-05 15:28:14 UTC
Permalink
Thanks Don! You're definitely M.V.P. in my book!

-Colm.
Maxim S. Shatskih
2004-08-05 16:36:27 UTC
Permalink
Great care must be taken with such a timer to avoid races.
--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
***@storagecraft.com
http://www.storagecraft.com
Post by Don Burn
First, unless you are able to complete the request immediately, you should
return status pending so there isn't in that sense a non-overlapped call.
The general approach here is to timestamp when the request reaches the
driver, and then through a timer mechanism complete the IRP with an error
such as STATUS_IO_TIMEOUT. For simple cases this can be create a timer
callback for the request, cancel the timer if the IRP completes, or complete
the IRP in the timer callback if not. For cases where many requests could
be queued a smarted model is desirable.
--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply
Post by thedirtyduck
Hi guys,
Just to jump on the bandwagon here, as this is the same problem I'm
having at the moment....
. how can I implement a timeout in a non-overlapped DeviceIoControl call?
Don, you mentioned implementing "a timeout independant of overlapped I/O"
- how do I do this in the driver?
Thanks!
- Colm.
Loading...