From patchwork Tue Nov 6 14:08:18 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: 197487 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D61C52C00BA for ; Wed, 7 Nov 2012 01:44:14 +1100 (EST) Received: from localhost ([::1]:56681 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TVjpI-0006yp-9R for incoming@patchwork.ozlabs.org; Tue, 06 Nov 2012 09:08:24 -0500 Received: from eggs.gnu.org ([208.118.235.92]:40868) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TVjof-0005SR-5o for qemu-devel@nongnu.org; Tue, 06 Nov 2012 09:07:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TVjoZ-00058M-6B for qemu-devel@nongnu.org; Tue, 06 Nov 2012 09:07:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:31116) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TVjoY-00058B-U8 for qemu-devel@nongnu.org; Tue, 06 Nov 2012 09:07:39 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qA6E7Yba010410 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 6 Nov 2012 09:07:38 -0500 Received: from localhost.localdomain.com (ovpn-112-29.ams2.redhat.com [10.36.112.29]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qA6E7MeJ012920; Tue, 6 Nov 2012 09:07:33 -0500 From: Hans de Goede To: Gerd Hoffmann Date: Tue, 6 Nov 2012 15:08:18 +0100 Message-Id: <1352210901-1923-6-git-send-email-hdegoede@redhat.com> In-Reply-To: <1352210901-1923-1-git-send-email-hdegoede@redhat.com> References: <1352210901-1923-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Hans de Goede , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 5/8] ehci: Lower timer freq when there are no iso packets in the periodic schedule 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 If there are no iso packets in the periodic schedule, then there can only be interrupt packets there, and for these usb-devices either return nak, meaning that the executing state will get passed every frame, causing async_stepdown to stay 0, or they are handled async, and then ehci_frame_timer will get called immediately from a bh, thus not introducing any latency to async handled interrupt packets. The advantage of this is that when we only have async handled interrupt packets in the periodic schedule, async_stepdown can do its work and significantly lower the frequency at which the frame_timer runs. Signed-off-by: Hans de Goede --- hw/usb/hcd-ehci.c | 18 ++++++++++++++---- hw/usb/hcd-ehci.h | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c index ee6c9ae..b804474 100644 --- a/hw/usb/hcd-ehci.c +++ b/hw/usb/hcd-ehci.c @@ -114,6 +114,7 @@ #define BUFF_SIZE 5*4096 // Max bytes to transfer per transaction #define MAX_QH 100 // Max allowable queue heads in a chain #define MIN_FR_PER_TICK 3 // Min frames to process when catching up +#define ISO_ACTIVE_COUNT 64 /* Internal periodic / asynchronous schedule state machine states */ @@ -1325,6 +1326,8 @@ static int ehci_process_itd(EHCIState *ehci, uint32_t i, len, pid, dir, devaddr, endp; uint32_t pg, off, ptr1, ptr2, max, mult; + ehci->iso_active_counter = ISO_ACTIVE_COUNT; + dir =(itd->bufptr[1] & ITD_BUFPTR_DIRECTION); devaddr = get_field(itd->bufptr[0], ITD_BUFPTR_DEVADDR); endp = get_field(itd->bufptr[0], ITD_BUFPTR_EP); @@ -2157,9 +2160,12 @@ static void ehci_frame_timer(void *opaque) ns_elapsed = t_now - ehci->last_run_ns; frames = ns_elapsed / FRAME_TIMER_NS; + if (ehci->async_stepdown < ehci->maxframes / 2) { + ehci->async_stepdown++; + } + if (ehci_periodic_enabled(ehci) || ehci->pstate != EST_INACTIVE) { need_timer++; - ehci->async_stepdown = 0; if (frames > ehci->maxframes) { skipped_frames = frames - ehci->maxframes; @@ -2183,14 +2189,18 @@ static void ehci_frame_timer(void *opaque) break; } } + if (ehci->iso_active_counter) { + ehci->iso_active_counter--; + } ehci_update_frindex(ehci, 1); ehci_advance_periodic_state(ehci); ehci->last_run_ns += FRAME_TIMER_NS; } - } else { - if (ehci->async_stepdown < ehci->maxframes / 2) { - ehci->async_stepdown++; + + if (ehci->iso_active_counter) { + ehci->async_stepdown = 0; } + } else { ehci_update_frindex(ehci, frames); ehci->last_run_ns += FRAME_TIMER_NS * frames; } diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h index d8078f4..ed9d89c 100644 --- a/hw/usb/hcd-ehci.h +++ b/hw/usb/hcd-ehci.h @@ -311,6 +311,7 @@ struct EHCIState { uint64_t last_run_ns; uint32_t async_stepdown; + uint32_t iso_active_counter; bool int_req_by_async; };