Blame 0160-ehci-Don-t-process-too-much-frames-in-1-timer-tick-v.patch

5544c1
From a5022829821b27e00790f8fe2fd9cd8090a47e36 Mon Sep 17 00:00:00 2001
93b7e3
From: Hans de Goede <hdegoede@redhat.com>
5544c1
Date: Mon, 10 Sep 2012 12:44:11 +0200
5544c1
Subject: [PATCH] ehci: Don't process too much frames in 1 timer tick (v2)
93b7e3
93b7e3
The Linux ehci isoc scheduling code fills the entire schedule ahead of
93b7e3
time minus 80 frames. If we make a large jump in where we are in the
93b7e3
schedule, ie 40 frames, then the scheduler all of a sudden will only have
93b7e3
40 frames left to work in, causing it to fail packet submissions
93b7e3
with error -27 (-EFBIG).
93b7e3
93b7e3
Changes in v2:
93b7e3
-Don't hardcode a maximum number of frames to process in one tick, instead:
93b7e3
 -Process a minimum number of frames to ensure we do eventually catch up
93b7e3
 -Stop (after the minimum number) when the guest has requested an irq
93b7e3
93b7e3
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
5544c1
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
5544c1
(cherry picked from commit 8f74ed1e43263293301031a10e440549bab19a6e)
5544c1
5544c1
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
93b7e3
---
93b7e3
 hw/usb/hcd-ehci.c | 14 ++++++++++++++
93b7e3
 1 file changed, 14 insertions(+)
93b7e3
93b7e3
diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
5544c1
index 54273d7..017a01d 100644
93b7e3
--- a/hw/usb/hcd-ehci.c
93b7e3
+++ b/hw/usb/hcd-ehci.c
93b7e3
@@ -139,6 +139,7 @@
93b7e3
 #define NB_PORTS         6        // Number of downstream ports
93b7e3
 #define BUFF_SIZE        5*4096   // Max bytes to transfer per transaction
93b7e3
 #define MAX_QH           100      // Max allowable queue heads in a chain
93b7e3
+#define MIN_FR_PER_TICK  3        // Min frames to process when catching up
93b7e3
 
93b7e3
 /*  Internal periodic / asynchronous schedule state machine states
93b7e3
  */
93b7e3
@@ -2448,6 +2449,19 @@ static void ehci_frame_timer(void *opaque)
93b7e3
         }
93b7e3
 
93b7e3
         for (i = 0; i < frames; i++) {
5544c1
+            /*
93b7e3
+             * If we're running behind schedule, we should not catch up
93b7e3
+             * too fast, as that will make some guests unhappy:
93b7e3
+             * 1) We must process a minimum of MIN_FR_PER_TICK frames,
93b7e3
+             *    otherwise we will never catch up
93b7e3
+             * 2) Process frames until the guest has requested an irq (IOC)
93b7e3
+             */
93b7e3
+            if (i >= MIN_FR_PER_TICK) {
93b7e3
+                ehci_commit_irq(ehci);
93b7e3
+                if ((ehci->usbsts & USBINTR_MASK) & ehci->usbintr) {
93b7e3
+                    break;
93b7e3
+                }
93b7e3
+            }
93b7e3
             ehci_update_frindex(ehci, 1);
93b7e3
             ehci_advance_periodic_state(ehci);
93b7e3
             ehci->last_run_ns += FRAME_TIMER_NS;
93b7e3
-- 
5544c1
1.7.12.1
93b7e3