Skip to content

net: fec: improve XDP copy mode and add AF_XDP zero-copy support

Wei Fang bpf imx lkml netdev 7 versions – Applied

Status from this message: This series was applied to netdev/net-next.git (main)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v7 Latest15 patches 0 repliesApplied 15/15
  2. v615 patches 4 repliesSuperseded
  3. v515 patches 2 repliesSuperseded
Earlier versions · 4
VersionPostedPatchesRepliesStatus
v415 patches10 repliesSuperseded
v315 patches1 replySuperseded
v214 patches14 repliesSuperseded
v111 patches12 repliesSuperseded

Changes in v7 from the cover letter

1. In fec_enet_rx_queue_xdp(), add trace_xdp_exception() for XDP_ABORTED and invalid XDP actions. Also add it to fec_enet_rx_queue_xsk().
2. In fec_enet_xsk_tx_xmit(), add dma_wmb() before setting status to BD_ENET_TX_READY.
3. Correct the typo in the commit message of patch 15.
v6 link: https://lore.kernel.org/imx/[email protected]/

Patches in v7 All 15 applied

#Subject and filesSizeRepliesApplied
1/15net: fec: add fec_txq_trigger_xmit() helperdrivers/net/ethernet/freescale/fec_main.c+14 -180 repliesApplied
2/15net: fec: add fec_rx_error_check() to check RX errorsdrivers/net/ethernet/freescale/fec_main.c+36 -220 repliesApplied
3/15net: fec: add rx_shift to indicate the extra bytes padded in front of RX framedrivers/net/ethernet/freescale/fec.h drivers/net/ethernet/freescale/fec_main.c+9 -130 repliesApplied
4/15net: fec: add fec_build_skb() to build a skbdrivers/net/ethernet/freescale/fec_main.c+60 -460 repliesApplied
5/15net: fec: improve fec_enet_rx_queue()drivers/net/ethernet/freescale/fec_main.c+15 -200 repliesApplied
6/15net: fec: add fec_enet_rx_queue_xdp() for XDP pathdrivers/net/ethernet/freescale/fec_main.c+170 -860 repliesApplied
7/15net: fec: add tx_qid parameter to fec_enet_xdp_tx_xmit()drivers/net/ethernet/freescale/fec_main.c+19 -190 repliesApplied
8/15net: fec: transmit XDP frames in bulkdrivers/net/ethernet/freescale/fec_main.c+9 -30 repliesApplied
9/15net: fec: remove unnecessary NULL pointer check when clearing TX BD ringdrivers/net/ethernet/freescale/fec_main.c+12 -230 repliesApplied
10/15net: fec: use switch statement to check the type of tx_bufdrivers/net/ethernet/freescale/fec_main.c+73 -610 repliesApplied
11/15net: fec: remove the size parameter from fec_enet_create_page_pool()drivers/net/ethernet/freescale/fec_main.c+3 -30 repliesApplied
12/15net: fec: move xdp_rxq_info* APIs out of fec_enet_create_page_pool()drivers/net/ethernet/freescale/fec_main.c+40 -180 repliesApplied
13/15net: fec: add fec_alloc_rxq_buffers_pp() to allocate buffers from page pooldrivers/net/ethernet/freescale/fec_main.c+58 -320 repliesApplied
14/15net: fec: improve fec_enet_tx_queue()drivers/net/ethernet/freescale/fec_main.c+17 -260 repliesApplied
15/15net: fec: add AF_XDP zero-copy supportdrivers/net/ethernet/freescale/fec.h drivers/net/ethernet/freescale/fec_main.c+754 -440 repliesApplied

Reviews trailers per patch

9 of 15 patches have a Reviewed-by or Acked-by.

PatchFrank Li
1/15R-b
2/15R-b
3/15R-b
4/15R-b
5/15R-b
6/15
7/15
8/15R-b
9/15R-b
10/15
11/15R-b
12/15
13/15
14/15R-b
15/15

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v7 thread

Cover letter [PATCH v7 net-next 00/15] net: fec: improve XDP copy mode and add AF_XDP zero-copy support

This patch set optimizes the XDP copy mode logic as follows.

1. Separate the processing of RX XDP frames from fec_enet_rx_queue(), and adds a separate function fec_enet_rx_queue_xdp() for handling XDP frames.

2. For TX XDP packets, using the batch sending method to avoid frequent MMIO writes.

3. Use the switch statement to check the tx_buf type instead of the if...else... statement, making the cleanup logic of TX BD ring cleared and more efficient.

We compared the performance of XDP copy mode before and after applying this patch set, and the results show that the performance has improved.

Before applying this patch set.

root@imx93evk:~# ./xdp-bench tx eth0
Summary                   396,868 rx/s                  0 err,drop/s
Summary                   396,024 rx/s                  0 err,drop/s
root@imx93evk:~# ./xdp-bench drop eth0
Summary                   684,781 rx/s                  0 err/s
Summary                   675,746 rx/s                  0 err/s
root@imx93evk:~# ./xdp-bench pass eth0
Summary                   208,552 rx/s                  0 err,drop/s
Summary                   208,654 rx/s                  0 err,drop/s
root@imx93evk:~# ./xdp-bench redirect eth0 eth0
eth0->eth0                311,210 rx/s                  0 err,drop/s      311,208 xmit/s
eth0->eth0                310,808 rx/s                  0 err,drop/s      310,809 xmit/s

After applying this patch set.

root@imx93evk:~# ./xdp-bench tx eth0
Summary                   425,778 rx/s                  0 err,drop/s
Summary                   426,042 rx/s                  0 err,drop/s
root@imx93evk:~# ./xdp-bench drop eth0
Summary                   698,351 rx/s                  0 err/s
Summary                   701,882 rx/s                  0 err/s
root@imx93evk:~# ./xdp-bench pass eth0
Summary                   210,348 rx/s                  0 err,drop/s
Summary                   210,016 rx/s                  0 err,drop/s
root@imx93evk:~# ./xdp-bench redirect eth0 eth0
eth0->eth0                354,407 rx/s                  0 err,drop/s      354,401 xmit/s
eth0->eth0                350,381 rx/s                  0 err,drop/s      350,389 xmit/s

This patch set also addes the AF_XDP zero-copy support, and we tested the performance on i.MX93 platform with xdpsock tool. The following is the performance comparison of copy mode and zero-copy mode. It can be seen that the performance of zero-copy mode is better than that of copy mode.

1. MAC swap L2 forwarding
1.1 Zero-copy mode

root@imx93evk:~# ./xdpsock -i eth0 -l -z
 sock0@eth0:0 l2fwd xdp-drv
                   pps            pkts           1.00
rx                 414715         415455
tx                 414715         415455

1.2 Copy mode

root@imx93evk:~# ./xdpsock -i eth0 -l -c
 sock0@eth0:0 l2fwd xdp-drv
                   pps            pkts           1.00
rx                 356396         356609
tx                 356396         356609

2. TX only
2.1 Zero-copy mode

root@imx93evk:~# ./xdpsock -i eth0 -t -s 64 -z
 sock0@eth0:0 txonly xdp-drv
                   pps            pkts           1.00
rx                 0              0
tx                 1119573        1126720

2.2 Copy mode

root@imx93evk:~# ./xdpsock -i eth0 -t -s 64 -c
sock0@eth0:0 txonly xdp-drv
                   pps            pkts           1.00
rx                 0              0
tx                 406864         407616

---
v7:
1. In fec_enet_rx_queue_xdp(), add trace_xdp_exception() for XDP_ABORTED and invalid XDP actions. Also add it to fec_enet_rx_queue_xsk().
2. In fec_enet_xsk_tx_xmit(), add dma_wmb() before setting status to BD_ENET_TX_READY.
3. Correct the typo in the commit message of patch 15.
v6 link: https://lore.kernel.org/imx/[email protected]/
v6:
1. Remove fec_xdp_drop() from XDP_PASS branch of fec_enet_rx_queue_xdp() v5 link: https://lore.kernel.org/imx/[email protected]/
v5:
1. Update the commit message of patch 6 and 13.
2. Fix the potential memory leak issue in fec_enet_alloc_rxq_buffers(), so free the buffers on failure.
3. Only initialize bdp->cbd_bufaddr in fec_alloc_rxq_buffers_pp() because the other fileds of bdp will be initialized in fec_enet_bd_init(). And move the initialization of ebdp to fec_enet_bd_init().
4. Refactor fec_alloc_rxq_buffers_zc().
5. Add a check to rxq->rx_buf[index].xdp in fec_enet_rx_queue_xsk(), for example, for the xdpsock tx only use case, the RX buffers are all NULL.
6. Refactor fec_setup_xsk_pool(), so add some new helpers like fec_enable_xsk_pool(), fec_disable_xsk_pool(), fec_alloc_new_rxq_xsk(), fec_alloc_new_rxq_pp() and fec_xsk_restart_napi(). This refactoring ensures that when fec_setup_xsk_pool() fails, it can revert to the original rxq configuration.
v4 link: https://lore.kernel.org/netdev/[email protected]/
v4:
1. Remove the unneeded semicolon in fec_enet_bd_init()
v3 link: https://lore.kernel.org/imx/[email protected]/
v3:
1. Fix build warning due to missing break for the FEC_TXBUF_T_XSK_TX branch in fec_enet_bd_init().
2. Add new patch 7, which is separated from patch 6
3. Collect Reviewed-by tags.
v2 link: https://lore.kernel.org/imx/[email protected]/
v2:
1. Improve the commit message
2. Remove the unused variable dma from fec_enet_rx_queue_xsk() to fix the build warning
3. Remove fec_txq_trigger_xmit() from fec_enet_xsk_tx_xmit()
4. Separate some new patches, patch 4, 8, 13.
5. Collect Reviewed-by tags.
vl link: https://lore.kernel.org/imx/[email protected]/
---

Wei Fang (15):
net: fec: add fec_txq_trigger_xmit() helper
net: fec: add fec_rx_error_check() to check RX errors
net: fec: add rx_shift to indicate the extra bytes padded in front of
RX frame
net: fec: add fec_build_skb() to build a skb
net: fec: improve fec_enet_rx_queue()
net: fec: add fec_enet_rx_queue_xdp() for XDP path
net: fec: add tx_qid parameter to fec_enet_xdp_tx_xmit()
net: fec: transmit XDP frames in bulk
net: fec: remove unnecessary NULL pointer check when clearing TX BD
ring
net: fec: use switch statement to check the type of tx_buf
net: fec: remove the size parameter from fec_enet_create_page_pool()
net: fec: move xdp_rxq_info* APIs out of fec_enet_create_page_pool()
net: fec: add fec_alloc_rxq_buffers_pp() to allocate buffers from page
pool
net: fec: improve fec_enet_tx_queue()
net: fec: add AF_XDP zero-copy support

 drivers/net/ethernet/freescale/fec.h      |   14 +-
 drivers/net/ethernet/freescale/fec_main.c | 1647 ++++++++++++++++-----
 2 files changed, 1258 insertions(+), 403 deletions(-)
Signature · 1 line
2.34.1