USB2 patches

Hans Petter Selasky hselasky at c2i.net
Sun Feb 1 11:29:33 PST 2009


On Sunday 01 February 2009, Andrew Thompson wrote:
> On Sun, Feb 01, 2009 at 08:01:05PM +0100, Hans Petter Selasky wrote:
> > Hi Andrew,
> >
> > Regarding using taskqueues.
> >
> > Yes - USB2 can use taskqueues, but I would very much like to have the
> > original queueing mechanism intact.
>
> Can you explain this further? What is t0 vs t1?
>
> A taskqueue will execute tasks sequentially, 

Hi Andrew,

I've looked in the taskqueue code:

        if (task->ta_pending) {
                task->ta_pending++;
                TQ_UNLOCK(queue);
                return 0;
        }

Take the following for example. Now you changed it a little bit, but I see 
similar issues where other commands are involved:

1) queue DTR on cmd
2) queue DTR off cmd
3) queue DTR on cmd

Using the taskqueue there is no guarantee that the last command queued is the 
last command executed! That is dangerous! Because the existing taskqueue 
enqueue will only increment the pending count and return, if the command/task 
is already queued.

In the example above you can end up like this:

DTR on (pending = 2)
DTR off (pending = 1)

This is not correct. The queuing mechanism in USB2 guarantees that the last 
queued command is last executed:

DTR on (first callback)
DTR off (first callback)
DTR on (second callback)

Queuing:

1) queue DTR on cmd
2) queue DTR off cmd
3) queue DTR on cmd
...
N) queue DTR XXX cmd

Results in:

1) DTR on (first callback)
2) DTR off (first callback
...
M) DTR XXX (second callback)

If the user application is faster than USB "M" count is not the same like "N" 
count, of course.

--HPS


More information about the freebsd-usb mailing list