Am Mittwoch, 25. April 2007 21:04 schrieb Alan Stern:
> On Tue, 24 Apr 2007, Oliver Neukum wrote:
> 
> > Am Dienstag, 24. April 2007 21:47 schrieb Alan Stern:
> > > On Tue, 24 Apr 2007, Oliver Neukum wrote:
> > > 
> > > > Hi,
> > > > 
> > > > some drivers'll need a lockless method to alter the pm count in order
> > > > to take locks by themselves in correct order.
> > > 
> > > (Minor comment: Acquiring the lock yourself to alter the pm count isn't
> > > quite the same as doing it locklessly.)
> > > 
> > > Can you give an example where this would be needed?  I can't think of one 
> > > offhand.
> > 
> > Certainly. I need this to do autosuspend for the storage driver.
> > 
> > usb_suspend()
> > usb_pm_lock(udev)
> > usb_suspend_both(udev)
> > storage:
> > storage_suspend()
> > mutex_lock(&us->dev_mutex);
> > 
> > The storage thread:
> > usb_stor_control_thread()
> > mutex_lock(&(us->dev_mutex));
> > usb_autopm_get_interface()
> > 
> > AB <-> BA deadlock
> 
> Yes, the problem is clear.  Presumably you want to change things to go
> like this:
> 
> usb_storage_control_thread():
> usb_pm_lock(us->pusb_dev);
> mutex_lock(&us->dev_mutex);
> if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) ...
> __usb_autopm_get_interface();
> usb_pm_unlock(us->pusb_dev);
> 
> Right?  I've been thinking about this exact same problem recently.  It
> affect every USB driver, in principle.  You might prefer the approach I 
> thought up; it involves adding a new mutex to struct us_data like so:
> 
> storage_suspend():
> mutex_lock(&us->suspend_mutex);
> 
> usb_stor_control_thread():
> mutex_lock(&us->dev_mutex);
> if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) ...
> usb_autopm_get_interface();
> mutex_lock(&us->suspend_mutex);
> 
> Either way is awkward, but mine is a little cleaner.  What do you think?

If you want me to think I can do that. If both solutions we come up
are awkward, we are doing something wrong. It seems to me we should
reduce the number of locks, not add new locks. Can we get rid of the
special pm lock, use a general lock and export that to the drivers?

        Regards
                Oliver

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
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