[Q] USB urb completion handler

Ezequiel Garcia elezegarcia at gmail.com
Wed May 23 22:41:26 EDT 2012


On Wed, May 23, 2012 at 10:44 PM, loody <miloody at gmail.com> wrote:
> take multi-core system for example, it is possible your completion
> handler execute at the same time, except you add a spin lock for
> activating your completion function.
>

That's the reason I'm asking in first place.
But if that is true, then it seems to me some drivers wouldn't be
working (unlikely, right?)

You can take a look at pwc completion for instance:

static void pwc_isoc_handler(struct urb *urb)
{
[snip]
        if (pdev->fill_buf == NULL)
                pdev->fill_buf = pwc_get_next_fill_buf(pdev);
---

As you can see, there is no lock here (though there is lock
to get the next fill_buf) and pdev->fill_buf is obviously not local.

On the other hand, em28xx has a tighter locking scheme:

static void em28xx_irq_callback(struct urb *urb)
{
[snip]
        /* Copy data from URB */
        spin_lock(&dev->slock);
        dev->isoc_ctl.isoc_copy(dev, urb);
        spin_unlock(&dev->slock);
---

Currently, I'm running a three core (yes three!) streaming at a high
rate and I'm following pwc locking (per queue). So far no races found (phew).

As a sidenote, em28xx locking can be improved for a very simple
reason: it's locking code instead of data.
Unfortunately, I don't own that hardware to fix and test such a patch.



More information about the Kernelnewbies mailing list