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 416F243F04; Thu, 25 Apr 2024 11:09:23 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BACD9436B3; Thu, 25 Apr 2024 11:09:22 +0200 (CEST) Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2083.outbound.protection.outlook.com [40.107.13.83]) by mails.dpdk.org (Postfix) with ESMTP id A5997436A5 for ; Thu, 25 Apr 2024 11:09:21 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HHVy24b69MZZdoxjBztlQo18rxg1FNimNnUeFuzJQMnkD6QmI/AFRYuoSbpCN1Xzc46e706baxgm201T+D93La6fgRJQaoXLMDeSgxNDjtExrytcxlXnD5jfP/dPEdLzwb+a63iuC0jQbiY17A7sfFi3eP111dMb+6N0cbmbEI/hk+t34y/ciAIjRQKGzzu66qW1T2cA+pvK0m/ZLISHhOBDQN32QDnSr8ABe+2NDAYj4Rx6CbO1JiQquqKLwE4X7N7UTC4Vm3Ubj8DEVQgU4NXsDho/8yXCjor4ocqUm3yi9tJuUmiEYsCHYdv1KgM7VUPojQ1PEIByJnR9qteV3Q== 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=fefagGg/AMhO+IsnQUFmTKRg7ddMLJ1biyG6VM2Jayo=; b=SQnIQDV0IGGtmIMLDfqBnu1GSyHO6R8vCY1Vq3tzOTU1dWXLZjDqCt6r/Wz50VQn1DSTGox2180kodYvwrCS9LdGoGduHHgNEYZfaqkr8h2cxB8ZaWwnGUO98SJCDr98PZr1WM+2mAfqv5X337C3Eial0nbUUuZ158zoHzDEjkl8/mCcrcNnJ20EV5OoKOcKbudnYIhoXfcgoqJ6MM2sqb5Njj0Xer5AQzZZEYlWIQgbHiFIWwZIzpI/uYJLs5icEizSZiTckkjCWbRV+Gzn3dVGP8diNkaZ1xdqfyrDmuKb5VHTobAp/yH1TGzmaTIQrtKwEhzAGa7OQ5WRD+zOyw== 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=fefagGg/AMhO+IsnQUFmTKRg7ddMLJ1biyG6VM2Jayo=; b=T7LKqUIjDzGDRaVQo/9IH+py3USJUUMIvReAUN3/mNz35ao3A3u3ShZgCgU1zeFMpjfuki23PHLxrRnS02cQDmYR1MmpJXZrH4WfsfYYPvrRJxTnKduy96jzLe85EzIv/6bD3Qpfaj48VAtWWI+4VAOSuLOzYvFYUpUNgExB5yG3icDiX37uUuUDQgMAzkQxMdFsnjaXm+i/KGeqmcG8efvR3oguwUkzYH84gHDUFW8Gv7Y22alTTLK9q36jvIV4l9vFafcUuzVXxP05BNSUNp1iAIqvh6OnTTtc3Erdm3Ht7zzPGJPuclJEOtUdyAM2AvvHuLW3i/Gh0reT2c9oYA== Received: from DU2PR04CA0171.eurprd04.prod.outlook.com (2603:10a6:10:2b0::26) by VI1PR07MB6432.eurprd07.prod.outlook.com (2603:10a6:800:137::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.22; Thu, 25 Apr 2024 09:09:18 +0000 Received: from DU2PEPF00028D0B.eurprd03.prod.outlook.com (2603:10a6:10:2b0:cafe::7b) by DU2PR04CA0171.outlook.office365.com (2603:10a6:10:2b0::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.25 via Frontend Transport; Thu, 25 Apr 2024 09:09:18 +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 DU2PEPF00028D0B.mail.protection.outlook.com (10.167.242.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.19 via Frontend Transport; Thu, 25 Apr 2024 09:09:17 +0000 Received: from seliicinfr00050.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; Thu, 25 Apr 2024 11:09:17 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 559891C006A; Thu, 25 Apr 2024 11:09:17 +0200 (CEST) From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= To: CC: , Heng Wang , "Stephen Hemminger" , Tyler Retzlaff , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Subject: [RFC v2 0/6] Improve EAL bit operations API Date: Thu, 25 Apr 2024 10:58:47 +0200 Message-ID: <20240425085853.97888-1-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240302135328.531940-2-mattias.ronnblom@ericsson.com> References: <20240302135328.531940-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: DU2PEPF00028D0B:EE_|VI1PR07MB6432:EE_ X-MS-Office365-Filtering-Correlation-Id: 6ece8a9a-8f1b-4575-2b10-08dc6507630a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|36860700004|82310400014|376005|1800799015; X-Microsoft-Antispam-Message-Info: =?utf-8?B?cnAzMk1GTFVpdDNJU2tEQmMzY2NqUHZlVG1PYVpBNDI2YW5UaXQrdHFCQXBi?= =?utf-8?B?N3gzcFNDcnBqeGtSRGk5VmhnV2tJYkpFaHZuVndrZVh2b1M1N1p1RHA4MFRy?= =?utf-8?B?T2d2a01mZVBacnMrUml5Sks0cFNCSkhuOEpCcFZ1dm94WFAvNWdTak5vUEIz?= =?utf-8?B?bC94VmNvaE1ydHlBQ1F2Rmk3MDY3TGx3YVI5TENuYWdYR1FoS0podTZ2M3BD?= =?utf-8?B?cFNBcjNxZGZxaU5CSU9seUJnQXliNXFMSnZVRFlrZC9keUhKRXIwendqdkpN?= =?utf-8?B?cnIzbjFZYVEwY0cwdDRBbEs5OXA5TDdNbkhzTVF1TFdRUHlPK3hIT01zWTVu?= =?utf-8?B?ckJzQzlPZzlhTnlWbGRxOCtWeDFaRGNldU05QUdibXY4Ym9MdWxKc1B3aGJV?= =?utf-8?B?OGRPRk43UU1qbmVJMjlDSU1NQXVrc1o5NVhyZUoyMWFRWi9nazVoOEZSMzBE?= =?utf-8?B?eU9uREF6OUpUS2o0NEFEQXhsM0RycytHUDRnQUU4VThtTWc1MW56UitjQytR?= =?utf-8?B?L1lVb0FOUU1MekloUktYbWhDNkwzaUdFOXc5QlJJMEFPOE45QjZqakgwMDA1?= =?utf-8?B?NVlqQWtxR21ydGtqV2gxN3IwWXNMRGlkaElMcXlNem9nRU5mZFRhZUIzMkhX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3SFAw?= =?utf-8?B?Nnp6cW1odDlFMkpqcHRGUjIvRzJCZmhSZkhBSU9SZXh6UzhEZ1RkclRNNTFJ?= =?utf-8?B?R21aWldLUG4rdncrM2JjZk1WcFFaVEZlN0pzSHFOV3I5cU5KSUM2NHN4SlAy?= =?utf-8?B?bnZJQXp3bWw4ZkM3NU50TjlRQnFqNUErT3lFTjgxTHBpZVlIMk8yMERrMVMz?= =?utf-8?B?RTFBUDJBMGJFT2tVY2RTSUVIMzJ4aE5PK1pGak45SHNHYXM1ZzVoL0htckhS?= =?utf-8?B?dzZRSUg3REgwZ1BpTy9aTVNpV0FVdU5iMU1BYStFKzZDT0p6Y29PcDAzTXhw?= =?utf-8?Q?wbS6wzQhtVpbg?= 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)(36860700004)(82310400014)(376005)(1800799015); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Apr 2024 09:09:17.9773 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6ece8a9a-8f1b-4575-2b10-08dc6507630a 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: DU2PEPF00028D0B.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB6432 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 (or more correctly, generic selection macros) 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. 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 | 624 ++++++++++++++++++++++++++++++++++- 2 files changed, 925 insertions(+), 18 deletions(-) -- 2.34.1