diff mbox series

[iwl-net] ice: Reset stats on queues num change

Message ID 20230714114721.335526-1-przemyslaw.kitszel@intel.com (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series [iwl-net] ice: Reset stats on queues num change | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1342 this patch: 1342
netdev/cc_maintainers warning 5 maintainers not CCed: kuba@kernel.org jesse.brandeburg@intel.com davem@davemloft.net pabeni@redhat.com edumazet@google.com
netdev/build_clang success Errors and warnings before: 1365 this patch: 1365
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1365 this patch: 1365
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 62 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Przemek Kitszel July 14, 2023, 11:47 a.m. UTC
Reset VSI stats on queues number change.

Commit 288ecf491b16 ("ice: Accumulate ring statistics over reset")
implemented functionality for interface statistics to persist over reset,
but it left stats persisting over queue count reconfiguration.

Following scenario is fixed here:
 # Observe statistics for Tx/Rx queues
ethtool -S ethX
 # change number of queues
ethtool -L ethX combined 10
 # Observe statistics for Tx/Rx queues (after reset)
ethtool -S ethX

Ben has left a note where to place the VSI stats reset,
what made this fix much easier to do.

Note that newly allocated structs (case of num_txq > prev_txq) don't
need zeroing.

Fixes: 288ecf491b16 ("ice: Accumulate ring statistics over reset")
Suggested-by: Benjamin Mikailenko <benjamin.mikailenko@intel.com>
Signed-off-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
---
 drivers/net/ethernet/intel/ice/ice_lib.c | 33 ++++++++++++++++++++----
 1 file changed, 28 insertions(+), 5 deletions(-)


base-commit: 9d23aac8a85f69239e585c8656c6fdb21be65695

Comments

Simon Horman July 19, 2023, 2:04 p.m. UTC | #1
On Fri, Jul 14, 2023 at 07:47:21AM -0400, Przemek Kitszel wrote:
> Reset VSI stats on queues number change.
> 
> Commit 288ecf491b16 ("ice: Accumulate ring statistics over reset")
> implemented functionality for interface statistics to persist over reset,
> but it left stats persisting over queue count reconfiguration.
> 
> Following scenario is fixed here:
>  # Observe statistics for Tx/Rx queues
> ethtool -S ethX
>  # change number of queues
> ethtool -L ethX combined 10
>  # Observe statistics for Tx/Rx queues (after reset)
> ethtool -S ethX
> 
> Ben has left a note where to place the VSI stats reset,
> what made this fix much easier to do.
> 
> Note that newly allocated structs (case of num_txq > prev_txq) don't
> need zeroing.
> 
> Fixes: 288ecf491b16 ("ice: Accumulate ring statistics over reset")
> Suggested-by: Benjamin Mikailenko <benjamin.mikailenko@intel.com>
> Signed-off-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>

Reviewed-by: Simon Horman <simon.horman@corigine.com>
Alexander Lobakin July 19, 2023, 3:25 p.m. UTC | #2
From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Date: Fri, 14 Jul 2023 07:47:21 -0400

> Reset VSI stats on queues number change.

Please don't.

> 
> Commit 288ecf491b16 ("ice: Accumulate ring statistics over reset")
> implemented functionality for interface statistics to persist over reset,
> but it left stats persisting over queue count reconfiguration.

And? Why do you guys think we need to zero stats for the turned off
queues? Let the stats have the same lifetime as pci_dev has.

> 
> Following scenario is fixed here:
>  # Observe statistics for Tx/Rx queues
> ethtool -S ethX
>  # change number of queues
> ethtool -L ethX combined 10
>  # Observe statistics for Tx/Rx queues (after reset)
> ethtool -S ethX
> 
> Ben has left a note where to place the VSI stats reset,
> what made this fix much easier to do.
> 
> Note that newly allocated structs (case of num_txq > prev_txq) don't
> need zeroing.
> 
> Fixes: 288ecf491b16 ("ice: Accumulate ring statistics over reset")
> Suggested-by: Benjamin Mikailenko <benjamin.mikailenko@intel.com>
> Signed-off-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
[...]

Thanks,
Olek
diff mbox series

Patch

diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c
index 00e3afd507a4..09942bdea25d 100644
--- a/drivers/net/ethernet/intel/ice/ice_lib.c
+++ b/drivers/net/ethernet/intel/ice/ice_lib.c
@@ -3130,13 +3130,15 @@  ice_vsi_rebuild_set_coalesce(struct ice_vsi *vsi,
 }
 
 /**
- * ice_vsi_realloc_stat_arrays - Frees unused stat structures
+ * ice_vsi_adjust_stat_arrays - Adjust VSI stat structures
  * @vsi: VSI pointer
  * @prev_txq: Number of Tx rings before ring reallocation
  * @prev_rxq: Number of Rx rings before ring reallocation
+ *
+ * Zero stat structures before reuse, free redundant ones.
  */
 static void
-ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi, int prev_txq, int prev_rxq)
+ice_vsi_adjust_stat_arrays(struct ice_vsi *vsi, int prev_txq, int prev_rxq)
 {
 	struct ice_vsi_stats *vsi_stat;
 	struct ice_pf *pf = vsi->back;
@@ -3149,7 +3151,17 @@  ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi, int prev_txq, int prev_rxq)
 
 	vsi_stat = pf->vsi_stats[vsi->idx];
 
-	if (vsi->num_txq < prev_txq) {
+	if (vsi->num_txq != prev_txq) {
+		/* first, reset structs that we will reuse */
+		int reuse_q_cnt = min_t(int, vsi->num_txq, prev_txq);
+
+		for (i = 0; i < reuse_q_cnt; i++) {
+			struct ice_ring_stats *rs = vsi_stat->tx_ring_stats[i];
+
+			if (rs)
+				memset(rs, 0, sizeof(*rs));
+		}
+		/* second, free redundant ones */
 		for (i = vsi->num_txq; i < prev_txq; i++) {
 			if (vsi_stat->tx_ring_stats[i]) {
 				kfree_rcu(vsi_stat->tx_ring_stats[i], rcu);
@@ -3158,7 +3170,16 @@  ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi, int prev_txq, int prev_rxq)
 		}
 	}
 
-	if (vsi->num_rxq < prev_rxq) {
+	/* apply very same logic as for tx */
+	if (vsi->num_rxq != prev_rxq) {
+		int reuse_q_cnt = min_t(int, vsi->num_rxq, prev_rxq);
+
+		for (i = 0; i < reuse_q_cnt; i++) {
+			struct ice_ring_stats *rs = vsi_stat->rx_ring_stats[i];
+
+			if (rs)
+				memset(rs, 0, sizeof(*rs));
+		}
 		for (i = vsi->num_rxq; i < prev_rxq; i++) {
 			if (vsi_stat->rx_ring_stats[i]) {
 				kfree_rcu(vsi_stat->rx_ring_stats[i], rcu);
@@ -3222,7 +3243,9 @@  int ice_vsi_rebuild(struct ice_vsi *vsi, u32 vsi_flags)
 		return ice_schedule_reset(pf, ICE_RESET_PFR);
 	}
 
-	ice_vsi_realloc_stat_arrays(vsi, prev_txq, prev_rxq);
+	ice_vsi_adjust_stat_arrays(vsi, prev_txq, prev_rxq);
+	if (vsi->num_txq != prev_txq || vsi->num_rxq != prev_rxq)
+		vsi->stat_offsets_loaded = false;
 
 	ice_vsi_rebuild_set_coalesce(vsi, coalesce, prev_num_q_vectors);
 	kfree(coalesce);