Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp2558274imi; Mon, 25 Jul 2022 01:43:21 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uMOFvRFm10NFGpFGVMsK2t3L/lnYGxnZKeXGhoo0Xd+TjgbiPrifnJ9tMhlG0CNIZ1wm4Z X-Received: by 2002:a17:906:58d6:b0:72f:2cce:7cf8 with SMTP id e22-20020a17090658d600b0072f2cce7cf8mr9321758ejs.452.1658738600779; Mon, 25 Jul 2022 01:43:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658738600; cv=none; d=google.com; s=arc-20160816; b=mKn8tlfOY1vt/bkv0aKnE2NAaAaeHHr676OKcHjZ8WsTYskhJnAnOa/BWCpwt7b8rS MMLg9Jfji6xV9Dfv09wPfwqdjAC+ybG0FL6ohcD+JK1IHFCQz4agf71Y1FoMwWevjgxu DG1vXPzvx8/7jO82fVX13LzDtO3h5mR2H5L2RX/H/SyIHID00bqT5OwT5WvR0uf9MDdz WQ8LtalRB3qsjH60/T0+MtepHcaD0uqvL9+i8Gf/DnMBPPmJmOTWa87z63shxyWP58f3 Kpx2cTncnuLNdXvDy6x+Zhrf8pHsSG45VLL5Z5+kbMdbsLJW2imB36y4nrfbPlXOQGW1 KvFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=bSa24RkLGOVb9mqXyzx5nIyXZhJRiDANt8v3RVr4jNw=; b=R9AJ1JV7oLQe0uZNuDHJG/uqeGv7tyXZgRp8Rxp/X19eFq7Yrcl0Uj1NgN7EbXamjS wY6WA6kYW600muxJgoAkdYuRaHKBPZ5aztzud3hzJN26+iKN+5H58GbGbD2h1ah9Fz3H U8wKvYZG7ltdib/poMbdtxzibfVCmiqSxjFt5CyDFvHkjwWSzxPCAHHhhKiWdIF6WO+q zvmTGtxB7jvrxfmpBQrsA1GQsrcZ6eTJiZ0lHMvFXbe73K1nfryv2UfDcAV0pGTzF5dm WIH5ML1nMl2MbbQnjJVO/0h4kyM1ZHV0lavtgvgdmUmqKpuDgCenPbGvNzhf69AoNxHY E0tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="NZEnL/5H"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g6-20020a50ee06000000b0043762bdbbfbsi11282292eds.621.2022.07.25.01.42.56; Mon, 25 Jul 2022 01:43:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="NZEnL/5H"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233971AbiGYI3r (ORCPT + 99 others); Mon, 25 Jul 2022 04:29:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233858AbiGYI3k (ORCPT ); Mon, 25 Jul 2022 04:29:40 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D62D813FBE; Mon, 25 Jul 2022 01:29:37 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id p21so4602566ljh.12; Mon, 25 Jul 2022 01:29:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=bSa24RkLGOVb9mqXyzx5nIyXZhJRiDANt8v3RVr4jNw=; b=NZEnL/5HwwpZkPsB4qWr1n9TlyT8CGVdbUGeyp3B+6OTVvXVjq94R/vWnIP5/sivRD Ur1DfxHDTUN1v7ujHMDWo/yb6BCdUPIf1m/zfO8QuYDcC7haEbJxRDF7Pn649G9cYR+K JqWOmH5SrK9pSbrKnnnKY+5Rb455r2EiMZ2PR0EY1Cx0z4T3U1FnXQNPQFSd825728uw +drQyj53j2SVztE1TZ9M0aEQJzN44LwBeE34w0/6YVcpxkM57UXuw5VNJc/X4l2s8VZB Y0XpHoJyLsGrQh3w7hbtBlmgC0kW2biVf5WF3HrDkjgtD7/HRt7maXTL4/d/vyL2Dn6a GA0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=bSa24RkLGOVb9mqXyzx5nIyXZhJRiDANt8v3RVr4jNw=; b=F3BTFi7YRVLASz1jhKphBDXgxj0OWvnQ5GKuZUVx5TcghkRn1XJj5Bkn+rX0/1E54v aS9hJKVnqmwiTEElVsy1p0me11XAZzmSsDGk7Ht6KEtXQM+fJoWuizRVhPlyeQHKLQp9 YdN7K0H4yhNXF5QaiA7ThuGn10xYdbHxANypxW5jydGOk+SNnrT7ruysQDLn4y/BCk5U QhSct/8VGHlos0IVPx0FcaR1jiNHK/0npXgAOUvP8y+xUzEeKdGz2pg9E9xvF6ZYKNYW V5V5DSGncfr/bU+S0ByGZuQl8h2pPoff4D9Ivif4k9XyCwqoGQybuVuboJD01vDBqTxB hQsw== X-Gm-Message-State: AJIora//h3blu0QXrK2dkiCI4MmXD7tSx2Fgfw/yRCb1FYMfZ1956xXK XKJkLz5Om40oB1W+WEDr/Ak= X-Received: by 2002:a2e:908:0:b0:25d:e37b:2cbb with SMTP id 8-20020a2e0908000000b0025de37b2cbbmr3763221ljj.401.1658737775869; Mon, 25 Jul 2022 01:29:35 -0700 (PDT) Received: from [192.168.1.103] ([31.173.82.139]) by smtp.gmail.com with ESMTPSA id p13-20020a2ea4cd000000b0025e0396786dsm715578ljm.93.2022.07.25.01.29.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Jul 2022 01:29:35 -0700 (PDT) Subject: Re: [PATCH v2] USB: HCD: Fix URB giveback issue in tasklet function To: Weitao Wang , stern@rowland.harvard.edu, gregkh@linuxfoundation.org, kishon@ti.com, dianders@chromium.org, s.shtylyov@omp.ru, mka@chromium.org, ming.lei@canonical.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: tonywwang@zhaoxin.com, weitaowang@zhaoxin.com References: <20220725065251.832087-1-WeitaoWang-oc@zhaoxin.com> From: Sergei Shtylyov Message-ID: <3b9a3fec-7716-3e9d-1e91-cfdac46845f7@gmail.com> Date: Mon, 25 Jul 2022 11:29:33 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20220725065251.832087-1-WeitaoWang-oc@zhaoxin.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello! On 7/25/22 9:52 AM, Weitao Wang wrote: > Usb core introduce the mechanism of giveback of URB in tasklet context to > reduce hardware interrupt handling time. On some test situation(such as > FIO with 4KB block size), when tasklet callback function called to > giveback URB, interrupt handler add URB node to the bh->head list also. > If check bh->head list again after finish all URB giveback of local_list, > then it may introduce a "dynamic balance" between giveback URB and add URB > to bh->head list. This tasklet callback function may not exit for a long > time, which will cause other tasklet function calls to be delayed. Some > real-time applications(such as KB and Mouse) will see noticeable lag. > > Fix this issue by taking new URBs giveback in next tasklet function call. > Add a member high_prio for structure giveback_urb_bh and replace the local > high_prio_bh variable with this structure member in usb_hcd_giveback_urb. > > Fixes: 94dfd7edfd5c ("USB: HCD: support giveback of URB in tasklet context") > Signed-off-by: Weitao Wang > --- > v1->v2: > - Fix compile warning by remove label "restart". > - Modify the patch description info. > - Change structure member from hi_priority to high_prio. > > drivers/usb/core/hcd.c | 25 ++++++++++++++----------- > include/linux/usb/hcd.h | 1 + > 2 files changed, 15 insertions(+), 11 deletions(-) > > diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c > index 06eea8848ccc..1feb9a604380 100644 > --- a/drivers/usb/core/hcd.c > +++ b/drivers/usb/core/hcd.c [...] > @@ -2959,6 +2961,7 @@ int usb_add_hcd(struct usb_hcd *hcd, > > /* initialize tasklets */ > init_giveback_urb_bh(&hcd->high_prio_bh); > + hcd->high_prio_bh.high_prio = 1; s/1/true/? > init_giveback_urb_bh(&hcd->low_prio_bh); > > /* enable irqs just before we start the controller, > diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h > index 2c1fc9212cf2..98d1921f02b1 100644 > --- a/include/linux/usb/hcd.h > +++ b/include/linux/usb/hcd.h > @@ -66,6 +66,7 @@ > > struct giveback_urb_bh { > bool running; > + bool high_prio; > spinlock_t lock; > struct list_head head; > struct tasklet_struct bh; MBR, Sergey