From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7828645637; Wed, 17 Jul 2024 18:34:18 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7D7DF40299; Wed, 17 Jul 2024 18:34:17 +0200 (CEST) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2040.outbound.protection.outlook.com [40.107.92.40]) by mails.dpdk.org (Postfix) with ESMTP id DBE6540272 for ; Wed, 17 Jul 2024 18:34:15 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vMWsjct9TkF5Pt68Z9F1bHHdBQEN3BEySL9sDHsQq9169DH2LGWyXH2HT79oEAKYOP3LZrFiSJRSzIslbkq0SPhe6MgWNftGXaE+zvmZcNOwI87oMW7u6TynLlhdmOtbraq6rOKKqdT7Kb8c/Gak6XHoc4+Wu9Qz9qgbTMyckVYh6P4Dg63lTUP3LkpIqObEZSdoCEGBanqGc6yAJIdxEDyrkXEB7bI2FnaSSl8rpqmu2e5JXpUYhibDwBWVyZ7OANBijqMB5ghwji4/dwAIgvvXfBWZcmOm0LEPrQQH+v/VloM/lLSq5EcireEmNNW8C9QNeQUwY278xdSa0YfZHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VeMsUc0+v9cCCywrTjTUQGKgfIQw0GycJUD2DKhXD1w=; b=ccy4qNHc6N9o5xoId5DN+CmGTC6z8JzTj7tn3GnX3D5pEeArTJQCcOFFY6B944xzlCom/IR9wUcJsJjaOUKSrdjrCoROqzvVBg8RuSndIahQjHSy+9UrMReO2VH1mkBim87mvqzUf3jbXL5T3tCZml0IvQjtr9CYxOAAeqYahQiBZF1tB9cAIsTAybdTwCp529Ady8N5jt4PQVqPHAfDFDlnhV40qAeUVMA3KuI2A28mDP/wSFoDxkjYQshxiDYSLMIBLzl+TnlRyrCmL469FSARi1SrxJRfP/1JKtGfSbiJFcn8N2iZ95rVSdDLmhY4fN7QkvYW8luFqoCTrZZZ0Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VeMsUc0+v9cCCywrTjTUQGKgfIQw0GycJUD2DKhXD1w=; b=cmqFcFxM5Rm4LZo2TeGEYTfTuSBH7YAJ9MppVZEfrkX2g2jKGfrVakyTwO7KF7TIzp3vFI7VJk+aj9eDuypzz62TVCQXWyDiu1Xbw3uStrtG3Tb9IjQ1xaSa4Sl7HR1mXosdcP+RoytuU5iBcnQhcG0ikGaXla4oPbQsEQZHdRwwF7bWNMGMsEtU/4B3UP2OkMPCPIwF0DuKxw2rlE8h+cxC9DcVnhSRHQ1lVjChRbOrELNOoIwTw/CvSDfW909tNfwdC+EZFKIvTOhrjrYMVZEL/gvD/ifRKvYZBSy973jagdsz7hKNbHi5bCsgG7IQ4p0dyxVHdj9W6mKP6ToRpA== Received: from BY3PR05CA0044.namprd05.prod.outlook.com (2603:10b6:a03:39b::19) by CY5PR12MB6525.namprd12.prod.outlook.com (2603:10b6:930:32::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.16; Wed, 17 Jul 2024 16:34:10 +0000 Received: from SJ1PEPF00002326.namprd03.prod.outlook.com (2603:10b6:a03:39b:cafe::40) by BY3PR05CA0044.outlook.office365.com (2603:10b6:a03:39b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.16 via Frontend Transport; Wed, 17 Jul 2024 16:34:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by SJ1PEPF00002326.mail.protection.outlook.com (10.167.242.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.11 via Frontend Transport; Wed, 17 Jul 2024 16:34:09 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 17 Jul 2024 09:33:54 -0700 Received: from nvidia.com (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 17 Jul 2024 09:33:51 -0700 From: Bing Zhao To: , , CC: , , , Subject: [PATCH] net/mlx5: fix end condition of reading xstats Date: Wed, 17 Jul 2024 19:33:37 +0300 Message-ID: <20240717163337.324741-1-bingz@nvidia.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00002326:EE_|CY5PR12MB6525:EE_ X-MS-Office365-Filtering-Correlation-Id: 8c3f65f1-a06b-4450-7eac-08dca67e48f0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|82310400026|36860700013|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?RcSO1IkD8olAU7ECi0wuJ0DW5UI1eALdI32JSoti5aWjhAvCUzRutYjpGlF1?= =?us-ascii?Q?3f5+xb4OFuu1gdetfigHA6wMYf+D7IJiQyGGUfPsNQb6uGSDV/pOP4Sf0AyN?= =?us-ascii?Q?Ecebe/LHCpoINKf6T/yRZkPVgyPYd9gtIx9hosIFKAatmhmh+kdbT9MqB7Yb?= =?us-ascii?Q?FJ5JXDDhzbOKfU2ZU4ri3uM1QLv+thwirCcN7lluQUiBUzFFTokItFTJ/2yv?= =?us-ascii?Q?cZQ1k8NplSXXtq/okOPlAeCYwquRfdIRtkqKYYVV+wl7t+s5JO/WmzNzI7AI?= =?us-ascii?Q?PO7LDHEoVEvnlgewbkiQd6lEpX041Q6WcJk9gjYsKGtibG71Lh+6gVrbf4C9?= =?us-ascii?Q?YUs1QPA8CszhSBdcul66SFqNgpm36ecurR50FeFIwD3CSRXwb9w+WlKWk925?= =?us-ascii?Q?+WvXLofuAuPaYStqb57v8xAkj6TOlsAlNd86S1ZVYTtsWKQzRTqc1oe4oZKf?= =?us-ascii?Q?S5Z27QL5lHZB6wjslQIJJMy27PpdWZSArKdKACNgCBcnJx8MJjQsyHtIlV/E?= =?us-ascii?Q?c++edM4fGz3NuxMIrbmvmtRQP+OVAbjVCOiTPah5yX4Im+nbKiCNOX6jehyt?= =?us-ascii?Q?1/jhundKAo3g+wc66BMW1oiHUBMglBkPkJ54RgeyQ1qyv5oXtvZEe7LTTsmX?= =?us-ascii?Q?QVoZRGDtl2+LUA1w+ENx81cvv9SZgamq9wAvLdV8aLWtsn+xFzr507NVq3qT?= =?us-ascii?Q?6WOvRHjtewHZlaY4liC2ZlobiRV8t7AJla+AP7Z85DL20cQGi5tLvgK/05lU?= =?us-ascii?Q?G58gxmH/GNnVUMh14ohc4QX2EWtw/cc1dy0QDk52XrNKWoRIkX2DW2aknv2t?= =?us-ascii?Q?3xUu89yTdSMfgDwI/UEx5wGPHT7OsY7e+VUFudEp0KOXK1gr/82p3kviOWma?= =?us-ascii?Q?w0FUECctqGogunhiP8x1pGv0rOQpnEoqZPlrU+OZsYmEr1Ur+j2wFq7rb34a?= =?us-ascii?Q?td4gP32kwkOsRoNmjAAmd2hK8ijFogSXzxeHwsRZz0jc6EjsyMc3xVrSVewP?= =?us-ascii?Q?h4G+tdIx7wPHf20kgtjDL0ZmQa8xfvfyOImkO0WMCuKrpIhg+ltkDiRj/bMJ?= =?us-ascii?Q?Ch64INay/+2lr5CccsQc4V0RAtD76O66Vf/jCUfAbF6BF9EiUvr4TIpLzAs3?= =?us-ascii?Q?ilHltJx5SHir7cVfM4GP+qM9kAymBIdeE9ujvwHrh/NKcaJ81qxytlywFsMV?= =?us-ascii?Q?KWq/4lzYwbyYnM4DwGN0WISA9cmmSekYulfuFUgK4kQFnJgNeSF5Hst6HPks?= =?us-ascii?Q?jYDWCbHJgJvpkVlXKUykYii+9+254Ucyj3vSVNilGG4ufEkUXF/DUtP8Y+Ez?= =?us-ascii?Q?E5FlUNzmqfYzipMjY5ffPJNEHABRdO9PEatLXMccKM1fsc5GUgQJVx/zzxK8?= =?us-ascii?Q?FfWmsV2qaKPvKXu+cUzVdQ5OrUt1tgj4CR24RnMtYPz/7Mqn3lnJP5G83tEM?= =?us-ascii?Q?YryijfeQrpk+b1KRLLIFkIikE9EIEOre?= X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230040)(1800799024)(82310400026)(36860700013)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2024 16:34:09.8327 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8c3f65f1-a06b-4450-7eac-08dca67e48f0 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00002326.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6525 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The "mlx5_stats_n" in the "struct mlx5_xstats_ctrl" is the number of device stats identified by PMD. Right now, the mapping of device stats to the xstats is not compact. The "input index" of the device stats would remain UINT16_MAX and be skipped when reading counters. If some DPDK stats cannot be identified in the middle of the map, the end condition should be bigger than the "mlx5_stats_n". Or else, some counters would not be read and calculated. Using the global const "xstats_n" as the end condition to traverse the whole array in case some counters are missed. The "xstats_o_idx" should be used instead of the iteration to check if the statistics is an IB device counter. In the meanwhile, adding another field to record the start index of the IB counters to reduce the redundancy iterations. Fixes: a687c3e658c2 ("net/mlx5: fix counters map in bonding mode") Signed-off-by: Bing Zhao Acked-by: Viacheslav Ovsiienko --- drivers/net/mlx5/linux/mlx5_ethdev_os.c | 23 +++++++++++++---------- drivers/net/mlx5/mlx5.h | 5 +++++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/net/mlx5/linux/mlx5_ethdev_os.c b/drivers/net/mlx5/linux/mlx5_ethdev_os.c index 82f651f2f3..5d64984022 100644 --- a/drivers/net/mlx5/linux/mlx5_ethdev_os.c +++ b/drivers/net/mlx5/linux/mlx5_ethdev_os.c @@ -1201,6 +1201,7 @@ _mlx5_os_read_dev_counters(struct rte_eth_dev *dev, int pf, uint64_t *stats) struct ethtool_stats *et_stats = (struct ethtool_stats *)et_stat_buf; int ret; uint16_t i_idx, o_idx; + uint32_t total_stats = xstats_n; et_stats->cmd = ETHTOOL_GSTATS; /* Pass the maximum value, the driver may ignore this. */ @@ -1218,19 +1219,19 @@ _mlx5_os_read_dev_counters(struct rte_eth_dev *dev, int pf, uint64_t *stats) return ret; } if (pf <= 0) { - for (i = 0; i != xstats_ctrl->mlx5_stats_n; i++) { + for (i = 0; i != total_stats; i++) { i_idx = xstats_ctrl->dev_table_idx[i]; - if (i_idx == UINT16_MAX || xstats_ctrl->info[i].dev) - continue; o_idx = xstats_ctrl->xstats_o_idx[i]; + if (i_idx == UINT16_MAX || xstats_ctrl->info[o_idx].dev) + continue; stats[o_idx] += (uint64_t)et_stats->data[i_idx]; } } else { - for (i = 0; i != xstats_ctrl->mlx5_stats_n; i++) { + for (i = 0; i != total_stats; i++) { i_idx = xstats_ctrl->dev_table_idx_2nd[i]; - if (i_idx == UINT16_MAX) - continue; o_idx = xstats_ctrl->xstats_o_idx_2nd[i]; + if (i_idx == UINT16_MAX || xstats_ctrl->info[o_idx].dev) + continue; stats[o_idx] += (uint64_t)et_stats->data[i_idx]; } } @@ -1273,11 +1274,11 @@ mlx5_os_read_dev_counters(struct rte_eth_dev *dev, bool bond_master, uint64_t *s return ret; } /* - * Read IB counters. - * The counters are unique per IB device but not per net IF. + * Read IB dev counters. + * The counters are unique per IB device but not per netdev IF. * In bonding mode, getting the stats name only from 1 port is enough. */ - for (i = 0; i != xstats_ctrl->mlx5_stats_n; i++) { + for (i = xstats_ctrl->dev_cnt_start; i < xstats_ctrl->mlx5_stats_n; i++) { if (!xstats_ctrl->info[i].dev) continue; /* return last xstats counter if fail to read. */ @@ -1573,7 +1574,7 @@ static const struct mlx5_counter_ctrl mlx5_counters_init[] = { }, }; -static const unsigned int xstats_n = RTE_DIM(mlx5_counters_init); +const unsigned int xstats_n = RTE_DIM(mlx5_counters_init); static int mlx5_os_get_stats_strings(struct rte_eth_dev *dev, bool bond_master, @@ -1619,6 +1620,7 @@ mlx5_os_get_stats_strings(struct rte_eth_dev *dev, bool bond_master, } if (!bond_master) { /* Add dev counters, unique per IB device. */ + xstats_ctrl->dev_cnt_start = xstats_ctrl->mlx5_stats_n; for (j = 0; j != xstats_n; j++) { if (mlx5_counters_init[j].dev) { idx = xstats_ctrl->mlx5_stats_n++; @@ -1660,6 +1662,7 @@ mlx5_os_get_stats_strings(struct rte_eth_dev *dev, bool bond_master, } } /* Dev counters are always at the last now. */ + xstats_ctrl->dev_cnt_start = xstats_ctrl->mlx5_stats_n; for (j = 0; j != xstats_n; j++) { if (mlx5_counters_init[j].dev) { idx = xstats_ctrl->mlx5_stats_n++; diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 75a1e170af..869aac032b 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -281,6 +281,8 @@ struct mlx5_xstats_ctrl { uint16_t stats_n_2nd; /* Number of device stats identified by PMD. */ uint16_t mlx5_stats_n; + /* First device counters index. */ + uint16_t dev_cnt_start; /* Index in the device counters table. */ uint16_t dev_table_idx[MLX5_MAX_XSTATS]; /* Index in the output table. */ @@ -295,6 +297,9 @@ struct mlx5_xstats_ctrl { uint16_t xstats_o_idx_2nd[MLX5_MAX_XSTATS]; }; +/* xstats array size. */ +extern const unsigned int xstats_n; + struct mlx5_stats_ctrl { /* Base for imissed counter. */ uint64_t imissed_base; -- 2.34.1