Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2364826pxf; Sat, 27 Mar 2021 09:19:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0iZoF/xr6pG9gkpHzJJAJEvFi5VazNBvi7VNpb2eyzil6NuzHvVFseODJKnqEbuPY1W6t X-Received: by 2002:a17:906:94ca:: with SMTP id d10mr20537419ejy.107.1616861987620; Sat, 27 Mar 2021 09:19:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616861987; cv=none; d=google.com; s=arc-20160816; b=HBVH8l+/xGfvWkEl41FHKoepx6AhJpC0F4vAQsRAkI+vvuVbrttAxX1JMjwC0Grsln aEt65bzi2ENsYh5M2dDmYp0fXzOHrgeF9xVyZj6K79IOQOpp8qkn5wTfyPQ0xBP4TT+Z mYaaYv5fCxH1Fj2HNQ1ddW7upQLJKyN0G+EKAun9K4VAH/sH4DjO3/jr53b/zqKajpJu KdYESahWx179NgEB4YPoum/lix77IovrdpZn+DaHlpkFy4g0/S25McQRJoDQB8hUpMi/ boSKcVw35gg/Ap3pexKx7004sVy7eus+gdDv0DTLM4xlEi0h3Xej7SyUs52Y8rSKaJLH bapQ== 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 :mime-version:user-agent:date:message-id:subject:cc:to:from; bh=A7ozKkCp9N1nsFwOSmvroABxiiooeVH+eH6nNXHFGWU=; b=xIyh8cZrINLBegn3Iz7Jls+3AL84Qe/BP6ID4EtbwWmBy5Db6tBLrPVk8SOmNZdoGI k7itcOMqMPxplz46QLYra93KL53NODLyz50MpblDHT1QRt4TXPSd0JeqEioLzOZabCph HdnF43Jt7a/DM4jjjxWaM6zUfeQY3sLzQTTSk3WtN8Go1PJ8OMMRpkt4+TZDcgBSEZth vUe8wptChNS6/BLbcdJAjsqU/ZGE22W2oa1oQWHrd9c/eWYwE1qJZ/edRQaVqRTotO/U slF7gLD2l2P6FRx9L06WGlaRosJKM5NNsh9go928s6Dd2cw0p/uXPde0kDwkJLq0MPMi wi8g== 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 j7si9313022ejx.732.2021.03.27.09.19.11; Sat, 27 Mar 2021 09:19:47 -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 S230092AbhC0QOf (ORCPT + 99 others); Sat, 27 Mar 2021 12:14:35 -0400 Received: from vps-vb.mhejs.net ([37.28.154.113]:37562 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229582AbhC0QO2 (ORCPT ); Sat, 27 Mar 2021 12:14:28 -0400 X-Greylist: delayed 1135 seconds by postgrey-1.27 at vger.kernel.org; Sat, 27 Mar 2021 12:14:27 EDT Received: from MUA by vps-vb.mhejs.net with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.93.0.4) (envelope-from ) id 1lQBHa-0006Gy-JO; Sat, 27 Mar 2021 16:55:26 +0100 From: "Maciej S. Szmigiero" To: linux-usb@vger.kernel.org Cc: linux-kernel , Alan Stern , Greg Kroah-Hartman Subject: >20 KB URBs + EHCI = bad performance due to stalls Message-ID: <6f5be7a5-bf82-e857-5c81-322f2886099a@maciej.szmigiero.name> Date: Sat, 27 Mar 2021 16:55:20 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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)? 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). 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): --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -6554,6 +6556,9 @@ break; } + if (tp->udev->speed == USB_SPEED_HIGH) + tp->rx_buf_sz = min(tp->rx_buf_sz, (u32)20 * 1024); + return ret; } 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. 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). 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. 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. Thanks, Maciej