net/mlx5: fix linux stats gathering function

Message ID 20220317132348.30240-1-geoffrey.le_gourrierec@6wind.com (mailing list archive)
State Accepted, archived
Delegated to: Raslan Darawsheh
Headers
Series net/mlx5: fix linux stats gathering function |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Functional fail Functional Testing issues
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS

Commit Message

Geoffrey Le Gourriérec March 17, 2022, 1:23 p.m. UTC
  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")
Signed-off-by: Didier Pallard <didier.pallard@6wind.com>
Signed-off-by: Geoffrey Le Gourriérec <geoffrey.le_gourrierec@6wind.com>
---
 drivers/net/mlx5/linux/mlx5_ethdev_os.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
  

Comments

Bassam ZaidAlKilani May 8, 2022, 2:21 p.m. UTC | #1
> -----Original Message-----
> From: Geoffrey Le Gourriérec <geoffrey.le_gourrierec@6wind.com>
> Sent: Thursday, March 17, 2022 15:24
> To: dev@dpdk.org
> Cc: Didier Pallard <didier.pallard@6wind.com>; Matan Azrad
> <matan@nvidia.com>; Slava Ovsiienko <viacheslavo@nvidia.com>
> Subject: [PATCH] net/mlx5: fix linux stats gathering function
> 
> [Some people who received this message don't often get email from
> geoffrey.le_gourrierec@6wind.com. Learn why this is important at
> http://aka.ms/LearnAboutSenderIdentification.]
> 
> External email: Use caution opening links or attachments
> 
> 
> 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")
> Signed-off-by: Didier Pallard <didier.pallard@6wind.com>
> Signed-off-by: Geoffrey Le Gourriérec <geoffrey.le_gourrierec@6wind.com>
> ---
>  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 8fe73f1adb58..b5819cc656ff 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.30.2

Tested-by: Bassam Zaid AlKilani <bzalkilani@nvidia.com>

Best,
Bassam
  
Matan Azrad June 2, 2022, 9:01 a.m. UTC | #2
From: Geoffrey Le Gourriérec
> 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")
> Signed-off-by: Didier Pallard <didier.pallard@6wind.com>
> Signed-off-by: Geoffrey Le Gourriérec
> <geoffrey.le_gourrierec@6wind.com>
Acked-by: Matan Azrad <matan@nvidia.com>
  
Raslan Darawsheh June 5, 2022, 3:05 p.m. UTC | #3
Hi,

> -----Original Message-----
> From: Geoffrey Le Gourriérec <geoffrey.le_gourrierec@6wind.com>
> Sent: Thursday, March 17, 2022 3:24 PM
> To: dev@dpdk.org
> Cc: Didier Pallard <didier.pallard@6wind.com>; Matan Azrad
> <matan@nvidia.com>; Slava Ovsiienko <viacheslavo@nvidia.com>
> Subject: [PATCH] net/mlx5: fix linux stats gathering function
> 
> 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")
> Signed-off-by: Didier Pallard <didier.pallard@6wind.com>
> Signed-off-by: Geoffrey Le Gourriérec
> <geoffrey.le_gourrierec@6wind.com>
> ---

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh
  

Patch

diff --git a/drivers/net/mlx5/linux/mlx5_ethdev_os.c b/drivers/net/mlx5/linux/mlx5_ethdev_os.c
index 8fe73f1adb58..b5819cc656ff 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];