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 44F3A45D55 for ; Wed, 20 Nov 2024 19:39:36 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3049F42E52; Wed, 20 Nov 2024 19:39:36 +0100 (CET) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2086.outbound.protection.outlook.com [40.107.237.86]) by mails.dpdk.org (Postfix) with ESMTP id 6DA8142E52 for ; Wed, 20 Nov 2024 19:39:34 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UXPA31MTa0nRXsb8A+GimvR2dt9DLPqo/hvL+BrtAXtFdTsxdFCh4wBXnZZ7mEFgxW6hfWDLjce2egfjiBPaS6v8h90xmA+uLhSSByL/WOrILmXOxK1RwVk//QH9VuGZXX999zsHSpAgBlO7sX+l4ycSqQ2j0B8KglqamM7sEzpdc8SjPf2VBZqm2EhRwDEMxMKZBY2XB+r7wFXt7JPCPbTwWeuwfvctjoQdcADDLUrJ0Jhn5b4VQqybAUFEFYpeZ2LFFfiLaz7MMhGn0Whs06O4kXGhbuh4nyNb+x3Cw2PiLiOGWKki3UtCbaks8UGfMkxlcQtCqeZ0S/QHdXdtlA== 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=x26qgujpCuyx9NSEb7forbHcJxNqNyovY/pngQfji9k=; b=sjtLDeUDzsT4jSlnAdM7dCz/kGN26cEnMmL8OzwmZUQ5Ly3Ce+271TcLU3TgWN38WHkyDUrOOH303DSpB1yXTG97kQ3tBX51HOuuiNCJtprjoyUvmnqO3+oRSWOHE1DoMarJhlVlMUOE3o5kAklCrTqBUNQBu8Np5uUZ4oYVBdySu16/wCrfG2NrP8tIEJIMB81He43kY1O/5Wk8Mi/E1UCfHGzv66XVmmypDjMAfOWW3UNptd1MLPReyKkew7LbqmTkOeMP20TKDCHTFC9Qh4wE15rPm79Gm3eHvwyJK266uRG8CtynYKWUETECAZ3NfHyFPtaV26C5tnOSDYF1Ag== 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=x26qgujpCuyx9NSEb7forbHcJxNqNyovY/pngQfji9k=; b=g2ekuF9WZYy5XAO4il/642XfzGGr6Zp5T/xoLjD8iRR7nBBusQh3h0DIdfGfkngytoVTewuYN1YLpcjkS8iLeh7OnHVNmKCTgmWpMHZzztXPeZcqqOPxxJqmrXh4bBHcpANTbUKlu6+OutYjal9VciaUkwYZjKLBPd0RrBmTISQlRUFzYRjQQWihCMRDz+0kr8phalmDF1/XccY+T4+1tzitt+7+sQAqmIq3O7y39yqRLyLGwEO2grwyFWG57E8P4f3WF2cUHCvIc+q5x18w4JEbZIXovIBxBaR0vefOMuyG4k79hFGMbTm4mfZZNmObcg9TNeCnBVpb1uBQpMR6fg== Received: from SN6PR05CA0016.namprd05.prod.outlook.com (2603:10b6:805:de::29) by LV2PR12MB5919.namprd12.prod.outlook.com (2603:10b6:408:173::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.23; Wed, 20 Nov 2024 18:39:28 +0000 Received: from SA2PEPF000015C6.namprd03.prod.outlook.com (2603:10b6:805:de:cafe::be) by SN6PR05CA0016.outlook.office365.com (2603:10b6:805:de::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.15 via Frontend Transport; Wed, 20 Nov 2024 18:39:28 +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 SA2PEPF000015C6.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.16 via Frontend Transport; Wed, 20 Nov 2024 18:39:28 +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, 20 Nov 2024 10:39:12 -0800 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, 20 Nov 2024 10:39:11 -0800 From: Viacheslav Ovsiienko To: CC: , Tim Martin Subject: [PATCH 22.11] net/mlx5: fix real time counter reading from PCI BAR Date: Wed, 20 Nov 2024 20:38:55 +0200 Message-ID: <20241120183855.2218388-1-viacheslavo@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: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015C6:EE_|LV2PR12MB5919:EE_ X-MS-Office365-Filtering-Correlation-Id: 9d75ac64-c2f4-4c5d-08fe-08dd0992aa52 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|1800799024|376014|82310400026|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?8yprSxMPDXt+42k6q0P4QLjCZhzhfY8IYdPGjinjkFhvNuja9btEZ5P2+kKZ?= =?us-ascii?Q?NpdtvvQoMNyTP4f3dUSkaASqSOYdccnKU3l5x5p2Y/IvhEfcQeaU4H5N2+LW?= =?us-ascii?Q?NpeO8Wn0GcnxJ1jq1YGIJQUdo+Yh5ZpMjIQT1lb9UfHj9OTi2x2FL9f9aZ08?= =?us-ascii?Q?omQgiU4uCs1pm4ZHHT9/6HzbEyh3kspNC4NdD7SYSwEMF1qo4dOJa88KUWBo?= =?us-ascii?Q?t9FdfR0WluTRRwHEINghvTrlSj0Ima/99GHuaYvigfwZmt8M29VOy76yVN7p?= =?us-ascii?Q?SJn2cuO8J/ez+cbbPRd+VzMyyxHSpsbahJ1PjXeiYlbaSabzFT4ox+Ed+vwt?= =?us-ascii?Q?zLt7iI+KZXmOL+caUNgeNpUhNLjTwumL2TljrHLgsfQZA2eg8TJbgCM0sPpY?= =?us-ascii?Q?E+8Mzc6uxYAQ5JfbPQL9lUULIUHiKSENu96svP2Vn9YpYzDAixwzYFTQ4B9N?= =?us-ascii?Q?1nFynDAm1GP6YairTrqqgJE5ynM118oTZV9QmuxE+j1TLbQ2Fs33MTYmTM1q?= =?us-ascii?Q?Qjk7LhQjWWwatPJCBV7VY4NMsEiVG3tNlG+UDAb3YTkjbWktp8lWOoHUFtBz?= =?us-ascii?Q?Io7PK+ZoajvyFPusiZpOHhauHuYNvgzHKL9w/O4WENPngGaEilpU/vl16x5+?= =?us-ascii?Q?48r3PEXvDObpWICybOuGDuOroBo74FKJQWJsBHj+qyVJFqO8iB26bnR9Irdl?= =?us-ascii?Q?aaaCH/dPCXLkyXh3pUCoIbGx+Ummp35ifUTQsC8u2ic+mZTg/KlAk0AagQw6?= =?us-ascii?Q?G0zpW20doQzXzjavvO7K/nvliROFW9Ngzdqm7ePzQouV6e9l5k//5o5FtdKj?= =?us-ascii?Q?RGWFNbLbIaP8algqHB3o13gZAhQr1sYltN/ZkOBgX2v8gkgFEg+iHZ0mlny3?= =?us-ascii?Q?ofATWVW6HBRVB5Rd83sUD92jaysgRGVfDBVU23zU00Qo0K36qYm9GyJ+ZBID?= =?us-ascii?Q?8Bn05VYLoHqUrTSQVilra/2vNkMrqbyX/j9Vzn12wQRJ8iIkZh/8bnxnwVyP?= =?us-ascii?Q?kxOYFrYMNRdNoyiWWLhyENVXonX8cpmZ2J/EgZgyqcdxNnIN9A7VIKXjOogI?= =?us-ascii?Q?mzWMDTpxiy/lebrbZelzwLom9NHkSGs/0tu8+XfSeq5b2eYeodwr7wYl3cj7?= =?us-ascii?Q?yyp9ULcFNRH5r+LwjJDnkBpbMkcgSDj6SRY23dewABoZ/jYZxXrUamMpOC0F?= =?us-ascii?Q?U6zDfBs1+VV6DKzQU5RRklKQcT2UotkPX4RHQ+rZCFKQq+KRZo9lgNv4W6cB?= =?us-ascii?Q?uoPYxRh6aW8v9oFVXU9BjWdMuWek2qTzUEsmt/4tNIIN1TkoxS0rleK+XdSR?= =?us-ascii?Q?OGZKpfg315aDnwP6cVhJB3ZndO31ktUh/ZI5lZEGiXahCMkJyuHVraw3KFA1?= =?us-ascii?Q?cDbzCI07TcT+a/HlKTI77pHtkZTvk/DPKDfzkkmzeN823sxIqg=3D=3D?= 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)(36860700013)(1800799024)(376014)(82310400026)(7053199007); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2024 18:39:28.2450 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9d75ac64-c2f4-4c5d-08fe-08dd0992aa52 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: SA2PEPF000015C6.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5919 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org From: Tim Martin [ upstream commit 7271cf3a27fad171880a6085af5bd1cdb5a4a624 ] There is the mlx5_txpp_read_clock() routine reading the 64-bit real time counter from the device PCI BAR. It introduced two issues: - it checks the PCI BAR mapping into process address space and tries to map this on demand. This might be problematic if something goes wrong and mapping fails. It happens on every read_clock API call, invokes kernel taking a long time and causing application malfunction. - the 64-bit counter should be read in single atomic transaction Fixes: b94d93ca7380 ("net/mlx5: support reading device clock") Cc: stable@dpdk.org Signed-off-by: Tim Martin Acked-by: Viacheslav Ovsiienko --- .mailmap | 1 + drivers/net/mlx5/mlx5.c | 4 ++++ drivers/net/mlx5/mlx5_tx.h | 30 ++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_txpp.c | 11 ++--------- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/.mailmap b/.mailmap index 025bd2daba..457af9abc2 100644 --- a/.mailmap +++ b/.mailmap @@ -1392,6 +1392,7 @@ Timmons C. Player Timothy McDaniel Timothy Miskell Timothy Redaelli +Tim Martin Tim Shearer Ting-Kai Ku Ting Xu diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index d66254740b..1076ad1721 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -1961,6 +1961,7 @@ int mlx5_proc_priv_init(struct rte_eth_dev *dev) { struct mlx5_priv *priv = dev->data->dev_private; + struct mlx5_dev_ctx_shared *sh = priv->sh; struct mlx5_proc_priv *ppriv; size_t ppriv_size; @@ -1981,6 +1982,9 @@ mlx5_proc_priv_init(struct rte_eth_dev *dev) dev->process_private = ppriv; if (rte_eal_process_type() == RTE_PROC_PRIMARY) priv->sh->pppriv = ppriv; + /* Check and try to map HCA PCI BAR to allow reading real time. */ + if (sh->dev_cap.rt_timestamp && mlx5_dev_is_pci(dev->device)) + mlx5_txpp_map_hca_bar(dev); return 0; } diff --git a/drivers/net/mlx5/mlx5_tx.h b/drivers/net/mlx5/mlx5_tx.h index ff23d87b8a..6b796b97e1 100644 --- a/drivers/net/mlx5/mlx5_tx.h +++ b/drivers/net/mlx5/mlx5_tx.h @@ -18,6 +18,7 @@ #include #include "mlx5.h" +#include "mlx5_rx.h" #include "mlx5_autoconf.h" /* TX burst subroutines return codes. */ @@ -361,6 +362,35 @@ mlx5_txpp_convert_tx_ts(struct mlx5_dev_ctx_shared *sh, uint64_t mts) return ci; } +/** + * Read real time clock counter directly from the device PCI BAR area. + * The PCI BAR must be mapped to the process memory space at initialization. + * + * @param dev + * Device to read clock counter from + * + * @return + * 0 - if HCA BAR is not supported or not mapped. + * !=0 - read 64-bit value of real-time in UTC formatv (nanoseconds) + */ +static __rte_always_inline uint64_t mlx5_read_pcibar_clock(struct rte_eth_dev *dev) +{ + struct mlx5_proc_priv *ppriv = dev->process_private; + + if (ppriv && ppriv->hca_bar) { + struct mlx5_priv *priv = dev->data->dev_private; + struct mlx5_dev_ctx_shared *sh = priv->sh; + uint64_t *hca_ptr = (uint64_t *)(ppriv->hca_bar) + + __mlx5_64_off(initial_seg, real_time); + uint64_t ts = __atomic_load_n(hca_ptr, __ATOMIC_SEQ_CST); + + ts = rte_be_to_cpu_64(ts); + ts = mlx5_txpp_convert_rx_ts(sh, ts); + return ts; + } + return 0; +} + /** * Set Software Parser flags and offsets in Ethernet Segment of WQE. * Flags must be preliminary initialized to zero. diff --git a/drivers/net/mlx5/mlx5_txpp.c b/drivers/net/mlx5/mlx5_txpp.c index 0e1da1d5f5..c43a5a7927 100644 --- a/drivers/net/mlx5/mlx5_txpp.c +++ b/drivers/net/mlx5/mlx5_txpp.c @@ -969,7 +969,6 @@ mlx5_txpp_read_clock(struct rte_eth_dev *dev, uint64_t *timestamp) { struct mlx5_priv *priv = dev->data->dev_private; struct mlx5_dev_ctx_shared *sh = priv->sh; - struct mlx5_proc_priv *ppriv; uint64_t ts; int ret; @@ -995,15 +994,9 @@ mlx5_txpp_read_clock(struct rte_eth_dev *dev, uint64_t *timestamp) *timestamp = ts; return 0; } - /* Check and try to map HCA PIC BAR to allow reading real time. */ - ppriv = dev->process_private; - if (ppriv && !ppriv->hca_bar && - sh->dev_cap.rt_timestamp && mlx5_dev_is_pci(dev->device)) - mlx5_txpp_map_hca_bar(dev); /* Check if we can read timestamp directly from hardware. */ - if (ppriv && ppriv->hca_bar) { - ts = MLX5_GET64(initial_seg, ppriv->hca_bar, real_time); - ts = mlx5_txpp_convert_rx_ts(sh, ts); + ts = mlx5_read_pcibar_clock(dev); + if (ts != 0) { *timestamp = ts; return 0; } -- 2.34.1