From 5c589a67f1e36b86a92f3ea18638dea5b4679830 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Fri, 21 Sep 2012 18:57:29 -0300
Subject: [RHEL6 qemu-kvm PATCH 08/23] ehci: rework frame skipping

RH-Author: Hans de Goede <hdegoede@redhat.com>
Message-id: <1348253864-3050-8-git-send-email-hdegoede@redhat.com>
Patchwork-id: 42184
O-Subject: [RHEL-6.4 qemu-kvm PATCH 07/22] ehci: rework frame skipping
Bugzilla: 805172
RH-Acked-by: Uri Lublin <uril@redhat.com>
RH-Acked-by: Arnon Gilboa <agilboa@redhat.com>
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>

From: Gerd Hoffmann <kraxel@redhat.com>

Move the framecount check out of the loop and use the new
ehci_update_frindex function to skip frames if needed.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Upstream commit: f020ed36fef7780e81a94543ae6388d8dc144ab6
Conflicts: hw/usb-ehci.c
---
 hw/usb-ehci.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/usb-ehci.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/hw/usb-ehci.c b/hw/usb-ehci.c
index d86a526..0f23fdd 100644
--- a/hw/usb-ehci.c
+++ b/hw/usb-ehci.c
@@ -2142,11 +2142,9 @@ static void ehci_frame_timer(void *opaque)
     EHCIState *ehci = opaque;
     int64_t expire_time, t_now;
     int usec_elapsed;
-    int frames;
+    int frames, skipped_frames;
     int usec_now;
     int i;
-    int skipped_frames = 0;
-
 
     t_now = qemu_get_clock(vm_clock);
     expire_time = t_now + (get_ticks_per_sec() / ehci->freq);
@@ -2159,24 +2157,20 @@ static void ehci_frame_timer(void *opaque)
     frames = usec_elapsed / FRAME_TIMER_USEC;
     ehci->frame_end_usec = usec_now + FRAME_TIMER_USEC - 10;
 
+    if (frames > ehci->maxframes) {
+        skipped_frames = frames - ehci->maxframes;
+        ehci_update_frindex(ehci, skipped_frames);
+        ehci->last_run_usec += FRAME_TIMER_USEC * skipped_frames;
+        frames -= skipped_frames;
+        DPRINTF("WARNING - EHCI skipped %d frames\n", skipped_frames);
+    }
+
     for (i = 0; i < frames; i++) {
         ehci_update_frindex(ehci, 1);
-
-        if (frames - i > ehci->maxframes) {
-            skipped_frames++;
-        } else {
-            ehci_advance_periodic_state(ehci);
-        }
-
+        ehci_advance_periodic_state(ehci);
         ehci->last_run_usec += FRAME_TIMER_USEC;
     }
 
-#if 0
-    if (skipped_frames) {
-        DPRINTF("WARNING - EHCI skipped %d frames\n", skipped_frames);
-    }
-#endif
-
     /*  Async is not inside loop since it executes everything it can once
      *  called
      */
-- 
1.7.11.4

