mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next v3 0/2] r8152: modify rx_bottom
@ 2023-09-26 11:17 Hayes Wang
  2023-09-26 11:17 ` [PATCH net-next v3 1/2] r8152: break the loop when the budget is exhausted Hayes Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Hayes Wang @ 2023-09-26 11:17 UTC (permalink / raw)
  To: kuba, davem
  Cc: netdev, nic_swsd, linux-kernel, linux-usb, edumazet, bjorn,
	pabeni, Hayes Wang

v3:
For patch #1, this patch is replaced. The new patch only break the loop,
and keep that the driver would queue the rx packets.

For patch #2, modify the code depends on patch #1. For work_down < budget,
napi_get_frags() and napi_gro_frags() would be used. For the others,
nothing is changed.

v2:
For patch #1, add comment, update commit message, and add Fixes tag.

v1:
These patches are used to improve rx_bottom().

Hayes Wang (2):
  r8152: break the loop when the budget is exhausted
  r8152: use napi_gro_frags

 drivers/net/usb/r8152.c | 85 ++++++++++++++++++++++++++++++-----------
 1 file changed, 63 insertions(+), 22 deletions(-)

-- 
2.41.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net-next v3 1/2] r8152: break the loop when the budget is exhausted
  2023-09-26 11:17 [PATCH net-next v3 0/2] r8152: modify rx_bottom Hayes Wang
@ 2023-09-26 11:17 ` Hayes Wang
  2023-09-26 11:17 ` [PATCH net-next v3 2/2] r8152: use napi_gro_frags Hayes Wang
  2023-10-05  0:10 ` [PATCH net-next v3 0/2] r8152: modify rx_bottom patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Hayes Wang @ 2023-09-26 11:17 UTC (permalink / raw)
  To: kuba, davem
  Cc: netdev, nic_swsd, linux-kernel, linux-usb, edumazet, bjorn,
	pabeni, Hayes Wang

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 <hayeswang@realtek.com>
---
 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);
 	}
 
-- 
2.41.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net-next v3 2/2] r8152: use napi_gro_frags
  2023-09-26 11:17 [PATCH net-next v3 0/2] r8152: modify rx_bottom Hayes Wang
  2023-09-26 11:17 ` [PATCH net-next v3 1/2] r8152: break the loop when the budget is exhausted Hayes Wang
@ 2023-09-26 11:17 ` Hayes Wang
  2023-10-05  0:10 ` [PATCH net-next v3 0/2] r8152: modify rx_bottom patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Hayes Wang @ 2023-09-26 11:17 UTC (permalink / raw)
  To: kuba, davem
  Cc: netdev, nic_swsd, linux-kernel, linux-usb, edumazet, bjorn,
	pabeni, Hayes Wang

Use napi_gro_frags() for the skb of fragments when the work_done is less
than budget.

Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
 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);
-- 
2.41.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next v3 0/2] r8152: modify rx_bottom
  2023-09-26 11:17 [PATCH net-next v3 0/2] r8152: modify rx_bottom Hayes Wang
  2023-09-26 11:17 ` [PATCH net-next v3 1/2] r8152: break the loop when the budget is exhausted Hayes Wang
  2023-09-26 11:17 ` [PATCH net-next v3 2/2] r8152: use napi_gro_frags Hayes Wang
@ 2023-10-05  0:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-10-05  0:10 UTC (permalink / raw)
  To: Hayes Wang
  Cc: kuba, davem, netdev, nic_swsd, linux-kernel, linux-usb, edumazet,
	bjorn, pabeni

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 26 Sep 2023 19:17:12 +0800 you wrote:
> v3:
> For patch #1, this patch is replaced. The new patch only break the loop,
> and keep that the driver would queue the rx packets.
> 
> For patch #2, modify the code depends on patch #1. For work_down < budget,
> napi_get_frags() and napi_gro_frags() would be used. For the others,
> nothing is changed.
> 
> [...]

Here is the summary with links:
  - [net-next,v3,1/2] r8152: break the loop when the budget is exhausted
    https://git.kernel.org/netdev/net-next/c/2cf51f931797
  - [net-next,v3,2/2] r8152: use napi_gro_frags
    https://git.kernel.org/netdev/net-next/c/788d30daa8f9

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-05  0:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-26 11:17 [PATCH net-next v3 0/2] r8152: modify rx_bottom Hayes Wang
2023-09-26 11:17 ` [PATCH net-next v3 1/2] r8152: break the loop when the budget is exhausted Hayes Wang
2023-09-26 11:17 ` [PATCH net-next v3 2/2] r8152: use napi_gro_frags Hayes Wang
2023-10-05  0:10 ` [PATCH net-next v3 0/2] r8152: modify rx_bottom patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®