From 038e7fc085746167f8a50c1612acada5a78fc7da Mon Sep 17 00:00:00 2001 From: Shy Shyman Date: Wed, 15 Jul 2020 13:50:55 +0300 Subject: [PATCH] net/mlx5: fix HW counters path in switchdev mode When debugging performance of a DPDK application the user may need to view the different statistics of DPDK (for example out_of_buffer) This can be enabled by using testpmd command 'show port xstats ' for example. The current implementation assumes legacy mode in which the counters are at //hw_counters/. In switchdev mode the counters file is located right after the device name, hence resides at /hw_counters. The fix tries to open the path in the second location after a failure to open the file from the first location. Fixes: 9c0a9eed37f1 ("net/mlx5: switch to the names in the shared IB context") Cc: stable@dpdk.org Signed-off-by: Shy Shyman Acked-by: Viacheslav Ovsiienko --- drivers/net/mlx5/linux/mlx5_os.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c index 9622eb31e2..c4e6c6f6f2 100644 --- a/drivers/net/mlx5/linux/mlx5_os.c +++ b/drivers/net/mlx5/linux/mlx5_os.c @@ -2166,10 +2166,20 @@ mlx5_os_read_dev_stat(struct mlx5_priv *priv, const char *ctr_name, if (priv->sh) { MKSTR(path, "%s/ports/%d/hw_counters/%s", - priv->sh->ibdev_path, - priv->dev_port, - ctr_name); + priv->sh->ibdev_path, + priv->dev_port, + ctr_name); fd = open(path, O_RDONLY); + /* + * in switchdev the file location is not per port + * but rather in /hw_counters/. + */ + if (fd == -1) { + MKSTR(path1, "%s/hw_counters/%s", + priv->sh->ibdev_path, + ctr_name); + fd = open(path1, O_RDONLY); + } if (fd != -1) { char buf[21] = {'\0'}; ssize_t n = read(fd, buf, sizeof(buf)); -- 2.20.1