From patchwork Tue Feb 19 15:41:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suwan Kim X-Patchwork-Id: 10820059 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EFEE3922 for ; Tue, 19 Feb 2019 15:41:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB0942C977 for ; Tue, 19 Feb 2019 15:41:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CDE3D2C97A; Tue, 19 Feb 2019 15:41:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 550102C977 for ; Tue, 19 Feb 2019 15:41:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726232AbfBSPlm (ORCPT ); Tue, 19 Feb 2019 10:41:42 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:33086 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725820AbfBSPlm (ORCPT ); Tue, 19 Feb 2019 10:41:42 -0500 Received: by mail-pl1-f196.google.com with SMTP id y10so10634970plp.0 for ; Tue, 19 Feb 2019 07:41:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=q5wdxYiTI3yrKaCY+Jc4QjY1zeNqaVwIZUhJq2JLvtc=; b=ldmyGrBbawGK+rsq9n1ncpiRo+U9EgMBSL0uvSInkzr1x5g10R7LQqFTJHmo2aiwG/ AVzIqKpxcoYbazvQB+nfIIKA14hgeopHtL4Q1Acgqu4FocVOGcQL5yvSSHZ+sBqFzbZ4 KWMcAkZOL3n9O7XIUxfjRbKPAlWACWg0qX3tsjvAVKirsLAujcaVM10E91yf3UBjYGb4 /8fkQ+ErSw98NyYMEcnRMOK29soHM9Upf5twMZJ3WuxlM3GLkD6iMbM6PwsdpSZRjInJ ElqvrK8LTICIOrXpc/6B6idW0ytSrgmeN58DLe3hC6CcO37vcXJkr/6XcTgaG93Yb1tg eGCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=q5wdxYiTI3yrKaCY+Jc4QjY1zeNqaVwIZUhJq2JLvtc=; b=C1wCBQPiTYDFhAv7sWjljiqrld9T7jLhEPYLY/Jlj8dWQ0WRpOj57dUxDGeTgrdTR4 Qwo/VcT7qF9HD/acd7ZiiWKyEvnlJ8pctPw8G4QDajx7GDsYtTYFyfpqKqWBuh4dlAEs JeL2JjiLXG6OVk8riUvhoRChZrmanIH19Cnbn6Ei3yUMf9ahsKnZRCf6zzItfMQBExVf S98lMktRa17b923GbNxMjOqhThKvTLSjBJ7MhO51NxDs5ZuTyuR1EiPrZTBHLUE0TWBn Y+fgCr9al+RbU5vzjX23T5vjqVvqyKeTcxmMhvHpBHF8nn8W/cfZeTQB0AUd5hUzufOt J83Q== X-Gm-Message-State: AHQUAubZCXEJC2LDfEjNvPVmTcZlypvSZKW+Q1lm8WkbtykEXF6N410c f7zTpOss10vWJWwIj6B8CjE= X-Google-Smtp-Source: AHgI3Iau6l4Oq1oNK0vKHAQPdcIiMZwvv/hREmGjCMJw6Ore0Sfrq8RXKWcEF7IWId15r7vO3cxGaw== X-Received: by 2002:a17:902:b01:: with SMTP id 1mr32033190plq.331.1550590901601; Tue, 19 Feb 2019 07:41:41 -0800 (PST) Received: from 192.168.nate.com ([2001:2d8:30c:60b8:649:ea79:95ac:1e0d]) by smtp.googlemail.com with ESMTPSA id k7sm4169676pgr.28.2019.02.19.07.41.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Feb 2019 07:41:41 -0800 (PST) From: Suwan Kim To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org Subject: [PATCH] usb: xhci: Support running urb giveback in tasklet context Date: Wed, 20 Feb 2019 00:41:35 +0900 Message-Id: <20190219154135.5967-1-suwan.kim027@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Patch "USB: HCD: support giveback of URB in tasklet context" introduced giveback of urb in tasklet context. [1] This patch was applied to ehci but not xhci. [2] It significantly reduces the hard irq time of xhci. Especially for the uvc driver, the hard irq including the uvc complete function runs quite long (about 300-350us in my Thinkpad s440 laptop with webcam) but applying this patch reduces the hard irq time of xhci to about 18-30us. As mentioned in the patch [1], when the urb complete function is executed in the tasklet, urb resubmission may be delayed and a time sensitive interrupt/isochronous pipe may be affected. However, as mentioned in [1], an interrupt pipe is mainly used for event report. So some delays are fine. In the case of isochronous pipe, executing the urb complete function in tasklet can cause late urb resubmissions due to tasklet schduling delay. Then the td can not match the endpoint service time interval resulting in an empty isochronous transfer ring and ring overrun/ underrun event. But this is not a problem. xhci spec 4.10.3.1 describes the xhc behavior when an empty isochronous transfer ring situation occurs due to the software's late resubmission of urb. And ehci also operates as the xhci specification. [3] If the driver can not match the endpoint service time interval, the isochronous transfer ring is empty and an overrun/underrun event occurs. Then the isochronous td that missed the frame is dropped and xhc shcedule the next td in appropriate frame. Or the xhc immediately schedules the missing td to the next frame as soon as possible if the driver sets the URB_ISO_ASAP flag in the urb->transfer_flags. Therefore, there is no scheduling issue for the late submitted isochronous td. And drivers using isochronous pipe usually submit multiple urbs. For example, uvc driver uses up to 5 urbs. Therefore, the time interval at which the isochronous transfer ring is empty is quite long.[4] Therefore, executing the urb complete function in the tasklet does not affect the isochronous transfer ring overrun/underrun. [1], https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=94dfd7edfd5c9b605caf7b562de7a813d216e011 [2], https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=428aac8a81058e2303677a8fbf26670229e51d3a [3], https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=46c73d1d3ebc38feed1d97c6980252a0a01f6a5b [4], https://marc.info/?l=linux-usb&m=137268420600615&w=2 Signed-off-by: Suwan Kim --- drivers/usb/host/xhci-ring.c | 2 -- drivers/usb/host/xhci.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 40fa25c4d041..0ede5265e6e2 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -644,10 +644,8 @@ static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci, } xhci_urb_free_priv(urb_priv); usb_hcd_unlink_urb_from_ep(hcd, urb); - spin_unlock(&xhci->lock); trace_xhci_urb_giveback(urb); usb_hcd_giveback_urb(hcd, urb, status); - spin_lock(&xhci->lock); } static void xhci_unmap_td_bounce_buffer(struct xhci_hcd *xhci, diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 005e65922608..b4610f70d660 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -5142,7 +5142,7 @@ static const struct hc_driver xhci_hc_driver = { * generic hardware linkage */ .irq = xhci_irq, - .flags = HCD_MEMORY | HCD_USB3 | HCD_SHARED, + .flags = HCD_MEMORY | HCD_USB3 | HCD_SHARED | HCD_BH, /* * basic lifecycle operations