eth: bnxt: maintain basic pkt/byte counters in SW
Jakub Kicinski
maintainerv2 cover eth: bnxt: maintain basic pkt/byte counters in SW
Some workloads want to be able to track bandwidth utilization on the scale of 10s of msecs. bnxt uses HW stats and async stats updates, with update frequency controlled via ethtool -C. Updating all HW stats more often than 100 msec is both hard for the device and consumes PCIe bandwidth. Switch to maintaining basic Rx / Tx packet and byte counters in SW.
Tested with drivers/net/stats.py:
# Totals: pass:7 fail:0 xfail:0 xpass:0 skip:0 error:0
Manually tested by comparing the ethtool -S stats (which continues to show HW stats) with qstats, and total interface stats. With and without HW-GRO, and with XDP on / off.
Stopping and starting the interface also doesn't corrupt the values.
v2:
- fix skipping XDP vs the XDP Tx ring handling (Michael)
- rename the defines as well as the structs (Przemek)
- fix counding frag'ed packets in XDP Tx
v1: https://lore.kernel.org/[email protected]
Jakub Kicinski (9):
eth: bnxt: use napi_consume_skb()
eth: bnxt: don't run xdp programs on fallback traffic
eth: bnxt: rename ring_err_stats -> ring_drv_stats
eth: bnxt: snapshot driver stats
eth: bnxt: don't use ifdef to check for CONFIG_INET in GRO
eth: bnxt: consolidate the GRO-but-not-really paths in bnxt_gro_skb()
eth: bnxt: maintain rx pkt/byte stats in SW
eth: bnxt: maintain tx pkt/byte stats in SW
eth: bnxt: count xdp xmit packets
drivers/net/ethernet/broadcom/bnxt/bnxt.h | 49 +++- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.h | 3 +- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 213 +++++++++++------- .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 20 +- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 43 +++- 5 files changed, 228 insertions(+), 100 deletions(-)
Signature · 1 line
2.48.1
Jakub Kicinski
maintainerPATCH v2 1/9 eth: bnxt: use napi_consume_skb()
Use napi_consume_skb() to improve skb recycling. __bnxt_tx_int() already has the real NAPI passed in budget.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -1
@@ -855,7 +855,7 @@ static bool __bnxt_tx_int(struct bnxt *bp, struct bnxt_tx_ring_info *txr, next_tx_int: cons =NEXT_TX (cons); -dev_consume_skb_any (skb); +napi_consume_skb (skb, budget); }WRITE_ONCE (txr->tx_cons, cons);
Signature · 1 line
2.48.1
Jakub Kicinski
maintainerPATCH v2 2/9 eth: bnxt: don't run xdp programs on fallback traffic
In reply to Jakub KicinskiThe XDP program attached to the PF should not be executed on the fallback traffic. Pass the desired dev to bnxt_rx_xdp() and abort if the packet is for a representor. bnxt_rx_xdp() has a lot of arguments already, so presumably adding one more is okay.
Compile tested only.
Well behaved drivers (nfp) do not execute XDP on fallback traffic, but perhaps this is a matter of opinion rather than a hard rule, therefore I'm not considering this a fix.
---
v2:
- pass dev to bnxt_rx_xdp(), and skip just the BPF execution, to avoid unintentionally skipping the Tx ring handling
v1: https://lore.kernel.org/[email protected]
--- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.h | 3 ++- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 11 +++++++---- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 8 ++++++-- 3 files changed, 15 insertions(+), 7 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.h +2 -1
@@ -17,7 +17,8 @@ struct bnxt_sw_tx_bd *bnxt_xmit_bd(struct bnxt *bp, dma_addr_t mapping, u32 len, struct xdp_buff *xdp);void bnxt_tx_int_xdp (struct bnxt *bp,struct bnxt_napi *bnapi,int budget); -bool bnxt_rx_xdp (struct bnxt *bp,struct bnxt_rx_ring_info *rxr,u16 cons, +bool bnxt_rx_xdp (struct bnxt *bp,struct net_device *dev, +struct bnxt_rx_ring_info *rxr,u16 cons,struct xdp_buff *xdp,struct page *page,u8 **data_ptr,unsigned int *len,u8 *event);int bnxt_xdp (struct net_device *dev,struct netdev_bpf *xdp);
drivers/net/ethernet/broadcom/bnxt/bnxt.c +7 -4
@@ -2036,7 +2036,7 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, {struct bnxt_napi *bnapi = cpr->bnapi;struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; -struct net_device *dev = bp->dev; +struct net_device *dev;struct rx_cmp *rxcmp;struct rx_cmp_ext *rxcmp1;u32 tmp_raw_cons = *raw_cons;
@@ -2159,6 +2159,10 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, len = flags >>RX_CMP_LEN_SHIFT ; dma_addr = rx_buf->mapping; + dev = bp->dev; +if (cmp_type ==CMP_TYPE_RX_L2_CMP ) + dev =bnxt_get_pkt_dev (bp,RX_CMP_CFA_CODE (rxcmp1)); +if (bnxt_xdp_attached (bp, rxr)) {bnxt_xdp_buff_init (bp, rxr, cons, data_ptr, len, &xdp);if (agg_bufs) {
@@ -2172,7 +2176,8 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, }if (xdp_active) { -if (bnxt_rx_xdp (bp, rxr, cons, &xdp, data, &data_ptr, &len, event)) { +if (bnxt_rx_xdp (bp, dev, rxr, cons, &xdp, data, &data_ptr, &len, + event)) { rc =1 ; goto next_rx; }
@@ -2239,8 +2244,6 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,skb_set_hash (skb,le32_to_cpu (rxcmp->rx_cmp_rss_hash), type); } -if (cmp_type ==CMP_TYPE_RX_L2_CMP ) - dev =bnxt_get_pkt_dev (bp,RX_CMP_CFA_CODE (rxcmp1)); skb->protocol =eth_type_trans (skb, dev);if (skb->dev->features &BNXT_HW_FEATURE_VLAN_ALL_RX ) {
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c +6 -2
@@ -221,7 +221,8 @@ void bnxt_xdp_buff_frags_free(struct bnxt_rx_ring_info *rxr,* true - packet consumed by XDP and new buffer is allocated. * false - packet should be passed to the stack. */ -bool bnxt_rx_xdp (struct bnxt *bp,struct bnxt_rx_ring_info *rxr,u16 cons, +bool bnxt_rx_xdp (struct bnxt *bp,struct net_device *dev, +struct bnxt_rx_ring_info *rxr,u16 cons,struct xdp_buff *xdp,struct page *page,u8 **data_ptr,unsigned int *len,u8 *event) {
@@ -246,7 +247,10 @@ bool bnxt_rx_xdp(struct bnxt *bp, struct bnxt_rx_ring_info *rxr, u16 cons,/* BNXT_RX_PAGE_MODE(bp) when XDP enabled */ orig_data = xdp->data; - act =bpf_prog_run_xdp (xdp_prog, xdp); +if (bp->dev == dev) + act =bpf_prog_run_xdp (xdp_prog, xdp); +else /* packet is for a VF representor */ + act =XDP_PASS ; tx_avail =bnxt_tx_avail (bp, txr);/* If the tx ring is not full, we must not update the rx producer yet
Signature · 1 line
2.48.1
Jakub Kicinski
maintainerPATCH v2 3/9 eth: bnxt: rename ring_err_stats -> ring_drv_stats
In reply to Jakub KicinskiWe will soon store non-error stats to the ring struct. Rename them to "drv" stats, as these are all maintained by the driver (even if partially based on info from descriptors).
Pure rename using sed.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 8 ++++---- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 14 ++++++------- .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 20 +++++++++---------- 3 files changed, 21 insertions(+), 21 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.h +4 -4
@@ -1136,7 +1136,7 @@ struct bnxt_sw_stats {struct bnxt_cmn_sw_stats cmn; }; -struct bnxt_total_ring_err_stats { +struct bnxt_total_ring_drv_stats {u64 rx_total_l4_csum_errors;u64 rx_total_resets;u64 rx_total_buf_errors;
@@ -2538,7 +2538,7 @@ struct bnxt {u8 pri2cos_idx[8 ];u8 pri2cos_valid; -struct bnxt_total_ring_err_stats ring_err_stats_prev; +struct bnxt_total_ring_drv_stats ring_drv_stats_prev;u16 hwrm_max_req_len;u16 hwrm_max_ext_req_len;
@@ -2936,8 +2936,8 @@ int bnxt_half_open_nic(struct bnxt *bp);void bnxt_half_close_nic (struct bnxt *bp);void bnxt_reenable_sriov (struct bnxt *bp);void bnxt_close_nic (struct bnxt *,bool ,bool ); -void bnxt_get_ring_err_stats (struct bnxt *bp, -struct bnxt_total_ring_err_stats *stats); +void bnxt_get_ring_drv_stats (struct bnxt *bp, +struct bnxt_total_ring_drv_stats *stats);bool bnxt_rfs_capable (struct bnxt *bp,bool new_rss_ctx);int bnxt_dbg_hwrm_rd_reg (struct bnxt *bp,u32 reg_off,u16 num_words,u32 *reg_buf);
drivers/net/ethernet/broadcom/bnxt/bnxt.c +7 -7
@@ -12941,7 +12941,7 @@ static void __bnxt_close_nic(struct bnxt *bp, bool irq_re_init,/* Save ring stats before shutdown */ if (bp->bnapi && irq_re_init) {bnxt_get_ring_stats (bp, &bp->net_stats_prev); -bnxt_get_ring_err_stats (bp, &bp->ring_err_stats_prev); +bnxt_get_ring_drv_stats (bp, &bp->ring_drv_stats_prev); }if (irq_re_init) {bnxt_free_irq (bp);
@@ -13191,8 +13191,8 @@ bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)clear_bit (BNXT_STATE_READ_STATS , &bp->state); } -static void bnxt_get_one_ring_err_stats (struct bnxt *bp, -struct bnxt_total_ring_err_stats *stats, +static void bnxt_get_one_ring_drv_stats (struct bnxt *bp, +struct bnxt_total_ring_drv_stats *stats,struct bnxt_cp_ring_info *cpr) {struct bnxt_sw_stats *sw_stats = cpr->sw_stats;
@@ -13211,13 +13211,13 @@ static void bnxt_get_one_ring_err_stats(struct bnxt *bp, stats->total_missed_irqs += sw_stats->cmn.missed_irqs; } -void bnxt_get_ring_err_stats (struct bnxt *bp, -struct bnxt_total_ring_err_stats *stats) +void bnxt_get_ring_drv_stats (struct bnxt *bp, +struct bnxt_total_ring_drv_stats *stats) {int i;for (i =0 ; i < bp->cp_nr_rings; i++) -bnxt_get_one_ring_err_stats (bp, stats, &bp->bnapi[i]->cp_ring); +bnxt_get_one_ring_drv_stats (bp, stats, &bp->bnapi[i]->cp_ring); }static bool bnxt_mc_list_updated (struct bnxt *bp,u32 *rx_mask)
@@ -15643,7 +15643,7 @@ static void bnxt_get_base_stats(struct net_device *dev, rx->packets = bp->net_stats_prev.rx_packets; rx->bytes = bp->net_stats_prev.rx_bytes; - rx->alloc_fail = bp->ring_err_stats_prev.rx_total_oom_discards; + rx->alloc_fail = bp->ring_drv_stats_prev.rx_total_oom_discards; tx->packets = bp->net_stats_prev.tx_packets; tx->bytes = bp->net_stats_prev.tx_bytes;
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +10 -10
@@ -340,7 +340,7 @@ enum { RX_NETPOLL_DISCARDS, }; -static const char *const bnxt_ring_err_stats_arr[] = { +static const char *const bnxt_ring_drv_stats_arr[] = {"rx_total_l4_csum_errors" ,"rx_total_resets" ,"rx_total_buf_errors" ,
@@ -500,7 +500,7 @@ static const struct { BNXT_TX_STATS_PRI_ENTRIES(tx_packets), }; -#define BNXT_NUM_RING_ERR_STATS ARRAY_SIZE(bnxt_ring_err_stats_arr) +#define BNXT_NUM_RING_DRV_STATS ARRAY_SIZE(bnxt_ring_drv_stats_arr)#define BNXT_NUM_PORT_STATS ARRAY_SIZE(bnxt_port_stats_arr)#define BNXT_NUM_STATS_PRI \ (ARRAY_SIZE(bnxt_rx_bytes_pri_arr) + \
@@ -539,7 +539,7 @@ static int bnxt_get_num_stats(struct bnxt *bp)int num_stats =bnxt_get_num_ring_stats (bp);int len; - num_stats +=BNXT_NUM_RING_ERR_STATS ; + num_stats +=BNXT_NUM_RING_DRV_STATS ;if (bp->flags &BNXT_FLAG_PORT_STATS ) num_stats +=BNXT_NUM_PORT_STATS ;
@@ -594,7 +594,7 @@ static bool is_tx_ring(struct bnxt *bp, int ring_num)static void bnxt_get_ethtool_stats (struct net_device *dev,struct ethtool_stats *stats,u64 *buf) { -struct bnxt_total_ring_err_stats ring_err_stats = {0 }; +struct bnxt_total_ring_drv_stats ring_drv_stats = {0 };struct bnxt *bp =netdev_priv (dev);u64 *curr, *prev;u32 tpa_stats;
@@ -643,12 +643,12 @@ static void bnxt_get_ethtool_stats(struct net_device *dev, buf[j] = sw[k]; } -bnxt_get_ring_err_stats (bp, &ring_err_stats); +bnxt_get_ring_drv_stats (bp, &ring_drv_stats); skip_ring_stats: - curr = &ring_err_stats.rx_total_l4_csum_errors; - prev = &bp->ring_err_stats_prev.rx_total_l4_csum_errors; -for (i =0 ; i <BNXT_NUM_RING_ERR_STATS ; i++, j++, curr++, prev++) + curr = &ring_drv_stats.rx_total_l4_csum_errors; + prev = &bp->ring_drv_stats_prev.rx_total_l4_csum_errors; +for (i =0 ; i <BNXT_NUM_RING_DRV_STATS ; i++, j++, curr++, prev++) buf[j] = *curr + *prev;if (bp->flags &BNXT_FLAG_PORT_STATS ) {
@@ -752,8 +752,8 @@ static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf)ethtool_sprintf (&buf,"[%d]: %s" , i, str); } } -for (i =0 ; i <BNXT_NUM_RING_ERR_STATS ; i++) -ethtool_puts (&buf, bnxt_ring_err_stats_arr[i]); +for (i =0 ; i <BNXT_NUM_RING_DRV_STATS ; i++) +ethtool_puts (&buf, bnxt_ring_drv_stats_arr[i]);if (bp->flags &BNXT_FLAG_PORT_STATS )for (i =0 ; i <BNXT_NUM_PORT_STATS ; i++) {
Signature · 1 line
2.48.1
Jakub Kicinski
maintainerPATCH v2 4/9 eth: bnxt: snapshot driver stats
In reply to Jakub KicinskiSubsequent commits will add datapath stats which need u64_stats protection. Make current readers work on a snapshot, so it's easier to extend this code without much duplication.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 31 +++++++++++++++-------- 1 file changed, 21 insertions(+), 10 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +21 -10
@@ -13093,6 +13093,12 @@ static int bnxt_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)return -EOPNOTSUPP ; } +static void bnxt_drv_stat_snapshot (const struct bnxt_sw_stats *sw_stats, +struct bnxt_sw_stats *snapshot) +{ +memcpy (snapshot, sw_stats,sizeof (*snapshot)); +} +static void bnxt_get_ring_stats (struct bnxt *bp,struct rtnl_link_stats64 *stats) {
@@ -13101,8 +13107,11 @@ static void bnxt_get_ring_stats(struct bnxt *bp,for (i =0 ; i < bp->cp_nr_rings; i++) {struct bnxt_napi *bnapi = bp->bnapi[i];struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; +struct bnxt_sw_stats sw_stats;u64 *sw = cpr->stats.sw_stats; +bnxt_drv_stat_snapshot (cpr->sw_stats, &sw_stats); + stats->rx_packets +=BNXT_GET_RING_STATS64 (sw, rx_ucast_pkts); stats->rx_packets +=BNXT_GET_RING_STATS64 (sw, rx_mcast_pkts); stats->rx_packets +=BNXT_GET_RING_STATS64 (sw, rx_bcast_pkts);
@@ -13127,8 +13136,8 @@ static void bnxt_get_ring_stats(struct bnxt *bp, stats->tx_dropped +=BNXT_GET_RING_STATS64 (sw, tx_error_pkts); stats->rx_dropped += - cpr->sw_stats->rx.rx_netpoll_discards + - cpr->sw_stats->rx.rx_oom_discards; + sw_stats.rx.rx_netpoll_discards + + sw_stats.rx.rx_oom_discards; } }
@@ -13195,20 +13204,22 @@ static void bnxt_get_one_ring_drv_stats(struct bnxt *bp,struct bnxt_total_ring_drv_stats *stats, struct bnxt_cp_ring_info *cpr) { - struct bnxt_sw_stats *sw_stats = cpr->sw_stats; u64 *hw_stats = cpr->stats.sw_stats; +struct bnxt_sw_stats sw_stats; - stats->rx_total_l4_csum_errors += sw_stats->rx.rx_l4_csum_errors; - stats->rx_total_resets += sw_stats->rx.rx_resets; - stats->rx_total_buf_errors += sw_stats->rx.rx_buf_errors; - stats->rx_total_oom_discards += sw_stats->rx.rx_oom_discards; - stats->rx_total_netpoll_discards += sw_stats->rx.rx_netpoll_discards; +bnxt_drv_stat_snapshot (cpr->sw_stats, &sw_stats); + + stats->rx_total_l4_csum_errors += sw_stats.rx.rx_l4_csum_errors; + stats->rx_total_resets += sw_stats.rx.rx_resets; + stats->rx_total_buf_errors += sw_stats.rx.rx_buf_errors; + stats->rx_total_oom_discards += sw_stats.rx.rx_oom_discards; + stats->rx_total_netpoll_discards += sw_stats.rx.rx_netpoll_discards; stats->rx_total_ring_discards +=BNXT_GET_RING_STATS64 (hw_stats, rx_discard_pkts); - stats->tx_total_resets += sw_stats->tx.tx_resets; + stats->tx_total_resets += sw_stats.tx.tx_resets; stats->tx_total_ring_discards +=BNXT_GET_RING_STATS64 (hw_stats, tx_discard_pkts); - stats->total_missed_irqs += sw_stats->cmn.missed_irqs; + stats->total_missed_irqs += sw_stats.cmn.missed_irqs; } void bnxt_get_ring_drv_stats(struct bnxt *bp,
Signature · 1 line
2.48.1
Jakub Kicinski
maintainerPATCH v2 5/9 eth: bnxt: don't use ifdef to check for CONFIG_INET in GRO
In reply to Jakub KicinskiUse IS_ENABLED(CONFIG_INET) to make the code easier to refactor. Now all packets which did not go thru GRO will exit in the same branch.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -3
@@ -1740,12 +1740,11 @@ static inline struct sk_buff *bnxt_gro_skb(struct bnxt *bp,struct rx_tpa_end_cmp_ext *tpa_end1, struct sk_buff *skb) { -#ifdef CONFIG_INET int payload_off;u16 segs; segs =TPA_END_TPA_SEGS (tpa_end); -if (segs ==1 ) +if (segs ==1 || !IS_ENABLED (CONFIG_INET ))return skb;NAPI_GRO_CB (skb)->count = segs;
@@ -1759,7 +1758,6 @@ static inline struct sk_buff *bnxt_gro_skb(struct bnxt *bp, skb = bp->gro_func (tpa_info, payload_off,TPA_END_GRO_TS (tpa_end), skb);if (likely (skb))tcp_gro_complete (skb); -#endif return skb; }
Signature · 1 line
2.48.1
Jakub Kicinski
maintainerPATCH v2 6/9 eth: bnxt: consolidate the GRO-but-not-really paths in bnxt_gro_skb()
In reply to Jakub Kicinskibnxt_tpa_end() skips calling bnxt_gro_skb() if it determines that GRO should not be performed. For ease of packet counting pass the gro bool into bnxt_gro_skb(), this way we have a single branch thru which all non-GRO packets coming out of bnxt_tpa_end() should pass.
bnxt_gro_skb() is a static inline with a single caller, it will be inlined so there is no concern about adding an extra call.
seg count will now be extracted every time, but tpa_end is touched by bnxt_tpa_end(), the field extraction will make no practical difference.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +3 -5
@@ -1735,6 +1735,7 @@ static struct sk_buff *bnxt_gro_func_5730x(struct bnxt_tpa_info *tpa_info, } static inline struct sk_buff *bnxt_gro_skb(struct bnxt *bp, + bool gro, struct bnxt_tpa_info *tpa_info, struct rx_tpa_end_cmp *tpa_end, struct rx_tpa_end_cmp_ext *tpa_end1,
@@ -1744,7 +1745,7 @@ static inline struct sk_buff *bnxt_gro_skb(struct bnxt *bp,u16 segs; segs =TPA_END_TPA_SEGS (tpa_end); -if (segs ==1 || !IS_ENABLED (CONFIG_INET )) +if (!gro || segs ==1 || !IS_ENABLED (CONFIG_INET ))return skb;NAPI_GRO_CB (skb)->count = segs;
@@ -1917,10 +1918,7 @@ static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp, (tpa_info->flags2 &RX_CMP_FLAGS2_T_L4_CS_CALC ) >>3 ; } -if (gro) - skb =bnxt_gro_skb (bp, tpa_info, tpa_end, tpa_end1, skb); - -return skb; +return bnxt_gro_skb (bp, gro, tpa_info, tpa_end, tpa_end1, skb); } static void bnxt_tpa_agg(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
Signature · 1 line
2.48.1
Jakub Kicinski
maintainerPATCH v2 7/9 eth: bnxt: maintain rx pkt/byte stats in SW
In reply to Jakub KicinskiSome workloads want to be able to track bandwidth utilization on the scale of 10s of msecs. Updating all HW stats at this rate is both hard and wasteful of PCIe bandwidth.
Maintain basic Rx pkt/byte counters in software. ethtool -S will still show the HW stats, but qstats and rtnl stats will show SW statistics.
We need to take care of HW-GRO, XDP and VF representors. Per netdev qstat definition Rx stats should reflect packets passed to XDP (if active, otherwise to the stack). XDP and GRO do not interoperate in bnxt, so we need to count the packets in a few places. Add a helper and call it where needed.
Do not count VF representor traffic as traffic for the main netdev.
The stats are added towards the end of the struct since ethtool code expects existing members to be first.
---
v2:
- adjust to skipping XDP inside bnxt_rx_pkt()
v1: https://lore.kernel.org/[email protected]
--- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 25 +++++++ drivers/net/ethernet/broadcom/bnxt/bnxt.c | 68 +++++++++++-------- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 14 +++- 3 files changed, 77 insertions(+), 30 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.h +25 -0
@@ -1118,8 +1118,12 @@ struct bnxt_rx_sw_stats {u64 rx_l4_csum_errors;u64 rx_resets;u64 rx_buf_errors; +/* non-ethtool stats follow */ u64 rx_oom_discards;u64 rx_netpoll_discards; +u64 rx_packets; +u64 rx_bytes; +struct u64_stats_sync syncp; };struct bnxt_tx_sw_stats {
@@ -1146,6 +1150,9 @@ struct bnxt_total_ring_drv_stats {u64 tx_total_resets;u64 tx_total_ring_discards;u64 total_missed_irqs; +/* non-ethtool stats follow */ +u64 rx_total_packets; +u64 rx_total_bytes; };struct bnxt_stats_mem {
@@ -2797,6 +2804,24 @@ static inline u32 bnxt_tx_avail(struct bnxt *bp,return bp->tx_ring_size - (used & bp->tx_ring_mask); } +static inline void bnxt_rx_pkt_cnt (struct bnxt *bp,struct bnxt_napi *bnapi, +struct net_device *dev, +int segs,int len,int payload_off) +{ +struct bnxt_sw_stats *sw_stats = bnapi->cp_ring.sw_stats; + +/* Packet is for a representor */ +if (bp->dev != dev) +return ; + +u64_stats_update_begin (&sw_stats->rx.syncp); + sw_stats->rx.rx_packets += segs; + sw_stats->rx.rx_bytes += len; +if (segs >1 ) + sw_stats->rx.rx_bytes += (segs -1 ) * payload_off; +u64_stats_update_end (&sw_stats->rx.syncp); +} +static inline void bnxt_writeq (struct bnxt *bp,u64 val,volatile void __iomem *addr) {
drivers/net/ethernet/broadcom/bnxt/bnxt.c +40 -28
146 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c +12 -2
@@ -247,10 +247,20 @@ bool bnxt_rx_xdp(struct bnxt *bp, struct net_device *dev,/* BNXT_RX_PAGE_MODE(bp) when XDP enabled */ orig_data = xdp->data; -if (bp->dev == dev) +if (bp->dev == dev) { +struct skb_shared_info *sinfo; +int stat_len = *len; + +if (unlikely (xdp_buff_has_frags (xdp))) { + sinfo =xdp_get_shared_info_from_buff (xdp); + stat_len += sinfo->xdp_frags_size; + } + +bnxt_rx_pkt_cnt (bp, rxr->bnapi, dev,1 , stat_len,0 ); act =bpf_prog_run_xdp (xdp_prog, xdp); -else /* packet is for a VF representor */ + }else {/* packet is for a VF representor */ act =XDP_PASS ; + } tx_avail =bnxt_tx_avail (bp, txr);/* If the tx ring is not full, we must not update the rx producer yet
Signature · 1 line
2.48.1
Jakub Kicinski
maintainerPATCH v2 8/9 eth: bnxt: maintain tx pkt/byte stats in SW
In reply to Jakub KicinskiSome workloads want to be able to track bandwidth utilization on the scale of 10s of msecs. Updating all HW stats at this rate is both hard and wasteful of PCIe bandwidth.
Maintain basic Tx pkt/byte counters in software. ethtool -S will still show the HW stats, but qstats and rtnl stats will show SW statistics.
We need to take care of TSO and VF representors, record relevant state in tx_buf to avoid touching potentially cold skb. Use existing holes in the struct (no size change). Note that according to TX_BD_HSIZE max header size is 255, so u8 should be enough.
It's not obvious whether VF representor traffic should be counted, on one hand it doesn't belong to the local interface. On the other it does go thru normal queuing so Qdisc will show it. I opted to _not_ count it.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 11 +++- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 70 ++++++++++++++--------- 2 files changed, 54 insertions(+), 27 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.h +10 -1
@@ -877,11 +877,14 @@ struct bnxt_sw_tx_bd {struct sk_buff *skb;struct xdp_frame *xdpf; }; +struct page *page;DEFINE_DMA_UNMAP_ADDR (mapping);DEFINE_DMA_UNMAP_LEN (len); -struct page *page; +u16 extra_segs; +u8 hdr_size;u8 is_ts_pkt;u8 is_push; +u8 is_vfr;u8 action;unsigned short nr_frags;union {
@@ -1128,6 +1131,10 @@ struct bnxt_rx_sw_stats {struct bnxt_tx_sw_stats {u64 tx_resets; +/* non-ethtool stats follow */ +u64 tx_packets; +u64 tx_bytes; +struct u64_stats_sync syncp; };struct bnxt_cmn_sw_stats {
@@ -1153,6 +1160,8 @@ struct bnxt_total_ring_drv_stats {/* non-ethtool stats follow */ u64 rx_total_packets;u64 rx_total_bytes; +u64 tx_total_packets; +u64 tx_total_bytes; };struct bnxt_stats_mem {
drivers/net/ethernet/broadcom/bnxt/bnxt.c +44 -26
155 lines not on this page · raw message
Signature · 1 line
2.48.1
Jakub Kicinski
maintainerPATCH v2 9/9 eth: bnxt: count xdp xmit packets
In reply to Jakub KicinskiCount XDP_TX and XDP_REDIRECT packets. Since the Tx rings are separate we count the packets sent to the base stats, not per-queues stats.
The XDP stats are protected by the Rx syncp since they are in NAPI context. Feels slightly less ugly than having a Tx stats in Rx struct. But neither is ideal.
---
v2:
- move tx_buf init sooner so that shinfo handling can access it
v1: https://lore.kernel.org/[email protected]
--- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 7 +++++- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 23 +++++++++++++++-- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 25 +++++++++++++++---- 3 files changed, 47 insertions(+), 8 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.h +6 -1
@@ -880,7 +880,10 @@ struct bnxt_sw_tx_bd {struct page *page;DEFINE_DMA_UNMAP_ADDR (mapping);DEFINE_DMA_UNMAP_LEN (len); -u16 extra_segs; +union { +u16 extra_segs; +u16 xdp_len; + };u8 hdr_size;u8 is_ts_pkt;u8 is_push;
@@ -1134,6 +1137,8 @@ struct bnxt_tx_sw_stats {/* non-ethtool stats follow */ u64 tx_packets;u64 tx_bytes; +u64 xdp_packets;/* under rx syncp */ +u64 xdp_bytes;/* under rx syncp */ struct u64_stats_sync syncp; };
drivers/net/ethernet/broadcom/bnxt/bnxt.c +21 -2
@@ -13160,6 +13160,8 @@ static void bnxt_get_ring_stats(struct bnxt *bp, stats->tx_packets += sw_stats.tx.tx_packets; stats->tx_bytes += sw_stats.tx.tx_bytes; + stats->tx_packets += sw_stats.tx.xdp_packets; + stats->tx_bytes += sw_stats.tx.xdp_bytes; stats->rx_missed_errors +=BNXT_GET_RING_STATS64 (sw, rx_discard_pkts);
@@ -13251,8 +13253,9 @@ static void bnxt_get_one_ring_drv_stats(struct bnxt *bp, stats->rx_total_bytes += sw_stats.rx.rx_bytes; stats->rx_total_ring_discards +=BNXT_GET_RING_STATS64 (hw_stats, rx_discard_pkts); - stats->tx_total_packets += sw_stats.tx.tx_packets; - stats->tx_total_bytes += sw_stats.tx.tx_bytes; + stats->tx_total_packets += + sw_stats.tx.tx_packets + sw_stats.tx.xdp_packets; + stats->tx_total_bytes += sw_stats.tx.tx_bytes + sw_stats.tx.xdp_bytes; stats->tx_total_resets += sw_stats.tx.tx_resets; stats->tx_total_ring_discards +=BNXT_GET_RING_STATS64 (hw_stats, tx_discard_pkts);
@@ -15677,6 +15680,7 @@ static void bnxt_get_base_stats(struct net_device *dev, struct netdev_queue_stats_tx *tx) {struct bnxt *bp =netdev_priv (dev); +int i; rx->packets = bp->ring_drv_stats_prev.rx_total_packets; rx->bytes = bp->ring_drv_stats_prev.rx_total_bytes;
@@ -15684,6 +15688,21 @@ static void bnxt_get_base_stats(struct net_device *dev, tx->packets = bp->ring_drv_stats_prev.tx_total_packets; tx->bytes = bp->ring_drv_stats_prev.tx_total_bytes; + +for (i =0 ; i < bp->cp_nr_rings; i++) { +struct bnxt_sw_stats *sw_stats = bp->bnapi[i]->cp_ring.sw_stats; +unsigned int seq; +u64 pkts, bytes; + +do { + seq =u64_stats_fetch_begin (&sw_stats->rx.syncp); + pkts = sw_stats->tx.xdp_packets; + bytes = sw_stats->tx.xdp_bytes; + }while (u64_stats_fetch_retry (&sw_stats->rx.syncp, seq)); + + tx->packets += pkts; + tx->bytes += bytes; + } }static const struct netdev_stat_ops bnxt_stat_ops = {
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c +20 -5
@@ -35,14 +35,17 @@ struct bnxt_sw_tx_bd *bnxt_xmit_bd(struct bnxt *bp,u16 prod;int i; -if (xdp &&xdp_buff_has_frags (xdp)) { - sinfo =xdp_get_shared_info_from_buff (xdp); - num_frags = sinfo->nr_frags; - } -/* fill up the first buffer */ prod = txr->tx_prod; tx_buf = &txr->tx_buf_ring[RING_TX (bp, prod)]; + tx_buf->xdp_len = len; + +if (xdp &&xdp_buff_has_frags (xdp)) { + sinfo =xdp_get_shared_info_from_buff (xdp); + tx_buf->xdp_len += sinfo->xdp_frags_size; + num_frags = sinfo->nr_frags; + } + tx_buf->nr_frags = num_frags;if (xdp) tx_buf->page =virt_to_head_page (xdp->data);
@@ -120,9 +123,11 @@ static void __bnxt_xmit_xdp_redirect(struct bnxt *bp,void bnxt_tx_int_xdp (struct bnxt *bp,struct bnxt_napi *bnapi,int budget) { +struct bnxt_sw_stats *sw_stats = bnapi->cp_ring.sw_stats;struct bnxt_tx_ring_info *txr = bnapi->tx_ring[0 ];struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;u16 tx_hw_cons = txr->tx_hw_cons; +unsigned int pkts =0 , bytes =0 ;bool rx_doorbell_needed = false;struct bnxt_sw_tx_bd *tx_buf;u16 tx_cons = txr->tx_cons;
@@ -135,6 +140,10 @@ void bnxt_tx_int_xdp(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)while (RING_TX (bp, tx_cons) != tx_hw_cons) { tx_buf = &txr->tx_buf_ring[RING_TX (bp, tx_cons)]; + pkts++; + bytes += tx_buf->xdp_len; + tx_buf->xdp_len =0 ; +if (tx_buf->action ==XDP_REDIRECT ) {struct pci_dev *pdev = bp->pdev;
@@ -163,6 +172,12 @@ void bnxt_tx_int_xdp(struct bnxt *bp, struct bnxt_napi *bnapi, int budget) tx_cons =NEXT_TX (tx_cons); } +/* Note: Rx sync here, because Rx == NAPI context */ +u64_stats_update_begin (&sw_stats->rx.syncp); + sw_stats->tx.xdp_packets += pkts; + sw_stats->tx.xdp_bytes += bytes; +u64_stats_update_end (&sw_stats->rx.syncp); + bnapi->events &= ~BNXT_TX_CMP_EVENT ;WRITE_ONCE (txr->tx_cons, tx_cons);if (rx_doorbell_needed) {
Signature · 1 line
2.48.1
Quoted 32 lines · Jakub Kicinski
Some workloads want to be able to track bandwidth utilization on the scale of 10s of msecs. bnxt uses HW stats and async stats updates, with update frequency controlled via ethtool -C. Updating all HW stats more often than 100 msec is both hard for the device and consumes PCIe bandwidth. Switch to maintaining basic Rx / Tx packet and byte counters in SW.
Tested with
drivers/net/stats.py:# Totals: pass:7 fail:0 xfail:0 xpass:0 skip:0 error:0Manually tested by comparing the ethtool -S stats (which continues to show HW stats) with qstats, and total interface stats. With and without HW-GRO, and with XDP on / off.
Stopping and starting the interface also doesn't corrupt the values.v2:
- fix skipping XDP vs the XDP Tx ring handling (Michael)
- rename the defines as well as the structs (Przemek)
- fix counding frag'ed packets in XDP Tx
v1: https://lore.kernel.org/[email protected]Jakub Kicinski (9):
eth: bnxt: usenapi_consume_skb()
eth: bnxt: don't run xdp programs on fallback traffic
eth: bnxt: renamering_err_stats->ring_drv_stats
eth: bnxt: snapshot driver stats
eth: bnxt: don't use ifdef to check forCONFIG_INETin GRO
eth: bnxt: consolidate the GRO-but-not-really paths inbnxt_gro_skb()
eth: bnxt: maintain rx pkt/byte stats in SW
eth: bnxt: maintain tx pkt/byte stats in SW
eth: bnxt: count xdp xmit packets
Quoted 7 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.h | 49 +++- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.h | 3 +- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 213 +++++++++++------- .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 20 +- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 43 +++- 5 files changed, 228 insertions(+), 100 deletions(-)
Re: [PATCH net-next v2 5/9] eth: bnxt: don't use ifdef to check for CONFIG_INET in GRO
In reply to Jakub KicinskiQuoted 6 lines · Jakub Kicinski
Use
IS_ENABLED(CONFIG_INET)to make the code easier to refactor. Now all packets which did not go thru GRO will exit in the same branch.Signed-off-by Jakub Kicinski <[email protected]>
In the old days, tcp_gro_complete() was undefined without CONFIG_INET and that's why we needed the #ifdef. Now there is a stub for tcp_gro_complete() so this will work.
Michael Chan
maintainerRe: [PATCH net-next v2 7/9] eth: bnxt: maintain rx pkt/byte stats in SW
In reply to Jakub KicinskiQuoted 14 lines · Jakub Kicinski
Some workloads want to be able to track bandwidth utilization on the scale of 10s of msecs. Updating all HW stats at this rate is both hard and wasteful of PCIe bandwidth.
Maintain basic Rx pkt/byte counters in software. ethtool -S will still show the HW stats, but qstats and rtnl stats will show SW statistics.
We need to take care of HW-GRO, XDP and VF representors. Per netdev qstat definition Rx stats should reflect packets passed to XDP (if active, otherwise to the stack). XDP and GRO do not interoperate in bnxt, so we need to count the packets in a few places. Add a helper and call it where needed.
Quoted 6 lines
Do not count VF representor traffic as traffic for the main netdev.
The stats are added towards the end of the struct since ethtool code expects existing members to be first.
Signed-off-by Jakub Kicinski <[email protected]>
The byte counting looks correct except for VLAN packets with the VLAN tag stripped. Do we want to count the 4 bytes for the VLAN tag?
Michael Chan
maintainerRe: [PATCH net-next v2 8/9] eth: bnxt: maintain tx pkt/byte stats in SW
In reply to Jakub KicinskiQuoted 13 lines · Jakub Kicinski
Some workloads want to be able to track bandwidth utilization on the scale of 10s of msecs. Updating all HW stats at this rate is both hard and wasteful of PCIe bandwidth.
Maintain basic Tx pkt/byte counters in software. ethtool -S will still show the HW stats, but qstats and rtnl stats will show SW statistics.
We need to take care of TSO and VF representors, record relevant state in
tx_bufto avoid touching potentially cold skb. Use existing holes in the struct (no size change). Note that according toTX_BD_HSIZEmax header size is 255, so u8 should be enough.
Quoted 6 lines
It's not obvious whether VF representor traffic should be counted, on one hand it doesn't belong to the local interface. On the other it does go thru normal queuing so Qdisc will show it. I opted to _not_ count it.
Signed-off-by Jakub Kicinski <[email protected]>
Same VLAN comment for TX.
Jakub Kicinski
maintainerRe: [PATCH net-next v2 7/9] eth: bnxt: maintain rx pkt/byte stats in SW
In reply to Michael ChanQuoted 17 lines · On Sun, 2 Mar 2025 23:06:29 -0800 Michael Chan wrote:
Quoted 16 lines · Jakub Kicinski
Some workloads want to be able to track bandwidth utilization on the scale of 10s of msecs. Updating all HW stats at this rate is both hard and wasteful of PCIe bandwidth.
Maintain basic Rx pkt/byte counters in software. ethtool -S will still show the HW stats, but qstats and rtnl stats will show SW statistics.
We need to take care of HW-GRO, XDP and VF representors. Per netdev qstat definition Rx stats should reflect packets passed to XDP (if active, otherwise to the stack). XDP and GRO do not interoperate in bnxt, so we need to count the packets in a few places. Add a helper and call it where needed.
Do not count VF representor traffic as traffic for the main netdev.
Quoted 7 lines
Quoted 4 lines
The stats are added towards the end of the struct since ethtool code expects existing members to be first.
Signed-off-by Jakub Kicinski <[email protected]>The byte counting looks correct except for VLAN packets with the VLAN tag stripped. Do we want to count the 4 bytes for the VLAN tag?
Not 100% clear to me. I looked at nfp and a couple of Intel drivers and if I read the code right they don't count VLAN tags if stripped. I suspect that's what most drivers which count in SW will do, simply because it's easier rather than intentional choice by their authors.
Happy to change if you have a preference, but to spell it out my understanding is that not counting stripped tags was more comment and that's what I intended to implement here.
Michael Chan
maintainerRe: [PATCH net-next v2 7/9] eth: bnxt: maintain rx pkt/byte stats in SW
Quoted 8 lines · Jakub Kicinski
Not 100% clear to me. I looked at nfp and a couple of Intel drivers and if I read the code right they don't count VLAN tags if stripped. I suspect that's what most drivers which count in SW will do, simply because it's easier rather than intentional choice by their authors.
Happy to change if you have a preference, but to spell it out my understanding is that not counting stripped tags was more comment and that's what I intended to implement here.
I believe our hardware byte counters will count the VLAN tag, but let me double check on that to be certain. I think for consistency, the software counters should match the hardware counters.
Michael Chan
maintainerRe: [PATCH net-next v2 7/9] eth: bnxt: maintain rx pkt/byte stats in SW
Quoted 7 lines · Michael Chan
Quoted 5 lines · Jakub Kicinski
Not 100% clear to me. I looked at nfp and a couple of Intel drivers and if I read the code right they don't count VLAN tags if stripped. I suspect that's what most drivers which count in SW will do, simply because it's easier rather than intentional choice by their authors.
Quoted 7 lines
Quoted 3 lines
Happy to change if you have a preference, but to spell it out my understanding is that not counting stripped tags was more comment and that's what I intended to implement here.
I believe our hardware byte counters will count the VLAN tag, but let me double check on that to be certain. I think for consistency, the software counters should match the hardware counters.
I've confirmed that our HW will count packet bytes on the network side. This means that the VLAN tag will be counted even if it gets stripped on RX or inserted on TX. This also means that padding bytes inserted by the HW will be counted as well. The driver only pads in software TX packets less than 52 bytes.
I think it's better for SW stats to match HW stats. Thanks.
Michael Chan
maintainerRe: [PATCH net-next v2 9/9] eth: bnxt: count xdp xmit packets
In reply to Jakub Kicinskidrivers/net/ethernet/broadcom/bnxt/bnxt.h struct bnxt_tx_sw_stats { · line 1141
Quoted 6 lines · Jakub Kicinski
drivers/net/ethernet/broadcom/bnxt/bnxt.h +2
-0@@ -1134,6 +1137,8 @@ struct bnxt_tx_sw_stats {/* non-ethtool stats follow */ u64 tx_packets;u64 tx_bytes; +u64 xdp_packets;/* under rx syncp */ +u64 xdp_bytes;/* under rx syncp */
Why do we need different TX counters for XDP? A TX ring is either for XDP or for regular TX. It cannot be for both so why do we need separate counters?
Jakub Kicinski
maintainerRe: [PATCH net-next v2 9/9] eth: bnxt: count xdp xmit packets
Quoted 10 lines · On Tue, 4 Mar 2025 14:48:05 -0800 Michael Chan wrote:
drivers/net/ethernet/broadcom/bnxt/bnxt.h struct bnxt_tx_sw_stats { · line 1141
Quoted 6 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.h +2
-0@@ -1134,6 +1137,8 @@ struct bnxt_tx_sw_stats {/* non-ethtool stats follow */ u64 tx_packets;u64 tx_bytes; +u64 xdp_packets;/* under rx syncp */ +u64 xdp_bytes;/* under rx syncp */ Why do we need different TX counters for XDP? A TX ring is either for XDP or for regular TX. It cannot be for both so why do we need separate counters?
No strong reason, felt cleaner given xdp is under a different lock.