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 F0B9C45AF1; Wed, 9 Oct 2024 13:41:15 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D7FD34278C; Wed, 9 Oct 2024 13:41:13 +0200 (CEST) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2053.outbound.protection.outlook.com [40.107.243.53]) by mails.dpdk.org (Postfix) with ESMTP id AA04842788; Wed, 9 Oct 2024 13:41:12 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Avt0YaW/D2lhse9CLodgeU+nhRmfao4JAE55dI69ZL+SAOoQDRhe82iKCkB76VIKOpqcuh4y6ZBTPoodL3SAvWtPQtlF8O2G3x/ficpf7ZZ1fe//5TCC2tPvaCagitP4wsR7LYL1SriNGM/Zsx7N0tvrk0wk+5HXNQeQUKZbchVGaE72a5/yndDh4NZ4VCI7ob6bXJ8Zn6K48Ai3mr45SDvSqM0LNKckvvLhojWfYrSLBMYTPX8F3LohnJc+gAQr9I9VYBCS1BYWQbnitXF8OkiMBQ+T+Kelkts2tkKNYRHiCPATwOBoJmtOCF28sE7y7JfkwpQVoDPg0Cf3ahGuEQ== 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=b5NZx5ZYGHoUaSwPiGA/atdORrHrxB4dUIE2Gz//lEg=; b=YXsNaOgVfulh3cJy6i1O6oPIpqbgA2Ee1DqfmATWRN2ulynqyT1iRDmMPDpPs26MEZ9koI2LIA0GKIlduxiQhlA0v6goiIou03d9x4OrQ5qadODTjIyZOE5japfJDrJCPtHre6w7zR9ihkWe5wBTJXNcZE6L3y64byYE1BEpKbGkJDd7M2tH6dOWdxMTAosAiv9M/Ky7tYsYqf02QM04GUwQULXCJtMiatRTs+O+jA8PlcuXnOD2HW7dIzUmVuYNazhUY3dAR2rQLSweZ34SO0Df59bxJzsp8YJl8svGH+TZvgR6LDyrSjic3imKIlB3ZphgCz7z9c7YuWQUtuzVPQ== 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=b5NZx5ZYGHoUaSwPiGA/atdORrHrxB4dUIE2Gz//lEg=; b=TR0EwtTt1oQZcmzb/lgC8gMGvFg7elqPOmFLhY5VhT3ryKYBebAKw7ZolEu05/c0H5/eIaRdDbu748xfeyHLLAeBsp9x+HQPhwVy4b4UZdVLKNu+9GEdsQHZThuRbUmdZSyJpHphy43bS09EtDTgMDyqXtrGm5ih4/DZrfjXsRfz10EqGoKFbXhcixD/drX1CkJXT28/lk+WJoz9z+DmG6jNjkVLUNCL83YqcSGfrv1b1VaaoIP0vAEzTKL0IoAAgdCJbln2km1euobILzrBRVjLxB2u5wR4HWr3UD2Pqzeb6XqbfbjW1vS87PzxwoPVYK8ER10P6LYomDSll5QV7w== Received: from CH0PR03CA0001.namprd03.prod.outlook.com (2603:10b6:610:b0::6) by IA0PR12MB7531.namprd12.prod.outlook.com (2603:10b6:208:43f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Wed, 9 Oct 2024 11:41:07 +0000 Received: from DS3PEPF000099E1.namprd04.prod.outlook.com (2603:10b6:610:b0:cafe::79) by CH0PR03CA0001.outlook.office365.com (2603:10b6:610:b0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.17 via Frontend Transport; Wed, 9 Oct 2024 11:41:05 +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 DS3PEPF000099E1.mail.protection.outlook.com (10.167.17.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.13 via Frontend Transport; Wed, 9 Oct 2024 11:41:05 +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; Wed, 9 Oct 2024 04:40:55 -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, 9 Oct 2024 04:40:52 -0700 From: Viacheslav Ovsiienko To: CC: , , , , Tim Martin , Subject: [PATCH 2/4] net/mlx5: fix real time counter reading from PCI BAR Date: Wed, 9 Oct 2024 14:40:26 +0300 Message-ID: <20241009114028.973284-3-viacheslavo@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241009114028.973284-1-viacheslavo@nvidia.com> References: <20241009114028.973284-1-viacheslavo@nvidia.com> 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: DS3PEPF000099E1:EE_|IA0PR12MB7531:EE_ X-MS-Office365-Filtering-Correlation-Id: d15da576-fe5f-45c3-a7bc-08dce8574290 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|36860700013|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?UplJFo0hCV0dOfw7fr9vaM8FiSgUngTI/h69wfIIYYARsPaiyI0G0gxXP7oi?= =?us-ascii?Q?SiPU/Qd6Mku0coIN9RWrtBJ+CoAadJ6GADd+dwK9gCh+glqSVNSsgne1ZUdv?= =?us-ascii?Q?POkHNl7i9W8dQv+esyqVECrz7ZJ4UAHMBXFAuTRpCRm8okpFbe6fGvdqxpYv?= =?us-ascii?Q?RH+qWqh6XimZ4tg2QxzREIztuJbGZKRrv+IMFrn1KMO2k0sMT3t/9CRvIr9v?= =?us-ascii?Q?3BlK7C69J5EsYBrW7q77yInhrIiyh4/dKoeKhsCq2EhSszUKcEpn1GV76wty?= =?us-ascii?Q?f9RExm3dg7K2LhBtm22lf2I/L3lQyVM/mzelkeZMq9MOBBLkYQhc9lk+8ADl?= =?us-ascii?Q?hGcaB6EdCzSea/UgojTjcz9Caz1ffN46QIBP2fBdmZoMhdB+cwrwo+1P0qOy?= =?us-ascii?Q?STzbbJVHqktOmGa07z5PwqmFMuzGQXVlsPDyoEJmkOr1u7cUY9oRxhDzKiI4?= =?us-ascii?Q?tiBokWzHMWqyEn7KEcfrE5YQXKC749x7Shxgj7AiFcE6tUVoMFkgMq/bpJJI?= =?us-ascii?Q?zRd0jV4W4RzrAYsftBb9iw6z7KHFfNrAiHvo2xNG4q66gJDgLB3gGmGbDMmB?= =?us-ascii?Q?Fogb+KCWIG0CVMs/Ttz6y/gFNEUlAG01vD9HMHkFhE6W5HDxBoJVDUMV8hln?= =?us-ascii?Q?VCLfUQvzW5oxTMxBbobGhR2ddKCbcO6lu4O3pEIzX8HUA3Xqx/r2GYTbo7c4?= =?us-ascii?Q?nbTcpo/9KBzyRtnZissHt6aSX/6VTtDTZNpV9WnMjkK14TvDd9Dl8KgejmtM?= =?us-ascii?Q?DMGmuOksqlfvILihLFPRysIhUIDUJutZPS3E7A9u3r0C+Bn+5Mq28qgViJj9?= =?us-ascii?Q?fcfDGaLi+wtK5Jh27qc70nNlxLIwbKL1tNY6eBP1waaSecjS5bOyccpLbXCD?= =?us-ascii?Q?u7loTKWwGcsVCUI4bKKHT1dm3bZN3L/P7CskWtiqraikUaOpTdLQZNHFjo77?= =?us-ascii?Q?4dH7ZEdhX+mJLVO3NXfTTca5ZAOzlqJoHeLMFWD7FE1OM1s/NnmVA+en5JsC?= =?us-ascii?Q?JanJoMeix80jQHLQkjUUQ1Qh8ZjfiYwr3LO4m9R0OrAlAyNtDCGSXPey+2LM?= =?us-ascii?Q?xginb+ZpRLChFWKHyF6eTgd5jO095/aW0CnwDi8FceGs+iBKTvVVlF6sbC53?= =?us-ascii?Q?LB7wOkySW3W/Z/bbSncMlyG2VznNgAgEB+Tzu4dhDXkGN8sjf01nq7feiWsc?= =?us-ascii?Q?1yQSU/qmiHtsRlIjXtLUvSV39+EEB1MlcrRF7yW8/nhsJoo1+Jf2jcIGnBod?= =?us-ascii?Q?MFJL3ioGlzMAowXspnoRj6xOOg5HQ9iAnZLmdjnfrR4NbRLf/w/ZQEcO7AbD?= =?us-ascii?Q?NdWGOikwfwpz9EYkdj+JNR5xzXNfVVFzH3plrjfJuVPRP3+VsqUBSG0Xx4AU?= =?us-ascii?Q?f35DcDmrLhacyRICUU0QZuKiT/Y6?= 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)(376014)(36860700013)(82310400026)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2024 11:41:05.4936 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d15da576-fe5f-45c3-a7bc-08dce8574290 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: DS3PEPF000099E1.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7531 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 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 | 53 +++++++++++++++++++++++++++++++++--- drivers/net/mlx5/mlx5_txpp.c | 11 ++------ 4 files changed, 56 insertions(+), 13 deletions(-) diff --git a/.mailmap b/.mailmap index dff07122f3..e36e0a4766 100644 --- a/.mailmap +++ b/.mailmap @@ -1494,6 +1494,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 cf34766a50..14676be484 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..55568c41b1 100644 --- a/drivers/net/mlx5/mlx5_tx.h +++ b/drivers/net/mlx5/mlx5_tx.h @@ -372,6 +372,46 @@ 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; +} + +static __rte_always_inline uint64_t mlx5_read_pcibar_clock_from_txq(struct mlx5_txq_data *txq) +{ + struct mlx5_txq_ctrl *txq_ctrl = container_of(txq, struct mlx5_txq_ctrl, txq); + struct rte_eth_dev *dev = ETH_DEV(txq_ctrl->priv); + + return mlx5_read_pcibar_clock(dev); +} + /** * Set Software Parser flags and offsets in Ethernet Segment of WQE. * Flags must be preliminary initialized to zero. @@ -809,6 +849,7 @@ mlx5_tx_cseg_init(struct mlx5_txq_data *__rte_restrict txq, unsigned int olx) { struct mlx5_wqe_cseg *__rte_restrict cs = &wqe->cseg; + uint64_t real_time; /* For legacy MPW replace the EMPW by TSO with modifier. */ if (MLX5_TXOFF_CONFIG(MPW) && opcode == MLX5_OPCODE_ENHANCED_MPSW) @@ -822,9 +863,12 @@ 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) - rte_pmd_mlx5_trace_tx_entry(txq->port_id, txq->idx); - rte_pmd_mlx5_trace_tx_wqe((txq->wqe_ci << 8) | opcode); + if (__rte_trace_point_fp_is_enabled()) { + real_time = mlx5_read_pcibar_clock_from_txq(txq); + if (!loc->pkts_sent) + rte_pmd_mlx5_trace_tx_entry(real_time, txq->port_id, txq->idx); + rte_pmd_mlx5_trace_tx_wqe(real_time, (txq->wqe_ci << 8) | opcode); + } } /** @@ -3786,7 +3830,8 @@ mlx5_tx_burst_tmpl(struct mlx5_txq_data *__rte_restrict txq, __mlx5_tx_free_mbuf(txq, pkts, loc.mbuf_free, olx); /* Trace productive bursts only. */ if (__rte_trace_point_fp_is_enabled() && loc.pkts_sent) - rte_pmd_mlx5_trace_tx_exit(loc.pkts_sent, pkts_n); + rte_pmd_mlx5_trace_tx_exit(mlx5_read_pcibar_clock_from_txq(txq), + loc.pkts_sent, pkts_n); return loc.pkts_sent; } 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