Skip to contentSkip to conversation

octeontx2-pf: Retain ethtool stats across interface down/up.

PATCH Superseded Anshumali Gaur 2 participants 2 messages May 14 – May 19

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 octeontx2-pf: Retain ethtool stats across interface down/up.

Currently the hardware counters reset when the interface is brought down, causing stats visible to userspace to drop to zero. Save the accumulated stats before bringing the interface down so they persist across routine down/up cycles.

---
v4:
- Move stats accumulation after disabling tx/rx (Dragos)
- Fetch latest HW counters before accumulating in otx2_stop()
v3:
- Code format according to kernel coding style
- Reword commit message
v2:
- Fix subject prefix to target net-next

 .../marvell/octeontx2/nic/otx2_common.c       | 20 +++++++-------
 .../marvell/octeontx2/nic/otx2_common.h       |  1 +
 .../ethernet/marvell/octeontx2/nic/otx2_pf.c  | 26 ++++++++++++++++---
 3 files changed, 35 insertions(+), 12 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +11 -9
index 971fcab1c248..0ffcc613a4b2 100644
@@ -139,19 +139,21 @@ void otx2_get_stats64(struct net_device *netdev,
 		      struct rtnl_link_stats64 *stats)
 {
 	struct otx2_nic *pfvf = netdev_priv(netdev);
-	struct otx2_dev_stats *dev_stats;
+	struct otx2_dev_stats *dev_stats, *old_stats;
 
 	otx2_get_dev_stats(pfvf);
 
 	dev_stats = &pfvf->hw.dev_stats;
-	stats->rx_bytes = dev_stats->rx_bytes;
-	stats->rx_packets = dev_stats->rx_frames;
-	stats->rx_dropped = dev_stats->rx_drops;
-	stats->multicast = dev_stats->rx_mcast_frames;
-
-	stats->tx_bytes = dev_stats->tx_bytes;
-	stats->tx_packets = dev_stats->tx_frames;
-	stats->tx_dropped = dev_stats->tx_drops;
+	old_stats = &pfvf->hw.old_stats;
+
+	stats->rx_bytes = old_stats->rx_bytes + dev_stats->rx_bytes;
+	stats->rx_packets = old_stats->rx_frames + dev_stats->rx_frames;
+	stats->rx_dropped = old_stats->rx_drops + dev_stats->rx_drops;
+	stats->multicast = old_stats->rx_mcast_frames + dev_stats->rx_mcast_frames;
+
+	stats->tx_bytes = old_stats->tx_bytes + dev_stats->tx_bytes;
+	stats->tx_packets = old_stats->tx_frames + dev_stats->tx_frames;
+	stats->tx_dropped = old_stats->tx_drops + dev_stats->tx_drops;
 }
 EXPORT_SYMBOL(otx2_get_stats64);
 
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +1 -0
index eecee612b7b2..ad65aa19b80d 100644
@@ -255,6 +255,7 @@ struct otx2_hw {
 
 	/* Stats */
 	struct otx2_dev_stats	dev_stats;
+	struct otx2_dev_stats	old_stats;
 	struct otx2_drv_stats	drv_stats;
 	u64			cgx_rx_stats[CGX_RX_STATS_COUNT];
 	u64			cgx_tx_stats[CGX_TX_STATS_COUNT];
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +23 -3
index ee623476e5ff..21fd1dd4d755 100644
@@ -2154,6 +2154,8 @@ EXPORT_SYMBOL(otx2_open);
 int otx2_stop(struct net_device *netdev)
 {
 	struct otx2_nic *pf = netdev_priv(netdev);
+	struct otx2_dev_stats *old_stats = &pf->hw.old_stats;
+	struct otx2_dev_stats *dev = &pf->hw.dev_stats;
 	struct otx2_cq_poll *cq_poll = NULL;
 	struct otx2_qset *qset = &pf->qset;
 	int qidx, vec, wrk;
@@ -2162,6 +2164,27 @@ int otx2_stop(struct net_device *netdev)
 	if (pf->flags & OTX2_FLAG_INTF_DOWN)
 		return 0;
 
+	/* First stop packet Rx/Tx */
+	otx2_rxtx_enable(pf, false);
+
+	/* Read final HW counters and accumulate */
+	otx2_get_dev_stats(pf);
+
+	/* Accumulate old stats */
+	old_stats->rx_bytes     += dev->rx_bytes;
+	old_stats->rx_drops     += dev->rx_drops;
+	old_stats->rx_bcast_frames      += dev->rx_bcast_frames;
+	old_stats->rx_mcast_frames      += dev->rx_mcast_frames;
+	old_stats->rx_ucast_frames      += dev->rx_ucast_frames;
+	old_stats->rx_frames            += dev->rx_frames;
+
+	old_stats->tx_bytes             += dev->tx_bytes;
+	old_stats->tx_drops             += dev->tx_drops;
+	old_stats->tx_bcast_frames      += dev->tx_bcast_frames;
+	old_stats->tx_mcast_frames      += dev->tx_mcast_frames;
+	old_stats->tx_ucast_frames      += dev->tx_ucast_frames;
+	old_stats->tx_frames            += dev->tx_frames;
+
 	netif_carrier_off(netdev);
 	netif_tx_stop_all_queues(netdev);
 
@@ -2169,9 +2192,6 @@ int otx2_stop(struct net_device *netdev)
 	/* 'intf_down' may be checked on any cpu */
 	smp_wmb();
 
-	/* First stop packet Rx/Tx */
-	otx2_rxtx_enable(pf, false);
-
 	/* Clear RSS enable flag */
 	pf->hw.rss_info.enable = false;
 
Signature · 1 line
2.25.1
maintainer
#1 lore raw

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c void otx2_get_stats64(struct net_device *netdev, · line 142

Quoted 10 lines · Anshumali Gaur
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +1 -1
index 971fcab1c248..0ffcc613a4b2 100644
@@ -139,19 +139,21 @@ void otx2_get_stats64(struct net_device *netdev,
 		      struct rtnl_link_stats64 *stats)
 {
 	struct otx2_nic *pfvf = netdev_priv(netdev);
-	struct otx2_dev_stats *dev_stats;
+	struct otx2_dev_stats *dev_stats, *old_stats;

Please respect the reverse christmas tree order above.

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c EXPORT_SYMBOL(otx2_open); · line 2161

Quoted 13 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +2 -0
index ee623476e5ff..21fd1dd4d755 100644
@@ -2154,6 +2154,8 @@ EXPORT_SYMBOL(otx2_open);
 int otx2_stop(struct net_device *netdev)
 {
 	struct otx2_nic *pf = netdev_priv(netdev);
+	struct otx2_dev_stats *old_stats = &pf->hw.old_stats;
+	struct otx2_dev_stats *dev = &pf->hw.dev_stats;
 	struct otx2_cq_poll *cq_poll = NULL;
 	struct otx2_qset *qset = &pf->qset;
 	int qidx, vec, wrk;

Same here. You need to split variable declaration and initialization.

Quoted 14 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +10 -0
@@ -2162,6 +2164,27 @@ int otx2_stop(struct net_device *netdev)
 	if (pf->flags & OTX2_FLAG_INTF_DOWN)
 		return 0;
 
+	/* First stop packet Rx/Tx */
+	otx2_rxtx_enable(pf, false);
+
+	/* Read final HW counters and accumulate */
+	otx2_get_dev_stats(pf);
+
+	/* Accumulate old stats */
+	old_stats->rx_bytes     += dev->rx_bytes;
+	old_stats->rx_drops     += dev->rx_drops;
+	old_stats->rx_bcast_frames      += dev->rx_bcast_frames;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c int otx2_stop(struct net_device *netdev) · line 2186

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +10 -0
+	old_stats->rx_mcast_frames      += dev->rx_mcast_frames;
+	old_stats->rx_ucast_frames      += dev->rx_ucast_frames;
+	old_stats->rx_frames            += dev->rx_frames;
+
+	old_stats->tx_bytes             += dev->tx_bytes;
+	old_stats->tx_drops             += dev->tx_drops;
+	old_stats->tx_bcast_frames      += dev->tx_bcast_frames;
+	old_stats->tx_mcast_frames      += dev->tx_mcast_frames;
+	old_stats->tx_ucast_frames      += dev->tx_ucast_frames;
+	old_stats->tx_frames            += dev->tx_frames;

Sashiko notes this is still racy, as napi can still run and update the counters. You should move the stat collection just before freeing H/W resources.

/P