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 6A5AE45778; Fri, 9 Aug 2024 12:08:08 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D177742EE0; Fri, 9 Aug 2024 12:08:07 +0200 (CEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2058.outbound.protection.outlook.com [40.107.20.58]) by mails.dpdk.org (Postfix) with ESMTP id 0A00E402C4 for ; Fri, 9 Aug 2024 12:08:05 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TGzcYpacX3w1qInP/cNyZ6QIimdXyiUAjS4pRcgKm/U8v7KgJuUBgFvp3chrJ4lggfPQV3f5zHS2YX59X07aRqqO4nOxdTGkLit6njOaI2ULiNTgAYhJWhD+pe9U8EYSzg88EbI6mPlLgxVD6sMLA3rlZeWSdSIZlzm680x0d55ovx3iVsLMUcqG1aPK6f0KuwuTF4mCJkWkcQVhMiaJCTgfSubiOPYLryBkIGResidkg7E7iyLA2joeBprR39zs0/Ld5HARVq2Fu2PoYgmG2AtlQK1g1X2sdMk0uvD5yCEdh7iIYWR8AvumsSa2dT4WPhdtFWoskEybC/HJjQLVdQ== 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=MMUN4N47gXKkOSZkq5IDkwMCtBWh8AgRAWT36IgszZg=; b=SIV5mOUcPjcsl/kmGhTMO5rBa2ZAE/C+r8tfyiLil5QIOigZgKOwsBaLFkBSk322owWfL+avjf/HlpV/GftgEQhI+CmwDwHrOwZ+6jIV9qjPfUvGICCBnLQjAxlH51ZfoK7SIvTE5lMSy8WBV/fc9ekBrW4neYavqEogvCn9uCpTFMk3NU2ktpkqHehDpw5y+CVJjkZGipIAsw3ZOCB0OfF6+cXjciT2/4Z8JsJBjYP9Mf0L12NpRWpiy5EUB/KrEteoR7i/EkDiTTDiNNmZaoe8FjJeBkz2QqWdhZZQwuxWo//dbkSQZFOrXchDVsU9bQqYmH+sBd+peC+PD/r7HQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 192.176.1.74) smtp.rcpttodomain=arm.com 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=MMUN4N47gXKkOSZkq5IDkwMCtBWh8AgRAWT36IgszZg=; b=WN5U3+HCCLJzNNx3qew91i4YbBcGzzNRL/F4vhn7MYjw2VTt2la2Mesr/rMimvQzA8FW3Qs/NYJsQf8MbLn1KT1NCRQoQw0R/h+e7sdtz3DpCOhsx0XBSmcUaG4XwErSJeTN40Xf7pZiEFiuA/nUoLgN8Enp5QGuHYARALb+6Xqe3WcdYhiZyDxrI5AfNt7P2kztnid2X5sfssme1ERw/3ISb2VlgFyRnRtqUcyDqjWlb7A90KDpU86HQCHccz4UUjbhydFyuK0y0qioky+TUOV9F/MRa0oqrLWA6MdCMXydaWiY+1vMqwSLVtSfhodebGdfgtQSkb7wFYaXXO95JQ== Received: from AS9PR01CA0003.eurprd01.prod.exchangelabs.com (2603:10a6:20b:540::7) by PAWPR07MB9467.eurprd07.prod.outlook.com (2603:10a6:102:362::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14; Fri, 9 Aug 2024 10:08:04 +0000 Received: from AMS0EPF000001AE.eurprd05.prod.outlook.com (2603:10a6:20b:540:cafe::99) by AS9PR01CA0003.outlook.office365.com (2603:10a6:20b:540::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.13 via Frontend Transport; Fri, 9 Aug 2024 10:08:04 +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 AMS0EPF000001AE.mail.protection.outlook.com (10.167.16.154) 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 10:08:04 +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.11; Fri, 9 Aug 2024 12:08:03 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 7D94E1C006A; Fri, 9 Aug 2024 12:08:03 +0200 (CEST) From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= To: CC: , Heng Wang , "Stephen Hemminger" , Joyce Kong , Tyler Retzlaff , =?UTF-8?q?Morten=20Br=C3=B8rup?= , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Subject: [PATCH v2 0/5] Improve EAL bit operations API Date: Fri, 9 Aug 2024 11:58:24 +0200 Message-ID: <20240809095829.589396-1-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240809090439.589295-2-mattias.ronnblom@ericsson.com> References: <20240809090439.589295-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: AMS0EPF000001AE:EE_|PAWPR07MB9467:EE_ X-MS-Office365-Filtering-Correlation-Id: adf6a8e6-7766-4c50-ad95-08dcb85b2889 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?WUh5c3N4dElhMzUyQ3J6UjdyMnR4REZKSnRJUFMvdTI0azJSd095RnFKdVI1?= =?utf-8?B?cTFBZ0hoZWN4alNhaExFMHhLa204VS9WaTdubzlSS2dNTjhlVGRsTzhxT2l0?= =?utf-8?B?aUFFTjNvMm9CTDlNWVJJOGk4VDlQSXNiellsTDFiR0VaSHVMN0F6bysxQmhE?= =?utf-8?B?UHA5elBYNithTElGQysrbHZxcWlMSStGMU1QaC8yZnlBZ1VMbGxUbkVuV3pL?= =?utf-8?B?b3JMR2FQdDh1dXo3Z2dvOFY2U2luVjRwQVhpb1FyUGNxNDNtTEltUDNKSms3?= =?utf-8?B?QUJrbW1qRDUrQmp4WjNxU0pGcE5FNlAvUldwWTBSNEQxVWhxbUNRaE1MR3Fx?= =?utf-8?B?Nk9HQytiREpTQ0pBTnU5eWpacU9PcXRBTkRiY2tlZHNJcCtGNU1FdllDV2R3?= =?utf-8?B?SHlOSWYxcXNVOFg3Mkg4K21xbWNxS2NuaXorYnRUR3hiZzBJL3VhTTNlSGFo?= =?utf-8?B?aFJkMHlQZ1B6VTNRdXlkWDMzRWlYa2p4VWNsZWVsRHBYTDM5Q1FiYllFV2RZ?= =?utf-8?B?OWppY3J0bVVsU1UrMTJybFlSeEVOeDkwc1VLNllzbDY3akNzMWl3Tzkwcnkx?= =?utf-8?B?UGVUc0g5SWdnZXN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utf-8?B?bTZtM2p0TkdkR0NmaWN2dzBxVGpyOVRhMEdCZDZIdlNzZGx0VXhpMzZ5bjZ4?= =?utf-8?B?TEJhdUllS3EreTlwc2xJcmFVSmpGL3RIYjlVVVJUUVd0UWt4VmtkK3hKN21n?= =?utf-8?B?MENwaWZXYnE3VEtKVkZvTDJLMzczU3FTbXBoZUtoTGtjTGhYYjhHYnByaEpN?= =?utf-8?B?QzdzMlNrMlVGWDFDTmdMUzlvSldQTnNKRVVMaUxxRmRmVkFicWd6cTloWkMz?= =?utf-8?B?MHBhTTkwRDRqRG43NTlYZEYrWUd4SjlCTDZQaXZsZU40TnBqWVVvelZ1amVz?= =?utf-8?B?U1RpYTA4a1BZZTJoUkZxTmYxS09MN05OTHdwekR6YkJ1bEVlQ1lMRHo5YWNh?= =?utf-8?B?WHFaZjl4bldBSDQ5MHVvdEVGZTVva0k5QSs2RXJuWmtnc1E9PQ==?= 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)(36860700013)(1800799024)(82310400026)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Aug 2024 10:08:04.0945 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: adf6a8e6-7766-4c50-ad95-08dcb85b2889 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: AMS0EPF000001AE.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR07MB9467 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_*() functions is replaced with two new families: rte_bit_[test|set|clear|assign|flip]() which provides no memory ordering or atomicity guarantees, 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_[test|set|clear|assign|flip]() may be used with volatile word pointers, in which case they guarantee that the program-level accesses actually occur. 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, implemented by means of a huge, complicated C macro mess. Mattias Rönnblom (5): eal: extend bit manipulation functionality eal: add unit tests for bit operations eal: add atomic bit operations eal: add unit tests for atomic bit access functions eal: extend bitops to handle volatile pointers app/test/test_bitops.c | 414 ++++++++++++++++++- lib/eal/include/rte_bitops.h | 778 ++++++++++++++++++++++++++++++++++- 2 files changed, 1174 insertions(+), 18 deletions(-) Mattias Rönnblom (5): eal: extend bit manipulation functionality eal: add unit tests for bit operations eal: add atomic bit operations eal: add unit tests for atomic bit access functions eal: extend bitops to handle volatile pointers app/test/test_bitops.c | 416 ++++++++++++++++++- lib/eal/include/rte_bitops.h | 778 ++++++++++++++++++++++++++++++++++- 2 files changed, 1176 insertions(+), 18 deletions(-) -- 2.34.1