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 7E4F145BC0; Tue, 29 Oct 2024 19:19:31 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6E76D42EFE; Tue, 29 Oct 2024 19:19:31 +0100 (CET) Received: from egress-ip11b.ess.de.barracuda.com (egress-ip11b.ess.de.barracuda.com [18.185.115.215]) by mails.dpdk.org (Postfix) with ESMTP id EDE1740267 for ; Tue, 29 Oct 2024 19:19:28 +0100 (CET) Received: from outbound.mail.protection.outlook.com (mail-am0eur02lp2237.outbound.protection.outlook.com [104.47.11.237]) by mx-outbound43-199.eu-central-1c.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 29 Oct 2024 18:19:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IOAfZEAupj9DyGxhJIof70SVZgQi8pCdYr2eQa/3QHRq8/zUyG9Al3dF4ZC8/L7olBDz+yK3gYD1yRQKnmGqcN13htxH2QJNCYb537tkYlXZcKUqcDafICCzwhPWlSTSu9gUKM4SU3TBKBSMtl5I1z7W8vGQoxPG52xBEoeUys3g2kmvG2ZbAzl5Q+aVLW16lf5qNURJu6UAqhmC7wsWfS+lSI3M9nS+uC4B6K7SoP+4PxeUKeH3Q7axNvEz8TNi1OukjtcCjqQH9urLnWOgBrJuSOPKyyXvKDzQLPM4A12oo6hzTCWPnFl6ZkuLyU6p9gRPV5JBkeE42w5g0BE2wg== 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=N53ClTR71LiMgqOIBlEK53zIThmyQuCV7Mfp3/oSYis=; b=DmLbFr+6URtVyZbO+Xxyjv0PEcnsGTAedfzSrL7q1n15jgBXSy098YmUeIILodksDEFRQTWWNoT82dNd0y9jO2hUUPHhVmt18hTHeBpdzjCJZPAUgTf0vZZgFVlmpumDum62eEqY/hZt5Nk+CVld4brVNajwGN/X1KQA63uNEdNSkOqyB+etfB9VVMPJYYVhrjIoRI2k+pmRxu90caVf2ukAY1JYhoDlYzRnEb3nFk+41fmu9P1kxlOHYFcz9hEPOwZ4w/AZwBryrH8viX/z+dB2FsjNddF33BqXMiX9x6e2d8R06EmdwhAvxOpR/pg/FV7llydkmJsHPoajqhuk2Q== 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=N53ClTR71LiMgqOIBlEK53zIThmyQuCV7Mfp3/oSYis=; b=ABf5ww7NLTcgL0r3dBCH3JCXyeAv7MEuVgXvcg3UCGZAuv9uvkSya0kQAZ5VJZ3g6DTot3nZoYvdURQb/CC8vMhPHOpIIO93IxcPBd5zvq0QPq8ScZlErPhpxIBIQ1+yXoJuOoHjEb3wFtdJ1lk3P4DG3d/+EcDqSLYWbDE0U4s= Received: from DUZPR01CA0197.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b6::11) by DB9P190MB1889.EURP190.PROD.OUTLOOK.COM (2603:10a6:10:390::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.23; Tue, 29 Oct 2024 16:44:10 +0000 Received: from DU2PEPF00028D06.eurprd03.prod.outlook.com (2603:10a6:10:4b6:cafe::33) by DUZPR01CA0197.outlook.office365.com (2603:10a6:10:4b6::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.29 via Frontend Transport; Tue, 29 Oct 2024 16:44:10 +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 DU2PEPF00028D06.mail.protection.outlook.com (10.167.242.166) with Microsoft SMTP Server id 15.20.8114.16 via Frontend Transport; Tue, 29 Oct 2024 16:44:09 +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 v4 78/86] net/ntnic: migrate to the RTE spinlock Date: Tue, 29 Oct 2024 17:42:22 +0100 Message-ID: <20241029164243.1648775-79-sil-plv@napatech.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20241029164243.1648775-1-sil-plv@napatech.com> References: <20241021210527.2075431-1-sil-plv@napatech.com> <20241029164243.1648775-1-sil-plv@napatech.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PEPF00028D06:EE_|DB9P190MB1889:EE_ Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 1aae3032-9b40-466d-08e8-08dcf838e9ac X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?pd0SL89v3VkLrTwx5MMOj0LjEx3GyD5sJnDe+I0TODA/fKsqZMZRoT46xTo+?= =?us-ascii?Q?m4GMzzR2C8edhtq/yBbpHsjl4VyC3jChNj1Vwm5qVtW+Ou9J7N1jzK7T8EyZ?= =?us-ascii?Q?Qb/WaxsBnGMF+dZj4LjK80s+jZng5NQZa7uSfVljxWWrHAm/+NFh8dmJGHPI?= =?us-ascii?Q?DP6sQqk1bah8QhpM0ZfxEijbb1paTU7gZUH28pEe1MIK8bWaPfca2JcivSV6?= =?us-ascii?Q?8hp4795hJLCKtjggTYbx9buY7F/KUj0uvN9ujR4sZN0NFV6rwCSlkqBTnoXY?= =?us-ascii?Q?wJE8EqReGkkdUv1FfznBJX9sBg4gO0geL6eiRoxWZF7R9YqC17gRERo70Mqw?= =?us-ascii?Q?sJ95APd5fju5AzeE/ST1YBFsp69MtnAQEmgarwGc2tHBashN7n36VooASoEp?= =?us-ascii?Q?1zfuZx09PJExIULDc9l4nJ1ZgwHTPfOCVN/2TkzH/MvQCfl3KexRMKlSOUGH?= =?us-ascii?Q?CpVtXOqJuSIvoVzvGMeZRatYhxDa1oD/Nm5vCgwOpiBNKRQCGiwhfYtp4Qfy?= =?us-ascii?Q?Q2SWyrGl4p8kx4XUEhDGM/tmF6fK3gBXTXtayHL242na658Nspfx6pOEoCY1?= =?us-ascii?Q?9dz6B3jOiVNrVqx+Uo/ccTWswyROK+JtlrtVZVImsyRISDQkvkJLAJqQQ60h?= =?us-ascii?Q?78BjdAIoiXbsS5KFx4dI6e7Y/LTKLxrBn3CpKy94eL26PUO/SHlBJ4JylR67?= =?us-ascii?Q?WtSpaJYFSQ1fyFiodGj3pqvexyGxTsyGP5LdkzyMM3dyCRdp0gTwHv0e2D3v?= =?us-ascii?Q?4kq7v7+gKe8348U0nr9Am+HB/TqJGB0nkCuvwQk6/n7vkaoUk5hf4M/h2wUj?= =?us-ascii?Q?V6cpnA99RRJyhb703zl2PpdMuSxhFApAn7XQ5yD2kir98tZAa5mNGbjqwNqg?= =?us-ascii?Q?m3Y2OZIeWRqp5MOD0hfPvPm8tDg/qWoFo1kIdityt9XL0sJgwigPrP9klmE2?= =?us-ascii?Q?uudCHv5i3CutRCK2UjhxtHvbFBHkFO7+tuXfsFlewFuuk+OREwfBGLAAcOhv?= =?us-ascii?Q?A5uUikVzxosqEKfNV2za17ebYYa0+yNW0elr7FtgWW6uSx+LDH7YDyztX5AV?= =?us-ascii?Q?0sHpVowIlJWXUA/4TmkDlobh6cj1MRJIEv6CqCE1T/p5vbPuHJrlrzOGZC6Y?= =?us-ascii?Q?HEuWmkQxkttv3M/3B1FYL98+zbJUEFj6oVZSEjn+6IvKybuLMfRioI3BAYZl?= =?us-ascii?Q?iS//rY8IKlbu02EFykbZjzLTS0XIUtOQqh6R7lwQ5hDYv3B2x8gi4ZtwyEEB?= =?us-ascii?Q?MBAxRGhX4xnZxnfLotlkSWcCJgNfwUR3U3BTam0Mmk3KNikrVIhCp4igXx+O?= =?us-ascii?Q?gWXTtHFuoWTDUgBlJCbnSc8ss+vV3slR/RncbGgZna0BwST+9RSbfy++Tgxf?= =?us-ascii?Q?dpl6gRR63ky6LJSGySJpNQac6ub+MrsRkApG0b38zM5UtR9spA=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)(376014)(1800799024)(36860700013)(82310400026); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: YEx5ANtHc41KOXhgeiUH9MZQg2BqEgU1a7UudRz2Be6J51Taagib0iQyIZCxmg2cQ2zh14fn9U9XATEIUaWVEJMS8hIFVTTKObDm3ia1gftIZ0dBUevQtuHt+pQclhY6QW2TS2h+eFf2Zq9ESsNzPvcQ0+W0Z+JVQflKvjyM4t6r8W2Sm/MEWNGTy8rDk3zTDg9SibELg1BW0X9HBahq80+u1IEp4ZSch5FofzDGD6mIE9HSfXDci99dPtsV14HgrSuWhBv5Ed8SsqZzYGlgEXMvamIUk+d0u/yQXDH9QCDytiTAbZdWWkhBt/qxvfrzugKUY0EuE6odkN7QI2YyhHaX/dytrF9436fNMe4TJgNj5i3xH+WcSWHXDLhBbU0rRrykoczmwJZlT7EVYx41yqfqdQ+527BSMh1szltt/ARgoOIaG+dF/wOa2XwPuajOuEcshb1J+UX3OTuCgahPg21bj4/DZgVmZIkPWw/rLBrDEHmbesDtd7YkD9k9vNC0qDvg50VmmiXPJojZ2t16DXn+TH12UTwqAgnF6hYTcFkC7N7Q39PRh/eL4Um8ohEFRfxb1/qT/MfPhAVUztFzUEOhVaaEhSQEvCwRXnNkZWLlbDXfLkF+VODmFGtEs2m9WqWhQjEHBrwIV+BAHVrNkFI+s/lInutx6Cj16z4GbEU= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2024 16:44:09.9334 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1aae3032-9b40-466d-08e8-08dcf838e9ac 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: DU2PEPF00028D06.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9P190MB1889 X-OriginatorOrg: napatech.com X-BESS-ID: 1730225963-311207-12668-32219-1 X-BESS-VER: 2019.1_20241018.1852 X-BESS-Apparent-Source-IP: 104.47.11.237 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVsamhkYmQGYGUNTEPNkw1TjNwC LVMAkonppommiakpxkbmGelJialGysVBsLAHvV9RFCAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.260065 [from cloudscan10-120.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 9164f4cc2e..9689aece58 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" @@ -44,7 +45,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 @@ -400,7 +401,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; @@ -454,7 +455,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); @@ -495,15 +496,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) { @@ -514,7 +515,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; } @@ -522,7 +523,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; } @@ -554,27 +555,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; } @@ -584,20 +585,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; @@ -684,15 +684,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); @@ -799,7 +798,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 98bfc01539..9c554ee7e2 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) @@ -4192,20 +4194,20 @@ struct flow_handle *flow_create_profile_inline(struct flow_eth_dev *dev, 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 && @@ -4239,19 +4241,27 @@ struct flow_handle *flow_create_profile_inline(struct flow_eth_dev *dev, 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; @@ -4312,6 +4322,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) { @@ -4320,6 +4331,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); @@ -4337,9 +4349,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; @@ -4427,7 +4439,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; @@ -4534,7 +4546,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; @@ -4543,7 +4555,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; @@ -5280,7 +5292,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) { @@ -5339,7 +5351,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