Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5188526yba; Tue, 30 Apr 2019 10:30:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqxVg4zfyA8gJPP0GqCJYP1Zz0FpnL1MAVvWVtJ1zHhJXm+umqP1uJ3faJi2PG0TllUk8CKT X-Received: by 2002:a63:231c:: with SMTP id j28mr14324741pgj.430.1556645455669; Tue, 30 Apr 2019 10:30:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556645455; cv=none; d=google.com; s=arc-20160816; b=cabuLqdTk4xheLd6joYcOpddkTXZApkYsPcX+VIiiJyN3vsdNha/ETV708qvIhrIl/ 3kPlaNB34r0oxOSByGBYRPJGvoFfLnGhvLyhH7gn8a/90Na22Tugohsdl9iA2rRinVGs EhNvmi22PzUBH1SclbqS+pDcDIizwBtJJCQ2coBmDxQzH2LqHvdlVzix93TAWVx2vgg8 jxAZi561zUp0j4NXEDupakI9QsKJPdIaCx+YASsjop6JDZYIf24/zCDqiPmOaq0S2J3+ 9IARieIR5XD+LCjt1uLQ7qm+hhfRbhvStqv+o4RTu0qWKrFLglFHRD+/ZKFu4bSzXyOz Zn1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date; bh=SfcR16BI8CzygAylFXRShYK4dIY31Chhjpv6wqWtaYg=; b=QrRN9eg2nXIFcsq0fFFbKP/aTdsvWD7Jz5HatTeU0uI+YS+L29pH5wNUUe68CkltYh kEoZpOLXJ707fxIe3+pfja7Ub+vtkgAp60MQ94z+R2TbSqChEP3RE3lvU04AnNIzcxD/ KxoCdjkReVS7lVt808hPqPNo5EgznGVjZpveCpINWXW+Lo3b8T0ljQj9b+rSM9+O8BRC qhuAde8zYRcwM+dWPKBiBBcOh2QZtc+dEZkBzf1m8E3R5AhMkbBoOFBtuOSuk3YhjkRq qaF00fka1+8VhCId5BCRKJFrgbR6mdf+cjbSgqi/ipwuiMT9BcsGfl5D6gI920KqUZKw Emqw== 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 b7si21280039plx.62.2019.04.30.10.30.39; Tue, 30 Apr 2019 10:30:55 -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 S1726772AbfD3R3g (ORCPT + 99 others); Tue, 30 Apr 2019 13:29:36 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:36016 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726017AbfD3R3g (ORCPT ); Tue, 30 Apr 2019 13:29:36 -0400 Received: (qmail 5374 invoked by uid 2102); 30 Apr 2019 13:29:35 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 30 Apr 2019 13:29:35 -0400 Date: Tue, 30 Apr 2019 13:29:35 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Bin Liu cc: "Matwey V. Kornilov" , , , , Subject: Re: [PATCH 6/6] usb: musb: Decrease URB starting latency in musb_advance_schedule() In-Reply-To: <20190430153118.GI20993@uda0271908> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 30 Apr 2019, Bin Liu wrote: > 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. > > If this potential is possible, is it a problem for any class driver? I don't know of any specific examples where this would be a problem. But it definitely goes against the guarantee that except for unlinks, URBs for each endpoint are always given back in order. There's also a guarantee that when an URB has an error status, it causes the endpoint queue to stop. This is necessary so that the class driver can cancel any outstanding URBs before they run and cause even more trouble. Your brief outline above doesn't mention this. On the other hand, it shouldn't be hard to maintain the order even here. For example, you could have a FIFO list of URBs waiting to be given back, and the BH could always give back the URB at the front of the list. Alan Stern