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 A1EC945B36 for ; Mon, 14 Oct 2024 10:05:43 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 979BF40151; Mon, 14 Oct 2024 10:05:43 +0200 (CEST) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2041.outbound.protection.outlook.com [40.107.92.41]) by mails.dpdk.org (Postfix) with ESMTP id 6C6E44064F; Mon, 14 Oct 2024 10:05:42 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DcQmDrdN+tn9+eBV5vPxpDlaFYU7DMd1f8k6XcT8ASNoIz4VPrTtAWkz83huBud9C9Ha75/lWDtqtMA6p38CZCdQN2DptgPnaQo+iR4WWUNuw7B05KLxMR32k4tH8MbAuJdrTK8P5ZiSS5vXxY3LsJUko82a9OllSUdWCsCr907Lw6Mvb4lJNXpoqw7g71VwdKM9WtLuhMARheSlIE/fak/hSqlH6aM6n553WjOWBZV46+rfj7dNbCBK1RlH4R1/z/DP5/J1dLI0maSNPSlnuio/T+PNilOUhdBhWfryWp73t2nsNiiOXk2SdBeqtIKlyKph3zmvMbvxY4726dLA5Q== 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=4ASPK0PHBJlmtid0uzme99rOpExor58aqqKrYKIMhfM=; b=KoJoh7eHPHcVL0u14mBzT1A+SoYDvBsUtQaL0vgWVynFcGGwBfo9ZeAc/ldfhuMIKiCQyekADLjOotPEi7gZfr6kIA01Uxr8sjHdvKDYbdwKOfwN5n+UqdofrUmXcvDGqfIpGusTHaODIH26YURzbvxrUHF6MB+buct/6GAv5RZcW/fLqIU3EMVL7rCRO+CXlOS3rJH/j8dxEPn87UK4n7SGiPA2Qo/4s+hHi/Ffu6aT0w1gMR7YZ1SQFdPz3NfNg/z1VhgNs3WQyuntWJvGMBBoYKsJTV1xbDO6aorLhlLYCQvpRBNVq7OBcacv/CZ6qDoG65dG/yvG7y9oOc7p2w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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=4ASPK0PHBJlmtid0uzme99rOpExor58aqqKrYKIMhfM=; b=ASCYx2Z/eYWLcj6U3uYk5Zj+hjgum593HMjE2M5vBtaCsOaoAN4XPcnzPIf5F0N5sNHzd24V+dKyc6Wlc9RXxaycSSPf+ZQeszaSHDce5q5myTF5Ts3moOSOFTyH0gm/tPzGmJvcHdR7L1HwezrZuE9kAdNAE2Q0qJ64WTCJJP6Ny5GBERvxX89BDuAXx25cDGrOCARoNSYy/Udl5QIroUW5lwuoae9ReLXrA8iXREs5Wy+lBSB/rvHQuhfiVgU4JYLGp7rxB8puc88lhbTSSbmf/bWiYbMkk8JuzkgxqT010AW8bTOXDVpbT+qj9lNtDBpm1FFggFKpNZiH7IjHFA== Received: from BYAPR08CA0016.namprd08.prod.outlook.com (2603:10b6:a03:100::29) by IA1PR12MB7688.namprd12.prod.outlook.com (2603:10b6:208:420::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.20; Mon, 14 Oct 2024 08:05:39 +0000 Received: from SJ5PEPF000001F0.namprd05.prod.outlook.com (2603:10b6:a03:100:cafe::2d) by BYAPR08CA0016.outlook.office365.com (2603:10b6:a03:100::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.26 via Frontend Transport; Mon, 14 Oct 2024 08:05:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by SJ5PEPF000001F0.mail.protection.outlook.com (10.167.242.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.13 via Frontend Transport; Mon, 14 Oct 2024 08:05:38 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 14 Oct 2024 01:05:27 -0700 Received: from nvidia.com (10.126.231.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; Mon, 14 Oct 2024 01:05:25 -0700 From: Viacheslav Ovsiienko To: CC: , , , , Tim Martin , Subject: [PATCH v2 2/4] net/mlx5: fix real time counter reading from PCI BAR Date: Mon, 14 Oct 2024 11:04:32 +0300 Message-ID: <20241014080434.1211629-3-viacheslavo@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241014080434.1211629-1-viacheslavo@nvidia.com> References: <20241009114028.973284-1-viacheslavo@nvidia.com> <20241014080434.1211629-1-viacheslavo@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.231.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: SJ5PEPF000001F0:EE_|IA1PR12MB7688:EE_ X-MS-Office365-Filtering-Correlation-Id: 42d8063f-d758-454d-a8a5-08dcec26fd73 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|36860700013|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?EJDLPURRaPWpIZoYGGbx3USzvRc/JKq2C99mloFGUkZkpRw06fPp4/ecG8uD?= =?us-ascii?Q?y0sUM5HttdqCpboP/vou8LZ8GVoEp0ZutdkQ9+x9eLyndg9FCP9gqMYqQZ0/?= =?us-ascii?Q?+Gf7wpo1w8RhPIhPzcZmsOM8OM/8deTCjZ0uALwucZ1L2EZDszyTSpZA4Ump?= =?us-ascii?Q?k40wcIMkeJgk4gGBgVPEHBPdMmXgEJwBmKDNqco1gKdipxpVpCFM6K98zpE1?= =?us-ascii?Q?09FPx3Ai4bSCiYcYCeEmkxVbsSUQKFFh3GTSAwfXH42n7W6x4bgrRaGmwIpg?= =?us-ascii?Q?5H0p0GbkEJTLv89JOB+/+2SQc2EIlA4xErKwjD7En9pSBuvzJNfaNWUTGHgO?= =?us-ascii?Q?dRXCwh8EEfxPZUvNez5fHEz/kuT8bcksbywamCcQ0nN6HlFYoLap+YMaWYYJ?= =?us-ascii?Q?+WXw9iy34oyxPYcuvbdSyFUTugTJYu+EUsCAN05MFpAn7l6MJxDDmZVjhWUP?= =?us-ascii?Q?ntpog5LgAa2U9z+YgjqtvyIWJCT5SQAlLqamZVONL9nJAhuZaLxuLez8o/xx?= =?us-ascii?Q?DuC8IYbfvTEJXKtZNk50M/Br1aDklP2Ku+hqveen5SGJQprIr+15eSVPCAWb?= =?us-ascii?Q?C3Tq5mQsRutpSOpD3FHjaqJHdEsI42ucPYkg077MMRAjMnZLjar3hLRp1eXD?= =?us-ascii?Q?8NtVYwFndFFV/hh2xyRVs49J3ixKpF48MGoO01r6QZsb0EMoMYv7kGTf1l6Q?= =?us-ascii?Q?1Cv3vo3Rwt1npJ53mvbe/4NNoWEfC/wr6VpOHniUqVWf3yr0Z9L0XJamJxEw?= =?us-ascii?Q?sa6pbeHd0qfge47Wr6ohm9u5iFd2TcPLEfzy8ZNUHohyAF2enbFiFEHq6S31?= =?us-ascii?Q?b0jM1Hi726lx1xgeDfPFpPzA7glzTssQo5uig384V5xX6vi78xw3aaanSEv4?= =?us-ascii?Q?efyvOCc131mZgSiAiyjeYhuheZaN0LV2LSDRnIxcdbe4WU1jvdj25w7SLZQr?= =?us-ascii?Q?/Jxi9tfKQJpfUk+9zhnVgTfmev5sCnsdNzsCwOPBW6/2s7AOs16YFyAIQy3A?= =?us-ascii?Q?gi7hymU70zvsrs2zpy9PCnDxvACv2AHLKyfxDfSikHdf3lmKM8I0pDKVPRfq?= =?us-ascii?Q?45zwes7i4a2bjhdzP//+3I/6zrfEJkyjgAAwaBFBvM/d1iHsqHAduXL4fdOH?= =?us-ascii?Q?Sz1x30MM/1aS2Vj1OAPIcWOymrjw9YhXatih3Wpp672oAOwGXFK81fpQD3Lt?= =?us-ascii?Q?HvHp9DfCh1j+HMIVmG6uoPVlmxvcuhTNzI2P854AMoEcJroYCA0am9G7gi+t?= =?us-ascii?Q?LlQrvXoK01sGEyycdhQX7/xRSreIPcLe8X2RxKQgXAEKxQff9GbK/lD++Wf5?= =?us-ascii?Q?EZyXnClsOjB9YtOK+q9cb51oydpupp1AWc2OrOwUYS8C/9wZiHcMxGCgFAXt?= =?us-ascii?Q?/fuKb8MGB7fGWxAbM1kd/OltPrJ5?= X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Oct 2024 08:05:38.4739 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 42d8063f-d758-454d-a8a5-08dcec26fd73 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.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ5PEPF000001F0.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7688 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 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: 9b31fc9007f9 ("net/mlx5: fix read device clock in real time mode") 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 | 34 +++++++++++++++++++++++++++++++++- drivers/net/mlx5/mlx5_txpp.c | 11 ++--------- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/.mailmap b/.mailmap index b30d993f3b..3065211c0a 100644 --- a/.mailmap +++ b/.mailmap @@ -1505,6 +1505,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 e36fa651a1..52b90e6ff3 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -2242,6 +2242,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; @@ -2262,6 +2263,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 983913faa2..587e6a9f7d 100644 --- a/drivers/net/mlx5/mlx5_tx.h +++ b/drivers/net/mlx5/mlx5_tx.h @@ -372,6 +372,38 @@ 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 __rte_atomic *ts_addr; + uint64_t ts; + + ts_addr = (uint64_t __rte_atomic *)hca_ptr; + ts = rte_atomic_load_explicit(ts_addr, rte_memory_order_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. @@ -822,7 +854,7 @@ mlx5_tx_cseg_init(struct mlx5_txq_data *__rte_restrict txq, cs->flags = RTE_BE32(MLX5_COMP_ONLY_FIRST_ERR << MLX5_COMP_MODE_OFFSET); cs->misc = RTE_BE32(0); - if (__rte_trace_point_fp_is_enabled() && !loc->pkts_sent) + if (__rte_trace_point_fp_is_enabled()) rte_pmd_mlx5_trace_tx_entry(txq->port_id, txq->idx); rte_pmd_mlx5_trace_tx_wqe((txq->wqe_ci << 8) | opcode); } diff --git a/drivers/net/mlx5/mlx5_txpp.c b/drivers/net/mlx5/mlx5_txpp.c index 4e26fa2db8..e6d3ad83e9 100644 --- a/drivers/net/mlx5/mlx5_txpp.c +++ b/drivers/net/mlx5/mlx5_txpp.c @@ -971,7 +971,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; @@ -997,15 +996,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