Skip to contentSkip to conversation

net: fec: add XDP_TX feature support

PATCH Applied Wei Fang 4 participants 6 messages Aug 15, 2023 – Aug 16, 2023

Subsystems (4)
lore
Share & tools
lore

Wei Fang

author maintainer
#0 lore raw

v6 cover net: fec: add XDP_TX feature support

This patch set is to support the XDP_TX feature of FEC driver, the first patch is add initial XDP_TX support, and the second patch improves the performance of XDP_TX by not using xdp_convert_buff_to_frame(). Please refer to the commit message of each patch for more details.

Wei Fang (2):
net: fec: add XDP_TX feature support
net: fec: improve XDP_TX performance

 drivers/net/ethernet/freescale/fec.h      |   6 +-
 drivers/net/ethernet/freescale/fec_main.c | 187 +++++++++++++++-------
 2 files changed, 132 insertions(+), 61 deletions(-)
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH v6 1/2 net: fec: add XDP_TX feature support

The XDP_TX feature is not supported before, and all the frames which are deemed to do XDP_TX action actually do the XDP_DROP action. So this patch adds the XDP_TX support to FEC driver.

I tested the performance of XDP_TX in XDP_DRV mode and XDP_SKB mode respectively on i.MX8MP-EVK platform, and as suggested by Jesper, I also tested the performance of XDP_REDIRECT on the same platform. And the test steps and results are as follows.

XDP_TX test:
Step 1: One board is used as generator and connects to switch,and the FEC port of DUT also connects to the switch. Both boards with flow control off. Then the generator runs the pktgen_sample03_burst_single_flow.sh script to generate and send burst traffic to DUT. Note that the size of packet was set to 64 bytes and the procotol of packet was UDP in my test scenario. In addition, the SMAC of the packet need to be different from the MAC of the generator, because the xdp2 program will swap the DMAC and SMAC of the packet and send it back to the generator. If the SMAC of the generated packet is the MAC of the generator, the generator will receive the returned traffic which increase the CPU loading and significantly degrade the transmit speed of the generator, and finally it affects the test of XDP_TX performance.

Step 2: The DUT runs the xdp2 program to transmit received UDP packets back out on the same port where they were received.

root@imx8mpevk:~# ./xdp2 eth0
proto 17:     353918 pkt/s
proto 17:     352923 pkt/s
proto 17:     353900 pkt/s
proto 17:     352672 pkt/s
proto 17:     353912 pkt/s
proto 17:     354219 pkt/s
root@imx8mpevk:~# ./xdp2 -S eth0
proto 17:     160604 pkt/s
proto 17:     160708 pkt/s
proto 17:     160564 pkt/s
proto 17:     160684 pkt/s
proto 17:     160640 pkt/s
proto 17:     160720 pkt/s

The above results show that the XDP_TX performance of XDP_DRV mode is much better than XDP_SKB mode, more than twice that of XDP_SKB mode, which is in line with our expectation.

XDP_REDIRECT test:
Step1: Both the generator and the FEC port of the DUT connet to the switch port. All the ports with flow control off, then the generator runs the pktgen script to generate and send burst traffic to DUT. Note that the size of packet was set to 64 bytes and the procotol of packet was UDP in my test scenario.

Step2: The DUT runs the xdp_redirect program to redirect the traffic from the FEC port to the FEC port itself.

root@imx8mpevk:~# ./xdp_redirect eth0 eth0
Redirecting from eth0 (ifindex 2; driver fec) to eth0
(ifindex 2; driver fec)
Summary        232,302 rx/s        0 err,drop/s      232,344 xmit/s
Summary        234,579 rx/s        0 err,drop/s      234,577 xmit/s
Summary        235,548 rx/s        0 err,drop/s      235,549 xmit/s
Summary        234,704 rx/s        0 err,drop/s      234,703 xmit/s
Summary        235,504 rx/s        0 err,drop/s      235,504 xmit/s
Summary        235,223 rx/s        0 err,drop/s      235,224 xmit/s
Summary        234,509 rx/s        0 err,drop/s      234,507 xmit/s
Summary        235,481 rx/s        0 err,drop/s      235,482 xmit/s
Summary        234,684 rx/s        0 err,drop/s      234,683 xmit/s
Summary        235,520 rx/s        0 err,drop/s      235,520 xmit/s
Summary        235,461 rx/s        0 err,drop/s      235,461 xmit/s
Summary        234,627 rx/s        0 err,drop/s      234,627 xmit/s
Summary        235,611 rx/s        0 err,drop/s      235,611 xmit/s
  Packets received    : 3,053,753
  Average packets/s   : 234,904
  Packets transmitted : 3,053,792
  Average transmit/s  : 234,907

Compared the performance of XDP_TX with XDP_REDIRECT, XDP_TX is also much better than XDP_REDIRECT. It's also in line with our expectation.

---
V2 changes:
According to Jakub's comments, the V2 patch adds two changes.
1. Call txq_trans_cond_update() in fec_enet_xdp_tx_xmit() to avoid tx timeout as XDP shares the queues with kernel stack.
2. Tx processing shouldn't call any XDP (or page pool) APIs if the "budget" is 0.

V3 changes:
1. Remove the second change in V2, because this change has been separated into another patch and it has been submmitted to the upstream [1].
[1] https://lore.kernel.org/r/[email protected]

V4 changes:
1. Based on Jakub's comments, add trace_xdp_exception() for the error path of XDP_TX.

V5 changes:
1. Implement Jesper's "sync_dma_len" suggestion and simultaneously use page_pool_put_page(pool, page, 0, true) for XDP_TX to avoid the DMA sync on page recycle, which is suggested by Jakub.
2. Based on Jesper's suggestion, add a benchmark comparison between XDP_TX and XDP_REDIRECT. So the commit message is also modified synchronously.

V6 changes:
Add some annotations to the code and fix a typo in commit message.

---
 drivers/net/ethernet/freescale/fec.h      |   1 +
 drivers/net/ethernet/freescale/fec_main.c | 107 +++++++++++++++++-----
 2 files changed, 87 insertions(+), 21 deletions(-)
drivers/net/ethernet/freescale/fec.h +1 -0
index 5ca9906d7c6a..7bb02a9da2a6 100644
@@ -548,6 +548,7 @@ enum {
 enum fec_txbuf_type {
 	FEC_TXBUF_T_SKB,
 	FEC_TXBUF_T_XDP_NDO,
+	FEC_TXBUF_T_XDP_TX,
 };
 
 struct fec_tx_buffer {
drivers/net/ethernet/freescale/fec_main.c +86 -21

203 lines not on this page · raw message

Signature · 1 line
2.25.1
author maintainer
#2 lore raw

PATCH v6 2/2 net: fec: improve XDP_TX performance

In reply to Wei Fang

As suggested by Jesper and Alexander, we can avoid converting xdp_buff to xdp_frame in case of XDP_TX to save a bunch of CPU cycles, so that we can further improve the XDP_TX performance.

Before this patch on i.MX8MP-EVK board, the performance shows as follows.

root@imx8mpevk:~# ./xdp2 eth0
proto 17:     353918 pkt/s
proto 17:     352923 pkt/s
proto 17:     353900 pkt/s
proto 17:     352672 pkt/s
proto 17:     353912 pkt/s
proto 17:     354219 pkt/s

After applying this patch, the performance is improved.

root@imx8mpevk:~# ./xdp2 eth0
proto 17:     369261 pkt/s
proto 17:     369267 pkt/s
proto 17:     369206 pkt/s
proto 17:     369214 pkt/s
proto 17:     369126 pkt/s
proto 17:     369272 pkt/s

---
V5 changes:
New patch. Separated from the first patch, to keep track of the changes and improvements (suggested by Jesper).

V6 changes:
No changes.

---
 drivers/net/ethernet/freescale/fec.h      |   5 +-
 drivers/net/ethernet/freescale/fec_main.c | 140 ++++++++++++----------
 2 files changed, 75 insertions(+), 70 deletions(-)
drivers/net/ethernet/freescale/fec.h +1 -4
index 7bb02a9da2a6..a8fbcada6b01 100644
@@ -552,10 +552,7 @@ enum fec_txbuf_type {
 };
 
 struct fec_tx_buffer {
-	union {
-		struct sk_buff *skb;
-		struct xdp_frame *xdp;
-	};
+	void *buf_p;
 	enum fec_txbuf_type type;
 };
 
drivers/net/ethernet/freescale/fec_main.c +74 -66

273 lines not on this page · raw message

Signature · 1 line
2.25.1
#3 lore raw

Re: [PATCH V6 net-next 2/2] net: fec: improve XDP_TX performance

From: Wei Fang <[email protected]>
Date: Tue, 15 Aug 2023 13:19:55 +0800

Quoted 22 lines

As suggested by Jesper and Alexander, we can avoid converting xdp_buff to xdp_frame in case of XDP_TX to save a bunch of CPU cycles, so that we can further improve the XDP_TX performance.

Before this patch on i.MX8MP-EVK board, the performance shows as follows.

root@imx8mpevk:~# ./xdp2 eth0
proto 17:     353918 pkt/s
proto 17:     352923 pkt/s
proto 17:     353900 pkt/s
proto 17:     352672 pkt/s
proto 17:     353912 pkt/s
proto 17:     354219 pkt/s

After applying this patch, the performance is improved.

root@imx8mpevk:~# ./xdp2 eth0
proto 17:     369261 pkt/s
proto 17:     369267 pkt/s
proto 17:     369206 pkt/s
proto 17:     369214 pkt/s
proto 17:     369126 pkt/s
proto 17:     369272 pkt/s
Quoted 3 lines

BTW I forgot to mention that it was Maciej Fijalkowski <[email protected]> who initially told me that converting xdp_buff -> xdp_frame is expensive and we can avoid that on XDP_TX (he introduced that improved to the ice driver half a year ago). Now I feel like he must've been credited, but it's too late already, sorry :z

Quoted 6 lines

---
V5 changes:
New patch. Separated from the first patch, to keep track of the changes and improvements (suggested by Jesper).

Quoted 6 lines

V6 changes:
No changes.

---
 drivers/net/ethernet/freescale/fec.h      |   5 +-
 drivers/net/ethernet/freescale/fec_main.c | 140 ++++++++++++----------
 2 files changed, 75 insertions(+), 70 deletions(-)

[...]

Thanks,
Olek

Acked-by on the v6 series
#4 lore raw
In reply to Wei Fang
Quoted 5 lines · Wei Fang

This patch set is to support the XDP_TX feature of FEC driver, the first patch is add initial XDP_TX support, and the second patch improves the performance of XDP_TX by not using xdp_convert_buff_to_frame(). Please refer to the commit message of each patch for more details.

Quoted 8 lines

Wei Fang (2):
net: fec: add XDP_TX feature support
net: fec: improve XDP_TX performance

  drivers/net/ethernet/freescale/fec.h      |   6 +-
  drivers/net/ethernet/freescale/fec_main.c | 187 +++++++++++++++-------
  2 files changed, 132 insertions(+), 61 deletions(-)

LGTM

#5 lore raw
In reply to Wei Fang
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Quoted 10 lines · On Tue, 15 Aug 2023 13:19:53 +0800 you wrote:

This patch set is to support the XDP_TX feature of FEC driver, the first patch is add initial XDP_TX support, and the second patch improves the performance of XDP_TX by not using xdp_convert_buff_to_frame(). Please refer to the commit message of each patch for more details.

Wei Fang (2):
net: fec: add XDP_TX feature support
net: fec: improve XDP_TX performance

[...]

Here is the summary with links:
- [V6,net-next,1/2] net: fec: add XDP_TX feature support

    https://git.kernel.org/netdev/net-next/c/f601899e4321
  - [V6,net-next,2/2] net: fec: improve XDP_TX performance
    https://git.kernel.org/netdev/net-next/c/af6f4791380c

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html