Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp299449yba; Sat, 4 May 2019 02:39:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxgk6c9c97dviSFt+sRlagJWLY4cq0WEZor6dzLj4VCTelab7rCsfKcdDXCeImITVM6P8bl X-Received: by 2002:a65:5886:: with SMTP id d6mr17326549pgu.295.1556962783010; Sat, 04 May 2019 02:39:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556962783; cv=none; d=google.com; s=arc-20160816; b=mpadbqCxfFxGRzdc3yQwlKffsuWSnusA2vUVsONLLBn7mJH3+e0nTvnONRdHxOcCkm IfKS9hK28pctfIL/lyoUGjv4KAitjIC58t6+ErjZ++YpGN9L+fF9UnD6a2ie9mJHLdw1 FwByEtPiE5QKv5G4Yz5ya5+SSvDYL2IBP/rrsrshHBH1uazYrvol3jjJ+t8VxO4kSvNu ojTc1ACpg+4l73yroH8yJC6H+jFEzuF9G/8smCvglMBOzPdEvRoriU8iILai45BzrD5P jexGE4eEVZItGA1TPbLN8FzNA5sNA6OtiLHnHgLtjgLCHxM0ANX4HKmTVDz9CJ7oY1JM 0MPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=kcyDPi6y1xG1r5TAoU0sEkuhqTIxA0HFOn4latVnGO8=; b=KLexXkgga9TYt35ohrWnbzNmtmhDwblhhp79qhqXS1Qr/KfrCndk48k0FBSS1C8J8p 5ig6H19DnF5MrVCYwGcrmQVHnY5+Mj/TwNDf1RPDFGmRqpZnTzq9MoPjr2p5QFiUw2pt YAthGtJew5FAZ9tpB5iEQpwytKugLfi92sDPlrzkF0Ui67Lwy5ZF+T3x/NhN7sqbDNLo a6klsh7XK+sjiDVPB+/RsEzKi/fMYtpQtCWXDRYfJA2/Za8c5I0NeqCxjfcBMrTReDis km/M3pfD0RDYpMPjiXzja+9Q72uGEArqNjdSHq644i/PJLr7s/3hKpwz9xMjRJwpxAGQ YApQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y10si6307204pga.96.2019.05.04.02.39.27; Sat, 04 May 2019 02:39:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726326AbfEDJig convert rfc822-to-8bit (ORCPT + 99 others); Sat, 4 May 2019 05:38:36 -0400 Received: from mail-oi1-f196.google.com ([209.85.167.196]:36369 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725823AbfEDJif (ORCPT ); Sat, 4 May 2019 05:38:35 -0400 Received: by mail-oi1-f196.google.com with SMTP id l203so6275458oia.3; Sat, 04 May 2019 02:38:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:content-transfer-encoding; bh=HFseoIWdZ0CgvYQXA3eAJnk39OPJTIq5Z9waS1ZE/Jc=; b=MLaA2HE++m5V4WSryK46H1oRcZYNNYjQ2OJNoCy1cZLuDhVOFP8hUXqIXwWv9vVb6t HUkEEAGwMbRUPzKAQW5J5smYBnJ80A1voiHLSeKHwbCvl03GwT+6IuLkHOUx1JI5TFQP JYRMIOUCa3IgBso2QXyYPVEf9aeEcf955H0LH9eCwAFF3DwFW5HO1v1ZRpcNvggpkFr9 LQ4do+TXESwwflNu7Me3T6u4yvbaF8Kdg1xxS92CjhuR4xC8al0khaXmxwnx9htdTmj/ tvxIQv5odfm3fIqCQVAaqaTOc3hYUtyYa9xzJpMLJj5uE0DW+/ea7IkT6HhIPx4j5kTO kcaA== X-Gm-Message-State: APjAAAU4AxqfOu2G4q+soLKHSb7sbtKrk42Cj2HiyrBaibBESPYy5kDJ EpxSWm7omIK8T3itSvJjAo5E9RghijkpM8JCP2s= X-Received: by 2002:aca:eb11:: with SMTP id j17mr2029311oih.67.1556962714541; Sat, 04 May 2019 02:38:34 -0700 (PDT) MIME-Version: 1.0 References: <20190403185310.8437-1-matwey@sai.msu.ru> <20190403185310.8437-7-matwey@sai.msu.ru> <20190430153118.GI20993@uda0271908> In-Reply-To: <20190430153118.GI20993@uda0271908> From: "Matwey V. Kornilov" Date: Sat, 4 May 2019 12:38:22 +0300 Message-ID: Subject: Re: [PATCH 6/6] usb: musb: Decrease URB starting latency in musb_advance_schedule() To: Bin Liu , "Matwey V. Kornilov" , Greg KH , =?UTF-8?B?0JzQsNGC0LLQtdC5INCa0L7RgNC90LjQu9C+0LI=?= , open list , "open list:MUSB MULTIPOINT HIGH SPEED DUAL-ROLE CONTROLLER" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org вт, 30 апр. 2019 г. в 18:31, Bin Liu : > > Hi Greg and all devs, > > On Wed, Apr 03, 2019 at 09:53:10PM +0300, Matwey V. Kornilov wrote: > > Previously, the algorithm was the following: > > > > 1. giveback current URB > > 2. if current qh is not empty > > then start next URB > > 3. if current qh is empty > > then dispose the qh, find next qh if any, and start URB. > > > > It may take a while to run urb->callback inside URB giveback which is > > run synchronously in musb. In order to improve the latency we rearrange > > the function behaviour for the case when qh is not empty: next URB is > > started before URB giveback. When qh is empty then the behaviour is > > intentionally kept in order not to break existing inter qh scheduling: > > URB giveback could potentionally enqueue other URB to the empty qh > > preventing it from being disposed. > > This patch changes the sequence of urb giveback in musb. > > before after > ------ ----- > 1. giveback current urb 1. start next urb if qh != empty > 2. start next urb if qh != empty 2. giveback current urb > > I see there is a potential that the urb giveback could be out of order, > for example, if urb giveback in BH and the next urb finishes before BH > runs. Could you please give more details? Frankly speaking, I am not sure that I understand the reordering issue origin correctly. I see in the existing implementation that the function call order is the following: 1. glue interrupt handler (for instance dsps_interrupt() in my am335x case) holds musb->lock; 2. musb_interrupt() 3. musb_host_rx() (or *_tx()) 4. musb_advance_schedule() 5. musb_giveback() releases and reacquires musb->lock around: 6. usb_hcd_giveback_urb() So, when musb_giveback() is called inside musb_advance_schedule() then the second instance of musb_advance_schedule() can be started simultaneously when the following interrupt is being handled at other CPU core. And we can see two usb_hcd_giveback_urb() running concurrently. Is it correct? > > If this potential is possible, is it a problem for any class driver? > > Thanks, > -Bin. > > > > > Before this patch, time spent in urb->callback led to the following > > glitches between the host and a hub during isoc transfer (line 4): > > > > 11.624492 d= 0.000124 [130.6 + 1.050] [ 4] SPLIT > > 11.624492 d= 0.000000 [130.6 + 1.467] [ 3] IN : 3.5 > > 11.624493 d= 0.000000 [130.6 + 1.967] [ 37] DATA0: aa 08 [skipped...] > > 11.625617 d= 0.001124 [131.7 + 1.050] [ 4] SPLIT > > 11.625617 d= 0.000000 [131.7 + 1.467] [ 3] IN : 3.5 > > 11.625867 d= 0.000250 [132.1 + 1.050] [ 4] SPLIT > > 11.625867 d= 0.000000 [132.1 + 1.467] [ 3] IN : 3.5 > > 11.625868 d= 0.000001 [132.1 + 1.983] [ 3] DATA0: 00 00 > > 11.626617 d= 0.000749 [132.7 + 1.050] [ 4] SPLIT > > 11.626617 d= 0.000000 [132.7 + 1.467] [ 3] IN : 3.5 > > 11.626867 d= 0.000250 [133.1 + 1.050] [ 4] SPLIT > > 11.626867 d= 0.000000 [133.1 + 1.467] [ 3] IN : 3.5 > > 11.626868 d= 0.000000 [133.1 + 1.967] [ 3] DATA0: 00 00 > > > > After the hub, they look as the following and may lead to broken > > perepherial transfer (as in case of PWC based webcam): > > > > 11.332004 d= 0.000997 [ 30.0 + 3.417] [ 3] IN : 5.5 > > 11.332007 d= 0.000003 [ 30.0 + 6.833] [800] DATA0: 8a 1c [skipped...] > > 11.334004 d= 0.001997 [ 32.0 + 3.417] [ 3] IN : 5.5 > > 11.334007 d= 0.000003 [ 32.0 + 6.750] [ 3] DATA0: 00 00 > > 11.335004 d= 0.000997 [ 33 + 3.417] [ 3] IN : 5.5 > > 11.335007 d= 0.000003 [ 33 + 6.750] [ 3] DATA0: 00 00 > > > > Removing this glitches makes us able to successfully run 10fps > > video stream from the webcam attached via USB hub. That was > > previously impossible. > > > > Signed-off-by: Matwey V. Kornilov > > --- > > drivers/usb/musb/musb_host.c | 18 ++++++++++++++++++ > > 1 file changed, 18 insertions(+) > > > > diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c > > index ed99ecd4e63a..75be92873b5b 100644 > > --- a/drivers/usb/musb/musb_host.c > > +++ b/drivers/usb/musb/musb_host.c > > @@ -85,6 +85,11 @@ static bool musb_qh_empty(struct musb_qh *qh) > > return list_empty(&qh->hep->urb_list); > > } > > > > +static bool musb_qh_singular(struct musb_qh *qh) > > +{ > > + return list_is_singular(&qh->hep->urb_list); > > +} > > + > > static void musb_qh_unlink_hep(struct musb_qh *qh) > > { > > if (!qh->hep) > > @@ -362,6 +367,19 @@ static void musb_advance_schedule(struct musb *musb, struct urb *urb, > > break; > > } > > > > + if (ready && !musb_qh_singular(qh)) { > > + struct urb *next_urb = list_next_entry(urb, urb_list); > > + > > + musb_dbg(musb, "... next ep%d %cX urb %p", hw_ep->epnum, is_in ? 'R' : 'T', next_urb); > > + musb_start_urb(musb, is_in, qh, next_urb); > > + > > + qh->is_ready = 0; > > + musb_giveback(musb, urb, status); > > + qh->is_ready = ready; > > + > > + return; > > + } > > + > > qh->is_ready = 0; > > musb_giveback(musb, urb, status); > > qh->is_ready = ready; > > -- > > 2.16.4 > > -- With best regards, Matwey V. Kornilov. Sternberg Astronomical Institute, Lomonosov Moscow State University, Russia 119234, Moscow, Universitetsky pr-k 13, +7 (495) 9392382