On Sat, 16 Apr 2005, Oliver Neukum wrote:

> A tasklet is useful only if you cannot enable interrupts because you are
> in hard irq context.

A tasklet can be useful for another reason.  Consider that even if an IRQ
handler does run with interrupts enabled, its own IRQ line still has to
remain disabled.  So any devices sharing the IRQ line are unable to
interrupt the CPU until the handler finishes.  With a tasklet, the handler 
finishes much sooner.

There are reasons for not enabling interrupts other than being in hard irq
context:

        You want to modify a data structure that other interrupt-time
        code also touches, so you don't want other interrupts to
        occur until you have finished the modifications.  (This applies
        just as well to code that's not in an interrupt handler.  You
        can think of this as a locking-related reason.)  If that other
        code can be moved into a tasklet, you win.

        Your caller has disabled interrupts and expects you to leave
        them disabled.  If you defer most of your work to a tasklet
        and return sooner, you win.

All of these reasons apply to uhci-hcd.

>  If you shift the existing enqueue code to a tasklet
> you gain nothing, because the spinlocks need to block irqs.

You're assuming that the tasklet needs to acquire the same spinlock as the
existing code and for the same length of time.  If you shift the enqueue
code to a tasklet and make the tasklet avoid the spinlock as much as
possible, then you do gain something.

> If you change the locking there you don't need a tasklet.

The locking in enqueue can't be changed, for the reasons mentioned above.

Perhaps you don't fully understand what's being planned here.  Right now
enqueue, dequeue, and uhci_irq all need to hold the spinlock with
interrupts disabled because they need to protect against each other.  But
if the three of them were moved almost entirely into a single tasklet, the
tasklet wouldn't need to protect against anything but the stubs remaining
in enqueue, dequeue, and uhci_irq.  (In particular, it wouldn't need to
protect against itself.)  So the total time spent in the tasklet with
interrupts disabled would be very low.

Alan Stern



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&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