Commit 98b74b0e authored by David Mosberger's avatar David Mosberger Committed by Greg Kroah-Hartman

drivers: usb: core: Don't disable irqs in usb_sg_wait() during URB submit.

usb_submit_urb() may take quite long to execute.  For example, a
single sg list may have 30 or more entries, possibly leading to that
many calls to DMA-map pages.  This can cause interrupt latency of
several hundred micro-seconds.

Avoid the problem by releasing the io->lock spinlock and re-enabling
interrupts before calling usb_submit_urb().  This opens races with
usb_sg_cancel() and sg_complete().  Handle those races by using
usb_block_urb() to stop URBs from being submitted after
usb_sg_cancel() or sg_complete() with error.

Note that usb_unlink_urb() is guaranteed to return -ENODEV if
!io->urbs[i]->dev and since the -ENODEV case is already handled,
we don't have to check for !io->urbs[i]->dev explicitly.

Before this change, reading 512MB from an ext3 filesystem on a USB
memory stick showed a throughput of 12 MB/s with about 500 missed
deadlines.

With this change, reading the same file gave the same throughput but
only one or two missed deadlines.
Signed-off-by: default avatarDavid Mosberger <davidm@egauge.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9360575c
...@@ -302,9 +302,10 @@ static void sg_complete(struct urb *urb) ...@@ -302,9 +302,10 @@ static void sg_complete(struct urb *urb)
*/ */
spin_unlock(&io->lock); spin_unlock(&io->lock);
for (i = 0, found = 0; i < io->entries; i++) { for (i = 0, found = 0; i < io->entries; i++) {
if (!io->urbs[i] || !io->urbs[i]->dev) if (!io->urbs[i])
continue; continue;
if (found) { if (found) {
usb_block_urb(io->urbs[i]);
retval = usb_unlink_urb(io->urbs[i]); retval = usb_unlink_urb(io->urbs[i]);
if (retval != -EINPROGRESS && if (retval != -EINPROGRESS &&
retval != -ENODEV && retval != -ENODEV &&
...@@ -515,12 +516,10 @@ void usb_sg_wait(struct usb_sg_request *io) ...@@ -515,12 +516,10 @@ void usb_sg_wait(struct usb_sg_request *io)
int retval; int retval;
io->urbs[i]->dev = io->dev; io->urbs[i]->dev = io->dev;
retval = usb_submit_urb(io->urbs[i], GFP_ATOMIC);
/* after we submit, let completions or cancellations fire;
* we handshake using io->status.
*/
spin_unlock_irq(&io->lock); spin_unlock_irq(&io->lock);
retval = usb_submit_urb(io->urbs[i], GFP_NOIO);
switch (retval) { switch (retval) {
/* maybe we retrying will recover */ /* maybe we retrying will recover */
case -ENXIO: /* hc didn't queue this one */ case -ENXIO: /* hc didn't queue this one */
...@@ -590,8 +589,8 @@ void usb_sg_cancel(struct usb_sg_request *io) ...@@ -590,8 +589,8 @@ void usb_sg_cancel(struct usb_sg_request *io)
for (i = 0; i < io->entries; i++) { for (i = 0; i < io->entries; i++) {
int retval; int retval;
if (!io->urbs[i]->dev) usb_block_urb(io->urbs[i]);
continue;
retval = usb_unlink_urb(io->urbs[i]); retval = usb_unlink_urb(io->urbs[i]);
if (retval != -EINPROGRESS if (retval != -EINPROGRESS
&& retval != -ENODEV && retval != -ENODEV
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment