From: Rayane Boussanni <rboussanni@gmail.com>
To: dev@dpdk.org
Cc: rasland@nvidia.com, Rayane Boussanni <rboussanni@gmail.com>
Subject: [PATCH] net/mlx5: add hardware query for basic stats
Date: Thu, 16 Apr 2026 18:40:12 -0400 [thread overview]
Message-ID: <20260416224011.14862-1-rboussanni@gmail.com> (raw)
When MLX5_PMD_SOFT_COUNTERS is not defined, the basic dev statistics
(rte_eth_stats) previously fell back to returning zeroed values for
all packet and byte metrics.
This patch resolves the FIXMEs in mlx5_stats_get and mlx5_stats_reset
by falling back to the target's dev counters map. It utilizes
mlx5_os_read_dev_counters to retrieve the bulk arrays from the hardware
and strategically filters them against the xstats_ctrl index to
summarize the basic opackets, obytes, ipackets, ibytes, oerrors,
and ierrors without duplicating the context-switch overhead.
Signed-off-by: Rayane Boussanni <rboussanni@gmail.com>
---
drivers/net/mlx5/mlx5_stats.c | 57 +++++++++++++++++++++++++++++++++--
1 file changed, 55 insertions(+), 2 deletions(-)
diff --git a/drivers/net/mlx5/mlx5_stats.c b/drivers/net/mlx5/mlx5_stats.c
index 5cd3e303cc..198f231559 100644
--- a/drivers/net/mlx5/mlx5_stats.c
+++ b/drivers/net/mlx5/mlx5_stats.c
@@ -280,7 +280,46 @@ mlx5_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
tmp.imissed = stats_ctrl->imissed;
}
#ifndef MLX5_PMD_SOFT_COUNTERS
- /* FIXME: retrieve and add hardware counters. */
+ {
+ uint64_t counters[MLX5_MAX_XSTATS];
+ struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
+ bool bond_master = (priv->master && priv->pf_bond >= 0);
+
+ ret = mlx5_os_read_dev_counters(dev, bond_master, counters);
+ if (ret) {
+ DRV_LOG(WARNING, "port %u unable to read device counters",
+ dev->data->port_id);
+ return ret;
+ }
+ for (i = 0; i != xstats_ctrl->mlx5_stats_n; ++i) {
+ const char *name = xstats_ctrl->info[i].dpdk_name;
+ uint64_t val = (counters[i] - xstats_ctrl->base[i]);
+
+ if (!strcmp(name, "rx_unicast_packets") ||
+ !strcmp(name, "rx_multicast_packets") ||
+ !strcmp(name, "rx_broadcast_packets"))
+ tmp.ipackets += val;
+ else if (!strcmp(name, "rx_unicast_bytes") ||
+ !strcmp(name, "rx_multicast_bytes") ||
+ !strcmp(name, "rx_broadcast_bytes"))
+ tmp.ibytes += val;
+ else if (!strcmp(name, "tx_unicast_packets") ||
+ !strcmp(name, "tx_multicast_packets") ||
+ !strcmp(name, "tx_broadcast_packets"))
+ tmp.opackets += val;
+ else if (!strcmp(name, "tx_unicast_bytes") ||
+ !strcmp(name, "tx_multicast_bytes") ||
+ !strcmp(name, "tx_broadcast_bytes"))
+ tmp.obytes += val;
+ else if (!strcmp(name, "rx_wqe_errors") ||
+ !strcmp(name, "rx_phy_crc_errors") ||
+ !strcmp(name, "rx_phy_in_range_len_errors") ||
+ !strcmp(name, "rx_phy_symbol_errors"))
+ tmp.ierrors += val;
+ else if (!strcmp(name, "tx_phy_errors"))
+ tmp.oerrors += val;
+ }
+ }
#endif
*stats = tmp;
return 0;
@@ -319,7 +358,21 @@ mlx5_stats_reset(struct rte_eth_dev *dev)
mlx5_os_read_dev_stat(priv, "out_of_buffer", &stats_ctrl->imissed_base);
stats_ctrl->imissed = 0;
#ifndef MLX5_PMD_SOFT_COUNTERS
- /* FIXME: reset hardware counters. */
+ {
+ uint64_t counters[MLX5_MAX_XSTATS];
+ struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
+ bool bond_master = (priv->master && priv->pf_bond >= 0);
+ int ret;
+
+ ret = mlx5_os_read_dev_counters(dev, bond_master, counters);
+ if (ret) {
+ DRV_LOG(WARNING, "port %u unable to read device counters",
+ dev->data->port_id);
+ return ret;
+ }
+ for (i = 0; i != xstats_ctrl->mlx5_stats_n; ++i)
+ xstats_ctrl->base[i] = counters[i];
+ }
#endif
return 0;
--
2.34.1
reply other threads:[~2026-04-16 22:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260416224011.14862-1-rboussanni@gmail.com \
--to=rboussanni@gmail.com \
--cc=dev@dpdk.org \
--cc=rasland@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox