From patchwork Thu Apr 25 08:58:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Mattias_R=C3=B6nnblom?= X-Patchwork-Id: 889 Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org 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_R=C3=B6nnblom?= To: CC: , Heng Wang , "Stephen Hemminger" , Tyler Retzlaff , =?utf-8?q?Mattias_R=C3=B6nnb?= =?utf-8?q?lom?= 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 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?q?rp32MFLUit3ISkDBc3ccjPveTmOaZA4?= =?utf-8?q?26anTit+tqBApb7x3pSCrpjxkRDi9VhgWkIbJEhvnVwkeXvoS57ZuDp80TrOgvkMf?= =?utf-8?q?ePZrs+RiyJK4pSBJHn8JBpVuvoxXP/5gSjNoPB3l/xVcohMrtyACQvFi7067LlwaR?= =?utf-8?q?9LCnagXGQhKJhu6v3pCpSAr3qdfqiNBIOlyBgAyb5qLJvUDYkd/dyHJEr0zwjvJMr?= =?utf-8?q?r3n1YaQ0cG0t4AlK99p9L7MnHsMQuLWQPyO+xHOMsY5nrBsC9Og9aNyVldq8+Vx1Z?= =?utf-8?q?DceuM9AGbmv8boLulJsPwhbU8dOFN7QMjneI29CIMMAuksZ95XreJ21aQZ/gk5h8F?= =?utf-8?q?R30DyOnDAz9JTKj44ADAxl3Drs+GP4gAE8U8mMg51nzR+cC+Q/YUoANQMLzIhRKXm?= =?utf-8?q?hC6L3iGE9w9BRI0AO8N9B6jjH00055YjAkqGmrtkjWh17r0YsLDidhILqyMzogENf?= =?utf-8?q?dTaeB32HWPLc/SnrA9hntY4ddGvY7nglJR/M+i7No2MDwmu/+ZNCFJBwtP9JTMVj8?= =?utf-8?q?VqiQitRX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; 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(-)