net: fec: add xdp and page pool statistics
Shenwei Wang
reviewerv4 cover net: fec: add xdp and page pool statistics
Changes in V4:
- Using u64 to record the XDP statistics
- Changing strncpy to strscpy
- Remove the "PAGE_POOL_STATS" select per Alexander's feedback
- Export the page_pool_stats definition in the page_pool.h
Changes in v3:
- change memcpy to strncpy to fix the warning reported by Paolo Abeni
- fix the compile errors on powerpc
Changes in v2:
- clean up and restructure the codes per Andrew Lunn's review comments
- clear the statistics when the adaptor is down
Shenwei Wang (2):
net: page_pool: export page_pool_stats definition
net: fec: add xdp and page pool statistics
drivers/net/ethernet/freescale/fec.h | 15 ++++ drivers/net/ethernet/freescale/fec_main.c | 100 ++++++++++++++++++++-- include/net/page_pool.h | 2 +- 3 files changed, 110 insertions(+), 7 deletions(-)
--
2.34.1
Shenwei Wang
reviewerPATCH v4 1/2 net: page_pool: export page_pool_stats definition
The definition of the 'struct page_pool_stats' is required even when the CONFIG_PAGE_POOL_STATS is not defined. Otherwise, it is required the drivers to handle the case of CONFIG_PAGE_POOL_STATS undefined.
--- include/net/page_pool.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/page_pool.h +1 -1
@@ -84,7 +84,6 @@ struct page_pool_params {void *init_arg; }; -#ifdef CONFIG_PAGE_POOL_STATSstruct page_pool_alloc_stats {u64 fast;/* fast path allocations */ u64 slow;/* slow-path order 0 allocations */
@@ -117,6 +116,7 @@ struct page_pool_stats {struct page_pool_recycle_stats recycle_stats; }; +#ifdef CONFIG_PAGE_POOL_STATS int page_pool_ethtool_stats_get_count (void );u8 *page_pool_ethtool_stats_get_strings (u8 *data);u64 *page_pool_ethtool_stats_get (u64 *data,void *stats);
Signature · 1 line
2.34.1
Re: [PATCH v4 1/2] net: page_pool: export page_pool_stats definition
Quoted 3 lines · Shenwei Wang
The definition of the 'struct
page_pool_stats' is required even when theCONFIG_PAGE_POOL_STATSis not defined. Otherwise, it is required the drivers to handle the case ofCONFIG_PAGE_POOL_STATSundefined.
I agree the API is broken, but i think there is a better fix.
There should be a stub of page_pool_get_stats() for when CONFIG_PAGE_POOL_STATS is disabled.
Nothing actually dereferences struct page_pool_stats when you have this stub. So it might be enough to simply have
struct page_pool_stats{
};
Andrew
Shenwei Wang
reviewerRE: [EXT] Re: [PATCH v4 1/2] net: page_pool: export page_pool_stats definition
Quoted 25 lines
-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Tuesday, November 15, 2022 11:12 AM
To: Shenwei Wang <[email protected]>
Cc: David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Jesper Dangaard Brouer <[email protected]>; Ilias Apalodimas <[email protected]>; Alexei Starovoitov <[email protected]>; Daniel Borkmann <[email protected]>; John Fastabend <[email protected]>; [email protected]; linux- [email protected]; [email protected]
Subject: [EXT] Re: [PATCH v4 1/2] net:page_pool: exportpage_pool_statsdefinitionCaution: EXT Email
Quoted 3 lines · Shenwei Wang
The definition of the 'struct
page_pool_stats' is required even when theCONFIG_PAGE_POOL_STATSis not defined. Otherwise, it is required the drivers to handle the case ofCONFIG_PAGE_POOL_STATSundefined.I agree the API is broken, but i think there is a better fix.
Quoted 9 lines
There should be a stub of
page_pool_get_stats()for whenCONFIG_PAGE_POOL_STATSis disabled.Nothing actually dereferences struct
page_pool_statswhen you have this stub. So it might be enough to simply havestruct page_pool_stats{
};
As the structure is open when the CONFIG_PAGE_POOL_STATS is enabled, you can not prevent a user to access its members. The empty stub will still have problems in this kind of situations.
Regards,
Shenwei
Quoted 1 line
Andrew
Re: [EXT] Re: [PATCH v4 1/2] net: page_pool: export page_pool_stats definition
Quoted 8 lines
Quoted 8 lines
I agree the API is broken, but i think there is a better fix.
There should be a stub of
page_pool_get_stats()for whenCONFIG_PAGE_POOL_STATSis disabled.Nothing actually dereferences struct
page_pool_statswhen you have this stub. So it might be enough to simply have
Quoted 7 lines
Quoted 3 lines
struct page_pool_stats{
};As the structure is open when the
CONFIG_PAGE_POOL_STATSis enabled, you can not prevent a user to access its members. The empty stub will still have problems in this kind of situations.
The users, i.e. the driver, has no need to access its members. The members can change, new ones can be added, and it will not cause a problem, given the way this API is defined. Ideally, page_pool_stats would of been an opaque cookie, but that is not how it was implemented :-(
Andrew
Shenwei Wang
reviewerRE: [EXT] Re: [PATCH v4 1/2] net: page_pool: export page_pool_stats definition
Quoted 31 lines
-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Tuesday, November 15, 2022 11:43 AM
To: Shenwei Wang <[email protected]>
Cc: David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Jesper Dangaard Brouer <[email protected]>; Ilias Apalodimas <[email protected]>; Alexei Starovoitov <[email protected]>; Daniel Borkmann <[email protected]>; John Fastabend <[email protected]>; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [EXT] Re: [PATCH v4 1/2] net:page_pool: exportpage_pool_statsdefinitionCaution: EXT Email
Quoted 6 lines
Quoted 6 lines
I agree the API is broken, but i think there is a better fix.
There should be a stub of
page_pool_get_stats()for whenCONFIG_PAGE_POOL_STATSis disabled.Nothing actually dereferences struct
page_pool_statswhen you have thisstub.
Quoted 6 lines
Quoted 5 lines
So it might be enough to simply have
struct page_pool_stats{
};
Quoted 9 lines
Quoted 3 lines
As the structure is open when the
CONFIG_PAGE_POOL_STATSis enabled, you can not prevent a user to access its members. The empty stub will still have problems in this kind of situations.The users, i.e. the driver, has no need to access its members. The members can change, new ones can be added, and it will not cause a problem, given the way this API is defined. Ideally,
page_pool_statswould of been an opaque cookie, but that is not how it was implemented :-(
Okay if the assumption is the user would never access its members.
Regards,
Shenwei
Quoted 1 line
Andrew
Shenwei Wang
reviewerPATCH v4 2/2 net: fec: add xdp and page pool statistics
In reply to Shenwei WangAdded xdp and page pool statistics.
--- drivers/net/ethernet/freescale/fec.h | 15 ++++ drivers/net/ethernet/freescale/fec_main.c | 100 ++++++++++++++++++++-- 2 files changed, 109 insertions(+), 6 deletions(-)
drivers/net/ethernet/freescale/fec.h +15 -0
@@ -526,6 +526,19 @@ struct fec_enet_priv_txrx_info {struct sk_buff *skb; }; +enum { +RX_XDP_REDIRECT =0 , +RX_XDP_PASS , +RX_XDP_DROP , +RX_XDP_TX , +RX_XDP_TX_ERRORS , +TX_XDP_XMIT , +TX_XDP_XMIT_ERRORS , + +/* The following must be the last one */ +XDP_STATS_TOTAL , +}; +struct fec_enet_priv_tx_q {struct bufdesc_prop bd;unsigned char *tx_bounce[TX_RING_SIZE ];
@@ -546,6 +559,8 @@ struct fec_enet_priv_rx_q {/* page_pool */ struct page_pool *page_pool;struct xdp_rxq_info xdp_rxq; +struct u64_stats_sync syncp; +u64 stats[XDP_STATS_TOTAL ];/* rx queue number, in the range 0-7 */ u8 id;
drivers/net/ethernet/freescale/fec_main.c +94 -6
194 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 26 lines
drivers/net/ethernet/freescale/fec_main.c +4
-1@@ -1582,6 +1586,7 @@ fec_enet_rx_queue(struct net_device *ndev, int budget, u16 queue_id)struct bpf_prog *xdp_prog =READ_ONCE (fep->xdp_prog);u32 ret, xdp_result =FEC_ENET_XDP_PASS ;u32 data_start =FEC_ENET_XDP_HEADROOM ; +u32 xdp_stats[XDP_STATS_TOTAL ];struct xdp_buff xdp;struct page *page;u32 sub_len =4 ;@@ -1656,11 +1661,13 @@ fec_enet_rx_queue(struct net_device *ndev, int budget, u16 queue_id)fec_enet_update_cbd (rxq, bdp, index);if (xdp_prog) { +memset (xdp_stats,0 ,sizeof (xdp_stats));xdp_buff_clear_frags_flag (&xdp);/* subtract 16bit shift and FCS */ xdp_prepare_buff (&xdp,page_address (page), data_start, pkt_len - sub_len, false); - ret =fec_enet_run_xdp (fep, xdp_prog, &xdp, rxq, index); + ret =fec_enet_run_xdp (fep, xdp_prog, &xdp, rxq, + xdp_stats, index); xdp_result |= ret;if (ret !=FEC_ENET_XDP_PASS ) goto rx_processing_done;@@ -1762,6 +1769,15 @@ fec_enet_rx_queue(struct net_device *ndev, int budget, u16 queue_id)if (xdp_result &FEC_ENET_XDP_REDIR )xdp_do_flush_map ();
drivers/net/ethernet/freescale/fec_main.c fec_enet_rx_queue(struct net_device *ndev, int budget, u16 queue_id) · line 1780
Quoted 10 lines
drivers/net/ethernet/freescale/fec_main.c +9
-0+if (xdp_prog) { +int i; + +u64_stats_update_begin (&rxq->syncp); +for (i =0 ; i <XDP_STATS_TOTAL ; i++) + rxq->stats[i] += xdp_stats[i]; +u64_stats_update_end (&rxq->syncp); + } +
This looks wrong. You are processing upto the napi budget, 64 frames, in a loop. The memset to 0 happens inside the loop, but you do the accumulation outside the loop?
This patch is getting pretty big. Please break it up, at least into one patch for XDP stats and one for page pool stats.
Andrew
Shenwei Wang
reviewerQuoted 47 lines
-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Tuesday, November 15, 2022 11:29 AM
To: Shenwei Wang <[email protected]>
Cc: David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Jesper Dangaard Brouer <[email protected]>; Ilias Apalodimas <[email protected]>; Alexei Starovoitov <[email protected]>; Daniel Borkmann <[email protected]>; John Fastabend <[email protected]>; [email protected]; linux- [email protected]; [email protected]; kernel test robot <[email protected]>
Subject: [EXT] Re: [PATCH v4 2/2] net: fec: add xdp and page pool statisticsCaution: EXT Email
Review fec_enet_rx_queue(struct net_device *ndev, int
Quoted 1 line
(quoted diff) +0
-0@@ -1582,6 +1586,7 @@ fec_enet_rx_queue(struct net_device *ndev, intbudget, u16
queue_id)drivers/net/ethernet/freescale/fec_main.c fec_enet_rx_queue(struct net_device *ndev, int
Quoted 8 lines
drivers/net/ethernet/freescale/fec_main.c +1
-0struct bpf_prog *xdp_prog =READ_ONCE (fep->xdp_prog);u32 ret, xdp_result =FEC_ENET_XDP_PASS ;u32 data_start =FEC_ENET_XDP_HEADROOM ; +u32 xdp_stats[XDP_STATS_TOTAL ];struct xdp_buff xdp;struct page *page;u32 sub_len =4 ;@@ -1656,11 +1661,13 @@ fec_enet_rx_queue(struct net_device *ndev, intbudget, u16
queue_id)Quoted 5 lines
drivers/net/ethernet/freescale/fec_main.c +1
-0fec_enet_update_cbd (rxq, bdp, index);if (xdp_prog) { +memset (xdp_stats,0 ,sizeof (xdp_stats));xdp_buff_clear_frags_flag (&xdp);drivers/net/ethernet/freescale/fec_main.c fec_enet_rx_queue(struct net_device *ndev, int budget, u16 queue_id)
Quoted 10 lines
drivers/net/ethernet/freescale/fec_main.c +3
-1/* subtract 16bit shift and FCS */ xdp_prepare_buff (&xdp,page_address (page), data_start, pkt_len - sub_len, false); - ret =fec_enet_run_xdp (fep, xdp_prog, &xdp, rxq, index); + ret =fec_enet_run_xdp (fep, xdp_prog, &xdp, rxq, + xdp_stats, index); xdp_result |= ret;if (ret !=FEC_ENET_XDP_PASS ) goto rx_processing_done; @@ -1762,6 +1769,15 @@ fec_enet_rx_queue(struct net_device *ndev, int budget, u16
queue_id)Quoted 3 lines
if (
xdp_result&FEC_ENET_XDP_REDIR)
xdp_do_flush_map();
Quoted 14 lines
drivers/net/ethernet/freescale/fec_main.c fec_enet_rx_queue(struct net_device *ndev, int budget, u16 queue_id) · line 1780
Quoted 9 lines
drivers/net/ethernet/freescale/fec_main.c +9
-0+if (xdp_prog) { +int i; + +u64_stats_update_begin (&rxq->syncp); +for (i =0 ; i <XDP_STATS_TOTAL ; i++) + rxq->stats[i] += xdp_stats[i]; +u64_stats_update_end (&rxq->syncp); + } +This looks wrong. You are processing upto the napi budget, 64 frames, in a loop. The memset to 0 happens inside the loop, but you do the accumulation outside the loop?
My bad. That should be moved outside the loop.
Thanks,
Shenwei
Quoted 4 lines
This patch is getting pretty big. Please break it up, at least into one patch for XDP stats and one for page pool stats.
Andrew
Quoted 6 lines · Shenwei Wang
Changes in V4:
- Using u64 to record the XDP statistics
- Changing strncpy to strscpy
- Remove the "PAGE_POOL_STATS" select per Alexander's feedback
- Export thepage_pool_statsdefinition in thepage_pool.h