From eadc35df59a1a1a5017c0db1c7a9978ca8eb56e9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Geoffrey=20Le=20Gourri=C3=A9rec?= Date: Thu, 17 Mar 2022 14:23:48 +0100 Subject: [PATCH] net/mlx5: fix statistics read on Linux MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch encompasses a few fixes carried by a previous patch that aimed to support bonding device stats counting. - If mlx5_os_read_dev_stat fails, it returns 1 instead of a negative value, causing mlx5_xstats_get to return an invalid number of counters. Since this error is not blocking, do not mess ret value with mlx5_os_read_dev_stat returned value. This allows avoiding the very annoying log: "n_xstats != n_xstats_names => skipping" - Invert the check for mlx5_os_read_dev_stat(), currently leading us to store the result if the function failed, and use a backup value if it succeeded, which is the opposite of what we actually want. Revert to the original (correct) test. - Add missing test on _mlx5_os_read_dev_counters() to prevent using trash stats values. Fixes: 7ed15acdcd69 ("net/mlx5: improve xstats of bonding port") Cc: stable@dpdk.org Signed-off-by: Didier Pallard Signed-off-by: Geoffrey Le Gourriérec Tested-by: Bassam Zaid AlKilani Acked-by: Matan Azrad --- drivers/net/mlx5/linux/mlx5_ethdev_os.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/net/mlx5/linux/mlx5_ethdev_os.c b/drivers/net/mlx5/linux/mlx5_ethdev_os.c index 6fbfcfad48..8d30ad0994 100644 --- a/drivers/net/mlx5/linux/mlx5_ethdev_os.c +++ b/drivers/net/mlx5/linux/mlx5_ethdev_os.c @@ -1386,15 +1386,16 @@ mlx5_os_read_dev_counters(struct rte_eth_dev *dev, uint64_t *stats) } } else { ret = _mlx5_os_read_dev_counters(dev, -1, stats); + if (ret) + return ret; } /* Read IB counters. */ for (i = 0; i != xstats_ctrl->mlx5_stats_n; ++i) { if (!xstats_ctrl->info[i].dev) continue; - ret = mlx5_os_read_dev_stat(priv, xstats_ctrl->info[i].ctr_name, - &stats[i]); /* return last xstats counter if fail to read. */ - if (ret != 0) + if (mlx5_os_read_dev_stat(priv, xstats_ctrl->info[i].ctr_name, + &stats[i]) == 0) xstats_ctrl->xstats[i] = stats[i]; else stats[i] = xstats_ctrl->xstats[i]; -- 2.39.5