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 4738043FAE; Sun, 5 May 2024 10:48:00 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D1CD0402DC; Sun, 5 May 2024 10:47:59 +0200 (CEST) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2040.outbound.protection.outlook.com [40.107.7.40]) by mails.dpdk.org (Postfix) with ESMTP id 426C44025D for ; Sun, 5 May 2024 10:47:58 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GFzOGNHsDoXfgBLw7TFcWun57MCep9CQwJYLAKc15+GNmrg8G5Rarz68YxJEY6QuG20GYMa3RAyR4Rd9CBzyJQ6lcj/Jz+t63xt7CEeiQd4Er5YJX7ZjMg1Mf2q+4J2WWcBMh4c5vLW2evRRclwODGd7AL9PCI1mjjXM/4WecJCE2QHZDMBqoFraaLbnxmEPISQrc9L/AljmhW/GWgOWhQ1p7YJ5FMGSUn/RCHZ9A1siRzjfyWgCvNPclc7AdrNmdLXsLwSh9MJrMNnbsM6SDMDh4B2WHkC5mFjZYagAKe8WTFsjFwn7MbbX2yUwJ+MRfVeR+tcBmNQ+zss5ssDXgg== 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=TrkNi/EMndIf2RXpgr/Rb1oquvFMCLGGmtMJsphswBs=; b=AWg4UCf3Za1qhPgJavvdi7CfwSXzaif5PDgg6cQTVZ9DjjPvKSzehhtP+VweRzsy+Z0kNNE6fji0Y3y4nJbSAVCQ3PGs0HgOOUNGUcM/vp0+zL79iAcCPJNo9tJQnzWRxsvgcN3E1hJjgbb2ePwXvw82VMqWRjXSmHTHy2X/ZSQrvBop8mpPG5gFXpgsFwjNriwBr8McFvZ5V5sbpUzOJFZ9laaFWQdRROPhplWaN6XZR0KK9vp4duPT08fkpTqeRZLyqgSCAu6qcZ3p9XJo8fldNIffch9txg531qomJFE/TkGV8i7M4UlUASfNNy6kW9kQ480Wd1FbhC/fvxVAJw== 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=TrkNi/EMndIf2RXpgr/Rb1oquvFMCLGGmtMJsphswBs=; b=NwAhXnEMA90WJHSSdYLfahOXBpqF+EaSURYv6Pk4XRT9Z0Pq1dKK4hWbg5f4tckDlgLCFj50q/Du13odH0bgLwGhLPi4wS7vpCSBpBS/C5klo5tMFjek8upWqq+faSWa0WfABSHhu4pGPJpCn0B5cMoJHocLs0zJbctjj4AeOes3XIJQati7VuuT5st7VkX8EY681fB7bX6ObuEMFLx6/jL4BDjwEscGOZSAGG7Lx/iqkopngJyh8oMPfEeNKiosq6dfMGUKez76IYPBk0aNGfyHEaBDOmyVN2S3wcXxZ2y7O6ybQQcM/5zbHpIifLwe+eZaUEjjuuflcjTq2zjNdg== Received: from AM0PR02CA0031.eurprd02.prod.outlook.com (2603:10a6:208:3e::44) by DUZPR07MB9934.eurprd07.prod.outlook.com (2603:10a6:10:4b2::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.39; Sun, 5 May 2024 08:47:56 +0000 Received: from AM3PEPF00009BA0.eurprd04.prod.outlook.com (2603:10a6:208:3e:cafe::3f) by AM0PR02CA0031.outlook.office365.com (2603:10a6:208:3e::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.40 via Frontend Transport; Sun, 5 May 2024 08:47:56 +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 AM3PEPF00009BA0.mail.protection.outlook.com (10.167.16.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.18 via Frontend Transport; Sun, 5 May 2024 08:47:56 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.68) with Microsoft SMTP Server id 15.2.1544.9; Sun, 5 May 2024 10:47:55 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id A4B7D38007A; Sun, 5 May 2024 10:47:55 +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 v7 0/6] Improve EAL bit operations API Date: Sun, 5 May 2024 10:37:31 +0200 Message-ID: <20240505083737.118649-1-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240502055706.112443-2-mattias.ronnblom@ericsson.com> References: <20240502055706.112443-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: AM3PEPF00009BA0:EE_|DUZPR07MB9934:EE_ X-MS-Office365-Filtering-Correlation-Id: 0837e9a6-41ce-47ab-25ef-08dc6ce00f1b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|82310400017|36860700004|1800799015|376005; X-Microsoft-Antispam-Message-Info: =?utf-8?B?RE9YaGlYT3pNNThqQXk2ZFhFaFNSSUxkSHFPaUFzWVVoNmMyYkw1aWlJeGRE?= =?utf-8?B?eUtMUHRtOFR0SFZ0bWxvVHVpRHdaLzNPOFR1NWk0TWJ1ZXJ3dmVodWRFM0pp?= =?utf-8?B?S20rcFRlMU4xMzJTZjExS3lFZUsyZzJzdVhaNjNTeUNFU0NZeEhDdUJqekFK?= =?utf-8?B?SFhhQ1NHbytVbC8vd3hnVW9uNldQSnJjUFFrWDB2MGthWTJNRk42MkE3cnVF?= =?utf-8?B?aG5FSUJiOVhiMm8ycUpkT3Fxc1FsZDVMQjlVR2ZsNExzUjBsbUo5cGVrL2xJ?= =?utf-8?B?YWp5Yk50ZG4zZXVUc2piZm9zOW9UUnBPUTZjNU1xZElwYnB5cnB6bUtwS2M4?= =?utf-8?B?RUpsSW81MXFZR3QyZzZaNzNKU0VsRE5rM3Q4SFJkMTlXQzY5MnQ2RnNrOXBa?= =?utf-8?B?OXpxZzY1cjh5MnowbU1pZlphLzVuYmhCalBRVWFjZGI1RHVFOHJrM1VuZnY3?= =?utf-8?B?T1BNbUZreWhYa1g2ckhTWHB1bFBncVJsbkJFZ3ZuOGFUMnlJb3hQaGFtZzZl?= =?utf-8?B?am53TjBrNmd5b1BpbDlMUThUMXlkRXJoWUdIYVNuRit3MUx3a29iU1NwR0t5?= =?utf-8?B?dXpWdVJhdmE1R2MreDBBb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FzRTFZZDkxdkczVlVWdW9QVUViMXVpN2xwWHBKait4MXMrMUhBOENU?= =?utf-8?B?aDR5V2FEd2h5Qlp4ZFJzUjg3Vk16RzB6RzU1dVIvbVI4WDE4ZHczdHE1eCtr?= =?utf-8?B?VEU5TzVTNkIySzFLNG4xaFliWUtQOFlYNzMrUTBVazhHVzBPU1RUZHRXTzRo?= =?utf-8?B?SzBNUkhZR3EyU2FrK3FqbzFMUzN1aEw5Zlh1aVRaVzZTK0l5d0tZUk1XL01q?= =?utf-8?B?cmM3dmpNUWFEc24vZy91anVzREtpbEYySERFUi9BSU0raUVrUEYrL3dKZ0Vz?= =?utf-8?B?U0hsYVNld3Joc3lDeDE5bmRQYmpuclpCdEVHeGNsOVhXa042VEdEZmlVZjdu?= =?utf-8?Q?mplOm8Mzis1WN?= 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)(82310400017)(36860700004)(1800799015)(376005); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2024 08:47:56.1210 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0837e9a6-41ce-47ab-25ef-08dc6ce00f1b 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: AM3PEPF00009BA0.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR07MB9934 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. 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 | 410 +++++++++++++++- lib/eal/include/rte_bitops.h | 873 ++++++++++++++++++++++++++++++++++- 2 files changed, 1265 insertions(+), 18 deletions(-) -- 2.34.1