Re: Mutual Exclusion for shared Buffer b/n User and Kernel

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Comments inline
"anton bassov" <xxx@xxxxxxx> wrote in message
news:e6175f5dc1d6472ca28f493e403cae0a@xxxxxxxxxxxxxx
Hi Don

You said that using events is the only scheme that is worth
consideration -
according to you,polling is just a waste of CPU time.

We have "clashed" on quite a few occasions when it comes to
"unsupported" stuff, and I even said that, apparently, you had had some
unpleasant experience with it. Now I see the possible explanation.

I would say that, as a general rule, the less the system knows about your
"unsupported" tricks, the better it is for you. Therefore, it is always a
good idea to make the system believe that nothing is happening.

Well, first I recomended against sharing the buffer period. Sharing an
event between the kernel and user space is documented by Microsoft and there
have be Microsoft provided samples for 10 years so I believe they will be
hard pressed to eliminate it.

Look at how I presented the polling option
while(1)
{
KeDelayExecutionThread();
...check the state of some variable that is available to user mode..
}

In the above example, there is no synchronization between driver and
application whatsoever, at least as far as the system is concerned. We do
waste few CPU cycles here, I don't argue about it. However, overhead is
not
that high, and, as far as I understand, performance is not the primary
concern here - otherwise, the bloke would not even think about making his
driver wait for user-mode application, would he??? Therefore, I would say
that,in terms of performance, the above approach is not much worse than
using events

Of course the above as you point out will have poor performance, and the
only reason anyone would share a buffer is for performance. If you are
doing it for an approach with slow performance then you are ignoring the
Windows model, that is just poor design. With the design you gain nothing,
but add complexity including making very hard for the next poor developer
who has to pick it up.


The ULTIMATE advantage of such approach is that, unlike the scheme that
relies upon events, our code cannot be broken by any system update.
Imagine
what happens if some future release prohibits using
ObReferenceObjectByHandle()on handles that have been opened by user-mode
code (currently the system just disallows to use these handles directly,
but,
in order to close the loophole, it may prohibit passing them to
ObReferenceObjectByHandle()as well).
However, it cannot do anything about KeDelayExecutionThread()and checking
the variable.

To summarize, when you try some hack, don't tell the system about it - it
increases reliability of your code dramatically


The claim of not telling the system, is very similar to some developers who
roll their own for things like spin locks and other kernel functions. Most
of the time they do not get the performance or compatibility they wanted,
but waste a lot of time and memory. One client I helped had such a driver,
it was 60000 lines of crap that dropped to below 8000 lines once we started
using the kernel calls, with WDF it would have shrunk significanly again.


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply



.



Relevant Pages

  • Re: Mutual Exclusion for shared Buffer b/n User and Kernel
    ... You said that using events is the only scheme that is worth consideration - ... according to you,polling is just a waste of CPU time. ... ObReferenceObjectByHandleon handles that have been opened by user-mode ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Nvidia driver fails to compile on kernel 3.X
    ... the kernel config file. ... Since Nov 5 I kick installing the driver to 3.0.7-rt20. ... For my needs this "waste" is good enough to build a stable Linux ...
    (Debian-User)
  • Galileo Masters competition results
    ... Electro-car public transport and a scheme to track the proper disposal of waste ... are two of smartest ideas for using satellite-navigation technology. ...
    (sci.geo.satellite-nav)
  • Re: malloc : just to be sure
    ... so just to be sure and not waste more hours on this: ... can i use malloc in a driver like in a normal user-process? ... but I notice that you are posting using Google Groups. ...
    (comp.os.minix)
  • Re: " DRIVER DETECTIVE "
    ... Driver detective is a pure waste of time and money. ... Should have read the reviews before spending 30 bucks on this waste of time. ... I'm having problems with my audio driver so I downloaded this software to fix it. ...
    (microsoft.public.windowsxp.general)