On Fri, 30 Mar 2007, Oliver Neukum wrote:

> Am Freitag, 30. März 2007 22:59 schrieb David Brownell:
> > On Friday 30 March 2007 1:38 pm, Oliver Neukum wrote:
> > > Am Freitag, 30. März 2007 22:04 schrieb David Brownell:
> > > > Remember that if every completion callback does
> > > > 
> > > >         status = urb->status;
> > > > 
> > > > at the top, the urb->status issue will by definition go away.  That's
> > > 
> > > Only if it does smp_mb(), which is the whole point of this thread.
> > 
> > Nope.  If an smp_mb() is needed, the reason is because of other
> > driver-internal bugs.
> > 
> > Remember that the driver isn't allowed to so much as *LOOK* at any
> > field of an URB until the completion callback.  That generalizes:
> > it mustn't do so until that callback (cleanly) hands the URB back

While correct, this summary sort of glides over the important point, which 
is: How should the completion routine cleanly hand the URB back to the 
rest of the driver?

Oliver's point is that this:

        completion routine:
                printk("urb->status = %d\n", urb->status);
                private_data->urb_done = 1;

        rest of driver:
                while (!private_data->urb_done)
                        do_something_else();
                use(urb);

isn't clean -- but several drivers do it this way.  I'm not even certain 
that adding smp_mb() to the completion routine will really fix it; memory 
barriers have to be used in pairs, and so there would also need to be a 
barrier between the test of private_data->urb_done and the call to 
use(urb).

There still remains the question of how to do this cleanly.  Obviously 
some sort of synchronization primitive is needed.  wait_for_completion() 
includes all the necessary memory barriers, whereas wait_event() does not.
Or a spinlock could be used, although it would be somewhat awkward.

Alan Stern


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to