Re: CreateFile performance
- From: r_konjeti@xxxxxxxxxxxx
- Date: 9 Nov 2006 06:30:49 -0800
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
);
.
- Follow-Ups:
- Re: CreateFile performance
- From: Don Burn
- Re: CreateFile performance
- References:
- CreateFile performance
- From: r_konjeti
- Re: CreateFile performance
- From: soviet_bloke
- CreateFile performance
- Prev by Date: Re: ReadFileEx and pending IRP
- Next by Date: Re: CreateFile performance
- Previous by thread: Re: CreateFile performance
- Next by thread: Re: CreateFile performance
- Index(es):
Relevant Pages
|