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 140CE43F3A; Tue, 30 Apr 2024 12:06:36 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 80E0A402E8; Tue, 30 Apr 2024 12:06:01 +0200 (CEST) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2051.outbound.protection.outlook.com [40.107.21.51]) by mails.dpdk.org (Postfix) with ESMTP id 42601402C6 for ; Tue, 30 Apr 2024 12:05:57 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W3zmAMy0t+jfWd/xSl0b9xEYKTZR27ZHQNw8YeHUyfIvATM/W2WNdWEIY0gqC2i7T2ph9zqb2mzEuAoRX7God4kNQeIrLoaUt34H0qWDo20yiCWBnPWTJ2obItbUjobJmGdPL3Np8wQ0XeAmcNtg4zy57HLV+OBDEPvig0urAzRq0jJQlHglDJXe/fW08MNSF+ipNybbqznFw/VTacQ0bN8jaTkaxaFbQ8cR02h/AXfnV1Y0nKK9rIfaoSgn76pAp7EQIOvvnJHcoddMWCfXhpVeLvPuIHGNJf/QaIOzyaMfWq2OpfsJcQwhMBx7z43ANI4IHMJ7sQ9NxQ5Kw3z5iQ== 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=Xbdd4PQDgBRni6OwWxtZoG89tGz9EEnJ4OO6YhM2tjU=; b=Zwb9/gFrnY+DuQDR5SNSKQ0VRJo0PIKUS9k8GUkXHe8mryu8b62zbIYJH3L5MQ+8W6fA7HcaWCPETixBAKrxJfwPFtju3qhCDFDcxN65VJseW5BZZvMicPlsjLwt/eEnxOycYGdHS6XO8wCk3dMV0X9vTIBnQ/CkMHdoDLYAdDxcKr6pWlYNsfYwbKAkhyh58UasVzjOnjkvXXPkwvow9Pm9/GbFNUM5+q3bnazhZX8uH2i2xdOhJMLSmYDovb2OIDTVRHo8vpQjeafQ8CtWx/hgrLKT1XF6vjEa9jb0HlPWTzEVkcIA/rM+ayG/cDi9ogYoj+4Tbb06bEjfCkPtBQ== 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=Xbdd4PQDgBRni6OwWxtZoG89tGz9EEnJ4OO6YhM2tjU=; b=l4j8K6jftGQDx4qaAwL3uqE00RmTQQcE6uOBGlqGgnJVVqPr8W3ez92f4FzqKDbsWrDLRjOC+pOUrLT1AZ73hlOqbFeXs+NN78GLaWJbB6velTvz9Ms0ho9bTA4k5ae4iyrnZ8ROglaD3PbB6cVNPKO3XDXa/hfcue7ur8YVEkv9ISJWXiQ8IS6M/TNTphQ+JKj5M51bbXa0mYcfS2h4yHZMlhfdJ8+l7ctZaRmjD7EfeHsabFMk/3YuLBY0tQvtDPCwydxgUs5CY1Os747dJQcAk/zbkBXcn5fxgxXxHwoAPNLizp7SkTOxoJGm6g379pqNyypW/tDuB7+i8e7Vpw== Received: from AM6P191CA0107.EURP191.PROD.OUTLOOK.COM (2603:10a6:209:8a::48) by DBAPR07MB6808.eurprd07.prod.outlook.com (2603:10a6:10:17f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.36; Tue, 30 Apr 2024 10:05:55 +0000 Received: from AMS1EPF00000042.eurprd04.prod.outlook.com (2603:10a6:209:8a:cafe::74) by AM6P191CA0107.outlook.office365.com (2603:10a6:209:8a::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.36 via Frontend Transport; Tue, 30 Apr 2024 10:05:55 +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 AMS1EPF00000042.mail.protection.outlook.com (10.167.16.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.18 via Frontend Transport; Tue, 30 Apr 2024 10:05:55 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.62) with Microsoft SMTP Server id 15.2.1544.9; Tue, 30 Apr 2024 12:05:54 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 5174D1C006A; Tue, 30 Apr 2024 12:05:54 +0200 (CEST) From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= To: CC: , Heng Wang , "Stephen Hemminger" , Tyler Retzlaff , =?UTF-8?q?Morten=20Br=C3=B8rup?= , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Subject: [RFC v4 5/6] eal: add atomic bit operations Date: Tue, 30 Apr 2024 11:55:22 +0200 Message-ID: <20240430095523.108688-6-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240430095523.108688-1-mattias.ronnblom@ericsson.com> References: <20240429095138.106849-2-mattias.ronnblom@ericsson.com> <20240430095523.108688-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: AMS1EPF00000042:EE_|DBAPR07MB6808:EE_ X-MS-Office365-Filtering-Correlation-Id: 12c161ac-c0a4-4acc-9249-08dc68fd201e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|1800799015|82310400014|36860700004|376005; X-Microsoft-Antispam-Message-Info: =?utf-8?B?TTlyaWo5K2huaG5oMXYxZlJNaVhZN3ZCSWVpSVozKy9PZXI1WFhkdlNWRkFC?= =?utf-8?B?SDVXZjh4Z0VQd2k4WUdsMWVPcDVjODZBRUNvUEZnMENrU3pYOHFQNlJvQjl5?= =?utf-8?B?dVZIeW9zV3ZKSGF1V1Rib0dmdkZhNlZkR3ZjNXNCUEtkWGJ2T1lET1pJelE2?= =?utf-8?B?THVlemFvL0g2MTB6SEVxbkZOamwzYjUrNG5TOWxmcWFieWkydzNXM0U4eXMy?= =?utf-8?B?ZlNpVitpdzFBRk9zL1B6c21DVDc4c2VSN2VMNEhVV2t2Vm1BRWtBNzZBSUVL?= =?utf-8?B?RmpEWVJRNU00MTJBVHB6QVE2VmxxNlpjZzQrRGd4bWg2T001ZUwyMkZIREZ3?= =?utf-8?B?eXdCQmYyUmFiOXJ1NzBEaVFWb01YSE00eEhSSm1uc1BPbng3YUZYQmFhRE4x?= =?utf-8?B?QVk5bk9wYVh3cXY2Ui95NUlmTllVcDFzSXN0QWhnOFhFSVZnRlh0M29ndTdD?= =?utf-8?B?Wm1EL2lQbi9lNEt3c3l2R2FZZW5OQkRCRWpsVHREakNTeFp6RUhoa1o0L2Vy?= =?utf-8?B?VnhrRDhJcitTd0U0QUwyM043Uks5SmVNN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OGdGWThIUUNTNzZvL3hsVXc4aXBqUWxx?= =?utf-8?B?NDBqMlkyaTVsQTFJQmRBc2oweGdETDFlK0tSY0tFcG9FNjhzN01aeU40L1Vw?= =?utf-8?B?U3JsU0wwK0kvM0MxV24rQmdsamdrY2RabTNYRXdBdDlqUDZSd2k4RjcxZXBX?= =?utf-8?B?M25wZDE5UFgyTzBKRURraWxTSjJ3TERYaHowMkpXQUo5dHluek5OejBYc1lV?= =?utf-8?B?WkF3ZzkrZGZ6aTIyYkxZS1ZhY3RlaGhmdTR4eGhickozTzgrQTBteGkwdjI5?= =?utf-8?B?bkVjL0pXcjZCdFlJTC9pbkY3bm9iNzZYcTJ6N1hxTmFPTWp3eUV5TDRrOTB4?= =?utf-8?B?eU9HMmhRTjYwQk1TNEVLd2ZlRXZrdVFscGtLTjZoOXYxV0NqRWdob20yKy9Z?= =?utf-8?Q?Mt/YNE6ukfbp4?= 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)(1800799015)(82310400014)(36860700004)(376005); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2024 10:05:55.4188 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 12c161ac-c0a4-4acc-9249-08dc68fd201e 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: AMS1EPF00000042.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR07MB6808 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 Add atomic bit test/set/clear/assign and test-and-set/clear functions. All atomic bit functions allow (and indeed, require) the caller to specify a memory order. RFC v4: * Add atomic bit flip. * Mark macro-generated private functions experimental. RFC v3: * Work around lack of C++ support for _Generic (Tyler Retzlaff). RFC v2: o Add rte_bit_atomic_test_and_assign() (for consistency). o Fix bugs in rte_bit_atomic_test_and_[set|clear](). o Use to support MSVC. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup Acked-by: Tyler Retzlaff --- lib/eal/include/rte_bitops.h | 194 +++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) diff --git a/lib/eal/include/rte_bitops.h b/lib/eal/include/rte_bitops.h index abfe96d531..f014bd913e 100644 --- a/lib/eal/include/rte_bitops.h +++ b/lib/eal/include/rte_bitops.h @@ -589,6 +589,199 @@ extern "C" { value, \ memory_order) +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Test if a particular bit in a word is set with a particular memory + * order. + * + * Test a bit with the resulting memory load ordered as per the + * specified memory order. + * + * @param addr + * A pointer to the word to query. + * @param nr + * The index of the bit. + * @param memory_order + * The memory order to use. See for details. + * @return + * Returns true if the bit is set, and false otherwise. + */ +#define rte_bit_atomic_test(addr, nr, memory_order) \ + _Generic((addr), \ + uint32_t *: __rte_bit_atomic_test32, \ + uint64_t *: __rte_bit_atomic_test64)(addr, nr, memory_order) + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Atomically set bit in word. + * + * Atomically set bit specified by @c nr in the word pointed to by @c + * addr to '1', with the memory ordering as specified by @c + * memory_order. + * + * @param addr + * A pointer to the word to modify. + * @param nr + * The index of the bit. + * @param memory_order + * The memory order to use. See for details. + */ +#define rte_bit_atomic_set(addr, nr, memory_order) \ + _Generic((addr), \ + uint32_t *: __rte_bit_atomic_set32, \ + uint64_t *: __rte_bit_atomic_set64)(addr, nr, memory_order) + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Atomically clear bit in word. + * + * Atomically set bit specified by @c nr in the word pointed to by @c + * addr to '0', with the memory ordering as specified by @c + * memory_order. + * + * @param addr + * A pointer to the word to modify. + * @param nr + * The index of the bit. + * @param memory_order + * The memory order to use. See for details. + */ +#define rte_bit_atomic_clear(addr, nr, memory_order) \ + _Generic((addr), \ + uint32_t *: __rte_bit_atomic_clear32, \ + uint64_t *: __rte_bit_atomic_clear64)(addr, nr, memory_order) + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Atomically assign a value to bit in word. + * + * Atomically set bit specified by @c nr in the word pointed to by @c + * addr to the value indicated by @c value, with the memory ordering + * as specified with @c memory_order. + * + * @param addr + * A pointer to the word to modify. + * @param nr + * The index of the bit. + * @param value + * The new value of the bit - true for '1', or false for '0'. + * @param memory_order + * The memory order to use. See for details. + */ +#define rte_bit_atomic_assign(addr, nr, value, memory_order) \ + _Generic((addr), \ + uint32_t *: __rte_bit_atomic_assign32, \ + uint64_t *: __rte_bit_atomic_assign64)(addr, nr, value, \ + memory_order) + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Atomically flip bit in word. + * + * Atomically negate the value of the bit specified by @c nr in the + * word pointed to by @c addr to the value indicated by @c value, with + * the memory ordering as specified with @c memory_order. + * + * @param addr + * A pointer to the word to modify. + * @param nr + * The index of the bit. + * @param memory_order + * The memory order to use. See for details. + */ +#define rte_bit_atomic_flip(addr, nr, memory_order) \ + _Generic((addr), \ + uint32_t *: __rte_bit_atomic_flip32, \ + uint64_t *: __rte_bit_atomic_flip64)(addr, nr, memory_order) + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Atomically test and set a bit in word. + * + * Atomically test and set bit specified by @c nr in the word pointed + * to by @c addr to '1', with the memory ordering as specified with @c + * memory_order. + * + * @param addr + * A pointer to the word to modify. + * @param nr + * The index of the bit. + * @param memory_order + * The memory order to use. See for details. + * @return + * Returns true if the bit was set, and false otherwise. + */ +#define rte_bit_atomic_test_and_set(addr, nr, memory_order) \ + _Generic((addr), \ + uint32_t *: __rte_bit_atomic_test_and_set32, \ + uint64_t *: __rte_bit_atomic_test_and_set64)(addr, nr, \ + memory_order) + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Atomically test and clear a bit in word. + * + * Atomically test and clear bit specified by @c nr in the word + * pointed to by @c addr to '0', with the memory ordering as specified + * with @c memory_order. + * + * @param addr + * A pointer to the word to modify. + * @param nr + * The index of the bit. + * @param memory_order + * The memory order to use. See for details. + * @return + * Returns true if the bit was set, and false otherwise. + */ +#define rte_bit_atomic_test_and_clear(addr, nr, memory_order) \ + _Generic((addr), \ + uint32_t *: __rte_bit_atomic_test_and_clear32, \ + uint64_t *: __rte_bit_atomic_test_and_clear64)(addr, nr, \ + memory_order) + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Atomically test and assign a bit in word. + * + * Atomically test and assign bit specified by @c nr in the word + * pointed to by @c addr the value specified by @c value, with the + * memory ordering as specified with @c memory_order. + * + * @param addr + * A pointer to the word to modify. + * @param nr + * The index of the bit. + * @param value + * The new value of the bit - true for '1', or false for '0'. + * @param memory_order + * The memory order to use. See for details. + * @return + * Returns true if the bit was set, and false otherwise. + */ +#define rte_bit_atomic_test_and_assign(addr, nr, value, memory_order) \ + _Generic((addr), \ + uint32_t *: __rte_bit_atomic_test_and_assign32, \ + uint64_t *: __rte_bit_atomic_test_and_assign64)(addr, nr, \ + value, \ + memory_order) + #define __RTE_GEN_BIT_TEST(family, fun, qualifier, size) \ __rte_experimental \ static inline bool \ @@ -1534,6 +1727,7 @@ rte_log2_u64(uint64_t v) #undef rte_bit_atomic_set #undef rte_bit_atomic_clear #undef rte_bit_atomic_assign +#undef rte_bit_atomic_flip #undef rte_bit_atomic_test_and_set #undef rte_bit_atomic_test_and_clear #undef rte_bit_atomic_test_and_assign -- 2.34.1