Skip to contentSkip to conversation

bnx2x: preserve net device stats across reload

PATCH In review Michal Schmidt 2 participants 2 messages Feb 13, 2012 – Feb 14, 2012 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bnx2x: preserve net device stats across reload

The network device statistics were reset to zero when the bnx2x driver reloaded the NIC, such as when changing the MTU.

To preserve the statistics across reloads, save the current values when unloading. Add the saved values to the values read currently from the hardware when updating the stats. Forget the saved values if the reason for unloading is that the device is going down.

---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x.h       |    3 +
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c   |    4 +
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c |   69 ++++++++++++++++-----
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.h |   21 ++++++
 4 files changed, 80 insertions(+), 17 deletions(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x.h +3 -0
index 7d184fb..14e8282 100644
@@ -1557,6 +1557,9 @@ struct bnx2x {
 
 	/* priority to cos mapping */
 	u8					prio_to_cos[8];
+
+	/* to preserve net device stats across unload/load */
+	struct bnx2x_nstats_base		nstats_base;
 };
 
 /* Tx queues may be less or equal to Rx queues */
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c +4 -0
index 518ec5c..959b785 100644
@@ -2084,6 +2084,10 @@ int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode)
 	bnx2x_drv_pulse(bp);
 
 	bnx2x_stats_handle(bp, STATS_EVENT_STOP);
+	if (unload_mode == UNLOAD_CLOSE)
+		bnx2x_stats_reset(bp);
+	else
+		bnx2x_stats_save(bp);
 
 	/* Cleanup the chip if needed */
 	if (unload_mode != UNLOAD_RECOVERY)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c +52 -17

119 lines not on this page · raw message

drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.h +21 -0
index 7e97968..1d8bbaa 100644
@@ -264,6 +264,24 @@ struct bnx2x_eth_q_stats {
 	u32 total_tpa_bytes_lo;
 };
 
+struct bnx2x_nstats_base {
+	unsigned long rx_packets;
+	unsigned long tx_packets;
+	unsigned long rx_bytes;
+	unsigned long tx_bytes;
+	unsigned long rx_dropped;
+	unsigned long multicast;
+	unsigned long collisions;
+	unsigned long rx_length_errors;
+	unsigned long rx_over_errors;
+	unsigned long rx_crc_errors;
+	unsigned long rx_frame_errors;
+	unsigned long rx_fifo_errors;
+	unsigned long tx_aborted_errors;
+	unsigned long tx_carrier_errors;
+	unsigned long tx_errors;
+};
+
 /****************************************************************************
 * Macros
 ****************************************************************************/
@@ -388,4 +406,7 @@ void bnx2x_stats_init(struct bnx2x *bp);
 
 void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event);
 
+void bnx2x_stats_save(struct bnx2x *bp);
+void bnx2x_stats_reset(struct bnx2x *bp);
+
 #endif /* BNX2X_STATS_H */
Signature · 1 line
1.7.7.6
#2 lore raw
In reply to a message not in the archive
Quoted 7 lines

The network device statistics were reset to zero when the bnx2x driver reloaded the NIC, such as when changing the MTU.

To preserve the statistics across reloads, save the current values when unloading. Add the saved values to the values read currently from the hardware when updating the stats. Forget the saved values if the reason for unloading is that the device is going down.

Thanks for this patch - indeed there is currently a problem with statistics reset during inner reloads such as MTU changes.

However, notice that keeping the net_device_stats statistics consistent across such changes is only a very partial solution, since most of the statistics will still be reset. E.g., bp->eth_stats will be reset, causing ethtool to output zero statistics after such an inner reload.

I'm currently working on a patch to fix this issue. Since my patch will make the statistics in bnx2x_eth_stats consistent after an inner reload, the changes made here will be unrequired, since all the net_device_stats are direct products of bnx2x_eth_stats (with the exception of one field).

I will try to submit it later on today.