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 1F58345BCC; Wed, 30 Oct 2024 23:15:28 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 013974344D; Wed, 30 Oct 2024 23:15:27 +0100 (CET) Received: from egress-ip11a.ess.de.barracuda.com (egress-ip11a.ess.de.barracuda.com [18.184.203.234]) by mails.dpdk.org (Postfix) with ESMTP id 6FC8043401 for ; Wed, 30 Oct 2024 23:15:22 +0100 (CET) Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03lp2113.outbound.protection.outlook.com [104.47.30.113]) by mx-outbound11-85.eu-central-1a.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 30 Oct 2024 22:15:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lScJf3OB9238RKXDyfotvSOUyitZexJZL3r0G0BGrg2WPWb+kP4XxtdI1yeCiPnAFr9lQMgGCLVaxuvqjz84G+WA6nmsj/yYx1H7xwT/cRh9UOMmdhQ/K7zgkp5FdsQn/ksqbRW1rexOKPjvWyuBiBdz0m1HxR+ggNWNBUT6eGjppg+Fq3OgyS+tN5tcowNg4Uv7VO69yWncYwpQn9zCpgXVkUtTKYBzsIE3WdFok3u+3LVy7EyG4NjzrLMdvxVntxlrhJuZa6KKBa8HWHZlNU+16SkztXxfSD37McseaWIl3E69X6+SRDis3yjhXiLLjsb57qi29LOBDhgkFmcEWw== 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=F1JPlT8h7nwFvf/DClVJ38tm5Re/9zvkCsmpcyfW3LI=; b=oIprGfjglZ8XtBaOW4OPw3VuG2sI5z5VBFrzsCYk554cxSX4JRCsMVd9nziY2PhS6W16TYVPDpI7unzsLpBXztm35P8Z4xZmDh5H5UMWvhXnTLxukDz12L7sFSMhBoUQr99M4fBwsnuePuOr3iY//lKBmNwAS0iFznuXGYPl3D9pFaGyls5mA+HWNGg9rCMHaNJhv7eNOefOEG+wT52WzzcK/ahWsKw6oYr9QL04V0DXbZ+stIgP0M3Xp4uPJAwJ1UW24sSZ097HTHoeMoQJ9kgtnPKcTBeehMEwnlvCNhdjKta0nROflUoV65y8zvh07S29eM43Gm0ib7PHEPf6Zw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 178.72.21.4) smtp.rcpttodomain=dpdk.org smtp.mailfrom=napatech.com; dmarc=fail (p=reject sp=reject pct=100) action=oreject header.from=napatech.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=napatech.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=F1JPlT8h7nwFvf/DClVJ38tm5Re/9zvkCsmpcyfW3LI=; b=Epuguobg3EsGZi8drCcUKDW1BqwSeRnGSloKZhzO8PxbIP6NDniA7XxWU/er/wGwIGtOEJi43kQsJQtj2EZX9T6axM3w0NPUJyPOX0uGUF3tdgzHshQ9QbZsigHpJ66814Ppzkp0fU4CXn8anDYmkR07ENF5bmDdW2aN5V0TOPc= Received: from DUZPR01CA0009.eurprd01.prod.exchangelabs.com (2603:10a6:10:3c3::16) by PR3P190MB0922.EURP190.PROD.OUTLOOK.COM (2603:10a6:102:86::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25; Wed, 30 Oct 2024 21:41:05 +0000 Received: from DU2PEPF00028D13.eurprd03.prod.outlook.com (2603:10a6:10:3c3:cafe::a2) by DUZPR01CA0009.outlook.office365.com (2603:10a6:10:3c3::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.22 via Frontend Transport; Wed, 30 Oct 2024 21:41:05 +0000 X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 178.72.21.4) smtp.mailfrom=napatech.com; dkim=none (message not signed) header.d=none;dmarc=fail action=oreject header.from=napatech.com; Received-SPF: Fail (protection.outlook.com: domain of napatech.com does not designate 178.72.21.4 as permitted sender) receiver=protection.outlook.com; client-ip=178.72.21.4; helo=localhost.localdomain; Received: from localhost.localdomain (178.72.21.4) by DU2PEPF00028D13.mail.protection.outlook.com (10.167.242.27) with Microsoft SMTP Server id 15.20.8114.16 via Frontend Transport; Wed, 30 Oct 2024 21:41:05 +0000 From: Serhii Iliushyk To: dev@dpdk.org Cc: mko-plv@napatech.com, sil-plv@napatech.com, ckm@napatech.com, andrew.rybchenko@oktetlabs.ru, ferruh.yigit@amd.com, stephen@networkplumber.org Subject: [PATCH v5 74/80] net/ntnic: migrate to the RTE spinlock Date: Wed, 30 Oct 2024 22:39:21 +0100 Message-ID: <20241030213940.3470062-75-sil-plv@napatech.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20241030213940.3470062-1-sil-plv@napatech.com> References: <20241021210527.2075431-1-sil-plv@napatech.com> <20241030213940.3470062-1-sil-plv@napatech.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PEPF00028D13:EE_|PR3P190MB0922:EE_ Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: ba04d14b-6b77-4e33-2dec-08dcf92b8ef7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|82310400026|376014|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?YjXBmD3YZKDzdAdQVinB47B347+706RBhAQq8yYskpIRh+gTH2nZxW6DfL6m?= =?us-ascii?Q?xRFpP6N1OZRIyM7SkHacluJtybGok7ByNVshW0WTc71gE4Iagqj5j4YFQqu9?= =?us-ascii?Q?dtHFGywPs3CXZzJBGTwP1ckMK1mtNHQqO0Bpw6oZPqXgg8uU0do12A1RI7mQ?= =?us-ascii?Q?PYBDuCN6L6PGxk8qZyGfHZfrctpn21D9TvrqN6hMdMUEEYHCI04grXWwhGE1?= =?us-ascii?Q?BqxGqH4/szYCwmIahtL4miv2eRaviz51ewrJnmF6KUJ7N/JHLOpkfhTPb1LE?= =?us-ascii?Q?qb7x/DAV9QkDwzu61jYdzUvoRIYT7cuk/LN41zRvb6r4v6u1HXzzePRoBRnA?= =?us-ascii?Q?ZP6dFN3WaXhnL1bbNZ+llj70ftcRXczUeLsvArbVVVrR6yxa1iBIokOhMJFw?= =?us-ascii?Q?QHfpzLbeT09DKQKU+QMsV4zgjq/GCtTVG5VHPWPhetvFhXwEgYY8phqfG7BL?= =?us-ascii?Q?+Bc4p67pWF4OtrJgc8j+UERphdzSXTvbg4vPUZt8st0g3GkJCvty21jHUYs7?= =?us-ascii?Q?0+rMvUFvhRYTrj56YPMvZMjzZinrMxza0JxnqEBP3oiQm1Wuge0ffjGBVUFn?= =?us-ascii?Q?4msTK6AVqbQSqz/RwNv6uHB5sOURoR0sOxYzhPKNudTxUCE35VSrVlOchvPa?= =?us-ascii?Q?Oh+mXD9jqj9wRdoVAhfnD8SDJA7Lyxb9UavoZmlYkGvblEAxX6VZeTRHoXan?= =?us-ascii?Q?vy6hpRRlxSj74K8KQyE9zpt6gXQ5eEjc6v03Ao5vLwELQsEB51CJUEBgt/QY?= =?us-ascii?Q?vJYE0T53LroQX2YSsq87Xe4HZ6uQ+FplMQANZ3fkczhIQ7v0FuKQ+YtT1qPs?= =?us-ascii?Q?NuUxl09qXT3hGZ4+3MT9UDo0+xYkna9PbFvJo6PS8yGNSMoFBBsiuU8NxTLj?= =?us-ascii?Q?s2dA4Os3JB/9UL05+s8BfFS5aCXk6+V+kZIecY+fc/gkBEhWvCK2lDWKz+9R?= =?us-ascii?Q?trjBKoImSA43gT5NG27NgdQE5HSgYKmTGu81yw8vvu+2LLWAvUu/1mIBhogf?= =?us-ascii?Q?zElTht0G2CXKR4PBfPnKwsOMU3f+maV/yv07rjHfQO1QAU+T1+j3/E/UV/2P?= =?us-ascii?Q?cBFF8PFry82mn7ht+iJhK8fAc1hMYppZb/e3EDtOFgby7496oZ0JOMQGP/5v?= =?us-ascii?Q?40MN1BjNGylhfodBYKl7H9jOUBrsPxgAElBC4blxkTzhvk7fhMg7KwaYbpjn?= =?us-ascii?Q?VYEs48QSc7EH+bR/y5EnwI2QJexJJ1FzP+GEqcsKRI8Kn3roxMOadijsDqs8?= =?us-ascii?Q?lUGFD6w2raAhxgO8/2Qs/BBgs4SWXM6TUIR5IL77TELFT3Fx5Y6DytsSwn/Y?= =?us-ascii?Q?zQcvgap+rfDfL41/Rv4oIU4LrrRSsL5l9L7GJ+tjtaD7CNlkWNUyZK2rsWsf?= =?us-ascii?Q?zVGoeJ/lCj4VrPplkeWM9jR44MVtVJbmd80s7pTw0dNlusXogg=3D=3D?= X-Forefront-Antispam-Report: CIP:178.72.21.4; CTRY:DK; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:localhost.localdomain; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(1800799024)(82310400026)(376014)(36860700013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: CurTPoxBly6kzvAKcZvQAbkxeYgr40IDKxaAINToHWBg5euZ14fWW0DL8xPj7NVS69ccvQpZ+yAVR5dNbXRAOmlh+0ZeaceM+IIlZsIEM6yEwQVFuFkFyUkVkWpC54iKWDR4a+frgANugGfSG+uG2C2K4NQZ02ljOUHBJmV0Pv25Za0SQdDgruCuQxYFj1wnxASo42zY2gZkQ+SgG9144bkraIEPZF+e1wpwOH3YR+AuzuF88u0dEfM0ZCJ23fWz7EbPSHsT3CMb3Vxy9HnZBYdWkxVdyoqUe94EitJZuP3dKNk09qej63XYgaaytLo/CVruSp1+z30x544f40HQxbl/DfuPZ2hS4CP3ztMxUdm47euojja5sYg5/JtxovoI7lK6vYPtE3QnSxt0Hj7HAlFn4UVFWlDWuglkp3Y29a2tO10wvjHEWDKtpvsFl79Jl508lMmt7XuB/MFAp34a4/Bu9VPh6nLnx1DADsEgdzkC/rNBY5brlnSt+qsF/tYkVZ4Ujl5M6HdTrqmRQJupJxJkQWen7WGrYn2ku7EuMa5d54F1jTr4jGy69DRIYVE9rYhe/rp5lD8V6z1xad20HhaNUZwQlU9A5i7QefLf+8kDDRMpWHoySd1eG+ZdrvyogjPUtxIysBtN5NW4WiMJzomVQsa4ZjTxVLj59RTLEB0= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2024 21:41:05.4116 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ba04d14b-6b77-4e33-2dec-08dcf92b8ef7 X-MS-Exchange-CrossTenant-Id: c4540d0b-728a-4233-9da5-9ea30c7ec3ed X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=c4540d0b-728a-4233-9da5-9ea30c7ec3ed; Ip=[178.72.21.4]; Helo=[localhost.localdomain] X-MS-Exchange-CrossTenant-AuthSource: DU2PEPF00028D13.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3P190MB0922 X-OriginatorOrg: napatech.com X-BESS-ID: 1730326517-302901-12794-44798-1 X-BESS-VER: 2019.1_20241018.1852 X-BESS-Apparent-Source-IP: 104.47.30.113 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVsamhiYGQGYGUNTCwiQl0cLSws LU2MDI1NTQMsncMs0w1SQFSKSYGZgq1cYCAOtcEA5CAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.260092 [from cloudscan15-95.eu-central-1a.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS113687 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 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 Migarte form the pthread to rte_spinlock Signed-off-by: Serhii Iliushyk --- drivers/net/ntnic/include/flow_api.h | 6 +- drivers/net/ntnic/include/ntdrv_4ga.h | 3 +- .../net/ntnic/nthw/core/include/nthw_i2cm.h | 4 +- .../net/ntnic/nthw/core/include/nthw_rpf.h | 5 +- drivers/net/ntnic/nthw/core/nthw_rpf.c | 3 +- drivers/net/ntnic/nthw/flow_api/flow_api.c | 43 +++++----- .../net/ntnic/nthw/flow_api/flow_id_table.c | 20 +++-- .../profile_inline/flow_api_profile_inline.c | 80 +++++++++++-------- .../ntnic/nthw/flow_filter/flow_nthw_flm.c | 47 +++++++++-- drivers/net/ntnic/nthw/nthw_rac.c | 38 ++------- drivers/net/ntnic/nthw/nthw_rac.h | 2 +- drivers/net/ntnic/ntnic_ethdev.c | 31 +++---- drivers/net/ntnic/ntnic_filter/ntnic_filter.c | 6 +- 13 files changed, 155 insertions(+), 133 deletions(-) diff --git a/drivers/net/ntnic/include/flow_api.h b/drivers/net/ntnic/include/flow_api.h index 032063712a..d5382669da 100644 --- a/drivers/net/ntnic/include/flow_api.h +++ b/drivers/net/ntnic/include/flow_api.h @@ -6,7 +6,7 @@ #ifndef _FLOW_API_H_ #define _FLOW_API_H_ -#include +#include #include "ntlog.h" @@ -110,13 +110,13 @@ struct flow_nic_dev { struct flow_handle *flow_base; /* linked list of all FLM flows created on this NIC */ struct flow_handle *flow_base_flm; - pthread_mutex_t flow_mtx; + rte_spinlock_t flow_mtx; /* NIC backend API */ struct flow_api_backend_s be; /* linked list of created eth-port devices on this NIC */ struct flow_eth_dev *eth_base; - pthread_mutex_t mtx; + rte_spinlock_t mtx; /* RSS hashing configuration */ struct nt_eth_rss_conf rss_conf; diff --git a/drivers/net/ntnic/include/ntdrv_4ga.h b/drivers/net/ntnic/include/ntdrv_4ga.h index 677aa7b6c8..78cf10368a 100644 --- a/drivers/net/ntnic/include/ntdrv_4ga.h +++ b/drivers/net/ntnic/include/ntdrv_4ga.h @@ -7,6 +7,7 @@ #define __NTDRV_4GA_H__ #include "nt4ga_adapter.h" +#include typedef struct ntdrv_4ga_s { uint32_t pciident; @@ -15,7 +16,7 @@ typedef struct ntdrv_4ga_s { volatile bool b_shutdown; rte_thread_t flm_thread; - pthread_mutex_t stat_lck; + rte_spinlock_t stat_lck; rte_thread_t stat_thread; rte_thread_t port_event_thread; } ntdrv_4ga_t; diff --git a/drivers/net/ntnic/nthw/core/include/nthw_i2cm.h b/drivers/net/ntnic/nthw/core/include/nthw_i2cm.h index 6e0ec4cf5e..eeb4dffe25 100644 --- a/drivers/net/ntnic/nthw/core/include/nthw_i2cm.h +++ b/drivers/net/ntnic/nthw/core/include/nthw_i2cm.h @@ -7,7 +7,7 @@ #define __NTHW_II2CM_H__ #include "nthw_fpga_model.h" -#include "pthread.h" +#include "rte_spinlock.h" struct nt_i2cm { nthw_fpga_t *mp_fpga; @@ -39,7 +39,7 @@ struct nt_i2cm { nthw_field_t *mp_fld_io_exp_rst; nthw_field_t *mp_fld_io_exp_int_b; - pthread_mutex_t i2cmmutex; + rte_spinlock_t i2cmmutex; }; typedef struct nt_i2cm nthw_i2cm_t; diff --git a/drivers/net/ntnic/nthw/core/include/nthw_rpf.h b/drivers/net/ntnic/nthw/core/include/nthw_rpf.h index 4c6c57ba55..00b322b2ea 100644 --- a/drivers/net/ntnic/nthw/core/include/nthw_rpf.h +++ b/drivers/net/ntnic/nthw/core/include/nthw_rpf.h @@ -7,7 +7,8 @@ #define NTHW_RPF_HPP_ #include "nthw_fpga_model.h" -#include "pthread.h" +#include "rte_spinlock.h" +#include struct nthw_rpf { nthw_fpga_t *mp_fpga; @@ -28,7 +29,7 @@ struct nthw_rpf { int m_default_maturing_delay; bool m_administrative_block; /* used to enforce license expiry */ - pthread_mutex_t rpf_mutex; + rte_spinlock_t rpf_mutex; }; typedef struct nthw_rpf nthw_rpf_t; diff --git a/drivers/net/ntnic/nthw/core/nthw_rpf.c b/drivers/net/ntnic/nthw/core/nthw_rpf.c index 81c704d01a..1ed4d7b4e0 100644 --- a/drivers/net/ntnic/nthw/core/nthw_rpf.c +++ b/drivers/net/ntnic/nthw/core/nthw_rpf.c @@ -8,6 +8,7 @@ #include "nthw_drv.h" #include "nthw_register.h" #include "nthw_rpf.h" +#include "rte_spinlock.h" nthw_rpf_t *nthw_rpf_new(void) { @@ -65,7 +66,7 @@ int nthw_rpf_init(nthw_rpf_t *p, nthw_fpga_t *p_fpga, int n_instance) nthw_fpga_get_product_param(p_fpga, NT_RPF_MATURING_DEL_DEFAULT, 0); /* Initialize mutex */ - pthread_mutex_init(&p->rpf_mutex, NULL); + rte_spinlock_init(&p->rpf_mutex); return 0; } diff --git a/drivers/net/ntnic/nthw/flow_api/flow_api.c b/drivers/net/ntnic/nthw/flow_api/flow_api.c index 1fcccd37fd..337902f654 100644 --- a/drivers/net/ntnic/nthw/flow_api/flow_api.c +++ b/drivers/net/ntnic/nthw/flow_api/flow_api.c @@ -2,6 +2,7 @@ * SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2023 Napatech A/S */ +#include "rte_spinlock.h" #include "ntlog.h" #include "nt_util.h" @@ -42,7 +43,7 @@ const char *dbg_res_descr[] = { }; static struct flow_nic_dev *dev_base; -static pthread_mutex_t base_mtx = PTHREAD_MUTEX_INITIALIZER; +static rte_spinlock_t base_mtx = RTE_SPINLOCK_INITIALIZER; /* * Error handling @@ -398,7 +399,7 @@ int flow_delete_eth_dev(struct flow_eth_dev *eth_dev) #endif /* delete all created flows from this device */ - pthread_mutex_lock(&ndev->mtx); + rte_spinlock_lock(&ndev->mtx); struct flow_handle *flow = ndev->flow_base; @@ -442,7 +443,7 @@ int flow_delete_eth_dev(struct flow_eth_dev *eth_dev) if (nic_remove_eth_port_dev(ndev, eth_dev) != 0) NT_LOG(ERR, FILTER, "ERROR : eth_dev %p not found", eth_dev); - pthread_mutex_unlock(&ndev->mtx); + rte_spinlock_unlock(&ndev->mtx); /* free eth_dev */ free(eth_dev); @@ -483,15 +484,15 @@ static void done_resource_elements(struct flow_nic_dev *ndev, enum res_type_e re static void list_insert_flow_nic(struct flow_nic_dev *ndev) { - pthread_mutex_lock(&base_mtx); + rte_spinlock_lock(&base_mtx); ndev->next = dev_base; dev_base = ndev; - pthread_mutex_unlock(&base_mtx); + rte_spinlock_unlock(&base_mtx); } static int list_remove_flow_nic(struct flow_nic_dev *ndev) { - pthread_mutex_lock(&base_mtx); + rte_spinlock_lock(&base_mtx); struct flow_nic_dev *nic_dev = dev_base, *prev = NULL; while (nic_dev) { @@ -502,7 +503,7 @@ static int list_remove_flow_nic(struct flow_nic_dev *ndev) else dev_base = nic_dev->next; - pthread_mutex_unlock(&base_mtx); + rte_spinlock_unlock(&base_mtx); return 0; } @@ -510,7 +511,7 @@ static int list_remove_flow_nic(struct flow_nic_dev *ndev) nic_dev = nic_dev->next; } - pthread_mutex_unlock(&base_mtx); + rte_spinlock_unlock(&base_mtx); return -1; } @@ -542,27 +543,27 @@ static struct flow_eth_dev *flow_get_eth_dev(uint8_t adapter_no, uint8_t port_no "ERROR: Internal array for multiple queues too small for API"); } - pthread_mutex_lock(&base_mtx); + rte_spinlock_lock(&base_mtx); struct flow_nic_dev *ndev = get_nic_dev_from_adapter_no(adapter_no); if (!ndev) { /* Error - no flow api found on specified adapter */ NT_LOG(ERR, FILTER, "ERROR: no flow interface registered for adapter %d", adapter_no); - pthread_mutex_unlock(&base_mtx); + rte_spinlock_unlock(&base_mtx); return NULL; } if (ndev->ports < ((uint16_t)port_no + 1)) { NT_LOG(ERR, FILTER, "ERROR: port exceeds supported port range for adapter"); - pthread_mutex_unlock(&base_mtx); + rte_spinlock_unlock(&base_mtx); return NULL; } if ((alloc_rx_queues - 1) > FLOW_MAX_QUEUES) { /* 0th is exception so +1 */ NT_LOG(ERR, FILTER, "ERROR: Exceeds supported number of rx queues per eth device"); - pthread_mutex_unlock(&base_mtx); + rte_spinlock_unlock(&base_mtx); return NULL; } @@ -572,20 +573,19 @@ static struct flow_eth_dev *flow_get_eth_dev(uint8_t adapter_no, uint8_t port_no if (eth_dev) { NT_LOG(DBG, FILTER, "Re-opening existing NIC port device: NIC DEV: %i Port %i", adapter_no, port_no); - pthread_mutex_unlock(&base_mtx); flow_delete_eth_dev(eth_dev); eth_dev = NULL; } + rte_spinlock_lock(&ndev->mtx); + eth_dev = calloc(1, sizeof(struct flow_eth_dev)); if (!eth_dev) { NT_LOG(ERR, FILTER, "ERROR: calloc failed"); - goto err_exit1; + goto err_exit0; } - pthread_mutex_lock(&ndev->mtx); - eth_dev->ndev = ndev; eth_dev->port = port_no; eth_dev->port_id = port_id; @@ -650,15 +650,14 @@ static struct flow_eth_dev *flow_get_eth_dev(uint8_t adapter_no, uint8_t port_no nic_insert_eth_port_dev(ndev, eth_dev); - pthread_mutex_unlock(&ndev->mtx); - pthread_mutex_unlock(&base_mtx); + rte_spinlock_unlock(&ndev->mtx); + rte_spinlock_unlock(&base_mtx); return eth_dev; err_exit0: - pthread_mutex_unlock(&ndev->mtx); - pthread_mutex_unlock(&base_mtx); + rte_spinlock_unlock(&ndev->mtx); + rte_spinlock_unlock(&base_mtx); -err_exit1: if (eth_dev) free(eth_dev); @@ -765,7 +764,7 @@ struct flow_nic_dev *flow_api_create(uint8_t adapter_no, const struct flow_api_b for (int i = 0; i < RES_COUNT; i++) assert(ndev->res[i].alloc_bm); - pthread_mutex_init(&ndev->mtx, NULL); + rte_spinlock_init(&ndev->mtx); list_insert_flow_nic(ndev); return ndev; diff --git a/drivers/net/ntnic/nthw/flow_api/flow_id_table.c b/drivers/net/ntnic/nthw/flow_api/flow_id_table.c index a3f5e1d7f7..a63f5542d1 100644 --- a/drivers/net/ntnic/nthw/flow_api/flow_id_table.c +++ b/drivers/net/ntnic/nthw/flow_api/flow_id_table.c @@ -3,12 +3,12 @@ * Copyright(c) 2024 Napatech A/S */ -#include #include #include #include #include "flow_id_table.h" +#include "rte_spinlock.h" #define NTNIC_ARRAY_BITS 14 #define NTNIC_ARRAY_SIZE (1 << NTNIC_ARRAY_BITS) @@ -25,7 +25,7 @@ struct ntnic_id_table_element { struct ntnic_id_table_data { struct ntnic_id_table_element *arrays[NTNIC_ARRAY_SIZE]; - pthread_mutex_t mtx; + rte_spinlock_t mtx; uint32_t next_id; @@ -68,7 +68,7 @@ void *ntnic_id_table_create(void) { struct ntnic_id_table_data *handle = calloc(1, sizeof(struct ntnic_id_table_data)); - pthread_mutex_init(&handle->mtx, NULL); + rte_spinlock_init(&handle->mtx); handle->next_id = 1; return handle; @@ -81,8 +81,6 @@ void ntnic_id_table_destroy(void *id_table) for (uint32_t i = 0; i < NTNIC_ARRAY_SIZE; ++i) free(handle->arrays[i]); - pthread_mutex_destroy(&handle->mtx); - free(id_table); } @@ -91,7 +89,7 @@ uint32_t ntnic_id_table_get_id(void *id_table, union flm_handles flm_h, uint8_t { struct ntnic_id_table_data *handle = id_table; - pthread_mutex_lock(&handle->mtx); + rte_spinlock_lock(&handle->mtx); uint32_t new_id = ntnic_id_table_array_pop_free_id(handle); @@ -103,7 +101,7 @@ uint32_t ntnic_id_table_get_id(void *id_table, union flm_handles flm_h, uint8_t element->type = type; memcpy(&element->handle, &flm_h, sizeof(union flm_handles)); - pthread_mutex_unlock(&handle->mtx); + rte_spinlock_unlock(&handle->mtx); return new_id; } @@ -112,7 +110,7 @@ void ntnic_id_table_free_id(void *id_table, uint32_t id) { struct ntnic_id_table_data *handle = id_table; - pthread_mutex_lock(&handle->mtx); + rte_spinlock_lock(&handle->mtx); struct ntnic_id_table_element *current_element = ntnic_id_table_array_find_element(handle, id); @@ -127,7 +125,7 @@ void ntnic_id_table_free_id(void *id_table, uint32_t id) if (handle->free_tail == 0) handle->free_tail = handle->free_head; - pthread_mutex_unlock(&handle->mtx); + rte_spinlock_unlock(&handle->mtx); } void ntnic_id_table_find(void *id_table, uint32_t id, union flm_handles *flm_h, uint8_t *caller_id, @@ -135,7 +133,7 @@ void ntnic_id_table_find(void *id_table, uint32_t id, union flm_handles *flm_h, { struct ntnic_id_table_data *handle = id_table; - pthread_mutex_lock(&handle->mtx); + rte_spinlock_lock(&handle->mtx); struct ntnic_id_table_element *element = ntnic_id_table_array_find_element(handle, id); @@ -143,5 +141,5 @@ void ntnic_id_table_find(void *id_table, uint32_t id, union flm_handles *flm_h, *type = element->type; memcpy(flm_h, &element->handle, sizeof(union flm_handles)); - pthread_mutex_unlock(&handle->mtx); + rte_spinlock_unlock(&handle->mtx); } diff --git a/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c b/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c index aae794864e..f9133ad802 100644 --- a/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c +++ b/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c @@ -3,6 +3,7 @@ * Copyright(c) 2023 Napatech A/S */ +#include "generic/rte_spinlock.h" #include "ntlog.h" #include "nt_util.h" @@ -20,6 +21,7 @@ #include "flow_api_profile_inline.h" #include "ntnic_mod_reg.h" +#include #include #define FLM_MTR_PROFILE_SIZE 0x100000 @@ -189,7 +191,7 @@ static int flow_mtr_create_meter(struct flow_eth_dev *dev, (void)policy_id; struct flm_v25_lrn_data_s *learn_record = NULL; - pthread_mutex_lock(&dev->ndev->mtx); + rte_spinlock_lock(&dev->ndev->mtx); learn_record = (struct flm_v25_lrn_data_s *) @@ -238,7 +240,7 @@ static int flow_mtr_create_meter(struct flow_eth_dev *dev, mtr_stat[mtr_id].flm_id = flm_id; atomic_store(&mtr_stat[mtr_id].stats_mask, stats_mask); - pthread_mutex_unlock(&dev->ndev->mtx); + rte_spinlock_unlock(&dev->ndev->mtx); return 0; } @@ -247,7 +249,7 @@ static int flow_mtr_probe_meter(struct flow_eth_dev *dev, uint8_t caller_id, uin { struct flm_v25_lrn_data_s *learn_record = NULL; - pthread_mutex_lock(&dev->ndev->mtx); + rte_spinlock_lock(&dev->ndev->mtx); learn_record = (struct flm_v25_lrn_data_s *) @@ -278,7 +280,7 @@ static int flow_mtr_probe_meter(struct flow_eth_dev *dev, uint8_t caller_id, uin flm_lrn_queue_release_write_buffer(flm_lrn_queue_arr); - pthread_mutex_unlock(&dev->ndev->mtx); + rte_spinlock_unlock(&dev->ndev->mtx); return 0; } @@ -287,7 +289,7 @@ static int flow_mtr_destroy_meter(struct flow_eth_dev *dev, uint8_t caller_id, u { struct flm_v25_lrn_data_s *learn_record = NULL; - pthread_mutex_lock(&dev->ndev->mtx); + rte_spinlock_lock(&dev->ndev->mtx); learn_record = (struct flm_v25_lrn_data_s *) @@ -330,7 +332,7 @@ static int flow_mtr_destroy_meter(struct flow_eth_dev *dev, uint8_t caller_id, u flm_lrn_queue_release_write_buffer(flm_lrn_queue_arr); - pthread_mutex_unlock(&dev->ndev->mtx); + rte_spinlock_unlock(&dev->ndev->mtx); return 0; } @@ -340,7 +342,7 @@ static int flm_mtr_adjust_stats(struct flow_eth_dev *dev, uint8_t caller_id, uin { struct flm_v25_lrn_data_s *learn_record = NULL; - pthread_mutex_lock(&dev->ndev->mtx); + rte_spinlock_lock(&dev->ndev->mtx); learn_record = (struct flm_v25_lrn_data_s *) @@ -377,7 +379,7 @@ static int flm_mtr_adjust_stats(struct flow_eth_dev *dev, uint8_t caller_id, uin flm_lrn_queue_release_write_buffer(flm_lrn_queue_arr); - pthread_mutex_unlock(&dev->ndev->mtx); + rte_spinlock_unlock(&dev->ndev->mtx); return 0; } @@ -514,9 +516,9 @@ static void flm_mtr_read_sta_records(struct flow_eth_dev *dev, uint32_t *data, u uint8_t port; bool remote_caller = is_remote_caller(caller_id, &port); - pthread_mutex_lock(&dev->ndev->mtx); + rte_spinlock_lock(&dev->ndev->mtx); ((struct flow_handle *)flm_h.p)->learn_ignored = 1; - pthread_mutex_unlock(&dev->ndev->mtx); + rte_spinlock_unlock(&dev->ndev->mtx); struct flm_status_event_s data = { .flow = flm_h.p, .learn_ignore = sta_data->lis, @@ -813,7 +815,7 @@ static uint8_t get_port_from_port_id(const struct flow_nic_dev *ndev, uint32_t p static void nic_insert_flow(struct flow_nic_dev *ndev, struct flow_handle *fh) { - pthread_mutex_lock(&ndev->flow_mtx); + rte_spinlock_lock(&ndev->flow_mtx); if (ndev->flow_base) ndev->flow_base->prev = fh; @@ -822,7 +824,7 @@ static void nic_insert_flow(struct flow_nic_dev *ndev, struct flow_handle *fh) fh->prev = NULL; ndev->flow_base = fh; - pthread_mutex_unlock(&ndev->flow_mtx); + rte_spinlock_unlock(&ndev->flow_mtx); } static void nic_remove_flow(struct flow_nic_dev *ndev, struct flow_handle *fh) @@ -830,7 +832,7 @@ static void nic_remove_flow(struct flow_nic_dev *ndev, struct flow_handle *fh) struct flow_handle *next = fh->next; struct flow_handle *prev = fh->prev; - pthread_mutex_lock(&ndev->flow_mtx); + rte_spinlock_lock(&ndev->flow_mtx); if (next && prev) { prev->next = next; @@ -847,12 +849,12 @@ static void nic_remove_flow(struct flow_nic_dev *ndev, struct flow_handle *fh) ndev->flow_base = NULL; } - pthread_mutex_unlock(&ndev->flow_mtx); + rte_spinlock_unlock(&ndev->flow_mtx); } static void nic_insert_flow_flm(struct flow_nic_dev *ndev, struct flow_handle *fh) { - pthread_mutex_lock(&ndev->flow_mtx); + rte_spinlock_lock(&ndev->flow_mtx); if (ndev->flow_base_flm) ndev->flow_base_flm->prev = fh; @@ -861,7 +863,7 @@ static void nic_insert_flow_flm(struct flow_nic_dev *ndev, struct flow_handle *f fh->prev = NULL; ndev->flow_base_flm = fh; - pthread_mutex_unlock(&ndev->flow_mtx); + rte_spinlock_unlock(&ndev->flow_mtx); } static void nic_remove_flow_flm(struct flow_nic_dev *ndev, struct flow_handle *fh_flm) @@ -869,7 +871,7 @@ static void nic_remove_flow_flm(struct flow_nic_dev *ndev, struct flow_handle *f struct flow_handle *next = fh_flm->next; struct flow_handle *prev = fh_flm->prev; - pthread_mutex_lock(&ndev->flow_mtx); + rte_spinlock_lock(&ndev->flow_mtx); if (next && prev) { prev->next = next; @@ -886,7 +888,7 @@ static void nic_remove_flow_flm(struct flow_nic_dev *ndev, struct flow_handle *f ndev->flow_base_flm = NULL; } - pthread_mutex_unlock(&ndev->flow_mtx); + rte_spinlock_unlock(&ndev->flow_mtx); } static inline struct nic_flow_def *prepare_nic_flow_def(struct nic_flow_def *fd) @@ -4188,20 +4190,20 @@ struct flow_handle *flow_create_profile_inline(struct flow_eth_dev *dev __rte_un struct nic_flow_def *fd = allocate_nic_flow_def(); if (fd == NULL) - goto err_exit; + goto err_exit0; res = interpret_flow_actions(dev, action, NULL, fd, error, &num_dest_port, &num_queues); if (res) - goto err_exit; + goto err_exit0; res = interpret_flow_elements(dev, elem, fd, error, forced_vlan_vid_local, &port_id, packet_data, packet_mask, &key_def); if (res) - goto err_exit; + goto err_exit0; - pthread_mutex_lock(&dev->ndev->mtx); + rte_spinlock_lock(&dev->ndev->mtx); /* Translate group IDs */ if (fd->jump_to_group != UINT32_MAX && @@ -4235,19 +4237,27 @@ struct flow_handle *flow_create_profile_inline(struct flow_eth_dev *dev __rte_un NT_LOG(DBG, FILTER, ">>>>> [Dev %p] Nic %i, Port %i: fh %p fd %p - implementation <<<<<", dev, dev->ndev->adapter_no, dev->port, fh, fd); - pthread_mutex_unlock(&dev->ndev->mtx); + rte_spinlock_unlock(&dev->ndev->mtx); return fh; err_exit: - if (fh) + if (fh) { flow_destroy_locked_profile_inline(dev, fh, NULL); - - else + fh = NULL; + } else { free(fd); + fd = NULL; + } + + rte_spinlock_unlock(&dev->ndev->mtx); - pthread_mutex_unlock(&dev->ndev->mtx); +err_exit0: + if (fd) { + free(fd); + fd = NULL; + } NT_LOG(ERR, FILTER, "ERR: %s", __func__); return NULL; @@ -4308,6 +4318,7 @@ int flow_destroy_locked_profile_inline(struct flow_eth_dev *dev, hw_db_inline_deref_idxs(dev->ndev, dev->ndev->hw_db_handle, (struct hw_db_idx *)fh->db_idxs, fh->db_idx_counter); free(fh->fd); + fh->fd = NULL; } if (err) { @@ -4316,6 +4327,7 @@ int flow_destroy_locked_profile_inline(struct flow_eth_dev *dev, } free(fh); + fh = NULL; #ifdef FLOW_DEBUG dev->ndev->be.iface->set_debug_mode(dev->ndev->be.be_dev, FLOW_BACKEND_DEBUG_MODE_NONE); @@ -4333,9 +4345,9 @@ int flow_destroy_profile_inline(struct flow_eth_dev *dev, struct flow_handle *fl if (flow) { /* Delete this flow */ - pthread_mutex_lock(&dev->ndev->mtx); + rte_spinlock_lock(&dev->ndev->mtx); err = flow_destroy_locked_profile_inline(dev, flow, error); - pthread_mutex_unlock(&dev->ndev->mtx); + rte_spinlock_unlock(&dev->ndev->mtx); } return err; @@ -4423,7 +4435,7 @@ int flow_actions_update_profile_inline(struct flow_eth_dev *dev, return -1; } - pthread_mutex_lock(&dev->ndev->mtx); + rte_spinlock_lock(&dev->ndev->mtx); /* Setup new actions */ uint32_t local_idx_counter = 0; @@ -4530,7 +4542,7 @@ int flow_actions_update_profile_inline(struct flow_eth_dev *dev, flow->flm_db_idxs[i] = local_idxs[i]; } - pthread_mutex_unlock(&dev->ndev->mtx); + rte_spinlock_unlock(&dev->ndev->mtx); free(fd); return 0; @@ -4539,7 +4551,7 @@ int flow_actions_update_profile_inline(struct flow_eth_dev *dev, hw_db_inline_deref_idxs(dev->ndev, dev->ndev->hw_db_handle, (struct hw_db_idx *)local_idxs, local_idx_counter); - pthread_mutex_unlock(&dev->ndev->mtx); + rte_spinlock_unlock(&dev->ndev->mtx); free(fd); return -1; @@ -5276,7 +5288,7 @@ int flow_dev_dump_profile_inline(struct flow_eth_dev *dev, { flow_nic_set_error(ERR_SUCCESS, error); - pthread_mutex_lock(&dev->ndev->mtx); + rte_spinlock_lock(&dev->ndev->mtx); if (flow != NULL) { if (flow->type == FLOW_HANDLE_TYPE_FLM) { @@ -5335,7 +5347,7 @@ int flow_dev_dump_profile_inline(struct flow_eth_dev *dev, } } - pthread_mutex_unlock(&dev->ndev->mtx); + rte_spinlock_unlock(&dev->ndev->mtx); return 0; } diff --git a/drivers/net/ntnic/nthw/flow_filter/flow_nthw_flm.c b/drivers/net/ntnic/nthw/flow_filter/flow_nthw_flm.c index 6f3b381a17..8855978349 100644 --- a/drivers/net/ntnic/nthw/flow_filter/flow_nthw_flm.c +++ b/drivers/net/ntnic/nthw/flow_filter/flow_nthw_flm.c @@ -678,11 +678,13 @@ int flm_nthw_buf_ctrl_update(const struct flm_nthw *p, uint32_t *lrn_free, uint3 uint32_t address_bufctrl = nthw_register_get_address(p->mp_buf_ctrl); nthw_rab_bus_id_t bus_id = 1; struct dma_buf_ptr bc_buf; - ret = nthw_rac_rab_dma_begin(rac); + rte_spinlock_lock(&rac->m_mutex); + ret = !rac->m_dma_active ? nthw_rac_rab_dma_begin(rac) : -1; if (ret == 0) { nthw_rac_rab_read32_dma(rac, bus_id, address_bufctrl, 2, &bc_buf); - ret = nthw_rac_rab_dma_commit(rac); + ret = rac->m_dma_active ? nthw_rac_rab_dma_commit(rac) : (assert(0), -1); + rte_spinlock_unlock(&rac->m_mutex); if (ret != 0) return ret; @@ -692,6 +694,13 @@ int flm_nthw_buf_ctrl_update(const struct flm_nthw *p, uint32_t *lrn_free, uint3 *lrn_free = bc_buf.base[bc_index & bc_mask] & 0xffff; *inf_avail = (bc_buf.base[bc_index & bc_mask] >> 16) & 0xffff; *sta_avail = bc_buf.base[(bc_index + 1) & bc_mask] & 0xffff; + } else { + rte_spinlock_unlock(&rac->m_mutex); + const struct fpga_info_s *const p_fpga_info = p->mp_fpga->p_fpga_info; + const char *const p_adapter_id_str = p_fpga_info->mp_adapter_id_str; + NT_LOG(ERR, NTHW, + "%s: DMA begin requested, but a DMA transaction is already active", + p_adapter_id_str); } return ret; @@ -716,8 +725,10 @@ int flm_nthw_lrn_data_flush(const struct flm_nthw *p, const uint32_t *data, uint *handled_records = 0; int max_tries = 10000; - while (*inf_avail == 0 && *sta_avail == 0 && records != 0 && --max_tries > 0) - if (nthw_rac_rab_dma_begin(rac) == 0) { + while (*inf_avail == 0 && *sta_avail == 0 && records != 0 && --max_tries > 0) { + rte_spinlock_lock(&rac->m_mutex); + int ret = !rac->m_dma_active ? nthw_rac_rab_dma_begin(rac) : -1; + if (ret == 0) { uint32_t dma_free = nthw_rac_rab_get_free(rac); if (dma_free != RAB_DMA_BUF_CNT) { @@ -770,7 +781,11 @@ int flm_nthw_lrn_data_flush(const struct flm_nthw *p, const uint32_t *data, uint /* Read buf ctrl */ nthw_rac_rab_read32_dma(rac, bus_id, address_bufctrl, 2, &bc_buf); - if (nthw_rac_rab_dma_commit(rac) != 0) + int ret = rac->m_dma_active ? + nthw_rac_rab_dma_commit(rac) : + (assert(0), -1); + rte_spinlock_unlock(&rac->m_mutex); + if (ret != 0) return -1; uint32_t bc_mask = bc_buf.size - 1; @@ -778,8 +793,15 @@ int flm_nthw_lrn_data_flush(const struct flm_nthw *p, const uint32_t *data, uint *lrn_free = bc_buf.base[bc_index & bc_mask] & 0xffff; *inf_avail = (bc_buf.base[bc_index & bc_mask] >> 16) & 0xffff; *sta_avail = bc_buf.base[(bc_index + 1) & bc_mask] & 0xffff; + } else { + rte_spinlock_unlock(&rac->m_mutex); + const struct fpga_info_s *const p_fpga_info = p->mp_fpga->p_fpga_info; + const char *const p_adapter_id_str = p_fpga_info->mp_adapter_id_str; + NT_LOG(ERR, NTHW, + "%s: DMA begin requested, but a DMA transaction is already active", + p_adapter_id_str); } - + } return 0; } @@ -801,7 +823,8 @@ int flm_nthw_inf_sta_data_update(const struct flm_nthw *p, uint32_t *inf_data, uint32_t mask; uint32_t index; - ret = nthw_rac_rab_dma_begin(rac); + rte_spinlock_lock(&rac->m_mutex); + ret = !rac->m_dma_active ? nthw_rac_rab_dma_begin(rac) : -1; if (ret == 0) { /* Announce the number of words to read from INF_DATA */ @@ -821,7 +844,8 @@ int flm_nthw_inf_sta_data_update(const struct flm_nthw *p, uint32_t *inf_data, } nthw_rac_rab_read32_dma(rac, bus_id, address_bufctrl, 2, &bc_buf); - ret = nthw_rac_rab_dma_commit(rac); + ret = rac->m_dma_active ? nthw_rac_rab_dma_commit(rac) : (assert(0), -1); + rte_spinlock_unlock(&rac->m_mutex); if (ret != 0) return ret; @@ -847,6 +871,13 @@ int flm_nthw_inf_sta_data_update(const struct flm_nthw *p, uint32_t *inf_data, *lrn_free = bc_buf.base[index & mask] & 0xffff; *inf_avail = (bc_buf.base[index & mask] >> 16) & 0xffff; *sta_avail = bc_buf.base[(index + 1) & mask] & 0xffff; + } else { + rte_spinlock_unlock(&rac->m_mutex); + const struct fpga_info_s *const p_fpga_info = p->mp_fpga->p_fpga_info; + const char *const p_adapter_id_str = p_fpga_info->mp_adapter_id_str; + NT_LOG(ERR, NTHW, + "%s: DMA begin requested, but a DMA transaction is already active", + p_adapter_id_str); } return ret; diff --git a/drivers/net/ntnic/nthw/nthw_rac.c b/drivers/net/ntnic/nthw/nthw_rac.c index 461da8e104..ca6aba6db2 100644 --- a/drivers/net/ntnic/nthw/nthw_rac.c +++ b/drivers/net/ntnic/nthw/nthw_rac.c @@ -3,6 +3,7 @@ * Copyright(c) 2023 Napatech A/S */ +#include "rte_spinlock.h" #include "nt_util.h" #include "ntlog.h" @@ -10,8 +11,6 @@ #include "nthw_register.h" #include "nthw_rac.h" -#include - #define RAB_DMA_WAIT (1000000) #define RAB_READ (0x01) @@ -217,7 +216,7 @@ int nthw_rac_init(nthw_rac_t *p, nthw_fpga_t *p_fpga, struct fpga_info_s *p_fpga } } - pthread_mutex_init(&p->m_mutex, NULL); + rte_spinlock_init(&p->m_mutex); return 0; } @@ -389,19 +388,6 @@ void nthw_rac_bar0_write32(const struct fpga_info_s *p_fpga_info, uint32_t reg_a int nthw_rac_rab_dma_begin(nthw_rac_t *p) { - const struct fpga_info_s *const p_fpga_info = p->mp_fpga->p_fpga_info; - const char *const p_adapter_id_str = p_fpga_info->mp_adapter_id_str; - - pthread_mutex_lock(&p->m_mutex); - - if (p->m_dma_active) { - pthread_mutex_unlock(&p->m_mutex); - NT_LOG(ERR, NTHW, - "%s: DMA begin requested, but a DMA transaction is already active", - p_adapter_id_str); - return -1; - } - p->m_dma_active = true; return 0; @@ -454,19 +440,11 @@ int nthw_rac_rab_dma_commit(nthw_rac_t *p) { int ret; - if (!p->m_dma_active) { - /* Expecting mutex not to be locked! */ - assert(0); /* alert developer that something is wrong */ - return -1; - } - nthw_rac_rab_dma_activate(p); ret = nthw_rac_rab_dma_wait(p); p->m_dma_active = false; - pthread_mutex_unlock(&p->m_mutex); - return ret; } @@ -602,7 +580,7 @@ int nthw_rac_rab_write32(nthw_rac_t *p, bool trc, nthw_rab_bus_id_t bus_id, uint return -1; } - pthread_mutex_lock(&p->m_mutex); + rte_spinlock_lock(&p->m_mutex); if (p->m_dma_active) { NT_LOG(ERR, NTHW, "%s: RAB: Illegal operation: DMA enabled", p_adapter_id_str); @@ -748,7 +726,7 @@ int nthw_rac_rab_write32(nthw_rac_t *p, bool trc, nthw_rab_bus_id_t bus_id, uint } exit_unlock_res: - pthread_mutex_unlock(&p->m_mutex); + rte_spinlock_unlock(&p->m_mutex); return res; } @@ -763,7 +741,7 @@ int nthw_rac_rab_read32(nthw_rac_t *p, bool trc, nthw_rab_bus_id_t bus_id, uint3 uint32_t out_buf_free; int res = 0; - pthread_mutex_lock(&p->m_mutex); + rte_spinlock_lock(&p->m_mutex); if (address > (1 << RAB_ADDR_BW)) { NT_LOG(ERR, NTHW, "%s: RAB: Illegal address: value too large %d - max %d", @@ -923,7 +901,7 @@ int nthw_rac_rab_read32(nthw_rac_t *p, bool trc, nthw_rab_bus_id_t bus_id, uint3 } exit_unlock_res: - pthread_mutex_unlock(&p->m_mutex); + rte_spinlock_unlock(&p->m_mutex); return res; } @@ -935,7 +913,7 @@ int nthw_rac_rab_flush(nthw_rac_t *p) uint32_t retry; int res = 0; - pthread_mutex_lock(&p->m_mutex); + rte_spinlock_lock(&p->m_mutex); /* Set the flush bit */ nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_BUF_USED_ADDR, @@ -960,6 +938,6 @@ int nthw_rac_rab_flush(nthw_rac_t *p) /* Clear flush bit when done */ nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_BUF_USED_ADDR, 0x0); - pthread_mutex_unlock(&p->m_mutex); + rte_spinlock_unlock(&p->m_mutex); return res; } diff --git a/drivers/net/ntnic/nthw/nthw_rac.h b/drivers/net/ntnic/nthw/nthw_rac.h index c64dac9da9..df92b487af 100644 --- a/drivers/net/ntnic/nthw/nthw_rac.h +++ b/drivers/net/ntnic/nthw/nthw_rac.h @@ -16,7 +16,7 @@ struct nthw_rac { nthw_fpga_t *mp_fpga; nthw_module_t *mp_mod_rac; - pthread_mutex_t m_mutex; + rte_spinlock_t m_mutex; int mn_param_rac_rab_interfaces; int mn_param_rac_rab_ob_update; diff --git a/drivers/net/ntnic/ntnic_ethdev.c b/drivers/net/ntnic/ntnic_ethdev.c index df9ee77e06..91669caceb 100644 --- a/drivers/net/ntnic/ntnic_ethdev.c +++ b/drivers/net/ntnic/ntnic_ethdev.c @@ -18,6 +18,7 @@ #include +#include "rte_spinlock.h" #include "ntlog.h" #include "ntdrv_4ga.h" #include "ntos_drv.h" @@ -236,7 +237,7 @@ static int dpdk_stats_reset(struct pmd_internals *internals, struct ntdrv_4ga_s if (!p_nthw_stat || !p_nt4ga_stat || n_intf_no < 0 || n_intf_no > NUM_ADAPTER_PORTS_MAX) return -1; - pthread_mutex_lock(&p_nt_drv->stat_lck); + rte_spinlock_lock(&p_nt_drv->stat_lck); /* Rx */ for (i = 0; i < internals->nb_rx_queues; i++) { @@ -256,7 +257,7 @@ static int dpdk_stats_reset(struct pmd_internals *internals, struct ntdrv_4ga_s p_nt4ga_stat->n_totals_reset_timestamp = time(NULL); - pthread_mutex_unlock(&p_nt_drv->stat_lck); + rte_spinlock_unlock(&p_nt_drv->stat_lck); return 0; } @@ -1519,9 +1520,9 @@ static int eth_xstats_get(struct rte_eth_dev *eth_dev, struct rte_eth_xstat *sta return -1; } - pthread_mutex_lock(&p_nt_drv->stat_lck); + rte_spinlock_lock(&p_nt_drv->stat_lck); nb_xstats = ntnic_xstats_ops->nthw_xstats_get(p_nt4ga_stat, stats, n, if_index); - pthread_mutex_unlock(&p_nt_drv->stat_lck); + rte_spinlock_unlock(&p_nt_drv->stat_lck); return nb_xstats; } @@ -1544,10 +1545,10 @@ static int eth_xstats_get_by_id(struct rte_eth_dev *eth_dev, return -1; } - pthread_mutex_lock(&p_nt_drv->stat_lck); + rte_spinlock_lock(&p_nt_drv->stat_lck); nb_xstats = ntnic_xstats_ops->nthw_xstats_get_by_id(p_nt4ga_stat, ids, values, n, if_index); - pthread_mutex_unlock(&p_nt_drv->stat_lck); + rte_spinlock_unlock(&p_nt_drv->stat_lck); return nb_xstats; } @@ -1566,9 +1567,9 @@ static int eth_xstats_reset(struct rte_eth_dev *eth_dev) return -1; } - pthread_mutex_lock(&p_nt_drv->stat_lck); + rte_spinlock_lock(&p_nt_drv->stat_lck); ntnic_xstats_ops->nthw_xstats_reset(p_nt4ga_stat, if_index); - pthread_mutex_unlock(&p_nt_drv->stat_lck); + rte_spinlock_unlock(&p_nt_drv->stat_lck); return dpdk_stats_reset(internals, p_nt_drv, if_index); } @@ -1749,14 +1750,14 @@ THREAD_FUNC port_event_thread_fn(void *context) if (p_nt4ga_stat->flm_stat_ver > 22 && p_nt4ga_stat->mp_stat_structs_flm) { if (flmdata.lookup != p_nt4ga_stat->mp_stat_structs_flm->load_lps || flmdata.access != p_nt4ga_stat->mp_stat_structs_flm->load_aps) { - pthread_mutex_lock(&p_nt_drv->stat_lck); + rte_spinlock_lock(&p_nt_drv->stat_lck); flmdata.lookup = p_nt4ga_stat->mp_stat_structs_flm->load_lps; flmdata.access = p_nt4ga_stat->mp_stat_structs_flm->load_aps; flmdata.lookup_maximum = p_nt4ga_stat->mp_stat_structs_flm->max_lps; flmdata.access_maximum = p_nt4ga_stat->mp_stat_structs_flm->max_aps; - pthread_mutex_unlock(&p_nt_drv->stat_lck); + rte_spinlock_unlock(&p_nt_drv->stat_lck); if (eth_dev && eth_dev->data && eth_dev->data->dev_private) { rte_eth_dev_callback_process(eth_dev, @@ -1773,7 +1774,7 @@ THREAD_FUNC port_event_thread_fn(void *context) if (p_nt4ga_stat->mp_port_load) { if (portdata.rx_bps != p_nt4ga_stat->mp_port_load[port_no].rx_bps || portdata.tx_bps != p_nt4ga_stat->mp_port_load[port_no].tx_bps) { - pthread_mutex_lock(&p_nt_drv->stat_lck); + rte_spinlock_lock(&p_nt_drv->stat_lck); portdata.rx_bps = p_nt4ga_stat->mp_port_load[port_no].rx_bps; portdata.tx_bps = p_nt4ga_stat->mp_port_load[port_no].tx_bps; portdata.rx_pps = p_nt4ga_stat->mp_port_load[port_no].rx_pps; @@ -1786,7 +1787,7 @@ THREAD_FUNC port_event_thread_fn(void *context) p_nt4ga_stat->mp_port_load[port_no].rx_bps_max; portdata.tx_bps_maximum = p_nt4ga_stat->mp_port_load[port_no].tx_bps_max; - pthread_mutex_unlock(&p_nt_drv->stat_lck); + rte_spinlock_unlock(&p_nt_drv->stat_lck); if (eth_dev && eth_dev->data && eth_dev->data->dev_private) { rte_eth_dev_callback_process(eth_dev, @@ -1957,9 +1958,9 @@ THREAD_FUNC adapter_stat_thread_fn(void *context) /* Check then collect */ { - pthread_mutex_lock(&p_nt_drv->stat_lck); + rte_spinlock_lock(&p_nt_drv->stat_lck); nt4ga_stat_ops->nt4ga_stat_collect(&p_nt_drv->adapter_info, p_nt4ga_stat); - pthread_mutex_unlock(&p_nt_drv->stat_lck); + rte_spinlock_unlock(&p_nt_drv->stat_lck); } } @@ -2232,7 +2233,7 @@ nthw_pci_dev_init(struct rte_pci_device *pci_dev) } } - pthread_mutex_init(&p_nt_drv->stat_lck, NULL); + rte_spinlock_init(&p_nt_drv->stat_lck); res = THREAD_CTRL_CREATE(&p_nt_drv->stat_thread, "nt4ga_stat_thr", adapter_stat_thread_fn, (void *)p_drv); diff --git a/drivers/net/ntnic/ntnic_filter/ntnic_filter.c b/drivers/net/ntnic/ntnic_filter/ntnic_filter.c index 8edaccb65c..4c18088681 100644 --- a/drivers/net/ntnic/ntnic_filter/ntnic_filter.c +++ b/drivers/net/ntnic/ntnic_filter/ntnic_filter.c @@ -910,7 +910,7 @@ static int poll_statistics(struct pmd_internals *internals) internals->last_stat_rtc = now_rtc; - pthread_mutex_lock(&p_nt_drv->stat_lck); + rte_spinlock_lock(&p_nt_drv->stat_lck); /* * Add the RX statistics increments since last time we polled. @@ -951,7 +951,7 @@ static int poll_statistics(struct pmd_internals *internals) /* Globally only once a second */ if ((now_rtc - last_stat_rtc) < rte_tsc_freq) { rte_spinlock_unlock(&hwlock); - pthread_mutex_unlock(&p_nt_drv->stat_lck); + rte_spinlock_unlock(&p_nt_drv->stat_lck); return 0; } @@ -988,7 +988,7 @@ static int poll_statistics(struct pmd_internals *internals) } rte_spinlock_unlock(&hwlock); - pthread_mutex_unlock(&p_nt_drv->stat_lck); + rte_spinlock_unlock(&p_nt_drv->stat_lck); return 0; } -- 2.45.0