multiple DeviceIOCONTROLS

Hi,

I’m looking for some sample code on how to handle multiple
DeviceIOControls to a driver from user mode.
I am planning to use overlapped io with multiple events .

In absence of any sample code are there any commments/advice
on useing such a method. Any potential gotcha’s.

The user mode application would have a number of buffers open with the
driver which would fill in the buffers with data as recieved and
complete the IO.

Any advantages/disadvantages to using this method over trying to define
a large shared memory buffer between the user mode and kernal mode and
passing the data that way.

Thanks in advance,
Sunil

The basic approach for queuing multiple concurrent IRPs is:

In DeviceIoControl (assuming CreateFile setup for async I/O):

1.) Map IRP data to system address space, if necessary.
2.) Set cancel routine.
3.) Mark the IRP as pending.
4.) Queue the IRP in a spinlock-protected list, probably using the IRP
Tail.Overlay.ListEntry field for the list pointer(s).
5.) Return STATUS_PENDING.

When buffer (IRP) is needed by driver.

1.) Fetch IRP from queue. CONTAINING_RECORD MACRO is your friend.
2.) Set cancel routine to NULL.
3.) Do work with IRP’s buffer.
4.) Complete the IRP, making sure that IoStatus.Information and
IoStatus.Status are set correctly.

You will also have to handle cancel routine, cleanup, etc.

Suggest that you get a book that describes this sort of function in mode
detail. There are details that you should attend to.

As for the merits of using multiple queued operations instead of large
shared memory buffer: It depends mostly on the anticipated frequency of
user/kernel transitions.

Windows is not a real-time OS and has unpredictable (and sometimes large)
kernel/user latency. If individual operations are performed at high
frequency (e.g., one buffer per network packet), then you will probably
loose packets when using smaller individual I/O operations. In this case,
minimizing kernel/user transition rate (i.e., by using larger shared memory)
will lead to better performance. The amount of data being transferred has a
much smaller performance effect then the frequency of the transfers.

PCAUSA’s Rawether network product has NDIS protocol drivers that uses both
techniques. Using larger buffers provides a definite performance improvement
on higher-speed networks.

(I realize that your application may have nothing to do with networks.
That’s simply where my experience is form.)

Hope this helps.

Thomas F. Divine

PCAUSA - Toolkits & Resources For Network Software Developers
NDIS Protocol - NDIS Intermediate - TDI Client/Filter
http: - http:

wrote in message news:xxxxx@ntdev…
>
> Hi,
>
> I’m looking for some sample code on how to handle multiple
> DeviceIOControls to a driver from user mode.
> I am planning to use overlapped io with multiple events .
>
> In absence of any sample code are there any commments/advice
> on useing such a method. Any potential gotcha’s.
>
> The user mode application would have a number of buffers open with the
> driver which would fill in the buffers with data as recieved and
> complete the IO.
>
> Any advantages/disadvantages to using this method over trying to define
> a large shared memory buffer between the user mode and kernal mode and
> passing the data that way.
>
> Thanks in advance,
> Sunil
>
></http:></http:>

Hi sunil
if u have been following the mail discussions on this list then this was
very similar to what i had asked?
The answer to ur question also depends on how frequently u call these
DeviceIoCtls. the Shared memory approach would
involve locking issues which can be additional overhead if too many people
are sharing that region.
Also i am not very sure that what advantage u would gain by issuing a
overlapped IOCTL other than that u will be able to
continue with something else in user mode while the kernel executes in ur
behalf and posts and event on completion.
Also if the amount of copy being done from the kernel to user mode is large
then the DIRECT_IO method must be used instead of the BUFFERED method.
But the best solution would be that which provides a zero copy transfer from
the user to kernel mode for large amounts of data without much locking and
synchronization issues.

Mayank

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of xxxxx@neesus.com
Sent: Friday, May 30, 2003 11:28 PM
To: NT Developers Interest List
Subject: [ntdev] multiple DeviceIOCONTROLS

Hi,

I’m looking for some sample code on how to handle multiple
DeviceIOControls to a driver from user mode.
I am planning to use overlapped io with multiple events .

In absence of any sample code are there any commments/advice
on useing such a method. Any potential gotcha’s.

The user mode application would have a number of buffers open with the
driver which would fill in the buffers with data as recieved and
complete the IO.

Any advantages/disadvantages to using this method over trying to define
a large shared memory buffer between the user mode and kernal mode and
passing the data that way.

Thanks in advance,
Sunil


You are currently subscribed to ntdev as:
xxxxx@intersolutions.stpn.soft.net
To unsubscribe send a blank email to xxxxx@lists.osr.com

> The user mode application would have a number of buffers open with
the

driver which would fill in the buffers with data as recieved and
complete the IO.

This is a very good idea. KS works this way.

Max