From patchwork Tue Jan 10 13:13:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 135416 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 91DC8B6EF1 for ; Thu, 12 Jan 2012 03:17:59 +1100 (EST) Received: from localhost ([::1]:46561 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RkzhM-0006Ji-FN for incoming@patchwork.ozlabs.org; Wed, 11 Jan 2012 10:02:44 -0500 Received: from eggs.gnu.org ([140.186.70.92]:60346) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RkbUm-0004cF-6n for qemu-devel@nongnu.org; Tue, 10 Jan 2012 08:12:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RkbUe-00006B-Qa for qemu-devel@nongnu.org; Tue, 10 Jan 2012 08:12:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:30341) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RkbUe-000066-Ho for qemu-devel@nongnu.org; Tue, 10 Jan 2012 08:12:00 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q0ADBxtX022474 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 10 Jan 2012 08:12:00 -0500 Received: from shalem.localdomain.com (vpn1-5-237.ams2.redhat.com [10.36.5.237]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q0ADBv5O003302; Tue, 10 Jan 2012 08:11:58 -0500 From: Hans de Goede To: Gerd Hoffmann Date: Tue, 10 Jan 2012 14:13:05 +0100 Message-Id: <1326201188-13478-2-git-send-email-hdegoede@redhat.com> In-Reply-To: <1326201188-13478-1-git-send-email-hdegoede@redhat.com> References: <1326201188-13478-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 X-Mailman-Approved-At: Wed, 11 Jan 2012 10:01:15 -0500 Cc: Hans de Goede , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 2/5] usb-redir: Dynamically adjust iso buffering size based on ep interval X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Note the bufpq_target_size id stored in the endpoint info struct, even though it only used once. This is done because it will be referenced from other code in a follow up patch. Signed-off-by: Hans de Goede --- usb-redir.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 48 insertions(+), 5 deletions(-) diff --git a/usb-redir.c b/usb-redir.c index 7678f1a..76cae16 100644 --- a/usb-redir.c +++ b/usb-redir.c @@ -61,6 +61,7 @@ struct endp_data { uint8_t interrupt_started; uint8_t interrupt_error; QTAILQ_HEAD(, buf_packet) bufpq; + int bufpq_target_size; }; struct USBRedirDevice { @@ -332,15 +333,42 @@ static int usbredir_handle_iso_data(USBRedirDevice *dev, USBPacket *p, uint8_t ep) { int status, len; - if (!dev->endpoint[EP2I(ep)].iso_started && !dev->endpoint[EP2I(ep)].iso_error) { struct usb_redir_start_iso_stream_header start_iso = { .endpoint = ep, - /* TODO maybe do something with these depending on ep interval? */ - .pkts_per_urb = 32, - .no_urbs = 3, }; + int pkts_per_sec; + + if (dev->dev.speed == USB_SPEED_HIGH) { + pkts_per_sec = 8000 / dev->endpoint[EP2I(ep)].interval; + } else { + pkts_per_sec = 1000 / dev->endpoint[EP2I(ep)].interval; + } + /* Testing has shown that we need circa 60 ms buffer */ + dev->endpoint[EP2I(ep)].bufpq_target_size = (pkts_per_sec * 60) / 1000; + + /* Aim for approx 100 interrupts / second on the client to + balance latency and interrupt load */ + start_iso.pkts_per_urb = pkts_per_sec / 100; + if (start_iso.pkts_per_urb < 1) { + start_iso.pkts_per_urb = 1; + } else if (start_iso.pkts_per_urb > 32) { + start_iso.pkts_per_urb = 32; + } + + start_iso.no_urbs = (dev->endpoint[EP2I(ep)].bufpq_target_size + + start_iso.pkts_per_urb - 1) / + start_iso.pkts_per_urb; + /* Output endpoints pre-fill only 1/2 of the packets, keeping the rest + as overflow buffer. Also see the usbredir protocol documentation */ + if (!(ep & USB_DIR_IN)) { + start_iso.no_urbs *= 2; + } + if (start_iso.no_urbs > 16) { + start_iso.no_urbs = 16; + } + /* No id, we look at the ep when receiving a status back */ usbredirparser_send_start_iso_stream(dev->parser, 0, &start_iso); usbredirparser_do_write(dev->parser); @@ -961,9 +989,24 @@ static void usbredir_ep_info(void *priv, dev->endpoint[i].type = ep_info->type[i]; dev->endpoint[i].interval = ep_info->interval[i]; dev->endpoint[i].interface = ep_info->interface[i]; - if (dev->endpoint[i].type != usb_redir_type_invalid) { + switch (dev->endpoint[i].type) { + case usb_redir_type_invalid: + break; + case usb_redir_type_iso: + case usb_redir_type_interrupt: + if (dev->endpoint[i].interval == 0) { + ERROR("Received 0 interval for isoc or irq endpoint\n"); + usbredir_device_disconnect(dev); + } + /* Fall through */ + case usb_redir_type_control: + case usb_redir_type_bulk: DPRINTF("ep: %02X type: %d interface: %d\n", I2EP(i), dev->endpoint[i].type, dev->endpoint[i].interface); + break; + default: + ERROR("Received invalid endpoint type\n"); + usbredir_device_disconnect(dev); } } }