On Sat, 26 Nov 2005 22:06:58 +0100, Pavel Machek <[EMAIL PROTECTED]> wrote:

> > >  It uses 'volatile' quite heavily, and that scares me a lot.
> > 
> > Alan Cox didn't like it either, but he wasn't able to give a clear 
> > explanation why not.  He just mumbled something about C compilers 
> > generating bad code for volatiles...

Alan, the "volatile" keyword has no meaning in kernel and should never be
used (most especially not in drivers). It is defined in context of
single-threaded computation interrupted by signals, so it has no sense
where SMP is involved. I have no idea why he "mumbled" about it,
the situation is pretty clear. Maybe your ignorance irritated him
into a terse oneliner.

If Pavel is willing to clean that up, more power to him. HOWEVER,
it usually is not correct to do  :%s/volatile//g
If an author used "volatile", he/she meant something by it.
Usually it signals a bigger problem with the locking scheme.

> Do you realize that it is okay for compiler to move assignment into
> context before increase of req_tag? What you probably want is
> 
>         ++fsg->ep0_req_tag;             // Record arrival of a new request
>       mb();
>         fsg->ep0req->context = NULL;
>         fsg->ep0req->length = 0;
>         dump_msg(fsg, "ep0-setup", (u8 *) ctrl, sizeof(*ctrl));
> 
> ...or something like that. Or perhaps atomic_inc(), that should have
> some barriers built-in.

This suggestion assumes that the author knew what he was doing.
If so, the replacement with atomic is usually sufficient. Otherwise,
a much wider bracket is in order, with a spinlock.

I try to avoid explicit barriers, because I always get in trouble
with them on preempt kernels. It is often very tricky. Pavel is right,
correct barriers are built into locking primitives.

In our little USB cabal, I found Oliver to have a very keen ability to
see locking, timing, and data sharing deficiencies. If you can engage
his attention, he'll wipe off your volatiles out easily.

-- Pete


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to