Re: [PATCH 5/5] usb_debug: EXPERIMENTAL - poll hcd device to forcewrites

From: Alan Stern
Date: Wed May 06 2009 - 15:25:15 EST


On Wed, 6 May 2009, Oliver Neukum wrote:

> Something a bit a like this:
>
> commit a02639fe7d3f9788263305cff0669eac91f54002
> Author: Oliver Neukum <oneukum@linux-d698.(none)>
> Date: Wed May 6 19:14:30 2009 +0200
>
> terrible implementation of usb serial write buffering

For algorithm discussions like this, I find reading code rather
difficult. English or pseudo-code presentations are a lot more
intelligible.

A little thought yielded the following algorithm. It assumes there is
a fixed set of URBs allocated, unlike what you have done. Does it make
sense to take this approach?

Let N be the total number of URBs allocated, each capable of holding up
to B bytes. Let NIF be the number of URBs in flight at any time, so
the number of available URBs is N - NIF. The number of available bytes
might be < (N - NIF)*B because the next URB might be partially full.

P is an adjustable parameter of the algorithm. For simplicity you can
take P = 1, but increasing P (any value below N is okay) would yield
reduced latency at the cost of more partially-filled URB submissions
(so possibly reduced throughput).

Write routine:
Copy bytes into the available URB buffers, submitting URBs as
they get filled. At the end, if the next URB is partially full
then submit it only if NIF < P.

Completion routine:
If the next URB to send is partially filled, submit it.

write_room routine:
Return the actual number of bytes remaining in the available
URBs, but no more than (N-P)*B.

How does that sound? Converting \n to \r\n will add some complication
but not too much.

Allocating URBs on the fly adds a lot of complication. There has to be
a minimum number of pre-allocated URBs; otherwise write_room could
never return a positive value. If you allocate additional URBs
later on, when would you free them?

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/