From patchwork Fri Aug 9 20:14:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Mattias_R=C3=B6nnblom?= X-Patchwork-Id: 143060 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CB4384577D; Fri, 9 Aug 2024 22:25:03 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5512642E8D; Fri, 9 Aug 2024 22:24:26 +0200 (CEST) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2050.outbound.protection.outlook.com [40.107.21.50]) by mails.dpdk.org (Postfix) with ESMTP id 82C1342E5C for ; Fri, 9 Aug 2024 22:24:20 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=B5cFAtQXwHXo1oSUhSt7lRiWQz9oT8CFnEKYvit5oJuE+sRfZsnI5cxeHNOW0FSYJO6+gzkFCzI+MKcYvhJjrYOa083DlNx+Rdhvys59BrfY4rOmlDGpL6UQNHQ9u3SJNyYznfrK0Ej56u2tK/k1KwZ05UiwC42nY2iI9Zwu4GOg33cBlQCh7dvKy7rXPbu4IxBS6U/N0daMEZUR8AKG/YKr0b7HGdcQ8sicgFartMM6/1A6w45aD4ZfCzDmjKYlRYTlvskasPgWZLVbEYjUi9VDpHdtGFq++4IR9AebtmKDMSZ4LK5oC/ib+oUPVKUpJuND37S/NxjqM9WPHs1e0A== 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=Q/piwczi3n4aqfjxagcziK2QUx6rtehUaviNWwb6gFI=; b=hF3G1wjYBPfasVcD6DFe1jrir0+54aeYlawKfi+GE376vB8uNZTIFeVMjkNnstH8qvbsoE7nc+LRNtx34nXzGhnsNxLCg9hzxj4CAF5NGqfhRpBmdxlBoDd8hftt1/qQp79H/52UvNKOsesYCbFvg8e7l/x6AFo6f5sP75YTVAmp1ItRi/mc6HcjRqRpW/LSQvOnWE4sUfhg5Quv0FcK1ObxzB2bNAQPJm2IQKGr4u0bPRR2xa/s/nEgu5EHXZUbkhli7vHaaIDeIoEbwfwOXHptRUwKrcNt1blt50XdDEcNuj1Prr2KFNX615cyCvZzTlOBZCUVuI+QJEmMcIW4tA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 192.176.1.74) smtp.rcpttodomain=dpdk.org smtp.mailfrom=ericsson.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ericsson.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Q/piwczi3n4aqfjxagcziK2QUx6rtehUaviNWwb6gFI=; b=XtUWa42L1W69+669SVr2PcgOc77JjeZjwHiAoP1F8sDd+oe1nLnLQVwcT3x7W1MtfUSXiGNrh3bXL64+2Z4UdZ3oX/0lLKspEyD+/3TTNEqjsbQdq+aDiG5Oj0mQj6knJAJkJO5OMHxVXo7LABW5PFI3aog/5/jw7ZEUxom3PMvl/F4X6o7pkNZAjodzMjr6g0RhrQgyoPWTkh600j1e21kjU8mMe4vpF9jL1vv89adxKNQlG21+GovgQE4fUIRaiDBDFpcALaDqPu37dDt03r1sv/kBYaoJlgNRVtnu2NPY2hhAAkcpEEfEWxxOxIW/Edno6WmjSHVP+pOcvd9u6A== Received: from AM0PR02CA0082.eurprd02.prod.outlook.com (2603:10a6:208:154::23) by AS8PR07MB7495.eurprd07.prod.outlook.com (2603:10a6:20b:2ab::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.15; Fri, 9 Aug 2024 20:24:18 +0000 Received: from AM3PEPF0000A794.eurprd04.prod.outlook.com (2603:10a6:208:154:cafe::a6) by AM0PR02CA0082.outlook.office365.com (2603:10a6:208:154::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14 via Frontend Transport; Fri, 9 Aug 2024 20:24:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 192.176.1.74) smtp.mailfrom=ericsson.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ericsson.com; Received-SPF: Pass (protection.outlook.com: domain of ericsson.com designates 192.176.1.74 as permitted sender) receiver=protection.outlook.com; client-ip=192.176.1.74; helo=oa.msg.ericsson.com; pr=C Received: from oa.msg.ericsson.com (192.176.1.74) by AM3PEPF0000A794.mail.protection.outlook.com (10.167.16.123) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.8 via Frontend Transport; Fri, 9 Aug 2024 20:24:18 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.66) with Microsoft SMTP Server id 15.2.1544.11; Fri, 9 Aug 2024 22:24:15 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 9EF911C006D; Fri, 9 Aug 2024 22:24:15 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , =?utf-8?q?Morten_Br=C3=B8rup?= , Tyler Retzlaff , Stephen Hemminger , Harry van Haaren , =?utf-8?q?Mattias_R=C3=B6nnb?= =?utf-8?q?lom?= Subject: [PATCH 3/6] eal: add atomic bitset functions Date: Fri, 9 Aug 2024 22:14:37 +0200 Message-ID: <20240809201440.590464-3-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240809201440.590464-1-mattias.ronnblom@ericsson.com> References: <20240505073313.118515-1-mattias.ronnblom@ericsson.com> <20240809201440.590464-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM3PEPF0000A794:EE_|AS8PR07MB7495:EE_ X-MS-Office365-Filtering-Correlation-Id: f8263dd2-6de7-4a40-2e99-08dcb8b13ec9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: =?utf-8?q?Sm+qAZeouHuchAEs4Oz5jlGSl1d8+7f?= =?utf-8?q?pzYgFxkgFpfmZpYhao/sFdsgUttS6CXapLyIR1+9YvWEq+wnXWGSGcDc729euPkXJ?= =?utf-8?q?gHEIsXsngxv8506Tz0VRlLu69o+YCjWmNCPC2uWEAcR3J9T4dv8qYMn+BTc1cXiG2?= =?utf-8?q?2cpALTnA6xTQc4Ox1gRIC/BlZc/uOdqZ5MOrL618/pAAKUvNRva7CQsybMMQrvm31?= =?utf-8?q?/HJD3qjPNKV8D7fJ7YAP8mPi3PwgghjBugZ8WnxNZj2M/LjxMVIHMwqrw/7WQuVmY?= =?utf-8?q?kE9crezjisz44zClM1KPYD6rzPO/bC8lbmPyDxeLSlj7XJfBCTrmnl6PjOZEssT9r?= =?utf-8?q?dsM92yFTCkTJga+jS1Tgf6+Qs1XxImlH4nEvtqd9We+voleCQil+BqRFcoH2XjEhM?= =?utf-8?q?UqjfUfE+vUGuQgClc2Pfwq61nnyfjczlQjzev6F/k91XJhM3fG0RKr8Fe6xtJxVJb?= =?utf-8?q?TkQ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?4TCYcWKet6eUPSNz+Petl5rVfyGeiuHi+g=3D=3D?= X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230040)(1800799024)(376014)(82310400026)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Aug 2024 20:24:18.1393 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f8263dd2-6de7-4a40-2e99-08dcb8b13ec9 X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=92e84ceb-fbfd-47ab-be52-080c6b87953f; Ip=[192.176.1.74]; Helo=[oa.msg.ericsson.com] X-MS-Exchange-CrossTenant-AuthSource: AM3PEPF0000A794.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR07MB7495 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 Extend the bitset API with atomic versions of the most basic bitset operations. Signed-off-by: Mattias Rönnblom Acked-by: Tyler Retzlaff --- lib/eal/include/rte_bitset.h | 155 +++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) diff --git a/lib/eal/include/rte_bitset.h b/lib/eal/include/rte_bitset.h index 49a07c77b8..c0441b0e22 100644 --- a/lib/eal/include/rte_bitset.h +++ b/lib/eal/include/rte_bitset.h @@ -376,6 +376,161 @@ rte_bitset_flip(uint64_t *bitset, size_t bit_num) __RTE_BITSET_DELEGATE(rte_bit_flip, bitset, bit_num); } +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Atomically test if a bit is set. + * + * Atomically test if a bit in a bitset is set with the specified + * memory ordering. + * + * @param bitset + * A pointer to the array of words making up the bitset. + * @param bit_num + * Index of the bit to test. Index 0 is the least significant bit. + * @param memory_order + * The memory order to use. + * @return + * Returns true if the bit is '1', and false if the bit is '0'. + */ + +__rte_experimental +static inline bool +rte_bitset_atomic_test(const uint64_t *bitset, size_t bit_num, + int memory_order) +{ + return __RTE_BITSET_DELEGATE_N(rte_bit_atomic_test, bitset, bit_num, + memory_order); +} + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Atomically set a bit in the bitset. + * + * Set a bit in a bitset as an atomic operation, with the specified + * memory ordering. + * + * rte_bitset_atomic_set() is multi-thread safe, provided all threads + * acting in parallel on the same bitset does so through + * @c rte_bitset_atomic_*() functions. + * + * Bits are numbered from 0 to (size - 1) (inclusive). + * + * @param bitset + * A pointer to the array of words making up the bitset. + * @param bit_num + * The index of the bit to be set. + * @param memory_order + * The memory order to use. + */ + +__rte_experimental +static inline void +rte_bitset_atomic_set(uint64_t *bitset, size_t bit_num, int memory_order) +{ + __RTE_BITSET_DELEGATE_N(rte_bit_atomic_set, bitset, bit_num, + memory_order); +} + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Atomically clear a bit in the bitset. + * + * Clear a bit in a bitset as an atomic operation, with the specified + * memory ordering. + * + * rte_bitset_atomic_clear() is multi-thread safe, provided all + * threads acting in parallel on the same bitset does so through @c + * rte_bitset_atomic_*() functions. + * + * Bits are numbered from 0 to (size - 1) (inclusive). + * + * @param bitset + * A pointer to the array of words making up the bitset. + * @param bit_num + * The index of the bit to be cleared. + * @param memory_order + * The memory order to use. + */ + +__rte_experimental +static inline void +rte_bitset_atomic_clear(uint64_t *bitset, size_t bit_num, int memory_order) +{ + __RTE_BITSET_DELEGATE_N(rte_bit_atomic_clear, bitset, bit_num, + memory_order); +} + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Atomically set or clear a bit in the bitset. + * + * Assign a value to a bit in a bitset as an atomic operation, with + * the specified memory ordering. + * + * rte_bitset_atomic_assign() is multi-thread safe, provided all + * threads acting in parallel on the same bitset does so through + * @c rte_bitset_atomic_*() functions. + * + * Bits are numbered from 0 to (size - 1) (inclusive). + * + * @param bitset + * A pointer to the array of words making up the bitset. + * @param bit_num + * The index of the bit to be set or cleared. + * @param bit_value + * Control if the bit should be set or cleared. + * @param memory_order + * The memory order to use. + */ + +__rte_experimental +static inline void +rte_bitset_atomic_assign(uint64_t *bitset, size_t bit_num, bool bit_value, + int memory_order) +{ + __RTE_BITSET_DELEGATE_N(rte_bit_atomic_assign, bitset, bit_num, + bit_value, memory_order); +} + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Atomically change the value of a bit in the bitset. + * + * Flip a bit in a bitset as an atomic operation, with the specified + * memory ordering. + * + * rte_bitset_atomic_flip() is multi-thread safe, provided all threads + * acting in parallel on the same bitset does so through + * @c rte_bitset_atomic_*() functions. + * + * Bits are numbered from 0 to (size - 1) (inclusive). + * + * @param bitset + * A pointer to the array of words making up the bitset. + * @param bit_num + * The index of the bit to be flipped. + * @param memory_order + * The memory order to use. + */ + +__rte_experimental +static inline void +rte_bitset_atomic_flip(uint64_t *bitset, size_t bit_num, int memory_order) +{ + __RTE_BITSET_DELEGATE_N(rte_bit_atomic_flip, bitset, bit_num, + memory_order); +} + /** * @warning * @b EXPERIMENTAL: this API may change without prior notice.