net: fec: using page pool to manage RX buffers
Shenwei Wang
reviewerPATCH v2 1/1 net: fec: using page pool to manage RX buffers
This patch optimizes the RX buffer management by using the page pool. The purpose for this change is to prepare for the following XDP support. The current driver uses one frame per page for easy management.
Added __maybe_unused attribute to the following functions to avoid the compiling warning. Those functions will be removed by a separate patch once this page pool solution is accepted.
- fec_enet_new_rxbdp
- fec_enet_copybreak
The following are the comparing result between page pool implementation and the original implementation (non page pool).
--- small packet (64 bytes) testing are almost the same --- no matter what the implementation is
--- on both i.MX8 and i.MX6SX platforms.
shenwei@5810:~/pktgen$ iperf -c 10.81.16.245 -w 2m -i 1 -l 64 ------------------------------------------------------------ Client connecting to 10.81.16.245, TCP port 5001 TCP window size: 416 KByte (WARNING: requested 1.91 MByte) ------------------------------------------------------------ [ 1] local 10.81.17.20 port 39728 connected with 10.81.16.245 port 5001 [ ID] Interval Transfer Bandwidth [ 1] 0.0000-1.0000 sec 37.0 MBytes 311 Mbits/sec [ 1] 1.0000-2.0000 sec 36.6 MBytes 307 Mbits/sec [ 1] 2.0000-3.0000 sec 37.2 MBytes 312 Mbits/sec [ 1] 3.0000-4.0000 sec 37.1 MBytes 312 Mbits/sec [ 1] 4.0000-5.0000 sec 37.2 MBytes 312 Mbits/sec [ 1] 5.0000-6.0000 sec 37.2 MBytes 312 Mbits/sec [ 1] 6.0000-7.0000 sec 37.2 MBytes 312 Mbits/sec [ 1] 7.0000-8.0000 sec 37.2 MBytes 312 Mbits/sec [ 1] 0.0000-8.0943 sec 299 MBytes 310 Mbits/sec
--- Page Pool implementation on i.MX8 ----
shenwei@5810:~$ iperf -c 10.81.16.245 -w 2m -i 1 ------------------------------------------------------------ Client connecting to 10.81.16.245, TCP port 5001 TCP window size: 416 KByte (WARNING: requested 1.91 MByte) ------------------------------------------------------------ [ 1] local 10.81.17.20 port 43204 connected with 10.81.16.245 port 5001 [ ID] Interval Transfer Bandwidth [ 1] 0.0000-1.0000 sec 111 MBytes 933 Mbits/sec [ 1] 1.0000-2.0000 sec 111 MBytes 934 Mbits/sec [ 1] 2.0000-3.0000 sec 112 MBytes 935 Mbits/sec [ 1] 3.0000-4.0000 sec 111 MBytes 933 Mbits/sec [ 1] 4.0000-5.0000 sec 111 MBytes 934 Mbits/sec [ 1] 5.0000-6.0000 sec 111 MBytes 933 Mbits/sec [ 1] 6.0000-7.0000 sec 111 MBytes 931 Mbits/sec [ 1] 7.0000-8.0000 sec 112 MBytes 935 Mbits/sec [ 1] 8.0000-9.0000 sec 111 MBytes 933 Mbits/sec [ 1] 9.0000-10.0000 sec 112 MBytes 935 Mbits/sec [ 1] 0.0000-10.0077 sec 1.09 GBytes 933 Mbits/sec
--- Non Page Pool implementation on i.MX8 ----
shenwei@5810:~$ iperf -c 10.81.16.245 -w 2m -i 1 ------------------------------------------------------------ Client connecting to 10.81.16.245, TCP port 5001 TCP window size: 416 KByte (WARNING: requested 1.91 MByte) ------------------------------------------------------------ [ 1] local 10.81.17.20 port 49154 connected with 10.81.16.245 port 5001 [ ID] Interval Transfer Bandwidth [ 1] 0.0000-1.0000 sec 104 MBytes 868 Mbits/sec [ 1] 1.0000-2.0000 sec 105 MBytes 878 Mbits/sec [ 1] 2.0000-3.0000 sec 105 MBytes 881 Mbits/sec [ 1] 3.0000-4.0000 sec 105 MBytes 879 Mbits/sec [ 1] 4.0000-5.0000 sec 105 MBytes 878 Mbits/sec [ 1] 5.0000-6.0000 sec 105 MBytes 878 Mbits/sec [ 1] 6.0000-7.0000 sec 104 MBytes 875 Mbits/sec [ 1] 7.0000-8.0000 sec 104 MBytes 875 Mbits/sec [ 1] 8.0000-9.0000 sec 104 MBytes 873 Mbits/sec [ 1] 9.0000-10.0000 sec 104 MBytes 875 Mbits/sec [ 1] 0.0000-10.0073 sec 1.02 GBytes 875 Mbits/sec
--- Page Pool implementation on i.MX6SX ----
shenwei@5810:~/pktgen$ iperf -c 10.81.16.245 -w 2m -i 1 ------------------------------------------------------------ Client connecting to 10.81.16.245, TCP port 5001 TCP window size: 416 KByte (WARNING: requested 1.91 MByte) ------------------------------------------------------------ [ 1] local 10.81.17.20 port 57288 connected with 10.81.16.245 port 5001 [ ID] Interval Transfer Bandwidth [ 1] 0.0000-1.0000 sec 78.8 MBytes 661 Mbits/sec [ 1] 1.0000-2.0000 sec 82.5 MBytes 692 Mbits/sec [ 1] 2.0000-3.0000 sec 82.4 MBytes 691 Mbits/sec [ 1] 3.0000-4.0000 sec 82.4 MBytes 691 Mbits/sec [ 1] 4.0000-5.0000 sec 82.5 MBytes 692 Mbits/sec [ 1] 5.0000-6.0000 sec 82.4 MBytes 691 Mbits/sec [ 1] 6.0000-7.0000 sec 82.5 MBytes 692 Mbits/sec [ 1] 7.0000-8.0000 sec 82.4 MBytes 691 Mbits/sec [ 1] 8.0000-9.0000 sec 82.4 MBytes 691 Mbits/sec [ 1] 9.0000-9.5506 sec 45.0 MBytes 686 Mbits/sec [ 1] 0.0000-9.5506 sec 783 MBytes 688 Mbits/sec
--- Non Page Pool implementation on i.MX6SX ----
shenwei@5810:~/pktgen$ iperf -c 10.81.16.245 -w 2m -i 1 ------------------------------------------------------------ Client connecting to 10.81.16.245, TCP port 5001 TCP window size: 416 KByte (WARNING: requested 1.91 MByte) ------------------------------------------------------------ [ 1] local 10.81.17.20 port 36486 connected with 10.81.16.245 port 5001 [ ID] Interval Transfer Bandwidth [ 1] 0.0000-1.0000 sec 70.5 MBytes 591 Mbits/sec [ 1] 1.0000-2.0000 sec 64.5 MBytes 541 Mbits/sec [ 1] 2.0000-3.0000 sec 73.6 MBytes 618 Mbits/sec [ 1] 3.0000-4.0000 sec 73.6 MBytes 618 Mbits/sec [ 1] 4.0000-5.0000 sec 72.9 MBytes 611 Mbits/sec [ 1] 5.0000-6.0000 sec 73.4 MBytes 616 Mbits/sec [ 1] 6.0000-7.0000 sec 73.5 MBytes 617 Mbits/sec [ 1] 7.0000-8.0000 sec 73.4 MBytes 616 Mbits/sec [ 1] 8.0000-9.0000 sec 73.4 MBytes 616 Mbits/sec [ 1] 9.0000-10.0000 sec 73.9 MBytes 620 Mbits/sec [ 1] 0.0000-10.0174 sec 723 MBytes 605 Mbits/sec
---
Changes in v2:
- adding the testing result on i.MX6SX platform.
- adding the testing result for small packets (64 bytes)
- remove the used member variable in fec_enet_private.
- reorder the local variable declarations in function of fec_enet_alloc_rxq_buffers.
drivers/net/ethernet/freescale/Kconfig | 1 + drivers/net/ethernet/freescale/fec.h | 21 ++- drivers/net/ethernet/freescale/fec_main.c | 155 ++++++++++++++-------- 3 files changed, 119 insertions(+), 58 deletions(-)
drivers/net/ethernet/freescale/Kconfig +1 -0
@@ -28,6 +28,7 @@ config FEC depends on PTP_1588_CLOCK_OPTIONAL select CRC32 select PHYLIB + select PAGE_POOL imply NET_SELFTESTS help Say Y here if you want to use the built-in 10/100 Fast ethernet
drivers/net/ethernet/freescale/fec.h +19 -2
@@ -17,6 +17,7 @@#include <linux/clocksource.h> #include <linux/net_tstamp.h> #include <linux/pm_qos.h> +#include <linux/bpf.h> #include <linux/ptp_clock_kernel.h> #include <linux/timecounter.h> #include <dt-bindings/firmware/imx/rsrc.h>
@@ -346,8 +347,11 @@ struct bufdesc_ex {* the skbuffer directly. */ +#define FEC_ENET_XDP_HEADROOM (XDP_PACKET_HEADROOM) +#define FEC_ENET_RX_PAGES 256 -#define FEC_ENET_RX_FRSIZE 2048 +#define FEC_ENET_RX_FRSIZE (PAGE_SIZE - FEC_ENET_XDP_HEADROOM \ + - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))#define FEC_ENET_RX_FRPPG (PAGE_SIZE / FEC_ENET_RX_FRSIZE)#define RX_RING_SIZE (FEC_ENET_RX_FRPPG * FEC_ENET_RX_PAGES)#define FEC_ENET_TX_FRSIZE 2048
@@ -517,6 +521,12 @@ struct bufdesc_prop {unsigned char dsize_log2; }; +struct fec_enet_priv_txrx_info { +int offset; +struct page *page; +struct sk_buff *skb; +}; +struct fec_enet_priv_tx_q {struct bufdesc_prop bd;unsigned char *tx_bounce[TX_RING_SIZE ];
@@ -532,7 +542,14 @@ struct fec_enet_priv_tx_q {struct fec_enet_priv_rx_q {struct bufdesc_prop bd; -struct sk_buff *rx_skbuff[RX_RING_SIZE ]; +struct fec_enet_priv_txrx_info rx_skb_info[RX_RING_SIZE ]; + +/* page_pool */ +struct page_pool *page_pool; +struct xdp_rxq_info xdp_rxq; + +/* rx queue number, in the range 0-7 */ +u8 id; };struct fec_stop_mode_gpr {
drivers/net/ethernet/freescale/fec_main.c +99 -56
244 lines not on this page · raw message
--
2.34.1
Jakub Kicinski
maintainerQuoted 4 lines · On Fri, 30 Sep 2022 15:44:27 -0500 Shenwei Wang wrote:
This patch optimizes the RX buffer management by using the page pool. The purpose for this change is to prepare for the following XDP support. The current driver uses one frame per page for easy management.
I believe this has been applied as:
commit 95698ff6177b ("net: fec: using page pool to manage RX buffers")
to net-next. Thanks!
Jesper Dangaard Brouer
Acked-byQuoted 6 lines · Jakub Kicinski
Quoted 4 lines · On Fri, 30 Sep 2022 15:44:27 -0500 Shenwei Wang wrote:
This patch optimizes the RX buffer management by using the page pool. The purpose for this change is to prepare for the following XDP support. The current driver uses one frame per page for easy management.
Quoted 6 lines
I believe this has been applied as:
commit
95698ff6177b("net: fec: using page pool to manage RX buffers")to net-next. Thanks!
Sorry, that I was not quick enough to review and ACK this patch. I just went over it quickly and the page_pool adding LGTM, so:
Hello,
while looking at the fec driver I noticed the following not explicitly initialized variable.
Quoted 4 lines · Shenwei Wang
This patch optimizes the RX buffer management by using the page pool. The purpose for this change is to prepare for the following XDP support. The current driver uses one frame per page for easy management.
[...]
Quoted 41 lines
drivers/net/ethernet/freescale/fec.h +11
-1@@ -17,6 +17,7 @@#include <linux/clocksource.h> #include <linux/net_tstamp.h> #include <linux/pm_qos.h> +#include <linux/bpf.h> #include <linux/ptp_clock_kernel.h> #include <linux/timecounter.h> #include <dt-bindings/firmware/imx/rsrc.h> @@ -346,8 +347,11 @@ struct bufdesc_ex {* the skbuffer directly. */ +#define FEC_ENET_XDP_HEADROOM (XDP_PACKET_HEADROOM) +#define FEC_ENET_RX_PAGES 256 -#define FEC_ENET_RX_FRSIZE 2048 +#define FEC_ENET_RX_FRSIZE (PAGE_SIZE - FEC_ENET_XDP_HEADROOM \ + - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))#define FEC_ENET_RX_FRPPG (PAGE_SIZE / FEC_ENET_RX_FRSIZE)#define RX_RING_SIZE (FEC_ENET_RX_FRPPG * FEC_ENET_RX_PAGES)#define FEC_ENET_TX_FRSIZE 2048@@ -517,6 +521,12 @@ struct bufdesc_prop {unsigned char dsize_log2; }; +struct fec_enet_priv_txrx_info { +int offset; +struct page *page; +struct sk_buff *skb; +}; +struct fec_enet_priv_tx_q {struct bufdesc_prop bd;unsigned char *tx_bounce[TX_RING_SIZE ];@@ -532,7 +542,14 @@ struct fec_enet_priv_tx_q {struct fec_enet_priv_rx_q {
drivers/net/ethernet/freescale/fec.h struct fec_enet_priv_tx_q { · line 552
Quoted 10 lines
drivers/net/ethernet/freescale/fec.h +8
-1struct bufdesc_prop bd; -struct sk_buff *rx_skbuff[RX_RING_SIZE ]; +struct fec_enet_priv_txrx_info rx_skb_info[RX_RING_SIZE ]; + +/* page_pool */ +struct page_pool *page_pool; +struct xdp_rxq_info xdp_rxq; + +/* rx queue number, in the range 0-7 */ +u8 id;
This number is never explicitly initialized, I think it's always 0.
Quoted 34 lines
drivers/net/ethernet/freescale/fec.h +0
-0};struct fec_stop_mode_gpr {drivers/net/ethernet/freescale/fec_main.c +16
-0@@ -66,6 +66,8 @@#include <linux/mfd/syscon.h> #include <linux/regmap.h> #include <soc/imx/cpuidle.h> +#include <linux/filter.h> +#include <linux/bpf.h> #include <asm/cacheflush.h> @@ -422,6 +424,48 @@ fec_enet_clear_csum(struct sk_buff *skb, struct net_device *ndev)return 0 ; } +static int +fec_enet_create_page_pool (struct fec_enet_private *fep, +struct fec_enet_priv_rx_q *rxq,int size) +{ +struct page_pool_params pp_params = { + .order =0 , + .flags =PP_FLAG_DMA_MAP |PP_FLAG_DMA_SYNC_DEV , + .pool_size = size, + .nid =dev_to_node (&fep->pdev->dev), + .dev = &fep->pdev->dev, + .dma_dir =DMA_FROM_DEVICE , + .offset =FEC_ENET_XDP_HEADROOM , + .max_len =FEC_ENET_RX_FRSIZE , + };
drivers/net/ethernet/freescale/fec_main.c fec_enet_clear_csum(struct sk_buff *skb, struct net_device *ndev) · line 450
Quoted 10 lines
drivers/net/ethernet/freescale/fec_main.c +10
-0+int err; + + rxq->page_pool =page_pool_create (&pp_params); +if (IS_ERR (rxq->page_pool)) { + err =PTR_ERR (rxq->page_pool); + rxq->page_pool =NULL ; +return err; + } + + err =xdp_rxq_info_reg (&rxq->xdp_rxq, fep->netdev, rxq->id,0 );
But it's used here.
Quoted 7 lines
drivers/net/ethernet/freescale/fec_main.c +7
-0+if (err <0 ) + goto err_free_pp; + + err =xdp_rxq_info_reg_mem_model (&rxq->xdp_rxq,MEM_TYPE_PAGE_POOL , + rxq->page_pool); +if (err) + goto err_unregister_rxq;
drivers/net/ethernet/freescale/fec_main.c fec_enet_clear_csum(struct sk_buff *skb, struct net_device *ndev) · line 467
Quoted 10 lines
drivers/net/ethernet/freescale/fec_main.c +10
-0+ +return 0 ; + +err_unregister_rxq: +xdp_rxq_info_unreg (&rxq->xdp_rxq); +err_free_pp: +page_pool_destroy (rxq->page_pool); + rxq->page_pool =NULL ; +return err; +}
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung Nürnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |