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 3AD9243F3A; Tue, 30 Apr 2024 12:05:56 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AE64A402A8; Tue, 30 Apr 2024 12:05:55 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2058.outbound.protection.outlook.com [40.107.22.58]) by mails.dpdk.org (Postfix) with ESMTP id B6D1C40262 for ; Tue, 30 Apr 2024 12:05:53 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XqWvYXNcvWCMX/AH13JU0rXHCkBUBJ91GS3U+QL6gazvwBPbvTknqgA2vhWg75ZF5VwhsMRaDHF6QiafAGHUBAoPNvd7AsmNNB0bBrwx4BhQMhbyBV8RJ22LGsT2ZtQb9N51LfIpOIF5qqjwow9RffcTs514Vb3zcz7J84OP8r3K70VLlGW7prSt3ISQ1/esocJLQTO09SxNkF1/P21rjHjvDB08k3VJgERriwK4VTvErBGfMc2b+CKk7a2RXugl4VjL/Td2FO4UtTLvQ2Id5j5yTFlMqbENvNuzfTTM7feytjphm6KDiTnWsps6lxZ5+/vG6X+fNJAfcE1sfqyNrw== 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=LLycexSOdgekjhb4hZTnJbwDzG8QTrUBVIwYbz13uis=; b=QPaaWj4Bw6+vBDEneLCjT93nNoqurevR8S1A83UOMWgdqKEzA4FSItxzbYFwqW2OlYHjKcEX/WwdOYQmQvDHJMo7IkoTLBVD1/1YbxSZwAg8opcIWUVDHqp37XevLzGtlhIgyxCoDqzEXU8A5hZ3+LWcRkAgzHmH3FG5WW9L2JPR2FO41MnX1gfpHcYCo7gobXvT9D7tHRzoww7DN33FNdk27AzMBAFPWUiVGBttAV/NatYTkzEphudJrtPUGjIhiMOeUlTho3BcSzDvXr+a+Ec/bZ5OOvMtYdoNcZWtWtcG3XCosxNH5qxAFxbXBshta8VyktcLUTqw0hgOsdzy7g== 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=LLycexSOdgekjhb4hZTnJbwDzG8QTrUBVIwYbz13uis=; b=zEhmf1PednkZETDS0FRxhh3BXAMNQQUgLqTEjVl82VyPgtVJPNYhT+Pc9RSrXBKxmTEv2ju26ztWQsg+EbC4RWcV25fCdafkvhExnD28migPPvwyi9twcWr8LA0eqJEeQWG0Jq0OVlxQGmjrs0aoqxdQtG6PN+qyYF+W4oKsIUFJ3XxUZ0tg7MyesqOVpuGr0b1o/rl3NAFHMkCwVnEQKRtawOd3bdsuBDsyc8bjORg59hx4wiD3MfmOcH6Q2fnyZ/tc5FFCtaLut2oI8yjwSZpVng/Wp2ZnwuO5JslSt5jgj52ldWmFiLfsRH3Bi0ZbJpHozuFT//uixPA6eUlkAA== Received: from AM6P191CA0074.EURP191.PROD.OUTLOOK.COM (2603:10a6:209:8a::15) by PAWPR07MB9482.eurprd07.prod.outlook.com (2603:10a6:102:35d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.31; Tue, 30 Apr 2024 10:05:52 +0000 Received: from AMS1EPF00000042.eurprd04.prod.outlook.com (2603:10a6:209:8a:cafe::1b) by AM6P191CA0074.outlook.office365.com (2603:10a6:209:8a::15) 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:52 +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:51 +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:51 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 5068B1C006A; Tue, 30 Apr 2024 12:05:51 +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 0/6] Improve EAL bit operations API Date: Tue, 30 Apr 2024 11:55:17 +0200 Message-ID: <20240430095523.108688-1-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240429095138.106849-2-mattias.ronnblom@ericsson.com> References: <20240429095138.106849-2-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_|PAWPR07MB9482:EE_ X-MS-Office365-Filtering-Correlation-Id: a824c6e2-ea54-45fa-0f84-08dc68fd1df3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|1800799015|376005|82310400014|36860700004; X-Microsoft-Antispam-Message-Info: =?utf-8?B?L2xhczFoU1JsaUZWZTAyNTJOWHNsblUxWkRydndCb1VJV2Zra3NMSkRmT2Jx?= =?utf-8?B?c3NDWDJya2wxaEMwUzQ0cUdNOVlZSHoxUVJKS0tYaW9jZWZwWWtJd1NoMXFK?= =?utf-8?B?dDlyUkZsNS9wdTk4d2RuZitmanBEbUNDWmN6MGRtd0taNGZVRTZsbzRZQzl2?= =?utf-8?B?TzFaTHBWTmROZE5hb0g2QXBIVTVqNlVxMWprNWVVajUyTXcvSElMN2hIczky?= =?utf-8?B?U0syNXRVS2RObTdKL2dvenJxM2dVdERqMktWMUt4TWVhN1U3NGpLd3hOa2Rk?= =?utf-8?B?Qit3TVg2aURFYmg3SlFNU084WkRkYUlKeFI4cXVGQ0h4bjg4VDdDQTdxaXRo?= =?utf-8?B?L2Vkb0E1NFRyK3hObXNwTkxJT1drT2lnbWZwMGt3NEc4YVdCS1drbTJIVjBO?= =?utf-8?B?Nk84UEExd0Y3dWpFeVZOOC9xMnVsRzVuN040T0RMY0ZlYWIwVkxsd2pMMXdp?= =?utf-8?B?OEFiZC8rcDcrb0piK3p4TllLRkx5YjVpUHhiVWwySTA2NTdMNU5ZazJVRStD?= =?utf-8?B?d0psTlBURkkwdVRMVndBay9BVkozS3YwekxoWG5rd3hvVDRDZ05MRHB5aFRR?= =?utf-8?B?MVhLR3ZJcElSS0xIOW5IM29WUVgzc1VnaWFTK2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2MvbCtQTWo1OGVyeVlBTXprc1JlS1NV?= =?utf-8?B?aVl3ZllVcHg3eWgwTm5XdTlpaUlQVzQyU2VQSGZwaUFtSjVwUFNOeUoxZko1?= =?utf-8?B?dUhLTkt0ZGhLT2RCdC9uc1NZdDNSeGora0xXWUVQaUcvR3hKQnVnUmFLLytP?= =?utf-8?B?bS9xeVg3RHMrWjhaR2NOMVdhSXVNSHllN05JYnRieDUva1VFRndhSUV0YmFk?= =?utf-8?B?ZkYwMGVhUXJHY0NZSlJ0MzZMN2pjZldwWmZjNmY1NGtlNDZUbDkvZXc0UWdv?= =?utf-8?B?YTlSdjhadGw3bUh2K2JDeDI0UzBneWpWSGxHMWxZR2hDMkJjS1NHZnJmMXhy?= =?utf-8?Q?h4xkTMUgoP3kz?= 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)(376005)(82310400014)(36860700004); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2024 10:05:51.7782 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a824c6e2-ea54-45fa-0f84-08dc68fd1df3 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: PAWPR07MB9482 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 This patch set represent an attempt to improve and extend the RTE bitops API, in particular for functions that operate on individual bits. All new functionality is exposed to the user as generic selection macros, delegating the actual work to private (__-marked) static inline functions. Public functions (e.g., rte_bit_set32()) would just be bloating the API. Such generic selection macros will here be referred to as "functions", although technically they are not. The legacy rte_bit_relaxed_*() family of functions is replaced with three families: rte_bit_[test|set|clear|assign|flip]() which provides no memory ordering or atomicity guarantees and no read-once or write-once semantics (e.g., no use of volatile), but does provide the best performance. The performance degradation resulting from the use of volatile (e.g., forcing loads and stores to actually occur and in the number specified) and atomic (e.g., LOCK-prefixed instructions on x86) may be significant. rte_bit_once_*() which guarantees program-level load and stores actually occurring (i.e., prevents certain optimizations). The primary use of these functions are in the context of memory mapped I/O. Feedback on the details (semantics, naming) here would be greatly appreciated, since the author is not much of a driver developer. rte_bit_atomic_*() which provides atomic bit-level operations, including the possibility to specifying memory ordering constraints (or the lack thereof). The atomic functions take non-_Atomic pointers, to be flexible, just like the GCC builtins and default . The issue with _Atomic APIs is that it may well be the case that the user wants to perform both non-atomic and atomic operations on the same word. Having _Atomic-marked addresses would complicate supporting atomic bit-level operations in the bitset API (proposed in a different RFC patchset), and potentially other APIs depending on RTE bitops for atomic bit-level ops). Either one needs two bitset variants, one _Atomic bitset and one non-atomic one, or the bitset code needs to cast the non-_Atomic pointer to an _Atomic one. Having a separate _Atomic bitset would be bloat and also prevent the user from both, in some situations, doing atomic operations against a bit set, while in other situations (e.g., at times when MT safety is not a concern) operating on the same objects in a non-atomic manner. Unlike rte_bit_relaxed_*(), individual bits are represented by bool, not uint32_t or uint64_t. The author found the use of such large types confusing, and also failed to see any performance benefits. A set of functions rte_bit_*_assign() are added, to assign a particular boolean value to a particular bit. All new functions have properly documented semantics. All new functions operate on both 32 and 64-bit words, with type checking. _Generic allow the user code to be a little more impact. Have a type-generic atomic test/set/clear/assign bit API also seems consistent with the "core" (word-size) atomics API, which is generic (both GCC builtins and are). The _Generic versions avoids having explicit unsigned long versions of all functions. If you have an unsigned long, it's safe to use the generic version (e.g., rte_set_bit()) and _Generic will pick the right function, provided long is either 32 or 64 bit on your platform (which it is on all DPDK-supported ABIs). The generic rte_bit_set() is a macro, and not a function, but nevertheless has been given a lower-case name. That's how C11 does it (for atomics, and other _Generic), and . Its address can't be taken, but it does not evaluate its parameters more than once. C++ doesn't support generic selection. In C++ translation units the _Generic macros are replaced with overloaded functions. Things that are left out of this patch set, that may be included in future versions: * Have all functions returning a bit number have the same return type (i.e., unsigned int). * Harmonize naming of some GCC builtin wrappers (i.e., rte_fls_u32()). * Add __builtin_ffsll()/ffs() wrapper and potentially other wrappers for useful/used bit-level GCC builtins. * Eliminate the MSVC #ifdef-induced documentation duplication. * _Generic versions of things like rte_popcount32(). (?) Mattias Rönnblom (6): eal: extend bit manipulation functionality eal: add unit tests for bit operations eal: add exactly-once bit access functions eal: add unit tests for exactly-once bit access functions eal: add atomic bit operations eal: add unit tests for atomic bit access functions app/test/test_bitops.c | 405 ++++++++++++- lib/eal/include/rte_bitops.h | 1070 +++++++++++++++++++++++++++++++++- 2 files changed, 1457 insertions(+), 18 deletions(-) -- 2.34.1