DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] net/mlx5: fix end condition of reading xstats
@ 2024-07-17 16:33 Bing Zhao
  2024-07-21 12:10 ` Raslan Darawsheh
  0 siblings, 1 reply; 2+ messages in thread
From: Bing Zhao @ 2024-07-17 16:33 UTC (permalink / raw)
  To: viacheslavo, dev, rasland; +Cc: orika, dsosnowski, suanmingm, matan

The "mlx5_stats_n" in the "struct mlx5_xstats_ctrl" is the number of
device stats identified by PMD. Right now, the mapping of device
stats to the xstats is not compact. The "input index" of the device
stats would remain UINT16_MAX and be skipped when reading counters.

If some DPDK stats cannot be identified in the middle of the map, the
end condition should be bigger than the "mlx5_stats_n". Or else, some
counters would not be read and calculated.

Using the global const "xstats_n" as the end condition to traverse
the whole array in case some counters are missed. The "xstats_o_idx"
should be used instead of the iteration to check if the statistics
is an IB device counter.

In the meanwhile, adding another field to record the start index of
the IB counters to reduce the redundancy iterations.

Fixes: a687c3e658c2 ("net/mlx5: fix counters map in bonding mode")

Signed-off-by: Bing Zhao <bingz@nvidia.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
---
 drivers/net/mlx5/linux/mlx5_ethdev_os.c | 23 +++++++++++++----------
 drivers/net/mlx5/mlx5.h                 |  5 +++++
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/drivers/net/mlx5/linux/mlx5_ethdev_os.c b/drivers/net/mlx5/linux/mlx5_ethdev_os.c
index 82f651f2f3..5d64984022 100644
--- a/drivers/net/mlx5/linux/mlx5_ethdev_os.c
+++ b/drivers/net/mlx5/linux/mlx5_ethdev_os.c
@@ -1201,6 +1201,7 @@ _mlx5_os_read_dev_counters(struct rte_eth_dev *dev, int pf, uint64_t *stats)
 	struct ethtool_stats *et_stats = (struct ethtool_stats *)et_stat_buf;
 	int ret;
 	uint16_t i_idx, o_idx;
+	uint32_t total_stats = xstats_n;
 
 	et_stats->cmd = ETHTOOL_GSTATS;
 	/* Pass the maximum value, the driver may ignore this. */
@@ -1218,19 +1219,19 @@ _mlx5_os_read_dev_counters(struct rte_eth_dev *dev, int pf, uint64_t *stats)
 		return ret;
 	}
 	if (pf <= 0) {
-		for (i = 0; i != xstats_ctrl->mlx5_stats_n; i++) {
+		for (i = 0; i != total_stats; i++) {
 			i_idx = xstats_ctrl->dev_table_idx[i];
-			if (i_idx == UINT16_MAX || xstats_ctrl->info[i].dev)
-				continue;
 			o_idx = xstats_ctrl->xstats_o_idx[i];
+			if (i_idx == UINT16_MAX || xstats_ctrl->info[o_idx].dev)
+				continue;
 			stats[o_idx] += (uint64_t)et_stats->data[i_idx];
 		}
 	} else {
-		for (i = 0; i != xstats_ctrl->mlx5_stats_n; i++) {
+		for (i = 0; i != total_stats; i++) {
 			i_idx = xstats_ctrl->dev_table_idx_2nd[i];
-			if (i_idx == UINT16_MAX)
-				continue;
 			o_idx = xstats_ctrl->xstats_o_idx_2nd[i];
+			if (i_idx == UINT16_MAX || xstats_ctrl->info[o_idx].dev)
+				continue;
 			stats[o_idx] += (uint64_t)et_stats->data[i_idx];
 		}
 	}
@@ -1273,11 +1274,11 @@ mlx5_os_read_dev_counters(struct rte_eth_dev *dev, bool bond_master, uint64_t *s
 			return ret;
 	}
 	/*
-	 * Read IB counters.
-	 * The counters are unique per IB device but not per net IF.
+	 * Read IB dev counters.
+	 * The counters are unique per IB device but not per netdev IF.
 	 * In bonding mode, getting the stats name only from 1 port is enough.
 	 */
-	for (i = 0; i != xstats_ctrl->mlx5_stats_n; i++) {
+	for (i = xstats_ctrl->dev_cnt_start; i < xstats_ctrl->mlx5_stats_n; i++) {
 		if (!xstats_ctrl->info[i].dev)
 			continue;
 		/* return last xstats counter if fail to read. */
@@ -1573,7 +1574,7 @@ static const struct mlx5_counter_ctrl mlx5_counters_init[] = {
 	},
 };
 
-static const unsigned int xstats_n = RTE_DIM(mlx5_counters_init);
+const unsigned int xstats_n = RTE_DIM(mlx5_counters_init);
 
 static int
 mlx5_os_get_stats_strings(struct rte_eth_dev *dev, bool bond_master,
@@ -1619,6 +1620,7 @@ mlx5_os_get_stats_strings(struct rte_eth_dev *dev, bool bond_master,
 	}
 	if (!bond_master) {
 		/* Add dev counters, unique per IB device. */
+		xstats_ctrl->dev_cnt_start = xstats_ctrl->mlx5_stats_n;
 		for (j = 0; j != xstats_n; j++) {
 			if (mlx5_counters_init[j].dev) {
 				idx = xstats_ctrl->mlx5_stats_n++;
@@ -1660,6 +1662,7 @@ mlx5_os_get_stats_strings(struct rte_eth_dev *dev, bool bond_master,
 		}
 	}
 	/* Dev counters are always at the last now. */
+	xstats_ctrl->dev_cnt_start = xstats_ctrl->mlx5_stats_n;
 	for (j = 0; j != xstats_n; j++) {
 		if (mlx5_counters_init[j].dev) {
 			idx = xstats_ctrl->mlx5_stats_n++;
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 75a1e170af..869aac032b 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -281,6 +281,8 @@ struct mlx5_xstats_ctrl {
 	uint16_t stats_n_2nd;
 	/* Number of device stats identified by PMD. */
 	uint16_t mlx5_stats_n;
+	/* First device counters index. */
+	uint16_t dev_cnt_start;
 	/* Index in the device counters table. */
 	uint16_t dev_table_idx[MLX5_MAX_XSTATS];
 	/* Index in the output table. */
@@ -295,6 +297,9 @@ struct mlx5_xstats_ctrl {
 	uint16_t xstats_o_idx_2nd[MLX5_MAX_XSTATS];
 };
 
+/* xstats array size. */
+extern const unsigned int xstats_n;
+
 struct mlx5_stats_ctrl {
 	/* Base for imissed counter. */
 	uint64_t imissed_base;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-21 12:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-17 16:33 [PATCH] net/mlx5: fix end condition of reading xstats Bing Zhao
2024-07-21 12:10 ` Raslan Darawsheh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).