From patchwork Sun May 5 07:33:10 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: 139862 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 404C343FAC; Sun, 5 May 2024 09:43:43 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9C84C402E1; Sun, 5 May 2024 09:43:38 +0200 (CEST) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2081.outbound.protection.outlook.com [40.107.14.81]) by mails.dpdk.org (Postfix) with ESMTP id 415024025D for ; Sun, 5 May 2024 09:43:36 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b+m/w39QFRggUL9MXYXUSi8ezR+NQ07SC6pXtdAoTFtgzQ2feKhdIR/gYmxjcJgjALo/Ds0IkKWSvvr9CLi3wqnI8Y80OywhA8PSFSqZ8WpneYeO7f30GSosswLxEJvwoRUxeArZca3DzCVkA23oW0r5g8fn/dchtugwjJRWj2WYZjwH5RyRlRwHFNl9Oggcjs1pOrOH8rSXkvwmqR9+i+qhL6B2k7AepukD8In1NI5XQzR6HMIp5o7zj5bwO9m1Ksi9vA5+5rEM+b4gcuOboAKP8nEQp1Cna32Ojz1YlEOncHiEkiumcFj1PsPOQmZaxBgyLdevUQHMu/TuknMZTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=Nh56iDndiaY0mp+ftcihY7xXJZMBXUtm0ytrVooWdMWaxosc4ZwYlVcpy4xhoqTTB5UldZOYtay/VvZ7doNhE+GugEVm0ljb19AmtAc+QPHmcOIt6wHLDW7Q0WN0hdTXqVRvCm6UTmSbKNu9UC7bDXHVOkoGPJ/nrRoAjlWjfDBBsMZFuXEn1vVV+jWGe5L/ilPLjWgTYpPKGEFgrCSSJcIXwM7lcv+QeedsWypAXc8467AS0/0q64J3S9aJ4r/XrwVGBjIbUOpHbDsQD1GfbYXkolWOsbJv0swDMUSgj8elqQjqWy/n+9B6sd+PBQJ42YEzNpKsmkGLX4eL0R85xA== 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=fnMgUoJ3B3XWyKP208pdZVKYoIzKWVIrKtfFdcizysN9c2v5LOFntcge3tYLT2Ktwq/poW4Vq9pshXbwzvQAc43mEk6/rHvwh6nnlIGO4gPOor5ON/8D8B6c3t22V1UNV8l5GE1NrZJ6FWgAD4q1gFMzuU5uVndrjX2oHgtKDlVHh7l5kMeDcwFCiFBCKuxpdz7bKTyBeJanXYAu4xFDtZ0CgRhhbOAkJAme7IVYcrZ+KRyxhf09XRxGdQ259SK26nQ7LAn4rsUUKKsSavqK/+lM3Phsf+SIHUtJLfaT9x6qb9d/vWhjaHfbbMo7hlpNrixLY3Cra9kEUs0CHtsm8g== Received: from AM6PR04CA0001.eurprd04.prod.outlook.com (2603:10a6:20b:92::14) by PAWPR07MB9484.eurprd07.prod.outlook.com (2603:10a6:102:34f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.28; Sun, 5 May 2024 07:43:34 +0000 Received: from AM2PEPF0001C717.eurprd05.prod.outlook.com (2603:10a6:20b:92:cafe::c0) by AM6PR04CA0001.outlook.office365.com (2603:10a6:20b:92::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.40 via Frontend Transport; Sun, 5 May 2024 07:43:34 +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 AM2PEPF0001C717.mail.protection.outlook.com (10.167.16.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.18 via Frontend Transport; Sun, 5 May 2024 07:43:33 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.60) with Microsoft SMTP Server id 15.2.1544.9; Sun, 5 May 2024 09:43:33 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 53A1B38007A; Sun, 5 May 2024 09:43:33 +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: [RFC v5 3/6] eal: add atomic bitset functions Date: Sun, 5 May 2024 09:33:10 +0200 Message-ID: <20240505073313.118515-3-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240505073313.118515-1-mattias.ronnblom@ericsson.com> References: <20240216102348.480407-1-mattias.ronnblom@ericsson.com> <20240505073313.118515-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM2PEPF0001C717:EE_|PAWPR07MB9484:EE_ X-MS-Office365-Filtering-Correlation-Id: 6353fccc-f6bd-4e76-e806-08dc6cd71115 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|376005|1800799015|82310400017|36860700004; X-Microsoft-Antispam-Message-Info: =?utf-8?q?7zL3tc5iYlklzYRgN+OLzrSmRQyK5Q3?= =?utf-8?q?UCtYAcuBH4KHw6mns/RcRtNXVTNc3NvwgfmiRYmsBY5po1pJbRuVnUGpnqhcgumDi?= =?utf-8?q?MCjm+m82L5kDeBPJ5zpvDY0varhgIPAZHTqbolCHchmuVnfNWj9gi8hRd1uc6EWhn?= =?utf-8?q?Xn1lRg0aD57ut+auoBzJGMwIno9xpngfASR6Hnx0b9juiD0AtJiwwaV7w+m7gpXxs?= =?utf-8?q?qyqUgWKlG6ojq2JyxZWh58882c3bWOPdfzUT4Vy86+pXzWYjEvJaSkbFpBGj6entC?= =?utf-8?q?4ixuPcVi3VHoZ7+Jr9IOkVT2hBAjw8YZ7KsdMNVib3E1EfzNcueIe+wwgGP4mnrzD?= =?utf-8?q?PyPW6Se2WBAtnvR7M7bv+qkvLQBf/8XH0f+NUzdKbTg3lC+2BFYoDp9uy0mg8hsg1?= =?utf-8?q?1xrq5O7eI2NrGNJrKjoz2Ju11tAh5pL7FKFmp/cBevvCETrBn/WPmmcrZqGdSh7Bx?= =?utf-8?q?qqz8Z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.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:(13230031)(376005)(1800799015)(82310400017)(36860700004); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2024 07:43:33.9403 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6353fccc-f6bd-4e76-e806-08dc6cd71115 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: AM2PEPF0001C717.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR07MB9484 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.