qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: Hans de Goede <hdegoede@redhat.com>, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 08/22] ehci: Retry to fill the queue while waiting for td completion
Date: Wed, 24 Oct 2012 18:14:04 +0200	[thread overview]
Message-ID: <1351095258-5579-9-git-send-email-hdegoede@redhat.com> (raw)
In-Reply-To: <1351095258-5579-1-git-send-email-hdegoede@redhat.com>

If the guest is using multiple transfers to try and keep the usb bus busy /
used at maximum efficiency, currently we would see / do the following:

1) submit transfer 1 to the device
2) submit transfer 2 to the device
3) report transfer 1 completion to guest
4) report transfer 2 completion to guest
5) submit transfer 1 to the device
6) report transfer 1 completion to guest
7) submit transfer 2 to the device
8) report transfer 2 completion to guest
etc.

So after the initial submission we would effectively only have 1 transfer
in flight, rather then 2. This is caused by us not checking the queue for
addition of new transfers by the guest (ie the resubmission of a recently
finished transfer), while waiting for a pending transfer to complete.
This patch does add a check for this, changing the sequence to:

1) submit transfer 1 to the device
2) submit transfer 2 to the device
3) report transfer 1 completion to guest
4) submit transfer 1 to the device
5) report transfer 2 completion to guest
6) submit transfer 2 to the device
etc.

Thus keeping 2 transfers in flight (most of the time, and always 1),
as intended by the guest.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 hw/usb/hcd-ehci.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index c906ab8..ad52850 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -381,7 +381,7 @@ struct EHCIQueue {
     uint32_t qhaddr;       /* address QH read from                 */
     uint32_t qtdaddr;      /* address QTD read from                */
     USBDevice *dev;
-    QTAILQ_HEAD(, EHCIPacket) packets;
+    QTAILQ_HEAD(pkts_head, EHCIPacket) packets;
 };
 
 typedef QTAILQ_HEAD(EHCIQueueHead, EHCIQueue) EHCIQueueHead;
@@ -488,6 +488,7 @@ static const char *ehci_mmio_names[] = {
 
 static int ehci_state_executing(EHCIQueue *q);
 static int ehci_state_writeback(EHCIQueue *q);
+static int ehci_fill_queue(EHCIPacket *p);
 
 static const char *nr2str(const char **n, size_t len, uint32_t nr)
 {
@@ -1993,7 +1994,7 @@ static int ehci_state_fetchqtd(EHCIQueue *q)
 {
     EHCIqtd qtd;
     EHCIPacket *p;
-    int again = 0;
+    int again = 1;
 
     get_dwords(q->ehci, NLPTR_GET(q->qtdaddr), (uint32_t *) &qtd,
                sizeof(EHCIqtd) >> 2);
@@ -2021,7 +2022,6 @@ static int ehci_state_fetchqtd(EHCIQueue *q)
             p = NULL;
         }
         ehci_set_state(q->ehci, q->async, EST_HORIZONTALQH);
-        again = 1;
     } else if (p != NULL) {
         switch (p->async) {
         case EHCI_ASYNC_NONE:
@@ -2030,6 +2030,9 @@ static int ehci_state_fetchqtd(EHCIQueue *q)
             ehci_set_state(q->ehci, q->async, EST_EXECUTE);
             break;
         case EHCI_ASYNC_INFLIGHT:
+            /* Check if the guest has added new tds to the queue */
+            again = (ehci_fill_queue(QTAILQ_LAST(&q->packets, pkts_head)) ==
+                     USB_RET_PROCERR) ? -1 : 1;
             /* Unfinished async handled packet, go horizontal */
             ehci_set_state(q->ehci, q->async, EST_HORIZONTALQH);
             break;
@@ -2041,13 +2044,11 @@ static int ehci_state_fetchqtd(EHCIQueue *q)
             ehci_set_state(q->ehci, q->async, EST_EXECUTING);
             break;
         }
-        again = 1;
     } else {
         p = ehci_alloc_packet(q);
         p->qtdaddr = q->qtdaddr;
         p->qtd = qtd;
         ehci_set_state(q->ehci, q->async, EST_EXECUTE);
-        again = 1;
     }
 
     return again;
-- 
1.7.12.1

  parent reply	other threads:[~2012-10-24 16:13 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-24 16:13 [Qemu-devel] usb: input-pipelining + speedups v3 Hans de Goede
2012-10-24 16:13 ` [Qemu-devel] [PATCH 01/22] uhci: Properly unmap packets on cancel / invalid pid Hans de Goede
2012-10-24 16:13 ` [Qemu-devel] [PATCH 02/22] uhci: Move checks to continue queuing to uhci_fill_queue() Hans de Goede
2012-10-24 16:13 ` [Qemu-devel] [PATCH 03/22] ehci: Get rid of packet tbytes field Hans de Goede
2012-10-24 16:14 ` [Qemu-devel] [PATCH 04/22] ehci: Set int flag on a short input packet Hans de Goede
2012-10-24 16:14 ` [Qemu-devel] [PATCH 05/22] ehci: Improve latency of interrupt delivery and async schedule scanning Hans de Goede
2012-10-24 16:14 ` [Qemu-devel] [PATCH 06/22] ehci: Speed up the timer of raising int from the async schedule Hans de Goede
2012-10-24 16:14 ` [Qemu-devel] [PATCH 07/22] ehci: Detect going in circles when filling the queue Hans de Goede
2012-10-24 16:14 ` Hans de Goede [this message]
2012-10-24 16:14 ` [Qemu-devel] [PATCH 09/22] xhci: Add a xhci_ep_nuke_one_xfer helper function Hans de Goede
2012-10-24 16:14 ` [Qemu-devel] [PATCH 10/22] usb: Rename __usb_packet_complete to usb_packet_complete_one Hans de Goede
2012-10-24 16:14 ` [Qemu-devel] [PATCH 11/22] usb: Add USB_RET_ADD_TO_QUEUE packet result code Hans de Goede
2012-10-24 16:14 ` [Qemu-devel] [PATCH 12/22] usb: Move clearing of queue on halt to the core Hans de Goede
2012-10-24 16:14 ` [Qemu-devel] [PATCH 13/22] usb: Move short-not-ok handling " Hans de Goede
2012-10-24 16:14 ` [Qemu-devel] [PATCH 14/22] usb: Add an int_req flag to USBPacket Hans de Goede
2012-10-24 16:14 ` [Qemu-devel] [PATCH 15/22] usb: Add packet combining functions Hans de Goede
2012-10-25  6:55   ` Gerd Hoffmann
2012-10-30 13:23     ` Hans de Goede
2012-10-30 13:25       ` Hans de Goede
2012-10-30 13:38       ` Hans de Goede
2012-10-24 16:14 ` [Qemu-devel] [PATCH 16/22] combined-packet: Add a workaround for Linux usbfs + live migration Hans de Goede
2012-10-24 16:14 ` [Qemu-devel] [PATCH 17/22] usb-redir: Add support for 32 bits bulk packet length Hans de Goede
2012-10-24 16:14 ` [Qemu-devel] [PATCH 18/22] usb-redir: Add support for input pipelining Hans de Goede
2012-10-24 16:14 ` [Qemu-devel] [PATCH 19/22] usb-redir: Add an usbredir_setup_usb_eps() helper function Hans de Goede
2012-10-24 16:14 ` [Qemu-devel] [PATCH 20/22] usb-redir: Use reject rather the disconnect on bad ep info Hans de Goede
2012-10-24 16:14 ` [Qemu-devel] [PATCH 21/22] usb-redir: Allow to attach USB 2.0 devices to 1.1 host controller Hans de Goede
2012-10-24 16:14 ` [Qemu-devel] [PATCH 22/22] usb-redir: Allow redirecting super speed devices to high speed controllers Hans de Goede
2012-10-25  7:13 ` [Qemu-devel] usb: input-pipelining + speedups v3 Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1351095258-5579-9-git-send-email-hdegoede@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).