Re: CreateFile performance



If many applications are calling driver, each application process
context need a separate handle or duplicate handle for CreateFile(). Is
it same to have a duplicate handle from other process in a given
application process. Or will it make a difference if we call
CreateFile() for each process context.

Will the driver unload if there is handle pending at the user mode for
a device. If the device is removed and handle not closed yet, will it
cause problems? If I implement this scheme, I want to close these file
handle lazy way.

Thinking of these situations, I am backing off from implementing this
optimization atleast for this version release. I appreciate if someone
can answer.

Thanks,
Raj

soviet_bloke@xxxxxxxxxxx wrote:
Hi mate

According to Knuth, "in 95% of cases optimization is mother of all
evil", and this is what you should keep in mind when you start thinking
about optimizing your code.

The beauty of your current approach is that your code is really easy to
understand and maintain, which is true for both kernel-mode code and
user-mode one. Certainly, CreateFile()+CloseHandle() pair on every IO
operation adds some certain overhead, but how significant is it,
compared to IO operation in itself?


I think that you should start thinking about changing your code only if
both statements below are true:

A. Performance is not satisfactory
B. Profiling shows that (A) occurs mainly because of unnecessary
CreateFile()+CloseHandle() calls on every IO operation


Anton Bassov




r_konjeti@xxxxxxxxxxxx wrote:
I wrote an application dll and firewire 1394 driver.

For sending data of any size (4 byte to 2048 bytes), application calls
dll routine. In dll routine each time I open a handle to the driver
(mostly non-overlap operations but few overlapped operations).

Will it be useful if I open the handle to each device only once and
keep using it. I can cache these handles and reuse them. Close device
handle only if there is plug & play (device add or device removed) or
when application is closed. Will it cause any new problems of
synchronization with respect to pnp or cancel Irps that are queud at
driver to receive incoming data.

Will I see any overall improvement in performance when I am handling
requests every 200 milliseconds. When I am receiving data, I receive
more than one packet from driver to user mode. But I cannot send more
than one packet because library function doesnot know how many
applications are sending or how application will send or if there is
next packet.

I think CreateFile and CloseHandle() for every request is a performance
hit because of user mode to kernel mode switches. Please advice if I
should make the effort.

hDevice = CreateFile( szDeviceName,
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_WRITE | FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
0,
NULL
);

.



Relevant Pages

  • Re: CreateFile performance
    ... context need a separate handle or duplicate handle for CreateFile. ... CreateFile() for each process context. ... unauthorized application can try to use you driver as an attack vector. ...
    (microsoft.public.development.device.drivers)
  • Re: WinCE USB
    ... do a CreateFile( ... If it's a storage card driver, ... If it's a network USB device, ... SetupDiEnumDeviceInterfaces() ...
    (microsoft.public.windowsce.platbuilder)
  • Re: USB Testing
    ... I have no idea if the port is displayed in a GUI or is in the ... Trying to do a CreateFile in XP...As I said above, ... As for using CreateFilefrom XP, I used the device ID for the USB ... WCEUSBSH driver to load. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: About the settings in CreateFile
    ... sharing modes really apply to file systems, ... But I still have confusion in sharing mode of CreateFile. ... If the dispatch routine for IRP_MJ_CREATE in my driver always returns ... > called in the driver there is no IOCTL present here. ...
    (microsoft.public.development.device.drivers)
  • Best practice of Device Driver to User Mode Application Notifcation,...
    ... practice of notifying a User Mode Application that ... holds a Handle to the Driver by CreateFile? ... to pass a piece of memory to my user mode application ...
    (microsoft.public.development.device.drivers)