net: fec: add XDP_TX feature support
Subsystems (4)
Wei Fang
maintainerPATCH v2 1/1 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.
According to Jakub's suggestions, the V2 patch adds two changes, one is calling txq_trans_cond_update() in fec_enet_xdp_tx_xmit() to avoid tx timeout, because XDP shares the queues with kernel stack (slow path). The other is that tx processing cannot call any XDP (or page pool) APIs if the "budget" is 0, please refer to [1] for more details.
I tested the performance of XDP_TX feature in XDP_DRV and XDP_SKB modes on i.MX8MM-EVK and i.MX8MP-EVK platforms respectively, and the test steps and results are as follows.
Step 1: Board A connects to the FEC port of the DUT and runs the pktgen_sample03_burst_single_flow.sh script to generate and send burst traffic to DUT. Note that the length of packet was set to 64 bytes and the procotol of packet was UDP in my test scenario.
Step 2: The DUT runs the xdp2 program to transmit received UDP packets back out on the same port where they were received.
root@imx8mmevk:~# ./xdp2 eth0 proto 17: 150326 pkt/s proto 17: 141920 pkt/s proto 17: 147338 pkt/s proto 17: 140783 pkt/s proto 17: 150400 pkt/s proto 17: 134651 pkt/s proto 17: 134676 pkt/s proto 17: 134959 pkt/s proto 17: 148152 pkt/s proto 17: 149885 pkt/s
root@imx8mmevk:~# ./xdp2 -S eth0 proto 17: 131094 pkt/s proto 17: 134691 pkt/s proto 17: 138930 pkt/s proto 17: 129347 pkt/s proto 17: 133050 pkt/s proto 17: 132932 pkt/s proto 17: 136628 pkt/s proto 17: 132964 pkt/s proto 17: 131265 pkt/s proto 17: 135794 pkt/s
root@imx8mpevk:~# ./xdp2 eth proto 17: 135817 pkt/s proto 17: 142776 pkt/s proto 17: 142237 pkt/s proto 17: 135673 pkt/s proto 17: 139508 pkt/s proto 17: 147340 pkt/s proto 17: 133329 pkt/s proto 17: 141171 pkt/s proto 17: 146917 pkt/s proto 17: 135488 pkt/s
root@imx8mpevk:~# ./xdp2 -S eth0 proto 17: 133150 pkt/s proto 17: 133127 pkt/s proto 17: 133538 pkt/s proto 17: 133094 pkt/s proto 17: 133690 pkt/s proto 17: 133199 pkt/s proto 17: 133905 pkt/s proto 17: 132908 pkt/s proto 17: 133292 pkt/s proto 17: 133511 pkt/s
[1] https://lore.kernel.org/netdev/[email protected]/T/
---
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.
--- drivers/net/ethernet/freescale/fec.h | 1 + drivers/net/ethernet/freescale/fec_main.c | 99 ++++++++++++++++++----- 2 files changed, 80 insertions(+), 20 deletions(-)
drivers/net/ethernet/freescale/fec.h +1 -0
@@ -547,6 +547,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 +79 -20
185 lines not on this page · raw message
Signature · 1 line
2.25.1
Jakub Kicinski
maintainerQuoted 16 lines · On Fri, 21 Jul 2023 14:21:53 +0800 Wei Fang wrote:
drivers/net/ethernet/freescale/fec_main.c +10
-1+/* Tx processing cannot call any XDP (or page pool) APIs if +* the "budget" is 0. Because NAPI is called with budget of +* 0 (such as netpoll) indicates we may be in an IRQ context, +* however, we can't use the page pool from IRQ context. +*/ +if (unlikely (!budget)) +break ; + xdpf = txq->tx_buf[index].xdp; -if (bdp->cbd_bufaddr) +if (bdp->cbd_bufaddr && + txq->tx_buf[index].type ==FEC_TXBUF_T_XDP_NDO ) dma_unmap_single(&fep->pdev->dev, fec32_to_cpu(bdp->cbd_bufaddr), fec16_to_cpu(bdp->cbd_datlen),
drivers/net/ethernet/freescale/fec_main.c fec_enet_tx_queue(struct net_device *ndev, u16 queue_id) · line 1492
Quoted 8 lines
drivers/net/ethernet/freescale/fec_main.c +4
-1@@ -1474,7 +1486,10 @@ fec_enet_tx_queue(struct net_device *ndev, u16 queue_id)/* Free the sk buffer associated with this last transmit */ dev_kfree_skb_any (skb); }else { -xdp_return_frame (xdpf); +if (txq->tx_buf[index].type ==FEC_TXBUF_T_XDP_NDO ) +xdp_return_frame (xdpf); +else +xdp_return_frame_rx_napi (xdpf);
I think that you need to also break if (!budget) here, xdp_return_frame() may call page pool APIs to return the frame to a page pool owned by another driver. And that needs to be fixed in net/main already?
Signature · 1 line
pw-bot: cr
Wei Fang
maintainerQuoted 17 lines · On Fri, 21 Jul 2023 14:21:53 +0800 Wei Fang wrote:
Quoted 5 lines
drivers/net/ethernet/freescale/fec_main.c +5
-0+/* Tx processing cannot call any XDP (or page pool) APIs if +* the "budget" is 0. Because NAPI is called with budget of +* 0 (such as netpoll) indicates we may be in an IRQ context, +* however, we can't use the page pool from IRQ context. +*/ drivers/net/ethernet/freescale/fec_main.c fec_enet_tx_queue(struct net_device *ndev, u16 queue_id)
Quoted 10 lines
drivers/net/ethernet/freescale/fec_main.c +5
-1+if (unlikely (!budget)) +break ; + xdpf = txq->tx_buf[index].xdp; -if (bdp->cbd_bufaddr) +if (bdp->cbd_bufaddr && + txq->tx_buf[index].type ==FEC_TXBUF_T_XDP_NDO )dma_unmap_single (&fep->pdev->dev,fec32_to_cpu (bdp->cbd_bufaddr), fec16_to_cpu(bdp->cbd_datlen), @@ -1474,7+1486,10 @@
Quoted 11 lines
drivers/net/ethernet/freescale/fec_main.c fec_enet_tx_queue(struct net_device *ndev, u16 queue_id) · line 1492
Quoted 9 lines
fec_enet_tx_queue(struct net_device *ndev, u16 queue_id)drivers/net/ethernet/freescale/fec_main.c +4
-1/* Free the sk buffer associated with this last transmit */ dev_kfree_skb_any (skb); }else { -xdp_return_frame (xdpf); +if (txq->tx_buf[index].type ==FEC_TXBUF_T_XDP_NDO ) +xdp_return_frame (xdpf); +else +xdp_return_frame_rx_napi (xdpf);I think that you need to also break if (!budget) here,
I think there is no need to break again here, because if the "budget" is 0, the code logic will no jump here.
Quoted 2 lines
xdp_return_frame()may call page pool APIs to return the frame to a page pool owned by another driver. And that needs to be fixed in net/main already?
Yes, you are right, I should fixed it in net tree first, and when the fix is merged into net-next tree, I will send a 3rd version of this patch.