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 2E90C43F49; Mon, 29 Apr 2024 12:02:05 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0F1A7402B3; Mon, 29 Apr 2024 12:02:05 +0200 (CEST) Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on2083.outbound.protection.outlook.com [40.107.15.83]) by mails.dpdk.org (Postfix) with ESMTP id D8664402A3 for ; Mon, 29 Apr 2024 12:02:03 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gO/jiEJzEVuE/xUzFwYchf5s6JvPinBm3b7RwMnPEKvskqyLo9YRDTj88+3GtvEEtbEk2mlyvFiPEJAz6mzdHPgyRS9vtwyebg0gHpGFLPU25F9bwaQQcLGJrKW5c7494xgr+N1/HZAbYcvob7uluqqwQQlN5v5fCxvqUfRwOO2XfdPey/fJeFagDvzFytUbh98P/GAulkk2BBFfsX8KCzJz4Xl/ds45oXJ3AGn8WG+aI0tSVklAE1xJT7Cta+x75/Vw4hOS5N6NZAiCTpcryNbsvjfhVd8vbqVaPWGrf4+TuqWWUTrT+djzVg2d8vlLjg12yju34p2gP52uLUIlcQ== 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=mUJjyh9tzcUVJ8DQDrL/G2qoaq+8lcDY3yhc95JMI+g=; b=HybKqDhII9ky+HmvW3tZ9XJjEQNKOFSdbRA+C0FNNpI8FFXy5OhmhCFug9VfzMQfFITaIzbdjGFskpW6nKvH4ulgnZD35bpZbOeUL5j9QXKX9AVX8PeDEveHdWcR8Cf4D2Zi9HleLLCYd9Zi/tJ9NK1ArPlKCzxymvR0KDLF9DC0DcxCc0aUpS8NhPPYaVOo82loJsHvFIWSBXRmy9SXor4tlRPMCHdB8mgEzHP7Ypu51plXSTAn5cb8cmjlrDpEl/NWwe3VZbw0m4asexdw614c3Z1O63IrIlmFn0BBq3zoDnMohMNQ8EsV2Tdzpgp1uTweG7Umms6VCiDRFLXM7g== 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=mUJjyh9tzcUVJ8DQDrL/G2qoaq+8lcDY3yhc95JMI+g=; b=wRAr38tBJZYQ+Kkh1VruAD26I8AjCPlcVMzWnWMmTmcUEdubPmd2DU6AJo74MB5LDVvRD4WvK2nJZnlHBzcz95KT0mcyoHNoo8ErKoODVlKsYCBJ2zJKITHsKfhjRCPKsJiW3e3BvN1RWRDBibnJ0ICPkPsWhlV1rTgxOIxAdb0iCkLHiWoesTPYKTi0QdJq69XKmsS7Qj4irNopfG5U+EdmxzYa6oPgTePvJi6u9pMcqGzsGRM+DIx6T8EqY916miy4MLt/H9UkjBtBM+8xw4QLSYZiVF/5wzoCpoIe8FVUvGOUcUUH8+Pp4CCDEOx9FcJAHfUClvUlobJ6rx+31w== Received: from DU2PR04CA0044.eurprd04.prod.outlook.com (2603:10a6:10:234::19) by DUZPR07MB10078.eurprd07.prod.outlook.com (2603:10a6:10:4de::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.34; Mon, 29 Apr 2024 10:02:02 +0000 Received: from DU2PEPF0001E9C1.eurprd03.prod.outlook.com (2603:10a6:10:234:cafe::df) by DU2PR04CA0044.outlook.office365.com (2603:10a6:10:234::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.34 via Frontend Transport; Mon, 29 Apr 2024 10:02:02 +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 DU2PEPF0001E9C1.mail.protection.outlook.com (10.167.8.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.19 via Frontend Transport; Mon, 29 Apr 2024 10:02:02 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.65) with Microsoft SMTP Server id 15.2.1544.9; Mon, 29 Apr 2024 12:02:01 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 6F8731C006D; Mon, 29 Apr 2024 12:02:01 +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 v3 0/6] Improve EAL bit operations API Date: Mon, 29 Apr 2024 11:51:32 +0200 Message-ID: <20240429095138.106849-1-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240425085853.97888-2-mattias.ronnblom@ericsson.com> References: <20240425085853.97888-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: DU2PEPF0001E9C1:EE_|DUZPR07MB10078:EE_ X-MS-Office365-Filtering-Correlation-Id: 00023252-d0ab-4703-94b5-08dc68336ac4 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?Vi9iUTJlYk9zSWpnNW00cmxoSHRjYjlTb3Q1V01Eb0xMS1BTck0wVGdBYy9j?= =?utf-8?B?RWR5aFE1MC9jWFF1OHJqcmR0WFNzOSs4eDkxSHZDaWYrcUJjWjY3b0E1NFQ5?= =?utf-8?B?Tis1QTJFT051OGVIUlFNK0FPWWhJRXZpY2VpMDZ6bkZZUFRSNkZmR2ZSaW13?= =?utf-8?B?YmdybXdxc1NrZ043YmFyWkRMWkNnQ2VkT1prZ3BzSWhackEzbXBLYm1hc0x1?= =?utf-8?B?Z2tlU0o4RTFmTmJzUjBXaHo5Q2ZqYTRjTk1IajZpc2IxcktVMXEvb0l5Z1BY?= =?utf-8?B?SjNmZlRsZ3F6aXNPTE9mVTlvSThGZ3o3d25xd3VFelBYRnpUam1aM3Q4amkr?= =?utf-8?B?aWFHVitWY3hsSW8zcGtKWDE5aXIyTmU1KzlMdjNSSldqajh0aEpnWXRhWHlq?= =?utf-8?B?SEd6RlY0TlpIdnBPY2VzakY4eU5GbzlsdWtmM3FTY3F0dmw2Sytsei9kVkdt?= =?utf-8?B?R3RnL3NFUXNYKzZSZmlYaUNmMFJoMStCTzVVazB5K0VITytjY3I5aUFYdVIx?= =?utf-8?B?SVJWVGFZUEtYZCtJWXhGbVgxQkpBQjgwMyswSjkxZlJyZElUMFJaZ2RVTXBK?= =?utf-8?B?cHQ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y9xeHlkanZMcGt2b0pM?= =?utf-8?B?Y0R0SWY4UlJSMkxHanhUdHgyWUlHNG1JRlFUWTJlNVlCTEJBVEp2R3cwTy9p?= =?utf-8?B?L3RsTzM0M2k4dEwwNTFlOHZraGlLL2IzdGgyc2F6NWs4cjViRmh1dzBxQlNM?= =?utf-8?B?bFhLRklnSUVuZzZoTGlCbW5LdzRGTE1WbGhRd2E4a1Zub1Z3cE04WHNUL2Nk?= =?utf-8?B?Y3BHbG50NHRYWVFLdStnRkR4VWxDcVRVeUFpemIrREtpR3JYYXB1Y0E1OGdk?= =?utf-8?B?dktKeVRwc3dKTE9jUE9XZElLSXRrOFJuTXEzUE9vQTNNcFNGRHVGVERNYk9H?= =?utf-8?B?eHJBdXhvYXVTUjE1U2hZc2YzZ25WcUY0Z0ZKSXBsQ1AyNklHdnlCbjlJZGxR?= =?utf-8?Q?BVud33vUjUvUR?= 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: 29 Apr 2024 10:02:02.2875 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 00023252-d0ab-4703-94b5-08dc68336ac4 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: DU2PEPF0001E9C1.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR07MB10078 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]() 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 generic selection, and 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 | 319 ++++++++++++++- lib/eal/include/rte_bitops.h | 768 ++++++++++++++++++++++++++++++++++- 2 files changed, 1069 insertions(+), 18 deletions(-) -- 2.34.1