netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: ag71xx: switch to napi_build_skb() to reuse skbuff_heads
@ 2022-07-05  0:44 Sieng-Piaw Liew
  2022-07-07  2:52 ` Jakub Kicinski
  0 siblings, 1 reply; 4+ messages in thread
From: Sieng-Piaw Liew @ 2022-07-05  0:44 UTC (permalink / raw)
  To: chris.snook, davem, edumazet, kuba, netdev, linux-kernel; +Cc: Sieng-Piaw Liew

napi_build_skb() reuses NAPI skbuff_head cache in order to save some
cycles on freeing/allocating skbuff_heads on every new Rx or completed
Tx.
Use napi_consume_skb() to feed the cache with skbuff_heads of completed
Tx, so it's never empty.

Signed-off-by: Sieng-Piaw Liew <liew.s.piaw@gmail.com>
---
 drivers/net/ethernet/atheros/ag71xx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/atheros/ag71xx.c b/drivers/net/ethernet/atheros/ag71xx.c
index cac509708e9d..5b6c4637349c 100644
--- a/drivers/net/ethernet/atheros/ag71xx.c
+++ b/drivers/net/ethernet/atheros/ag71xx.c
@@ -825,7 +825,7 @@ static int ag71xx_tx_packets(struct ag71xx *ag, bool flush)
 		if (!skb)
 			continue;
 
-		dev_kfree_skb_any(skb);
+		napi_consume_skb(skb, !flush);
 		ring->buf[i].tx.skb = NULL;
 
 		bytes_compl += ring->buf[i].tx.len;
@@ -1657,7 +1657,7 @@ static int ag71xx_rx_packets(struct ag71xx *ag, int limit)
 		ndev->stats.rx_packets++;
 		ndev->stats.rx_bytes += pktlen;
 
-		skb = build_skb(ring->buf[i].rx.rx_buf, ag71xx_buffer_size(ag));
+		skb = napi_build_skb(ring->buf[i].rx.rx_buf, ag71xx_buffer_size(ag));
 		if (!skb) {
 			skb_free_frag(ring->buf[i].rx.rx_buf);
 			goto next;
-- 
2.17.1


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

* Re: [PATCH] net: ag71xx: switch to napi_build_skb() to reuse skbuff_heads
  2022-07-05  0:44 [PATCH] net: ag71xx: switch to napi_build_skb() to reuse skbuff_heads Sieng-Piaw Liew
@ 2022-07-07  2:52 ` Jakub Kicinski
  2022-07-07 14:10   ` [PATCH net-next v2] " Sieng-Piaw Liew
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2022-07-07  2:52 UTC (permalink / raw)
  To: Sieng-Piaw Liew; +Cc: chris.snook, davem, edumazet, netdev, linux-kernel

On Tue,  5 Jul 2022 08:44:34 +0800 Sieng-Piaw Liew wrote:
> --- a/drivers/net/ethernet/atheros/ag71xx.c
> +++ b/drivers/net/ethernet/atheros/ag71xx.c
> @@ -825,7 +825,7 @@ static int ag71xx_tx_packets(struct ag71xx *ag, bool flush)
>  		if (!skb)
>  			continue;
>  
> -		dev_kfree_skb_any(skb);
> +		napi_consume_skb(skb, !flush);

!flush is not sufficient here, napi can be called with a budget of 0.

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

* [PATCH net-next v2] net: ag71xx: switch to napi_build_skb() to reuse skbuff_heads
  2022-07-07  2:52 ` Jakub Kicinski
@ 2022-07-07 14:10   ` Sieng-Piaw Liew
  2022-07-08 13:30     ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 4+ messages in thread
From: Sieng-Piaw Liew @ 2022-07-07 14:10 UTC (permalink / raw)
  To: chris.snook, davem, edumazet, kuba, netdev, linux-kernel; +Cc: Sieng-Piaw Liew

napi_build_skb() reuses NAPI skbuff_head cache in order to save some
cycles on freeing/allocating skbuff_heads on every new Rx or completed
Tx.
Use napi_consume_skb() to feed the cache with skbuff_heads of completed
Tx, so it's never empty. The budget parameter is added to indicate NAPI
context, as a value of zero can be passed in the case of netpoll.

Signed-off-by: Sieng-Piaw Liew <liew.s.piaw@gmail.com>
---
 drivers/net/ethernet/atheros/ag71xx.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/atheros/ag71xx.c b/drivers/net/ethernet/atheros/ag71xx.c
index 1c6ea6766aa1..e461f4764066 100644
--- a/drivers/net/ethernet/atheros/ag71xx.c
+++ b/drivers/net/ethernet/atheros/ag71xx.c
@@ -786,7 +786,7 @@ static bool ag71xx_check_dma_stuck(struct ag71xx *ag)
 	return false;
 }
 
-static int ag71xx_tx_packets(struct ag71xx *ag, bool flush)
+static int ag71xx_tx_packets(struct ag71xx *ag, bool flush, int budget)
 {
 	struct ag71xx_ring *ring = &ag->tx_ring;
 	int sent = 0, bytes_compl = 0, n = 0;
@@ -825,7 +825,7 @@ static int ag71xx_tx_packets(struct ag71xx *ag, bool flush)
 		if (!skb)
 			continue;
 
-		dev_kfree_skb_any(skb);
+		napi_consume_skb(skb, budget);
 		ring->buf[i].tx.skb = NULL;
 
 		bytes_compl += ring->buf[i].tx.len;
@@ -970,7 +970,7 @@ static void ag71xx_fast_reset(struct ag71xx *ag)
 	mii_reg = ag71xx_rr(ag, AG71XX_REG_MII_CFG);
 	rx_ds = ag71xx_rr(ag, AG71XX_REG_RX_DESC);
 
-	ag71xx_tx_packets(ag, true);
+	ag71xx_tx_packets(ag, true, 0);
 
 	reset_control_assert(ag->mac_reset);
 	usleep_range(10, 20);
@@ -1657,7 +1657,7 @@ static int ag71xx_rx_packets(struct ag71xx *ag, int limit)
 		ndev->stats.rx_packets++;
 		ndev->stats.rx_bytes += pktlen;
 
-		skb = build_skb(ring->buf[i].rx.rx_buf, ag71xx_buffer_size(ag));
+		skb = napi_build_skb(ring->buf[i].rx.rx_buf, ag71xx_buffer_size(ag));
 		if (!skb) {
 			skb_free_frag(ring->buf[i].rx.rx_buf);
 			goto next;
@@ -1703,7 +1703,7 @@ static int ag71xx_poll(struct napi_struct *napi, int limit)
 	int tx_done, rx_done;
 	u32 status;
 
-	tx_done = ag71xx_tx_packets(ag, false);
+	tx_done = ag71xx_tx_packets(ag, false, limit);
 
 	netif_dbg(ag, rx_status, ndev, "processing RX ring\n");
 	rx_done = ag71xx_rx_packets(ag, limit);
-- 
2.17.1


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

* Re: [PATCH net-next v2] net: ag71xx: switch to napi_build_skb() to reuse skbuff_heads
  2022-07-07 14:10   ` [PATCH net-next v2] " Sieng-Piaw Liew
@ 2022-07-08 13:30     ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-07-08 13:30 UTC (permalink / raw)
  To: Sieng-Piaw Liew; +Cc: chris.snook, davem, edumazet, kuba, netdev, linux-kernel

Hello:

This patch was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:

On Thu,  7 Jul 2022 22:10:56 +0800 you wrote:
> napi_build_skb() reuses NAPI skbuff_head cache in order to save some
> cycles on freeing/allocating skbuff_heads on every new Rx or completed
> Tx.
> Use napi_consume_skb() to feed the cache with skbuff_heads of completed
> Tx, so it's never empty. The budget parameter is added to indicate NAPI
> context, as a value of zero can be passed in the case of netpoll.
> 
> [...]

Here is the summary with links:
  - [net-next,v2] net: ag71xx: switch to napi_build_skb() to reuse skbuff_heads
    https://git.kernel.org/netdev/net-next/c/67d7ebdeb2d5

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:[~2022-07-08 13:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-05  0:44 [PATCH] net: ag71xx: switch to napi_build_skb() to reuse skbuff_heads Sieng-Piaw Liew
2022-07-07  2:52 ` Jakub Kicinski
2022-07-07 14:10   ` [PATCH net-next v2] " Sieng-Piaw Liew
2022-07-08 13:30     ` 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;
as well as URLs for NNTP newsgroup(s).