net: fec: add initial XDP support
Shenwei Wang
reviewerPATCH v2 1/1 net: fec: add initial XDP support
This patch adds the initial XDP support to Freescale driver. It supports XDP_PASS, XDP_DROP and XDP_REDIRECT actions. Upcoming patches will add support for XDP_TX and Zero Copy features.
As the patch is rather large, the part of codes to collect the statistics is separated and will prepare a dedicated patch for that part.
The driver has a macro RX_RING_SIZE to configure the RX ring size. After testing with the RX ring size, it turned out the small the rign size the better the better performance for XDP mode. So the different ring size is selected for XDP mode and normal mode in this patch.
I just tested with the application of xdpsock.
-- Native here means running command of "xdpsock -i eth0" -- SKB-Mode means running command of "xdpsock -S -i eth0"
RX Ring Size 16 32 64 128
Native 230K 227K 196K 160K
SKB-Mode 207K 208K 203K 204KNormal mode performance by iperf.
RX Ring Size 16 64 128
iperf 300Mbps 830Mbps 933Mbps
The following are the testing result relating to XDP mode:
root@imx8qxpc0mek:~/bpf# ./xdpsock -i eth0
sock0@eth0:0 rxdrop xdp-drv
pps pkts 1.00
rx 384397 8048130
tx 0 0root@imx8qxpc0mek:~/bpf# ./xdpsock -S -i eth0
sock0@eth0:0 rxdrop xdp-skb
pps pkts 1.00
rx 204151 204295
tx 0 0root@imx8qxpc0mek:~/bpf# ./xdp2 eth0 proto 0: 499359 pkt/s proto 0: 508270 pkt/s proto 0: 508160 pkt/s proto 0: 508264 pkt/s
root@imx8qxpc0mek:~/bpf# ./xdp2 -S eth0 proto 0: 0 pkt/s proto 17: 119155 pkt/s proto 0: 1 pkt/s proto 17: 119518 pkt/s proto 17: 119363 pkt/s proto 0: 0 pkt/s proto 17: 119479 pkt/s proto 17: 119484 pkt/s
---
changes in V2:
- Get rid of the expensive fec_net_close/open function calls during XDP/Normal Mode switch.
- Update the testing data on i.mx8qxp mek board.
- fix the compile issue reported by kernel_test_robot
drivers/net/ethernet/freescale/fec.h | 4 + drivers/net/ethernet/freescale/fec_main.c | 245 +++++++++++++++++++++- 2 files changed, 248 insertions(+), 1 deletion(-)
drivers/net/ethernet/freescale/fec.h +4 -0
@@ -348,6 +348,7 @@ struct bufdesc_ex {*/ #define FEC_ENET_XDP_HEADROOM (XDP_PACKET_HEADROOM) +#define XDP_RX_RING_SIZE 16#define FEC_ENET_RX_PAGES 256#define FEC_ENET_RX_FRSIZE (PAGE_SIZE - FEC_ENET_XDP_HEADROOM \
@@ -663,6 +664,9 @@ struct fec_enet_private {struct imx_sc_ipc *ipc_handle; +/* XDP BPF Program */ +struct bpf_prog *xdp_prog; +u64 ethtool_stats[]; };
drivers/net/ethernet/freescale/fec_main.c +244 -1
305 lines not on this page · raw message
--
2.34.1
Quoted 23 lines
drivers/net/ethernet/freescale/fec_main.c +23
-0+static int fec_enet_bpf (struct net_device *dev,struct netdev_bpf *bpf) +{ +struct fec_enet_private *fep =netdev_priv (dev); +bool is_run =netif_running (dev); +struct bpf_prog *old_prog; +unsigned int dsize; +int i; + +switch (bpf->command) { +case XDP_SETUP_PROG : +if (is_run) { +napi_disable (&fep->napi); +netif_tx_disable (dev); + } + + old_prog =xchg (&fep->xdp_prog, bpf->prog); + +/* Update RX ring size */ + dsize = fep->bufdesc_ex ?sizeof (struct bufdesc_ex ) : +sizeof (struct bufdesc ); +for (i =0 ; i < fep->num_rx_queues; i++) { +struct fec_enet_priv_rx_q *rxq = fep->rx_queue[i]; +struct bufdesc *cbd_base;
drivers/net/ethernet/freescale/fec_main.c static u16 fec_enet_select_queue(struct net_device *ndev, struct sk_buff *skb, · line 3589
Quoted 10 lines
drivers/net/ethernet/freescale/fec_main.c +10
-0+unsigned int size; + + cbd_base = rxq->bd.base; +if (bpf->prog) + rxq->bd.ring_size =XDP_RX_RING_SIZE ; +else + rxq->bd.ring_size =RX_RING_SIZE ; + size = dsize * rxq->bd.ring_size; + cbd_base = (struct bufdesc *)(((void *)cbd_base) + size); + rxq->bd.last = (struct bufdesc *)(((void *)cbd_base) - dsize);
This does not look safe. netif_tx_disable(dev) will stop new transmissions, but the hardware can be busy receiving, DMAing frames, using the descriptors, etc. Modifying rxq->bd.last in particular seems risky. I think you need to disable the receiver, wait for it to indicate it really has stopped, and only then make these modifications.
Andrew
Shenwei Wang
reviewerQuoted 16 lines
-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, October 31, 2022 12:10 PM
To: Shenwei Wang <[email protected]>drivers/net/ethernet/freescale/fec_main.c static u16 fec_enet_select_queue(struct net_device *ndev, struct sk_buff *skb,
Quoted 9 lines
drivers/net/ethernet/freescale/fec_main.c +9
-0+ cbd_base = rxq->bd.base; +if (bpf->prog) + rxq->bd.ring_size =XDP_RX_RING_SIZE ; +else + rxq->bd.ring_size =RX_RING_SIZE ; + size = dsize * rxq->bd.ring_size; + cbd_base = (struct bufdesc *)(((void *)cbd_base) + size); + rxq->bd.last = (struct bufdesc *)(((void + *)cbd_base) - dsize);
Quoted 6 lines
This does not look safe.
netif_tx_disable(dev)will stop new transmissions, but the hardware can be busy receiving, DMAing frames, using the descriptors, etc. Modifyingrxq->bd.lastin particular seems risky. I think you need to disable the receiver, wait for it to indicate it really has stopped, and only then make these modifications.
Sounds reasonable. How about moving the codes of updating ring size to the place right after the enet reset inside the fec_restart? This should clear those risky corner cases.
Thanks,
Shenwei
Quoted 1 line
Andrew
Quoted 17 lines
Quoted 10 lines
drivers/net/ethernet/freescale/fec_main.c static u16 fec_enet_select_queue(struct net_device *ndev, struct sk_buff *skb,
Quoted 9 lines
drivers/net/ethernet/freescale/fec_main.c +9
-0+ cbd_base = rxq->bd.base; +if (bpf->prog) + rxq->bd.ring_size =XDP_RX_RING_SIZE ; +else + rxq->bd.ring_size =RX_RING_SIZE ; + size = dsize * rxq->bd.ring_size; + cbd_base = (struct bufdesc *)(((void *)cbd_base) + size); + rxq->bd.last = (struct bufdesc *)(((void + *)cbd_base) - dsize);Quoted 6 lines
This does not look safe.
netif_tx_disable(dev)will stop new transmissions, but the hardware can be busy receiving, DMAing frames, using the descriptors, etc. Modifyingrxq->bd.lastin particular seems risky. I think you need to disable the receiver, wait for it to indicate it really has stopped, and only then make these modifications.
Quoted 3 lines
Sounds reasonable. How about moving the codes of updating ring size to the place right after the enet reset inside the
fec_restart? This should clear those risky corner cases.
That sounds reasonable. But please add some comments. The driver has RX_RING_SIZE elements allocated, but you are only using a subset. This needs to be clear for when somebody implements the ethtool --rings option.
And i still think it would be good to implement that code. As your numbers show, the ring size does affect performance, and it is hard to know if your hard coded XDP_RX_RING_SIZE is the right value, depending on what the eBPF program is doing. If the ethtool option was provided, it allows users to benchmark different ring sizes for their workload.
Andrew
Shenwei Wang
reviewerQuoted 9 lines
-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, October 31, 2022 3:17 PMQuoted 4 lines
Quoted 3 lines
to disable the receiver, wait for it to indicate it really has stopped, and only then make these modifications.
Quoted 8 lines
Quoted 3 lines
Sounds reasonable. How about moving the codes of updating ring size to the place right after the enet reset inside the
fec_restart? This should clear those risky corner cases.That sounds reasonable. But please add some comments. The driver has
RX_RING_SIZEelements allocated, but you are only using a subset. This needs to be clear for when somebody implements the ethtool --rings option.
The latest performance data regarding the native XDP has got improved a lot. The ring size change doesn't seem necessary any more. The v3 patch has removed that part
of codes, and that logic can be added back in future if necessary as well as the ethtool -rings option.
Thanks,
Shenwei
Quoted 7 lines
And i still think it would be good to implement that code. As your numbers show, the ring size does affect performance, and it is hard to know if your hard coded
XDP_RX_RING_SIZEis the right value, depending on what the eBPF program is doing. If the ethtool option was provided, it allows users to benchmark different ring sizes for their workload.Andrew