net: stmmac: fix & improve driver statistics
Subsystems (5)
v3 cover net: stmmac: fix & improve driver statistics
improve the stmmac driver statistics:
1. don't clear network driver statistics in .ndo_close() and .ndo_open() cycle
2. avoid some network driver statistics overflow on 32 bit platforms
3. use pcpu statistics where necessary to remove frequent cacheline ping pongs.
NOTE: v1 and v2 are back ported from an internal LTS tree, I made some mistakes when backporting and squashing. Now, net-next + v3 has been well tested with 'ethtool -s' and 'ip -s link show'.
Since v2:
- fix ethtool .get_sset_count, .get_strings and per queue stats couting.
- fix .ndo_get_stats64 only counts the last cpu's pcpu stats.
- fix typo: s/iff/if in commit msg.
- remove unnecessary if statement brackets since we have removed one LoC.
Since v1:
- rebase on net-next
- fold two original patches into one patch
- fix issues found by lkp
- update commit msg
Jisheng Zhang (2):
net: stmmac: don't clear network statistics in .ndo_open()
net: stmmac: use pcpu 64 bit statistics where necessary
drivers/net/ethernet/stmicro/stmmac/common.h | 54 +++-- .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 15 +- .../ethernet/stmicro/stmmac/dwmac100_dma.c | 7 +- .../ethernet/stmicro/stmmac/dwmac4_descs.c | 16 +- .../net/ethernet/stmicro/stmmac/dwmac4_lib.c | 15 +- .../net/ethernet/stmicro/stmmac/dwmac_lib.c | 10 +- .../ethernet/stmicro/stmmac/dwxgmac2_descs.c | 6 +- .../ethernet/stmicro/stmmac/dwxgmac2_dma.c | 13 +- .../net/ethernet/stmicro/stmmac/enh_desc.c | 20 +- drivers/net/ethernet/stmicro/stmmac/hwif.h | 12 +- .../net/ethernet/stmicro/stmmac/norm_desc.c | 15 +- .../ethernet/stmicro/stmmac/stmmac_ethtool.c | 108 +++++++--- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 190 +++++++++++++----- 13 files changed, 312 insertions(+), 169 deletions(-)
Signature · 1 line
2.40.1
PATCH v3 1/2 net: stmmac: don't clear network statistics in .ndo_open()
FWICT, the common style in other network drivers: the network statistics are not cleared since initialization, follow the common style for stmmac.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -4
@@ -3827,10 +3827,6 @@ static int __stmmac_open(struct net_device *dev, } } -/* Extra statistics */ -memset (&priv->xstats,0 ,sizeof (struct stmmac_extra_stats )); - priv->xstats.threshold = tc; - priv->rx_copybreak =STMMAC_RX_COPYBREAK ; buf_sz = dma_conf->dma_buf_sz;
@@ -7315,6 +7311,8 @@ int stmmac_dvr_probe(struct device *device,#endif priv->msg_enable =netif_msg_init (debug, default_msg_level); + priv->xstats.threshold = tc; +/* Initialize RSS */ rxq = priv->plat->rx_queues_to_use;netdev_rss_key_fill (priv->rss.key,sizeof (priv->rss.key));
Signature · 1 line
2.40.1
PATCH v3 2/2 net: stmmac: use pcpu 64 bit statistics where necessary
In reply to Jisheng ZhangCurrently, there are two major issues with stmmac driver statistics First of all, statistics in stmmac_extra_stats, stmmac_rxq_stats and stmmac_txq_stats are 32 bit variables on 32 bit platforms. This can cause some stats to overflow after several minutes of high traffic, for example rx_pkt_n, tx_pkt_n and so on.
Secondly, if HW supports multiqueues, there are frequent cacheline ping pongs on some driver statistic vars, for example, normal_irq_n, tx_pkt_n and so on. What's more, frequent cacheline ping pongs on normal_irq_n happens in ISR, this makes the situation worse.
To improve the driver, we convert those statistics to 64 bit, implement ndo_get_stats64 and update .get_ethtool_stats implementation accordingly. We also use pcpu statistics where necessary to remove the cacheline ping pongs as much as possible to make multiqueue operations faster. Those statistics which are not possible to overflow and not frequently updated are kept as is.
--- drivers/net/ethernet/stmicro/stmmac/common.h | 54 +++-- .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 15 +- .../ethernet/stmicro/stmmac/dwmac100_dma.c | 7 +- .../ethernet/stmicro/stmmac/dwmac4_descs.c | 16 +- .../net/ethernet/stmicro/stmmac/dwmac4_lib.c | 15 +- .../net/ethernet/stmicro/stmmac/dwmac_lib.c | 10 +- .../ethernet/stmicro/stmmac/dwxgmac2_descs.c | 6 +- .../ethernet/stmicro/stmmac/dwxgmac2_dma.c | 13 +- .../net/ethernet/stmicro/stmmac/enh_desc.c | 20 +- drivers/net/ethernet/stmicro/stmmac/hwif.h | 12 +- .../net/ethernet/stmicro/stmmac/norm_desc.c | 15 +- .../ethernet/stmicro/stmmac/stmmac_ethtool.c | 108 +++++++--- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 184 +++++++++++++----- 13 files changed, 310 insertions(+), 165 deletions(-)
drivers/net/ethernet/stmicro/stmmac/common.h +35 -19
@@ -59,19 +59,44 @@/* #define FRAME_FILTER_DEBUG */ struct stmmac_txq_stats { -unsigned long tx_pkt_n; -unsigned long tx_normal_irq_n; +u64 tx_pkt_n; +u64 tx_normal_irq_n; };struct stmmac_rxq_stats { -unsigned long rx_pkt_n; -unsigned long rx_normal_irq_n; +u64 rx_pkt_n; +u64 rx_normal_irq_n; +}; + +struct stmmac_pcpu_stats { +struct u64_stats_sync syncp; +/* per queue statistics */ +struct stmmac_txq_stats txq_stats[MTL_MAX_TX_QUEUES ]; +struct stmmac_rxq_stats rxq_stats[MTL_MAX_RX_QUEUES ]; +/* device stats */ +u64 rx_packets; +u64 rx_bytes; +u64 tx_packets; +u64 tx_bytes; +/* Tx/Rx IRQ Events */ +u64 tx_pkt_n; +u64 rx_pkt_n; +u64 normal_irq_n; +u64 rx_normal_irq_n; +u64 napi_poll; +u64 tx_normal_irq_n; +u64 tx_clean; +u64 tx_set_ic_bit; +/* TSO */ +u64 tx_tso_frames; +u64 tx_tso_nfrags; };/* Extra statistic and debug information exposed by ethtool */ struct stmmac_extra_stats { +struct stmmac_pcpu_stats __percpu *pstats;/* Transmit errors */ -unsigned long tx_underflow____cacheline_aligned ; +unsigned long tx_underflow;unsigned long tx_carrier;unsigned long tx_losscarrier;unsigned long vlan_tag;
@@ -81,6 +106,7 @@ struct stmmac_extra_stats {unsigned long tx_frame_flushed;unsigned long tx_payload_error;unsigned long tx_ip_header_error; +unsigned long tx_collision;/* Receive errors */ unsigned long rx_desc;unsigned long sa_filter_fail;
@@ -113,14 +139,6 @@ struct stmmac_extra_stats {/* Tx/Rx IRQ Events */ unsigned long rx_early_irq;unsigned long threshold; -unsigned long tx_pkt_n; -unsigned long rx_pkt_n; -unsigned long normal_irq_n; -unsigned long rx_normal_irq_n; -unsigned long napi_poll; -unsigned long tx_normal_irq_n; -unsigned long tx_clean; -unsigned long tx_set_ic_bit;unsigned long irq_receive_pmt_irq_n;/* MMC info */ unsigned long mmc_tx_irq_n;
@@ -190,18 +208,16 @@ struct stmmac_extra_stats {unsigned long mtl_rx_fifo_ctrl_active;unsigned long mac_rx_frame_ctrl_fifo;unsigned long mac_gmii_rx_proto_engine; -/* TSO */ -unsigned long tx_tso_frames; -unsigned long tx_tso_nfrags;/* EST */ unsigned long mtl_est_cgce;unsigned long mtl_est_hlbs;unsigned long mtl_est_hlbf;unsigned long mtl_est_btre;unsigned long mtl_est_btrlm; -/* per queue statistics */ -struct stmmac_txq_stats txq_stats[MTL_MAX_TX_QUEUES ]; -struct stmmac_rxq_stats rxq_stats[MTL_MAX_RX_QUEUES ]; +unsigned long rx_dropped; +unsigned long rx_errors; +unsigned long tx_dropped; +unsigned long tx_errors; };/* Safety Feature statistics exposed by ethtool */
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +9 -6
@@ -440,6 +440,7 @@ static int sun8i_dwmac_dma_interrupt(struct stmmac_priv *priv, struct stmmac_extra_stats *x, u32 chan, u32 dir) { + struct stmmac_pcpu_stats *stats = this_cpu_ptr(priv->xstats.pstats);u32 v;int ret =0 ;
@@ -450,11 +451,18 @@ static int sun8i_dwmac_dma_interrupt(struct stmmac_priv *priv,else if (dir ==DMA_DIR_TX ) v &=EMAC_INT_MSK_TX ; +u64_stats_update_begin (&stats->syncp);if (v &EMAC_TX_INT ) { ret |= handle_tx; - x->tx_normal_irq_n++; + stats->tx_normal_irq_n++; } +if (v &EMAC_RX_INT ) { + ret |= handle_rx; + stats->rx_normal_irq_n++; + } +u64_stats_update_end (&stats->syncp); +if (v &EMAC_TX_DMA_STOP_INT ) x->tx_process_stopped_irq++;
@@ -472,11 +480,6 @@ static int sun8i_dwmac_dma_interrupt(struct stmmac_priv *priv,if (v &EMAC_TX_EARLY_INT ) x->tx_early_irq++; -if (v &EMAC_RX_INT ) { - ret |= handle_rx; - x->rx_normal_irq_n++; - } -if (v &EMAC_RX_BUF_UA_INT ) x->rx_buf_unav_irq++;
drivers/net/ethernet/stmicro/stmmac/dwmac100_dma.c +1 -6
@@ -82,29 +82,24 @@ static void dwmac100_dump_dma_regs(struct stmmac_priv *priv, }/* DMA controller has two counters to track the number of the missed frames. */ -static void dwmac100_dma_diagnostic_fr (struct net_device_stats *stats, -struct stmmac_extra_stats *x, +static void dwmac100_dma_diagnostic_fr (struct stmmac_extra_stats *x,void __iomem *ioaddr) {u32 csr8 =readl (ioaddr +DMA_MISSED_FRAME_CTR );if (unlikely (csr8)) {if (csr8 &DMA_MISSED_FRAME_OVE ) { - stats->rx_over_errors +=0x800 ; x->rx_overflow_cntr +=0x800 ; }else {unsigned int ove_cntr; ove_cntr = ((csr8 &DMA_MISSED_FRAME_OVE_CNTR ) >>17 ); - stats->rx_over_errors += ove_cntr; x->rx_overflow_cntr += ove_cntr; }if (csr8 &DMA_MISSED_FRAME_OVE_M ) { - stats->rx_missed_errors +=0xffff ; x->rx_missed_cntr +=0xffff ; }else {unsigned int miss_f = (csr8 &DMA_MISSED_FRAME_M_CNTR ); - stats->rx_missed_errors += miss_f; x->rx_missed_cntr += miss_f; } }
drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c +5 -11
@@ -13,8 +13,7 @@#include "dwmac4.h" #include "dwmac4_descs.h" -static int dwmac4_wrback_get_tx_status (struct net_device_stats *stats, -struct stmmac_extra_stats *x, +static int dwmac4_wrback_get_tx_status (struct stmmac_extra_stats *x,struct dma_desc *p,void __iomem *ioaddr) {
@@ -40,15 +39,13 @@ static int dwmac4_wrback_get_tx_status(struct net_device_stats *stats, x->tx_frame_flushed++;if (unlikely (tdes3 &TDES3_LOSS_CARRIER )) { x->tx_losscarrier++; - stats->tx_carrier_errors++; }if (unlikely (tdes3 &TDES3_NO_CARRIER )) { x->tx_carrier++; - stats->tx_carrier_errors++; }if (unlikely ((tdes3 &TDES3_LATE_COLLISION ) || (tdes3 &TDES3_EXCESSIVE_COLLISION ))) - stats->collisions += + x->tx_collision += (tdes3 &TDES3_COLLISION_COUNT_MASK ) >>TDES3_COLLISION_COUNT_SHIFT ;
@@ -73,8 +70,7 @@ static int dwmac4_wrback_get_tx_status(struct net_device_stats *stats,return ret; } -static int dwmac4_wrback_get_rx_status (struct net_device_stats *stats, -struct stmmac_extra_stats *x, +static int dwmac4_wrback_get_rx_status (struct stmmac_extra_stats *x,struct dma_desc *p) {unsigned int rdes1 =le32_to_cpu (p->des1);
@@ -93,7 +89,7 @@ static int dwmac4_wrback_get_rx_status(struct net_device_stats *stats,if (unlikely (rdes3 &RDES3_ERROR_SUMMARY )) {if (unlikely (rdes3 &RDES3_GIANT_PACKET )) - stats->rx_length_errors++; + x->rx_length++;if (unlikely (rdes3 &RDES3_OVERFLOW_ERROR )) x->rx_gmac_overflow++;
@@ -103,10 +99,8 @@ static int dwmac4_wrback_get_rx_status(struct net_device_stats *stats,if (unlikely (rdes3 &RDES3_RECEIVE_ERROR )) x->rx_mii++; -if (unlikely (rdes3 &RDES3_CRC_ERROR )) { +if (unlikely (rdes3 &RDES3_CRC_ERROR )) x->rx_crc_errors++; - stats->rx_crc_errors++; - }if (unlikely (rdes3 &RDES3_DRIBBLE_ERROR )) x->dribbling_bit++;
drivers/net/ethernet/stmicro/stmmac/dwmac4_lib.c +10 -5
@@ -168,6 +168,7 @@ void dwmac410_disable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,int dwmac4_dma_interrupt (struct stmmac_priv *priv,void __iomem *ioaddr,struct stmmac_extra_stats *x,u32 chan,u32 dir) { +struct stmmac_pcpu_stats *stats =this_cpu_ptr (priv->xstats.pstats);const struct dwmac4_addrs *dwmac4_addrs = priv->plat->dwmac4_addrs;u32 intr_status =readl (ioaddr +DMA_CHAN_STATUS (dwmac4_addrs, chan));u32 intr_en =readl (ioaddr +DMA_CHAN_INTR_ENA (dwmac4_addrs, chan));
@@ -198,18 +199,22 @@ int dwmac4_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, } }/* TX/RX NORMAL interrupts */ +u64_stats_update_begin (&stats->syncp);if (likely (intr_status &DMA_CHAN_STATUS_NIS )) - x->normal_irq_n++; + stats->normal_irq_n++; +if (likely (intr_status &DMA_CHAN_STATUS_RI )) { - x->rx_normal_irq_n++; - x->rxq_stats[chan].rx_normal_irq_n++; + stats->rx_normal_irq_n++; + stats->rxq_stats[chan].rx_normal_irq_n++; ret |= handle_rx; }if (likely (intr_status &DMA_CHAN_STATUS_TI )) { - x->tx_normal_irq_n++; - x->txq_stats[chan].tx_normal_irq_n++; + stats->tx_normal_irq_n++; + stats->txq_stats[chan].tx_normal_irq_n++; ret |= handle_tx; } +u64_stats_update_end (&stats->syncp); +if (unlikely (intr_status &DMA_CHAN_STATUS_TBU )) ret |= handle_tx;if (unlikely (intr_status &DMA_CHAN_STATUS_ERI ))
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +7 -3
@@ -10,6 +10,7 @@#include <linux/iopoll.h> #include "common.h" #include "dwmac_dma.h" +#include "stmmac.h" #define GMAC_HI_REG_AE 0x80000000
@@ -161,6 +162,7 @@ static void show_rx_process_state(unsigned int status)int dwmac_dma_interrupt (struct stmmac_priv *priv,void __iomem *ioaddr,struct stmmac_extra_stats *x,u32 chan,u32 dir) { +struct stmmac_pcpu_stats *stats =this_cpu_ptr (priv->xstats.pstats);int ret =0 ;/* read the status register (CSR5) */ u32 intr_status =readl (ioaddr +DMA_STATUS );
@@ -208,19 +210,21 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, }/* TX/RX NORMAL interrupts */ if (likely (intr_status &DMA_STATUS_NIS )) { - x->normal_irq_n++; +u64_stats_update_begin (&stats->syncp); + stats->normal_irq_n++;if (likely (intr_status &DMA_STATUS_RI )) {u32 value =readl (ioaddr +DMA_INTR_ENA );/* to schedule NAPI on real RIE event. */ if (likely (value &DMA_INTR_ENA_RIE )) { - x->rx_normal_irq_n++; + stats->rx_normal_irq_n++; ret |= handle_rx; } }if (likely (intr_status &DMA_STATUS_TI )) { - x->tx_normal_irq_n++; + stats->tx_normal_irq_n++; ret |= handle_tx; } +u64_stats_update_end (&stats->syncp);if (unlikely (intr_status &DMA_STATUS_ERI )) x->rx_early_irq++; }
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c +2 -4
@@ -8,8 +8,7 @@#include "common.h" #include "dwxgmac2.h" -static int dwxgmac2_get_tx_status (struct net_device_stats *stats, -struct stmmac_extra_stats *x, +static int dwxgmac2_get_tx_status (struct stmmac_extra_stats *x,struct dma_desc *p,void __iomem *ioaddr) {unsigned int tdes3 =le32_to_cpu (p->des3);
@@ -23,8 +22,7 @@ static int dwxgmac2_get_tx_status(struct net_device_stats *stats,return ret; } -static int dwxgmac2_get_rx_status (struct net_device_stats *stats, -struct stmmac_extra_stats *x, +static int dwxgmac2_get_rx_status (struct stmmac_extra_stats *x,struct dma_desc *p) {unsigned int rdes3 =le32_to_cpu (p->des3);
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c +8 -5
@@ -337,6 +337,7 @@ static int dwxgmac2_dma_interrupt(struct stmmac_priv *priv, struct stmmac_extra_stats *x, u32 chan, u32 dir) { + struct stmmac_pcpu_stats *stats = this_cpu_ptr(priv->xstats.pstats);u32 intr_status =readl (ioaddr +XGMAC_DMA_CH_STATUS (chan));u32 intr_en =readl (ioaddr +XGMAC_DMA_CH_INT_EN (chan));int ret =0 ;
@@ -364,18 +365,20 @@ static int dwxgmac2_dma_interrupt(struct stmmac_priv *priv,/* TX/RX NORMAL interrupts */ if (likely (intr_status &XGMAC_NIS )) { - x->normal_irq_n++; +u64_stats_update_begin (&stats->syncp); + stats->normal_irq_n++;if (likely (intr_status &XGMAC_RI )) { - x->rx_normal_irq_n++; - x->rxq_stats[chan].rx_normal_irq_n++; + stats->rx_normal_irq_n++; + stats->rxq_stats[chan].rx_normal_irq_n++; ret |= handle_rx; }if (likely (intr_status & (XGMAC_TI |XGMAC_TBU ))) { - x->tx_normal_irq_n++; - x->txq_stats[chan].tx_normal_irq_n++; + stats->tx_normal_irq_n++; + stats->txq_stats[chan].tx_normal_irq_n++; ret |= handle_tx; } +u64_stats_update_end (&stats->syncp); }/* Clear interrupts */
drivers/net/ethernet/stmicro/stmmac/enh_desc.c +7 -13
@@ -12,8 +12,7 @@#include "common.h" #include "descs_com.h" -static int enh_desc_get_tx_status (struct net_device_stats *stats, -struct stmmac_extra_stats *x, +static int enh_desc_get_tx_status (struct stmmac_extra_stats *x,struct dma_desc *p,void __iomem *ioaddr) {unsigned int tdes0 =le32_to_cpu (p->des0);
@@ -38,15 +37,13 @@ static int enh_desc_get_tx_status(struct net_device_stats *stats,if (unlikely (tdes0 &ETDES0_LOSS_CARRIER )) { x->tx_losscarrier++; - stats->tx_carrier_errors++; }if (unlikely (tdes0 &ETDES0_NO_CARRIER )) { x->tx_carrier++; - stats->tx_carrier_errors++; }if (unlikely ((tdes0 &ETDES0_LATE_COLLISION ) || (tdes0 &ETDES0_EXCESSIVE_COLLISIONS ))) - stats->collisions += + x->tx_collision += (tdes0 &ETDES0_COLLISION_COUNT_MASK ) >>3 ;if (unlikely (tdes0 &ETDES0_EXCESSIVE_DEFERRAL ))
@@ -117,8 +114,7 @@ static int enh_desc_coe_rdes0(int ipc_err, int type, int payload_err)return ret; } -static void enh_desc_get_ext_status (struct net_device_stats *stats, -struct stmmac_extra_stats *x, +static void enh_desc_get_ext_status (struct stmmac_extra_stats *x,struct dma_extended_desc *p) {unsigned int rdes0 =le32_to_cpu (p->basic.des0);
@@ -182,8 +178,7 @@ static void enh_desc_get_ext_status(struct net_device_stats *stats, } } -static int enh_desc_get_rx_status (struct net_device_stats *stats, -struct stmmac_extra_stats *x, +static int enh_desc_get_rx_status (struct stmmac_extra_stats *x,struct dma_desc *p) {unsigned int rdes0 =le32_to_cpu (p->des0);
@@ -193,14 +188,14 @@ static int enh_desc_get_rx_status(struct net_device_stats *stats,return dma_own;if (unlikely (!(rdes0 &RDES0_LAST_DESCRIPTOR ))) { - stats->rx_length_errors++; + x->rx_length++;return discard_frame; }if (unlikely (rdes0 &RDES0_ERROR_SUMMARY )) {if (unlikely (rdes0 &RDES0_DESCRIPTOR_ERROR )) { x->rx_desc++; - stats->rx_length_errors++; + x->rx_length++; }if (unlikely (rdes0 &RDES0_OVERFLOW_ERROR )) x->rx_gmac_overflow++;
@@ -209,7 +204,7 @@ static int enh_desc_get_rx_status(struct net_device_stats *stats,pr_err ("\tIPC Csum Error/Giant frame\n" );if (unlikely (rdes0 &RDES0_COLLISION )) - stats->collisions++; + x->rx_collision++;if (unlikely (rdes0 &RDES0_RECEIVE_WATCHDOG )) x->rx_watchdog++;
@@ -218,7 +213,6 @@ static int enh_desc_get_rx_status(struct net_device_stats *stats,if (unlikely (rdes0 &RDES0_CRC_ERROR )) { x->rx_crc_errors++; - stats->rx_crc_errors++; } ret = discard_frame; }
drivers/net/ethernet/stmicro/stmmac/hwif.h +4 -8
@@ -57,8 +57,7 @@ struct stmmac_desc_ops {/* Last tx segment reports the transmit status */ int (*get_tx_ls)(struct dma_desc *p);/* Return the transmit status looking at the TDES1 */ -int (*tx_status)(struct net_device_stats *stats, -struct stmmac_extra_stats *x, +int (*tx_status)(struct stmmac_extra_stats *x,struct dma_desc *p,void __iomem *ioaddr);/* Get the buffer size from the descriptor */ int (*get_tx_len)(struct dma_desc *p);
@@ -67,11 +66,9 @@ struct stmmac_desc_ops {/* Get the receive frame size */ int (*get_rx_frame_len)(struct dma_desc *p,int rx_coe_type);/* Return the reception status looking at the RDES1 */ -int (*rx_status)(struct net_device_stats *stats, -struct stmmac_extra_stats *x, +int (*rx_status)(struct stmmac_extra_stats *x,struct dma_desc *p); -void (*rx_extended_status)(struct net_device_stats *stats, -struct stmmac_extra_stats *x, +void (*rx_extended_status)(struct stmmac_extra_stats *x,struct dma_extended_desc *p);/* Set tx timestamp enable bit */ void (*enable_tx_timestamp) (struct dma_desc *p);
@@ -191,8 +188,7 @@ struct stmmac_dma_ops {void (*dma_tx_mode)(struct stmmac_priv *priv,void __iomem *ioaddr,int mode,u32 channel,int fifosz,u8 qmode);/* To track extra statistic (if supported) */ -void (*dma_diagnostic_fr)(struct net_device_stats *stats, -struct stmmac_extra_stats *x, +void (*dma_diagnostic_fr)(struct stmmac_extra_stats *x,void __iomem *ioaddr);void (*enable_dma_transmission) (void __iomem *ioaddr); void (*enable_dma_irq)(struct stmmac_priv *priv, void __iomem *ioaddr,
drivers/net/ethernet/stmicro/stmmac/norm_desc.c +4 -11
@@ -12,8 +12,7 @@#include "common.h" #include "descs_com.h" -static int ndesc_get_tx_status (struct net_device_stats *stats, -struct stmmac_extra_stats *x, +static int ndesc_get_tx_status (struct stmmac_extra_stats *x,struct dma_desc *p,void __iomem *ioaddr) {unsigned int tdes0 =le32_to_cpu (p->des0);
@@ -31,15 +30,12 @@ static int ndesc_get_tx_status(struct net_device_stats *stats,if (unlikely (tdes0 &TDES0_ERROR_SUMMARY )) {if (unlikely (tdes0 &TDES0_UNDERFLOW_ERROR )) { x->tx_underflow++; - stats->tx_fifo_errors++; }if (unlikely (tdes0 &TDES0_NO_CARRIER )) { x->tx_carrier++; - stats->tx_carrier_errors++; }if (unlikely (tdes0 &TDES0_LOSS_CARRIER )) { x->tx_losscarrier++; - stats->tx_carrier_errors++; } if (unlikely((tdes0 & TDES0_EXCESSIVE_DEFERRAL) || (tdes0 & TDES0_EXCESSIVE_COLLISIONS) ||
@@ -47,7 +43,7 @@ static int ndesc_get_tx_status(struct net_device_stats *stats,unsigned int collisions; collisions = (tdes0 &TDES0_COLLISION_COUNT_MASK ) >>3 ; - stats->collisions += collisions; + x->tx_collision += collisions; } ret = tx_err; }
@@ -70,8 +66,7 @@ static int ndesc_get_tx_len(struct dma_desc *p)* and, if required, updates the multicast statistics. * In case of success, it returns good_frame because the GMAC device * is supposed to be able to compute the csum in HW. */ -static int ndesc_get_rx_status (struct net_device_stats *stats, -struct stmmac_extra_stats *x, +static int ndesc_get_rx_status (struct stmmac_extra_stats *x,struct dma_desc *p) {int ret = good_frame;
@@ -81,7 +76,7 @@ static int ndesc_get_rx_status(struct net_device_stats *stats,return dma_own;if (unlikely (!(rdes0 &RDES0_LAST_DESCRIPTOR ))) { - stats->rx_length_errors++; + x->rx_length++;return discard_frame; }
@@ -96,11 +91,9 @@ static int ndesc_get_rx_status(struct net_device_stats *stats, x->ipc_csum_error++;if (unlikely (rdes0 &RDES0_COLLISION )) { x->rx_collision++; - stats->collisions++; }if (unlikely (rdes0 &RDES0_CRC_ERROR )) { x->rx_crc_errors++; - stats->rx_crc_errors++; } ret = discard_frame; }
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +78 -30
164 lines not on this page · raw message
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +140 -44
455 lines not on this page · raw message
Signature · 1 line
2.40.1
Jakub Kicinski
maintainerRe: [PATCH net-next v3 2/2] net: stmmac: use pcpu 64 bit statistics where necessary
Quoted 12 lines · On Tue, 20 Jun 2023 00:52:20 +0800 Jisheng Zhang wrote:
drivers/net/ethernet/stmicro/stmmac/common.h +12
-0+struct stmmac_pcpu_stats { +struct u64_stats_sync syncp; +/* per queue statistics */ +struct stmmac_txq_stats txq_stats[MTL_MAX_TX_QUEUES ]; +struct stmmac_rxq_stats rxq_stats[MTL_MAX_RX_QUEUES ]; +/* device stats */ +u64 rx_packets; +u64 rx_bytes; +u64 tx_packets; +u64 tx_bytes; +/* Tx/Rx IRQ Events */ +u64 tx_pkt_n;
drivers/net/ethernet/stmicro/stmmac/common.h line 92
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/common.h +10
-0+u64 rx_pkt_n; +u64 normal_irq_n; +u64 rx_normal_irq_n; +u64 napi_poll; +u64 tx_normal_irq_n; +u64 tx_clean; +u64 tx_set_ic_bit; +/* TSO */ +u64 tx_tso_frames; +u64 tx_tso_nfrags;
AFAICT you're using the same structure and syncp for the stats updated from within IRQ and from xmit and NAPI. That's not safe. The documentation of u64_stats_sync suggests using _irqsave() variant for that case but really, I think you should split these stats up.
The statistics which are counting packets / bytes should all go into respective queue structs, like struct stmmac_tx_queue, and have their own syncp per context (i.e. separate for xmit and completions if they can run in parallel).
Having the counters in queue structs is much more common in drivers, it usually saves memory and allows reporting stats per queue.
You can keep the per-cpu stats for IRQs if there's no IRQ struct, if you prefer.
Signature · 1 line
pw-bot: cr
Re: [PATCH net-next v3 2/2] net: stmmac: use pcpu 64 bit statistics where necessary
In reply to Jisheng ZhangOn Tue, Jun 20, 2023 at 12:52:20AM +0800, Jisheng Zhang wrote:
...
Hi Jisheng Zhang,
some minor feedback from my side, as it seems there will be a v4 anyway.
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +1
-1@@ -535,23 +548,37 @@ static void stmmac_get_per_qstats(struct stmmac_priv *priv, u64 *data) {u32 tx_cnt = priv->plat->tx_queues_to_use;u32 rx_cnt = priv->plat->rx_queues_to_use; -int q, stat; +unsigned int start;
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c static void stmmac_get_per_qstats(struct stmmac_priv *priv, u64 *data) · line 554
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +2
-7+int q, stat, cpu;char *p; - -for (q =0 ; q < tx_cnt; q++) { - p = (char *)priv + offsetof(struct stmmac_priv , - xstats.txq_stats[q].tx_pkt_n); -for (stat =0 ; stat <STMMAC_TXQ_STATS ; stat++) { - *data++ = (*(unsigned long *)p); - p +=sizeof (unsigned long ); +u64 *pos;
Please use reverse xmas tree - longest line to shortest - for local variable declarations in new Networking code.
...
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c static void stmmac_get_ethtool_stats(struct net_device *dev, · line 594
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +2
-1@@ -563,7 +590,8 @@ static void stmmac_get_ethtool_stats(struct net_device *dev,u32 rx_queues_count = priv->plat->rx_queues_to_use;u32 tx_queues_count = priv->plat->tx_queues_to_use;unsigned long count; -int i, j =0 , ret; +unsigned int start; +int i, j =0 , pos, ret, cpu;
Ditto.
...
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +3
-0@@ -606,6 +633,22 @@ static void stmmac_get_ethtool_stats(struct net_device *dev, data[j++] = (stmmac_gstrings_stats[i].sizeof_stat ==sizeof (u64)) ? (*(u64 *)p) : (*(u32 *)p); } + pos = j; +for_each_possible_cpu (cpu) { +struct stmmac_pcpu_stats *stats, snapshot;
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c static void stmmac_get_ethtool_stats(struct net_device *dev, · line 648
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +10
-0+ + stats =per_cpu_ptr (priv->xstats.pstats, cpu); + j = pos; +do { + start =u64_stats_fetch_begin (&stats->syncp); + snapshot = *stats; + }while (u64_stats_fetch_retry (&stats->syncp, start)); + +for (i =0 ; i <STMMAC_PCPU_STATS_LEN ; i++) { +char *p = (char *)&snapshot + stmmac_gstrings_pcpu_stats[i].stat_offset;
Blank line here please.
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +3
-0+ data[j++] += *(u64 *)p; + } + }stmmac_get_per_qstats (priv, &data[j]); }
...
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c static void stmmac_get_strings(struct net_device *dev, u32 stringset, u8 *data) · line 743
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +3
-0@@ -695,6 +738,11 @@ static void stmmac_get_strings(struct net_device *dev, u32 stringset, u8 *data) ETH_GSTRING_LEN); p +=ETH_GSTRING_LEN ; } +for (i =0 ; i <STMMAC_PCPU_STATS_LEN ; i++) { +memcpy (p, stmmac_gstrings_pcpu_stats[i].stat_string, +ETH_GSTRING_LEN );
The indentation of the line above isn't quite right: it should align with the inside of the opening parentheses on the previous line.
memcpy(p, stmmac_gstrings_pcpu_stats[i].stat_string, ETH_GSTRING_LEN);
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +2
-0+ p +=ETH_GSTRING_LEN ; + }stmmac_get_qstats_string (priv, p);break ;case ETH_SS_TEST :
...
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static struct stmmac_xdp_buff *xsk_buff_to_stmmac_ctx(struct xdp_buff *xdp) · line 5051
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2
-0@@ -5015,8 +5042,10 @@ static struct stmmac_xdp_buff *xsk_buff_to_stmmac_ctx(struct xdp_buff *xdp)static int stmmac_rx_zc (struct stmmac_priv *priv,int limit,u32 queue) { +struct stmmac_pcpu_stats *stats =this_cpu_ptr (priv->xstats.pstats);struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];unsigned int count =0 , error =0 , len =0 ; +u32 rx_errors =0 , rx_dropped =0 ;int dirty =stmmac_rx_dirty (priv, queue);unsigned int next_entry = rx_q->cur_rx;unsigned int desc_size;
Reverse xmas tree here too.
...