From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 3017DA0545;
	Wed, 15 Jul 2020 12:51:01 +0200 (CEST)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id A1F331BED3;
	Wed, 15 Jul 2020 12:50:59 +0200 (CEST)
Received: from git-send-mailer.rdmz.labs.mlnx (unknown [37.142.13.130])
 by dpdk.org (Postfix) with ESMTP id 167801BEBF;
 Wed, 15 Jul 2020 12:50:58 +0200 (CEST)
From: Shy Shyman <shys@mellanox.com>
To: dev@dpdk.org
Cc: viacheslavo@mellanox.com,
	stable@dpdk.org
Date: Wed, 15 Jul 2020 13:50:55 +0300
Message-Id: <20200715105055.80089-1-shys@mellanox.com>
X-Mailer: git-send-email 2.21.0
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Subject: [dpdk-dev] [PATCH] net/mlx5: fix file path location of HW counters
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

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
<port_id>' for example.

The current implementation assumes legacy mode in which the
counters
are at <ibdev_path>/<port_id>/hw_counters/<file_name>.
In switchdev mode the counters file is located right after the device
name, hence resides at <ibdev_path>/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
Cc: viacheslavo@mellanox.com

Signed-off-by: Shy Shyman <shys@mellanox.com>
---
 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 2dc57b20ef..0edc96299c 100644
--- a/drivers/net/mlx5/linux/mlx5_os.c
+++ b/drivers/net/mlx5/linux/mlx5_os.c
@@ -1948,10 +1948,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 <ibdev_path>/hw_counters/<file_name>.
+		*/
+		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.21.0