Jiri Kosina wrote: > On Tue, 3 Jul 2007, Felipe Balbi wrote: > >> So looks like we don't have (yet) a way to make it work nicely in both >> cases... does anyone has a clue about how to implement this one?? > > You of course still can > > local_irq_save(flags); > spin_lock(&some_lock); > ... > spin_unlock(&some_lock); > usb_hcd_giveback_urb(hcd, urb); > local_irq_restore(flags); > > which is safe even against future removal of preempt inc/dec from > spin_lock_irq{save,restore}() functions. >
Unfortunately that would not work in the RT case either. Because in RT, that spin_lock can schedule, and we are not allowed to schedule with interrupts disabled. What we could do that would work in all cases (but is butt-ugly) is the following: { DEFINE_SPINLOCK(local); unsigned long flags; spin_lock_irqsave(&local, flags); spin_lock(&some_lock); ... spin_unlock(&some_lock); usb_hcb_giveback_urb(hcd, urb); spin_unlock_irqrestore(&local, flags); } Because the "local" lock is on the stack, it will never be in contention. Which means that it basically acts like a local_irq_save. The benefit is that it also works in RT, because that case the interrupts would *not* be disabled in that entire path. For those that don't know, RT has interrupts running as threads, so the need here to disable interrupts is gone. I can send a note to Ingo, and see if he has better ideas. Perhaps there's a way that we can do a local_irq_restore that matches spinlocks. Maybe we can add a primitive of local_irqs_restore_from_spinlock(flags); This would document that the local_irq_save came from a spinlock as it will allow things like this to seamlessly change for RT. (/me decides to just add Ingo on this thread) -- Steve ------------------------------------------------------------------------- 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