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 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=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: [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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit 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?B?N3pMM3RjNWlZbGtsellSZ04rT0x6clNtUlF5SzVRM1VDdFlBY3VCSDRLSHc2?= =?utf-8?B?bW5zL1JjUnROWFZUTmMzTnZ3Z2ZtaVJZbXNCWTVwbzFwSmJSdVZuVUdwbnFo?= =?utf-8?B?Y2d1bURpTUNqbSttODJMNWtEZUJQSjV6cHZEWTB2YXJoZ0lQQVpIVHFib2xD?= =?utf-8?B?SGNobXVWbmZOV2o5Z2k4aFJkMXVjNkVXaG5YbjFsUmcwYUQ1N3V0K2F1b0J6?= =?utf-8?B?SkdNd0lubzl4cG5nZkFTUjZIbngwYjlqdWlEMEF0Sml3d2FWN3crbTdncFh4?= =?utf-8?B?c3F5cVVnV0tsRzZvanEySnl4WldoNTg4ODJjM2JXT1BkZnpVVDRWeTg2K3BY?= =?utf-8?B?eldZakV2SmFTa2JGcEJHajZlbnRDNGl4dVBjVmkzVkhvWjcrSnI5SU9rVlQy?= =?utf-8?B?aEJBanc4WVo3S3NkTU5WaWIzRTFFZnpOY3VlSWUrd3dnR1A0bW5yekRQeVBX?= =?utf-8?B?NlNlMldCQXRudlI3TTdiditxa3ZMUUJmLzhYSDBmK05VemRLYlRnM2xDKzJC?= =?utf-8?B?RllvRHA5dXkwbWc4aHNnMTF4cnE1TzdlSTJOckdOSnJLam96Mkp1MTF0QWg1?= =?utf-8?B?cEw3RktGbXA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XM1?= =?utf-8?B?SnQ2SUx3d3hiR1E5LzFYOHZJWTRybGFBeHBMb0hDWGZzWW9EeUdBMFA3eXQ4?= =?utf-8?B?N3NYSm5pWjF4b0NvOW15aVVFdUJZRDNWdllON2JBU2xOTTRsUlAwUnAyUko0?= =?utf-8?B?SzB3ZTNkTHpxam1GbVBZMytQejhDWXQ3N2MwMlloanFUSHR4dHN4SXlXWnZa?= =?utf-8?B?TDBOQkNuWHU4dTlEcFkrZENDM2VqNCsrQmxDbzVPa0c0R3FQN1ZrejU2TG9L?= =?utf-8?B?STQ3MHpWMHNzVDFNcms2ZkdOSTduSFdGWlVLWEg2MzNnM2YrS2lMcWM5djd0?= =?utf-8?Q?Foz/6y7/NJeqJPIfEwz/cLHTjkyCVBO/yeT7A=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:(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. -- 2.34.1