Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3672465pxf; Mon, 29 Mar 2021 08:24:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKcGj+gZz/WN+WrB1SjsVdRTUnzfGQHyUYG8nqIknktPU6zPwGLQ+UoMqvY1gC8+c6Mg/4 X-Received: by 2002:a05:6402:11c9:: with SMTP id j9mr29043974edw.348.1617031451305; Mon, 29 Mar 2021 08:24:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617031451; cv=none; d=google.com; s=arc-20160816; b=aKQtD6maOMpjeF/rUy5kgvh9KbG+2L5SUBmZzr074KYACmQUX7qdZr6NS1iE9kSB1s N5S8XmYW2/OAxkys/bS9Oh5tgeIPSdj+B4lcU+1WbjnTTqtfgvAkHoZrTG/SNrHRTsKW p7c2NYxRS0EJgOC4JI5yYYqT9Zip5/UCh+leWmkZw9gquDNCccQYIbradXB5DdQbPgAj /CpELboZR/DBLLzXdL5rDVwWJvLlgDg3mL2EctvAhBbW1KO6mpsDkA30n7/c6W3/tN99 FUS3Bec3dpfLKrOYcPl0D1mRQjJ2/zB1IfP2NlJMyjfD8ZcOjthmAp1awIh0S8/d+K8V oPfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=2GlMF/CvQ6dUberBFHUD86wEuTNoO0o92i8ocuOMsUg=; b=LnUzZEsQdXnrQUlU5Nf7ZkeCq/QvqX3oQJrrvsQ9ny05uv9rUE/ry0h1mhfMIjMJ7Q CWvSBOkgVcf5h9XawB7d8AZvZ3uI6Vg/2xacIjDVrfBt+JjKv6P8mZ9fqwNnqvSVZ3gs 8jaYVNgt7PpaAmWjL23v1NuTigU6dsW6A/G9njBDzI1Mo5ZnEB8uV06CThT9Ykq2quQB C5cxtIbWNCpe3kUJz4vR8Ndi63AKx0GVmR0i9YcfF17wvXRufjTDHJSh8nRtfycbhxYa FC/TTPAUy2LxRnvL0BABlUu4jNXHdG232t8YU4FelpD4gK6dsq0U2dinYXybgwWv69XL RU2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v10si8208447edc.569.2021.03.29.08.23.48; Mon, 29 Mar 2021 08:24:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230467AbhC2PW1 (ORCPT + 99 others); Mon, 29 Mar 2021 11:22:27 -0400 Received: from netrider.rowland.org ([192.131.102.5]:59289 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S231233AbhC2PWD (ORCPT ); Mon, 29 Mar 2021 11:22:03 -0400 Received: (qmail 936342 invoked by uid 1000); 29 Mar 2021 11:22:01 -0400 Date: Mon, 29 Mar 2021 11:22:01 -0400 From: Alan Stern To: "Maciej S. Szmigiero" Cc: linux-usb@vger.kernel.org, linux-kernel , Greg Kroah-Hartman Subject: Re: >20 KB URBs + EHCI = bad performance due to stalls Message-ID: <20210329152201.GA933773@rowland.harvard.edu> References: <6f5be7a5-bf82-e857-5c81-322f2886099a@maciej.szmigiero.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6f5be7a5-bf82-e857-5c81-322f2886099a@maciej.szmigiero.name> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Mar 27, 2021 at 04:55:20PM +0100, Maciej S. Szmigiero wrote: > Hi, > > Is there any specific reason that URBs without URB_SHORT_NOT_OK flag that > span multiple EHCI qTDs have Alternate Next qTD pointer set to the dummy > qTD in their every qTD besides the last one (instead of to the first qTD > of the next URB to that endpoint)? Quick answer: I don't know. I can't think of any good reason. This code was all written a long time ago. Maybe the issue was overlooked or the details were misunderstood. > This causes that endpoint queue to stall in case of a short read that > does not reach the last qTD (I guess this condition persists until an > URB is (re)submitted to that endpoint, but I am not sure here). It persists until the driver cleans up the queue. > One of affected drivers here is drivers/net/usb/r8152.c. > > If I simply reduce its per-URB transfer buffer to 20 KB (the maximum > that fits in a well-aligned qTD) the RX rate increases from around > 100 Mbps to 200+ Mbps (on an ICH8M controller): > The driver default is to use 32 KB buffers (which span two qTDs), > but the device rarely fully fills the first qTD resulting in > repetitive stalls and more than halving the performance. > > As far as I can see, the relevant code in > drivers/usb/host/ehci-q.c::qh_urb_transaction() predates the git era. Like I said, a long time ago. > The comment in that function before setting the Alternate Next qTD > pointer: > > /* > > * short reads advance to a "magic" dummy instead of the next > > * qtd ... that forces the queue to stop, for manual cleanup. > > * (this will usually be overridden later.) > > */ > > ...suggests the idea was to override that pointer when > URB_SHORT_NOT_OK is not set, but this is actually done only for > the last qTD from the URB (also, that's the only one that ends > with interrupt flag set). The hw_alt_next field should be updated for all the qTDs in the URB. Failure to this was probably an oversight. Or maybe the omission was to simplify the procedure for cleaning up the queue after a short transfer. > Looking at OHCI and UHCI host controller drivers the equivalent > limits seem to be different there (8 KB and 2 KB), while I don't > see any specific limit in the XHCI case. I'd have to review the details of ohci-hcd and uhci-hcd to make sure. In principle, the queue isn't supposed to stop merely because of a short transfer unless URB_SHORT_NOT_OK is set. However, the UHCI hardware in particular may offer no other way to handle a short transfer. > Because of that variance in the URB buffer limit it seems strange > to me that this should be managed by a particular USB device driver > rather than by the host controller driver, because this would mean > every such driver would need to either use the lowest common > denominator for the URB buffer size (which is very small) or > hardcode the limit for every host controller that the device can > be connected to, which seems a bit inefficient. I don't understand what you're saying in this paragraph. What do you think USB device drivers are supposed to be managing? The URB buffer size? They should set that field without regard to the type of host controller in use. In short, the behavior you observed is a bug, resulting in a loss of throughput (though not in any loss of data). It needs to be fixed. If you would like to write and submit a patch, that would be great. Otherwise, I'll try to find time to work on it. I would appreciate any effort you could make toward checking the code in qh_completions(); I suspect that the checks it does involving EHCI_LIST_END may not be right. At the very least, they should be encapsulated in a macro so that they are easier to understand. Alan Stern