Alan Stern wrote:
Everyone has convinced me that there's no point in making usbdev->serialize an rw-semaphore, so that's out. A big relief to some people, no doubt :-)

I still have a problem with marking devices as soon as we know they are
unplugged.  Even using David's scheme where this is done using a separate
unprotected flag in struct usb_device, I can't see any way to make it work
without introducing a new lock.

Hmm, I seem to recall hearing more approval of the variant that uses a spinlock to protect the flag during dev->state transitions.

In fact, the requirements you list below are a great match for
a spinlock:  virtually no contention (connect and disconnect are
rare), no heavy work to be done (no kmalloc etc), clearly defined
scope (protects a data structure tree, for one brief shining moment).

So the disconnect would be "grab the lock, walk the subtree being
disconnected and mark everything disconnected, down_trylock() to
get dev->serialize and if it succeeds, mark it NOTATTACHED".  And
then schedule khubd disconnect processing for those devices, to
unbind all the drivers and destroy all the devices.

- Dave


The problem is that when the "unplugged" flag is set for a hub, it must be
set recursively for all the children as well.  This requires reading
through the list of the hub's children, but it takes place asynchronously
with respect to other tasks that may be updating the list.  It's not
enough to say those other tasks should check the hub's unplugged flag
before they update anything; setting and checking a flag does not
constitute a true synchronization operation.  Either a spinlock or a
semaphore is required.

Basically the new lock would have to be held while adding or removing a
device from a hub's list of children and while the recursive
set-the-unplugged-flag takes place.  This doesn't seem likely to create a
lot of contention, but still, if anyone can think of a way to do this
without a lock I would be pleased to hear it.

Alan Stern






-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to