From patchwork Sat Nov 7 01:50:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 7574591 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7FFC19F4F5 for ; Sat, 7 Nov 2015 01:51:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 970B62071E for ; Sat, 7 Nov 2015 01:51:23 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B9FCC206B8 for ; Sat, 7 Nov 2015 01:51:22 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zusf3-0002os-1X; Sat, 07 Nov 2015 01:51:21 +0000 Received: from mail-pa0-x22b.google.com ([2607:f8b0:400e:c03::22b]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zusf0-0002ml-DR for linux-rockchip@lists.infradead.org; Sat, 07 Nov 2015 01:51:19 +0000 Received: by padhx2 with SMTP id hx2so130978452pad.1 for ; Fri, 06 Nov 2015 17:50:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=Jx8+W2NnZV0A+yoRMZ61qntMtx6D7Dt8Xc3h8dDsH/0=; b=X+JmCTPCIkqnl3BPdhdDuOamJs8NPMCmXc9hPYNiaP93C877jJxEJeEr4xrdXa+7rD U1ywnKft5cbFxAjHjl2fKFzJ230zeDWyo+6WW1xAgCpKlx99jwmf6xAcmFSAPxOfO3+Y l8on3IIXFAHksH0jndIVI7gC4o2YCvt6pTWn0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-type:content-transfer-encoding; bh=Jx8+W2NnZV0A+yoRMZ61qntMtx6D7Dt8Xc3h8dDsH/0=; b=jZb5/hGMRjtvEEw7qE1rLAp12aBKQ0ucWcQeMmU3lkHcnfgZ11O4e40L0PI+a3WHTf dDWm3YXdn5fW6LH/y4SUP5wmnr0ZdcL22RRq5DXuWN9jvKEctU+B7jpV+AWjcacfhewy 3+4O2ErVOHNBI4rmooAFJxR8s1hw9iv6KoRoePdk5KkoWOaSFH3GEtQYcxAzGsk9mnXp 68YdwFA9Sz1Fn18b2q64ifHTR0jCRgtePkb+EAbnEGBWg0eQx07O1Q6bYqZtysfipr/R XsOHDALxaaJGoTuKPbt90hNEKw0fDa1VmYS/BxPHd7Uxdmvnjw7Ha2bxXJ9fWNOPejyh lP8g== X-Gm-Message-State: ALoCoQlzM9FSYgcIPFLbUClWQXukKL0U1FwchoEhYjqCpLXeddi9qD9ciDDdbYd/3kAGvQjvJnt7 X-Received: by 10.68.134.1 with SMTP id pg1mr22016145pbb.133.1446861057078; Fri, 06 Nov 2015 17:50:57 -0800 (PST) Received: from tictac.mtv.corp.google.com ([172.22.65.76]) by smtp.gmail.com with ESMTPSA id ea1sm2355093pbb.76.2015.11.06.17.50.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 Nov 2015 17:50:56 -0800 (PST) From: Douglas Anderson To: John Youn , balbi@ti.com Subject: [RFC PATCH] usb: dwc2: host: Rewrite the microframe scheduler Date: Fri, 6 Nov 2015 17:50:51 -0800 Message-Id: <1446861051-20135-1-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 2.6.0.rc2.230.g3dd15c0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151106_175118_500177_473C33A1 X-CRM114-Status: GOOD ( 17.03 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: gregory.herrero@intel.com, =?UTF-8?q?Heiko=20St=C3=BCbner?= , johnyoun@synopsys.com, gregkh@linuxfoundation.org, ming.lei@canonical.com, linux-usb@vger.kernel.org, Douglas Anderson , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, yousaf.kaukab@intel.com, stern@rowland.harvard.edu, Yunzhi Li , Julius Werner , dinguyen@opensource.altera.com Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The old microframe scheduler was terribly hard to follow and (it seemed to me) that it had some bugs in it. Let's re-write it in a simpler, easier-to-read way. Hopefully this will work better. Note: no known problems are fixed by this patch, and in fact I can see very little impact of the microframe scheduler overall. Signed-off-by: Douglas Anderson --- drivers/usb/dwc2/hcd_queue.c | 72 ++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 40 deletions(-) diff --git a/drivers/usb/dwc2/hcd_queue.c b/drivers/usb/dwc2/hcd_queue.c index 7d8d06cfe3c1..d6c24decee08 100644 --- a/drivers/usb/dwc2/hcd_queue.c +++ b/drivers/usb/dwc2/hcd_queue.c @@ -359,57 +359,49 @@ static int dwc2_find_single_uframe(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) */ static int dwc2_find_multi_uframe(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) { - unsigned short utime = qh->usecs; - unsigned short xtime; - int t_left; + int utime; int i; int j; - int k; for (i = 0; i < 8; i++) { if (hsotg->frame_usecs[i] <= 0) continue; - /* - * we need n consecutive slots so use j as a start slot - * j plus j+1 must be enough time (for now) - */ - xtime = hsotg->frame_usecs[i]; - for (j = i + 1; j < 8; j++) { + for (utime = qh->usecs, j = i; utime > 0 && j < 8; j++) { + /* Give the available time from this uframe */ + utime -= hsotg->frame_usecs[j]; + /* - * if we add this frame remaining time to xtime we may - * be OK, if not we need to test j for a complete frame + * Except for first frame, we can't continue past this + * frame if it wasn't full, so bail now. We might still + * be successful the above subtract made utime <= 0. */ - if (xtime + hsotg->frame_usecs[j] < utime) { - if (hsotg->frame_usecs[j] < - max_uframe_usecs[j]) - continue; - } - if (xtime >= utime) { - t_left = utime; - for (k = i; k < 8; k++) { - t_left -= hsotg->frame_usecs[k]; - if (t_left <= 0) { - qh->frame_usecs[k] += - hsotg->frame_usecs[k] - + t_left; - hsotg->frame_usecs[k] = -t_left; - return i; - } else { - qh->frame_usecs[k] += - hsotg->frame_usecs[k]; - hsotg->frame_usecs[k] = 0; - } - } - } - /* add the frame time to x time */ - xtime += hsotg->frame_usecs[j]; - /* we must have a fully available next frame or break */ - if (xtime < utime && - hsotg->frame_usecs[j] == max_uframe_usecs[j]) - continue; + if ((i != j) && + (hsotg->frame_usecs[j] < max_uframe_usecs[j])) + break; + } + + /* If utime > 0 after above loop, try a different start (i) */ + if (utime > 0) + continue; + + dev_dbg(hsotg->dev, "Assigned %d us starting at i=%d + %d us\n", + qh->usecs, i, + max_uframe_usecs[i] - hsotg->frame_usecs[i]); + + /* We've got success, so allocate */ + for (utime = qh->usecs, j = i; utime > 0 && j < 8; j++) { + qh->frame_usecs[i] = min_t(u16, utime, + hsotg->frame_usecs[j]); + utime -= qh->frame_usecs[i]; + hsotg->frame_usecs[j] -= qh->frame_usecs[i]; } + + return i; } + + dev_dbg(hsotg->dev, "Failed to assign %d us\n", qh->usecs); + return -ENOSPC; }