From patchwork Tue Sep 26 11:17:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hayes Wang X-Patchwork-Id: 144824 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1836388vqu; Tue, 26 Sep 2023 04:24:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGz3OSk1870O6WtdXyg4vIby9AHDQHsKnBVqR6WWFMBIJGMKmy1iV0LR2t5fwiOL1VjrVZh X-Received: by 2002:a17:90a:4f4a:b0:26b:2538:d717 with SMTP id w10-20020a17090a4f4a00b0026b2538d717mr7037760pjl.25.1695727454818; Tue, 26 Sep 2023 04:24:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695727454; cv=none; d=google.com; s=arc-20160816; b=oRMg7IhHTch82sxfkz8feyqvV2rizeqCBx9CXcpXHHd7viEBSaL+kYesAoCABh6Hjt vq0Bp8VNcc6kgMb+PLwikVH7WOGQEIGrB+Xdju8j2oiD9LT0gYEFndalmCLNKiJbSLpA cqfnze+nHWZ++8X93WfE5iF6smCj272ro4D4JP69/9mRnxAKvy3ojYlyBmya+YY95yry BBmCYMGfRk3kfltcVlh54ugbIjCeRlpL/tu32n19DSmoY/cF0U0oiq+n70VseC9V+Azs sjt2V0wN3j7fmKsvR0jp1iV9AM+c24RKQ+iXZYdFMIjmOX5tD7PK6JJuX2o+3/eA6b5d 7Apw== 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=bH84+PckuqMSYdURkezXS6exuatn0Y2BOunmWMRXqPk=; fh=ihIYiilCZXBu9x8WrnA4PYm4Oe+ipaGNn90/3600c/4=; b=S3pkpOjbTodXwGwuVF3rFGpi6f5rS/sr1gjovWF94VEfC7FSiNFyBjvUpzcnu5A5tC 7+L5K6Hup/2EVUAwRRo8ANNDFPonezvIXO0R/XXF3tVQSBGStY6A4mP0F4loKi6BQz7j +vpaGVfGsRe3UHEOxpUWm4TrwNQ0dYYjPZuae+i1a2sjomnI5gyL+1LnDYVd3Jw8F2pI BLL7/HUxOvhQvTwwLJERc/vqB+Q4N0GlGllSiaFKoN1vJ7+a/8PcjxKvRqij0PhroxEX RxAoHKyouJNFCUlkSchN3zii//i7eN2JfPMHHJ1TfZi4UQz0zadV0g44MQyTJbNScXRW RAtg== 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:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id ls8-20020a17090b350800b002684bc84493si9714777pjb.131.2023.09.26.04.24.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 04:24:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 1228F81DDE72; Tue, 26 Sep 2023 04:18:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231695AbjIZLSl (ORCPT + 27 others); Tue, 26 Sep 2023 07:18:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231575AbjIZLSj (ORCPT ); Tue, 26 Sep 2023 07:18:39 -0400 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B41E9120; Tue, 26 Sep 2023 04:18:31 -0700 (PDT) X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 38QBHi1eA857842, 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 38QBHi1eA857842 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Sep 2023 19:17:44 +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, 26 Sep 2023 19:17:44 +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, 26 Sep 2023 19:17:43 +0800 From: Hayes Wang To: , CC: , , , , , , , Hayes Wang Subject: [PATCH net-next v3 1/2] r8152: break the loop when the budget is exhausted Date: Tue, 26 Sep 2023 19:17:13 +0800 Message-ID: <20230926111714.9448-433-nic_swsd@realtek.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230926111714.9448-432-nic_swsd@realtek.com> References: <20230926111714.9448-432-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=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Tue, 26 Sep 2023 04:18:48 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778099111967312680 X-GMAIL-MSGID: 1778099111967312680 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. This patch would break the loop about getting next bulk transfer, when the budget is exhausted. That is, only the current bulk transfer would be handled, and the other bulk transfers would be queued for next schedule. Besides, the packets which are more than the budget in the current bulk trasnfer would be still queued in the driver, as the original method. In addition, a bulk transfer wouldn't contain more than 400 packets, so the check of queue length is unnecessary. Therefore, I replace it with WARN_ON_ONCE(). Fixes: cf74eb5a5bc8 ("eth: r8152: try to use a normal budget") Signed-off-by: Hayes Wang --- drivers/net/usb/r8152.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index 0c13d9950cd8..c4038def193f 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -2449,7 +2449,7 @@ static int rx_bottom(struct r8152 *tp, int budget) } } - if (list_empty(&tp->rx_done)) + if (list_empty(&tp->rx_done) || work_done >= budget) goto out1; clear_bit(RX_EPROTO, &tp->flags); @@ -2465,6 +2465,15 @@ static int rx_bottom(struct r8152 *tp, int budget) struct urb *urb; u8 *rx_data; + /* A bulk transfer of USB may contain may packets, so the + * total packets 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; + list_del_init(cursor); agg = list_entry(cursor, struct rx_agg, list); @@ -2484,9 +2493,7 @@ 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; + WARN_ON_ONCE(skb_queue_len(&tp->rx_queue) >= 1000); pkt_len = le32_to_cpu(rx_desc->opts1) & RX_LEN_MASK; if (pkt_len < ETH_ZLEN) @@ -2564,9 +2571,10 @@ static int rx_bottom(struct r8152 *tp, int budget) } } + /* 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); } From patchwork Tue Sep 26 11:17:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hayes Wang X-Patchwork-Id: 144826 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1836953vqu; Tue, 26 Sep 2023 04:25:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHpnQIH/v1UMOtmJ/zeUoMoU9fJHoz/eHEn25AFv6rxB2xwVgzExLRYwTdTMThWtQ8tVCTk X-Received: by 2002:a05:6870:d287:b0:1bf:df47:7b5d with SMTP id d7-20020a056870d28700b001bfdf477b5dmr9365174oae.24.1695727522945; Tue, 26 Sep 2023 04:25:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695727522; cv=none; d=google.com; s=arc-20160816; b=a2yNLNog7rL56X7PxkVl/ymzF9UYAKDn6XFfNkueuLrBQoauurISBTK2phOqcAfoWT cl1syy6o+HUvcqhV4DXGCv6QFlr2315uQQVRJbvWPcMWbSnsfRvoPorYxPMjrSKmy+qK WyRhW0OpeZP6jCV+uEqOBtBz6zkY+HGaICwqp6tgYvlQTr1LCPvzg7LkudxnUtm9EUCi 4Zhl9EBK9uy/0Iq1Ttnpt0HnDVTswnF4xibAf80q+py3hK0q8JTKqjt2T/71VH5JV4qd JtsJ7UbfNv43qnEcwDG3fXAfu5uTGw+8n2ri8Cf9wnZadnGq7j3FWiRgqjvAtAUuGuso YWZg== 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=RRo3QZux3e9khO05WnBqhkDbWtJpQjoNBnfV8VOE5OU=; fh=ihIYiilCZXBu9x8WrnA4PYm4Oe+ipaGNn90/3600c/4=; b=e2+1k5PCbtA2siUYj5aABRY3wab5bhwzhFCl9CPfsjZtcbA46elM2j5HfAwI8q6HUv izHlbLvNPxWTsZpYvT4ByaOtc5AxJaJx6TJoLGrR8jWjQ61NRm/BNBC/04heW7MGN08m A4o+UjBJBz9PsMKm+ky7IMbSFIPkGTrI+CNFO17H5bMu/yFZ3dXDDlUQocYmxaABvU5L WrILPKweLpbzWSM5nRBVzaG0MZQxiRTDFJeJHIJhWfJLLQv9dx+jkYLNfjY4z978vKGC WYb+qsws2pQwIHhmM9CgHsC7iI8vbELDBcEPdASMcplII+ezo5whz47xw0bxSmb1K5rr qQTA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id 19-20020a631753000000b005789f94cd34si12260566pgx.636.2023.09.26.04.25.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 04:25:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 86C808348234; Tue, 26 Sep 2023 04:18:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231899AbjIZLSn (ORCPT + 27 others); Tue, 26 Sep 2023 07:18:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231517AbjIZLSj (ORCPT ); Tue, 26 Sep 2023 07:18:39 -0400 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DB6211F; Tue, 26 Sep 2023 04:18:31 -0700 (PDT) X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 38QBHkQpA857841, 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 38QBHkQpA857841 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Sep 2023 19:17:46 +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, 26 Sep 2023 19:17:44 +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, 26 Sep 2023 19:17:43 +0800 From: Hayes Wang To: , CC: , , , , , , , Hayes Wang Subject: [PATCH net-next v3 2/2] r8152: use napi_gro_frags Date: Tue, 26 Sep 2023 19:17:14 +0800 Message-ID: <20230926111714.9448-434-nic_swsd@realtek.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230926111714.9448-432-nic_swsd@realtek.com> References: <20230926111714.9448-432-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,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 (howler.vger.email [0.0.0.0]); Tue, 26 Sep 2023 04:18:42 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778099183434356823 X-GMAIL-MSGID: 1778099183434356823 Use napi_gro_frags() for the skb of fragments when the work_done is less than budget. Signed-off-by: Hayes Wang --- drivers/net/usb/r8152.c | 67 ++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 17 deletions(-) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index c4038def193f..1231bf365796 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -2490,8 +2490,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, rx_frag_head_sz, len; struct sk_buff *skb; + bool use_frags; WARN_ON_ONCE(skb_queue_len(&tp->rx_queue) >= 1000); @@ -2504,45 +2505,77 @@ static int rx_bottom(struct r8152 *tp, int budget) break; pkt_len -= ETH_FCS_LEN; + len = pkt_len; rx_data += sizeof(struct rx_desc); - if (!agg_free || tp->rx_copybreak > pkt_len) - rx_frag_head_sz = pkt_len; + if (!agg_free || tp->rx_copybreak > len) + use_frags = false; else - rx_frag_head_sz = tp->rx_copybreak; + use_frags = true; + + if (use_frags) { + /* If the budget is exhausted, the packet + * would be queued in the driver. That is, + * napi_gro_frags() wouldn't be called, so + * we couldn't use napi_get_frags(). + */ + if (work_done >= budget) { + rx_frag_head_sz = tp->rx_copybreak; + skb = napi_alloc_skb(napi, + rx_frag_head_sz); + } else { + rx_frag_head_sz = 0; + skb = napi_get_frags(napi); + } + } else { + rx_frag_head_sz = 0; + skb = napi_alloc_skb(napi, 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) { + if (rx_frag_head_sz) { + memcpy(skb->data, rx_data, + rx_frag_head_sz); + skb_put(skb, rx_frag_head_sz); + len -= rx_frag_head_sz; + rx_data += rx_frag_head_sz; + skb->protocol = eth_type_trans(skb, + netdev); + } + skb_add_rx_frag(skb, 0, agg->page, agg_offset(agg, rx_data), - pkt_len, - SKB_DATA_ALIGN(pkt_len)); + len, SKB_DATA_ALIGN(len)); get_page(agg->page); + } else { + memcpy(skb->data, rx_data, len); + skb_put(skb, len); + skb->protocol = eth_type_trans(skb, netdev); } - skb->protocol = eth_type_trans(skb, netdev); - rtl_rx_vlan_tag(rx_desc, skb); if (work_done < budget) { + if (use_frags) + napi_gro_frags(napi); + else + napi_gro_receive(napi, skb); + work_done++; stats->rx_packets++; - stats->rx_bytes += skb->len; - napi_gro_receive(napi, skb); + stats->rx_bytes += pkt_len; } else { __skb_queue_tail(&tp->rx_queue, skb); } find_next_rx: - rx_data = rx_agg_align(rx_data + pkt_len + ETH_FCS_LEN); + rx_data = rx_agg_align(rx_data + len + ETH_FCS_LEN); rx_desc = (struct rx_desc *)rx_data; len_used = agg_offset(agg, rx_data); len_used += sizeof(struct rx_desc);