From patchwork Tue Sep 19 03:13:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hayes Wang X-Patchwork-Id: 141674 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3102023vqi; Mon, 18 Sep 2023 20:15:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhHdYX3mTQ8bb/T/3SdmLEvvwMa2glreQ7nYgL+d+IsFz09WFgxaNy8PC8o9HU/gogXnBF X-Received: by 2002:a17:902:ec83:b0:1bb:fcb9:f85 with SMTP id x3-20020a170902ec8300b001bbfcb90f85mr1808546plg.32.1695093319442; Mon, 18 Sep 2023 20:15:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695093319; cv=none; d=google.com; s=arc-20160816; b=MSSZfjVUikQ+dMw4/+l7wa9dnYDDicDPhwSxXOgdv7M+55r9jIwwiHsp2mGdP6HNet s5RjFYQRrv6VWmfN/DYiUpFHi5HgmoKXQBpKvBDAqRaIn/6arYQIxhdghH5XNlEiZf+K +vG3cFDyzGlYRtLkDKtlR36TgV7Ul6D4/13mMfR6PNf9tZ2DhdEUaSSRDf8BwtiKGqh7 sggINWSuYPGzWTbQ4KS2/O4N9e3EbIdqosvp8gQXDwpGc30XOd7bDA7Y3tOyFHe7elru YrHRk6mNd3bmKxA6VCUIzWbmGKBO1qvg035Oah/QWQt5BmTDlTgZ3ZigoZM9rS+R7R4q RlzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=DQ92o00/fGjAvmWdsNgb4MtEi8mttgz/YNULBzKnsNo=; fh=ihIYiilCZXBu9x8WrnA4PYm4Oe+ipaGNn90/3600c/4=; b=a5IUV9ru8dCsk6ilFHim4RZgKoSPwJ289mdASjKVPn6cnv/SC/Eo1kcdHuccFQT99u GPr5Uo1FkF3xUAZpwytxn8a7HYAlGGqZTtN+49ou0LFFtOS+oNO0E+e1FoDiRnXzT32n 8+CNPmDUpF7qBU1HfUgYgkY8KYV6OeEeQSoWEeszkMfpGa2AqvdMotSiTEBkSj7Wxuqb v2ih6FMwmyMJY0xGhdCBpNvCzuUv2zgrnTbQSjgh5Ee6HVDKrimxi5mnUuXGsaffkwYF 3nn/dY6w+LjtMob9T8HXd0lc0fNQuSRrJaQZBg2JDfPTGjLA1Udtb7uJuwtmDEcfVy8h 8Q3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id jy6-20020a17090342c600b001bf0cc53d2csi8671260plb.261.2023.09.18.20.15.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 20:15:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 8212181B6A82; Mon, 18 Sep 2023 20:15:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231195AbjISDPH (ORCPT + 26 others); Mon, 18 Sep 2023 23:15:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231248AbjISDPD (ORCPT ); Mon, 18 Sep 2023 23:15:03 -0400 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C57610F; Mon, 18 Sep 2023 20:14:54 -0700 (PDT) X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 38J3E4jvC2932235, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36506.realtek.com.tw[172.21.6.27]) by rtits2.realtek.com.tw (8.15.2/2.92/5.92) with ESMTPS id 38J3E4jvC2932235 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Sep 2023 11:14:05 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXH36506.realtek.com.tw (172.21.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.17; Tue, 19 Sep 2023 11:14:05 +0800 Received: from fc38.localdomain (172.22.228.98) by RTEXMBS04.realtek.com.tw (172.21.6.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Tue, 19 Sep 2023 11:14:02 +0800 From: Hayes Wang To: , CC: , , , , , , , Hayes Wang Subject: [PATCH net-next v2 1/2] r8152: remove queuing rx packets in driver Date: Tue, 19 Sep 2023 11:13:50 +0800 Message-ID: <20230919031351.7334-430-nic_swsd@realtek.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230919031351.7334-429-nic_swsd@realtek.com> References: <20230919031351.7334-429-nic_swsd@realtek.com> MIME-Version: 1.0 X-Originating-IP: [172.22.228.98] X-ClientProxiedBy: RTEXH36506.realtek.com.tw (172.21.6.27) To RTEXMBS04.realtek.com.tw (172.21.6.97) X-KSE-ServerInfo: RTEXMBS04.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 18 Sep 2023 20:15:09 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777434172645264440 X-GMAIL-MSGID: 1777434172645264440 A bulk transfer of the USB may contain many packets. And, the total number of the packets in the bulk transfer may be more than budget. Originally, only budget packets would be handled by napi_gro_receive(), and the other packets would be queued in the driver for next schedule. Now, deal with all packets in the current bulk transfer through napi_gro_receive(), even the number is more than the budget. And, stop to handle the next bulk transfer until next schedule, if the budget is exhausted. Then, we don't need to queue the packets in the driver. Fixes: cf74eb5a5bc8 ("eth: r8152: try to use a normal budget") Signed-off-by: Hayes Wang --- drivers/net/usb/r8152.c | 56 ++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 37 deletions(-) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index 0c13d9950cd8..03bb3a58f2a6 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -871,7 +871,7 @@ struct r8152 { struct tx_agg tx_info[RTL8152_MAX_TX]; struct list_head rx_info, rx_used; struct list_head rx_done, tx_free; - struct sk_buff_head tx_queue, rx_queue; + struct sk_buff_head tx_queue; spinlock_t rx_lock, tx_lock; struct delayed_work schedule, hw_phy_work; struct mii_if_info mii; @@ -2031,7 +2031,6 @@ static int alloc_all_mem(struct r8152 *tp) INIT_LIST_HEAD(&tp->tx_free); INIT_LIST_HEAD(&tp->rx_done); skb_queue_head_init(&tp->tx_queue); - skb_queue_head_init(&tp->rx_queue); atomic_set(&tp->rx_count, 0); for (i = 0; i < RTL8152_MAX_RX; i++) { @@ -2431,24 +2430,6 @@ static int rx_bottom(struct r8152 *tp, int budget) int ret = 0, work_done = 0; struct napi_struct *napi = &tp->napi; - if (!skb_queue_empty(&tp->rx_queue)) { - while (work_done < budget) { - struct sk_buff *skb = __skb_dequeue(&tp->rx_queue); - struct net_device *netdev = tp->netdev; - struct net_device_stats *stats = &netdev->stats; - unsigned int pkt_len; - - if (!skb) - break; - - pkt_len = skb->len; - napi_gro_receive(napi, skb); - work_done++; - stats->rx_packets++; - stats->rx_bytes += pkt_len; - } - } - if (list_empty(&tp->rx_done)) goto out1; @@ -2484,10 +2465,6 @@ static int rx_bottom(struct r8152 *tp, int budget) unsigned int pkt_len, rx_frag_head_sz; struct sk_buff *skb; - /* limit the skb numbers for rx_queue */ - if (unlikely(skb_queue_len(&tp->rx_queue) >= 1000)) - break; - pkt_len = le32_to_cpu(rx_desc->opts1) & RX_LEN_MASK; if (pkt_len < ETH_ZLEN) break; @@ -2525,14 +2502,10 @@ static int rx_bottom(struct r8152 *tp, int budget) skb->protocol = eth_type_trans(skb, netdev); rtl_rx_vlan_tag(rx_desc, skb); - if (work_done < budget) { - work_done++; - stats->rx_packets++; - stats->rx_bytes += skb->len; - napi_gro_receive(napi, skb); - } else { - __skb_queue_tail(&tp->rx_queue, skb); - } + work_done++; + stats->rx_packets++; + stats->rx_bytes += skb->len; + napi_gro_receive(napi, skb); find_next_rx: rx_data = rx_agg_align(rx_data + pkt_len + ETH_FCS_LEN); @@ -2562,16 +2535,28 @@ static int rx_bottom(struct r8152 *tp, int budget) urb->actual_length = 0; list_add_tail(&agg->list, next); } + + /* A bulk transfer of USB may contain may packets, so the + * work_done may more than the budget. Deal with all packets + * in current bulk transfer, and stop to handle the next + * bulk transfer until next schedule, if budget is exhausted. + */ + if (work_done >= budget) + break; } + /* Splice the remained list back to rx_done for next schedule */ if (!list_empty(&rx_queue)) { spin_lock_irqsave(&tp->rx_lock, flags); - list_splice_tail(&rx_queue, &tp->rx_done); + list_splice(&rx_queue, &tp->rx_done); spin_unlock_irqrestore(&tp->rx_lock, flags); } out1: - return work_done; + if (work_done > budget) + return budget; + else + return work_done; } static void tx_bottom(struct r8152 *tp) @@ -2992,9 +2977,6 @@ static int rtl_stop_rx(struct r8152 *tp) list_splice(&tmp_list, &tp->rx_info); spin_unlock_irqrestore(&tp->rx_lock, flags); - while (!skb_queue_empty(&tp->rx_queue)) - dev_kfree_skb(__skb_dequeue(&tp->rx_queue)); - return 0; } From patchwork Tue Sep 19 03:13:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hayes Wang X-Patchwork-Id: 141673 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3102016vqi; Mon, 18 Sep 2023 20:15:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQRa5akmlnTCLdKm3bMADZXD+hqOMaIehVCWH3G0AnXe1tFudpdo9UVtBpChrjfTLtLfAO X-Received: by 2002:a17:902:7b82:b0:1c4:62a:e4a with SMTP id w2-20020a1709027b8200b001c4062a0e4amr7788494pll.64.1695093317748; Mon, 18 Sep 2023 20:15:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695093317; cv=none; d=google.com; s=arc-20160816; b=V5xNCJWHoxDJ4IMq1Je2KF63qm9lkBgj+NrNFRfrg5nw3DdFE8Ylr24u0pvcQCQCYR /M876/8UHSW4H+dBdjVjpPZYIpGNMeyNIlq6BNMoBadbSbF3m+Dju/ytQhsG0SIeZ0Rd ERKaaY896YmstUgCYzU4jpooW+ZirToPJFC+fSQvM2M/WKKjfFIYcZoDm1UqylCdi0w1 QsrwwnioFeaGxSz0CoxHVYwajdI8RgjvocjthozBbACmNPk87LqDNlAQwMaBVE0jHMAf 81O8s8H0E9X0NcrKKpesZ5c/gFAD17L3843Ns/mDO16V6ZJvyvgIQrVc9po3idpmbgOQ zZuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=F/mXHAq3XCckMMibigKB+DrV85KJepANh5baPxTqGyI=; fh=ihIYiilCZXBu9x8WrnA4PYm4Oe+ipaGNn90/3600c/4=; b=CmLKlFMON3SMU4O+HWAGoZ6Uybuow8kMbh9cEWmFQqiT+aJJFpNhDOsUjOzXVCQD99 gKJGvoZTdO3R7G65YGh5K9c2oVWJr23Hn3d5Hgv+ans74eVCqBUPLU9a2L+ROdk7C2Pm UGMChX3Yz73l7lGGUteezh08YnJXFd2OLcp+EoDXjVoBzG2mXHcM1rIJoret697i+eUA hv1G0L1ED0lLsBygEh96GIgM4JHUP8k55pFIS1AUJR0FJd6vnN7V8ZeN0Ef2QuUW8TKu pm3aZnY0YG3b3FNojViOQArvesbtTu1mX/0o7sbzc89N049jJSDUp1kLveXrdhb2Ox/D klSA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id z2-20020a170903018200b001b8a8f7af21si9157875plg.557.2023.09.18.20.15.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 20:15:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 3081D81B6AA5; Mon, 18 Sep 2023 20:15:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231272AbjISDPF (ORCPT + 26 others); Mon, 18 Sep 2023 23:15:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231236AbjISDPC (ORCPT ); Mon, 18 Sep 2023 23:15:02 -0400 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C4DD111; Mon, 18 Sep 2023 20:14:54 -0700 (PDT) X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 38J3EMDj82933326, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36505.realtek.com.tw[172.21.6.25]) by rtits2.realtek.com.tw (8.15.2/2.92/5.92) with ESMTPS id 38J3EMDj82933326 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Sep 2023 11:14:22 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXH36505.realtek.com.tw (172.21.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.32; Tue, 19 Sep 2023 11:14:05 +0800 Received: from fc38.localdomain (172.22.228.98) by RTEXMBS04.realtek.com.tw (172.21.6.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Tue, 19 Sep 2023 11:14:04 +0800 From: Hayes Wang To: , CC: , , , , , , , Hayes Wang Subject: [PATCH net-next v2 2/2] r8152: use napi_gro_frags Date: Tue, 19 Sep 2023 11:13:51 +0800 Message-ID: <20230919031351.7334-431-nic_swsd@realtek.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230919031351.7334-429-nic_swsd@realtek.com> References: <20230919031351.7334-429-nic_swsd@realtek.com> MIME-Version: 1.0 X-Originating-IP: [172.22.228.98] X-ClientProxiedBy: RTEXH36506.realtek.com.tw (172.21.6.27) To RTEXMBS04.realtek.com.tw (172.21.6.97) X-KSE-ServerInfo: RTEXMBS04.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-ServerInfo: RTEXH36505.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 18 Sep 2023 20:15:05 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777434170837443676 X-GMAIL-MSGID: 1777434170837443676 Use napi_gro_frags() for the skb of fragments. Signed-off-by: Hayes Wang --- drivers/net/usb/r8152.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index 03bb3a58f2a6..00dac52dea44 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -2462,8 +2462,9 @@ static int rx_bottom(struct r8152 *tp, int budget) while (urb->actual_length > len_used) { struct net_device *netdev = tp->netdev; struct net_device_stats *stats = &netdev->stats; - unsigned int pkt_len, rx_frag_head_sz; + unsigned int pkt_len; struct sk_buff *skb; + bool use_frags; pkt_len = le32_to_cpu(rx_desc->opts1) & RX_LEN_MASK; if (pkt_len < ETH_ZLEN) @@ -2477,35 +2478,40 @@ static int rx_bottom(struct r8152 *tp, int budget) rx_data += sizeof(struct rx_desc); if (!agg_free || tp->rx_copybreak > pkt_len) - rx_frag_head_sz = pkt_len; + use_frags = false; else - rx_frag_head_sz = tp->rx_copybreak; + use_frags = true; + + if (use_frags) + skb = napi_get_frags(napi); + else + skb = napi_alloc_skb(napi, pkt_len); - skb = napi_alloc_skb(napi, rx_frag_head_sz); if (!skb) { stats->rx_dropped++; goto find_next_rx; } skb->ip_summed = r8152_rx_csum(tp, rx_desc); - memcpy(skb->data, rx_data, rx_frag_head_sz); - skb_put(skb, rx_frag_head_sz); - pkt_len -= rx_frag_head_sz; - rx_data += rx_frag_head_sz; - if (pkt_len) { + rtl_rx_vlan_tag(rx_desc, skb); + + if (use_frags) { skb_add_rx_frag(skb, 0, agg->page, agg_offset(agg, rx_data), pkt_len, SKB_DATA_ALIGN(pkt_len)); get_page(agg->page); + napi_gro_frags(napi); + } else { + memcpy(skb->data, rx_data, pkt_len); + skb_put(skb, pkt_len); + skb->protocol = eth_type_trans(skb, netdev); + napi_gro_receive(napi, skb); } - skb->protocol = eth_type_trans(skb, netdev); - rtl_rx_vlan_tag(rx_desc, skb); work_done++; stats->rx_packets++; - stats->rx_bytes += skb->len; - napi_gro_receive(napi, skb); + stats->rx_bytes += pkt_len; find_next_rx: rx_data = rx_agg_align(rx_data + pkt_len + ETH_FCS_LEN);