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 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=20R=C3=B6nnblom?= To: CC: , =?UTF-8?q?Morten=20Br=C3=B8rup?= , Tyler Retzlaff , Stephen Hemminger , Harry van Haaren , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit 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?B?U20rcUFaZW91SHVjaEFFczRPejVqbEdTbDFkOCs3ZnB6WWdGeGtnRnBmbVpw?= =?utf-8?B?WWhhby9zRmRzZ1V0dFM2Q1hhcEx5SVIxKzlZdldFcSt3blhXR1NHY0RjNzI5?= =?utf-8?B?ZXVQa1hKZ0hFSXNYc25neHY4NTA2VHowVlJsTHU2OW8rWUNqV21OQ1BDMnVX?= =?utf-8?B?RUFjUjNKOVQ0ZHY4cVlNbitCVGMxY1hpRzIyY3BBTFRuQTZ4VFFjNE94MWdS?= =?utf-8?B?SUMvQmxaYy91T2RxWjVNT3JMNjE4L3BBQUtVdk5SdmE3Q1FzeWJNTVFydm0z?= =?utf-8?B?MS9ISkQzcWpQTktWOEQ3Zko3WUFQOG1QaTNQd2dnaGpCdWdaOFdueE5aajJN?= =?utf-8?B?L0xqeE1WSUhNd3Fydy83V1F1Vm1Za0U5Y3Jlemppc3o0NHpDbE0xS1BZRDZy?= =?utf-8?B?elBPL2JDOGxibVB5RHhlTFNsajdYSmZCQ1RybW5sNlBqT1pFc3NUOXJkc005?= =?utf-8?B?MnlGVENrVEpnYStqUzFUZ2Y2K1FzMVh4SW1sSDRuRXZ0cWQ5V2Urdm9sZUNR?= =?utf-8?B?aWwrQnFSRmNvSDJYakVoTVVxamZVZkUrdlVHdVFnQ2xjMlBmd3E2MW5ueWZ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o1bE55eExyM2NsaWVRS09pbnBFZ3NY?= =?utf-8?B?a2Z1cXhuQUhtTlBTVnBDMVFobEg0Yi8wR2lrdUxaRVFvLzNzWG94NThXUHdt?= =?utf-8?B?dnVLK0ptUktLTjFVSzA4OVZLRGFkUElTRHhpRFp6N1pYWmErekxkUWVXelZ5?= =?utf-8?B?MmE4RGQwOUlzL3NEOVlPam80MDRZeHRXNTR4Njkwb0dRQUpOcmdhRElDOUMy?= =?utf-8?B?RnhSR1lzRXh1NWFGTHNVb1BmUm5mWU81ZmxGempuTHJZd09GU1Noa05meHp4?= =?utf-8?B?Y21lZEUza0NWOFlWR1BEUDNIeUsrRzFySjF0U2xEcUpuMGN6c1I1QTJZbHZz?= =?utf-8?B?TVBZUUl5UHY4WkcyeVlCS2VtRUdwUXZuWHY1M0E5ZFJJcGc4cDNYbitIVnNa?= =?utf-8?B?SDRUQ1ljV0tldDZlVVBTTnorUGV0bDVyVmZ5R2VpdUhpK2c9PQ==?= 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 --- 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. -- 2.34.1