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 BB32E457A1; Mon, 12 Aug 2024 14:59:05 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AB3B1402C3; Mon, 12 Aug 2024 14:59:05 +0200 (CEST) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2069.outbound.protection.outlook.com [40.107.104.69]) by mails.dpdk.org (Postfix) with ESMTP id E60244029C for ; Mon, 12 Aug 2024 14:59:04 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=u+XQSrDP4o/RoqVAtxr+oUsnJEySmodYzLQplRcLMqMZ6dVp3K4tcRt1ZkNPuOtNB1OmC/VoZM6UlQKUQ669JWgYhAwcsL7Ndp04jSH7x8P2Tltq/kQMciJgbvODOPipBZ3ThuM4R/D7wnnkuRjxpUAvEaUHbPeXh+07EkHDmahPvvDRt3w5pWdjaNJdYxeDPk+m5f0ZfPy0H+9EIL18EgMAnc1KcfXHPexxnKu5Lmp5sIg6rcwBiowvgselj3YibvoRAXkBMAB+eVUUpX+oovmd49+bIbVrIpeJ4jIlmUS71AtkVZEYK6eNsPFc2Z6zi061BGSxW/8Up5ZGzXZ4uQ== 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=jJNa2Bz3o5yB/oFrWpv05CuEqDCDToSLrmM6hXCHJP0=; b=PwvJHIh60wuonvPmsxb8yUptLuzg5X5oTLkIfwOlKTk0+RLQsNt74jYpmZ8yOOqeObasupxO61qkN8zpLweDT3ruiRATFNViFwjEcnhcNKlUlH3Ztps33BVi7wBfOYzmu8Y7sWVbW+bU5VV8BPsnkbqghd5Zl46IJp7BUXMl8dn4sKPkrWbs0Ga5HHZ/KIKLXLxsa8fJ0Htah+inuT2Mm9oOpyDhy2xu5o84lQovBvjF0P+GUP3+zuKDSB3qdN5yZOKj+UDBrEngbXy98fyQiEfwefWoX4blgiLlWdMK64QfCk9qxQLAUimBCY3x5Xtf3MaQxgpre7GlQ2snskhaNA== 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=jJNa2Bz3o5yB/oFrWpv05CuEqDCDToSLrmM6hXCHJP0=; b=sTW8krxqLzezVi8hPFVKF2fxKLjzr2WZHTBfjc3oXWl8y6hGGX36k/JRi+FmOmc8gk5A+xlEDclRWPoi3J3cz7V4Pgb86ZHCgO0ych5siAbNBhJTaVFiwC//eE9ik3VQxHBvnh4rUs4loThGm+Mpo+QSuPWl7NpoSspxN4DzkxPiJ+EphnWEuBNKJh8BbrwoXdqgdzQzPzfOcrlaLT2QcKp9Aho9sQxdXK0gxjzKSQp2usGMqc6JWgCy5awoKEpAMvKkToa3+DerR9eEfLMtEMRjD0H8O8ckYSLJOisBDkfm4KV/EcMHoHhnJLiP1iTbqUhGnGgTa/DWKThSJnl1rA== Received: from DUZPR01CA0071.eurprd01.prod.exchangelabs.com (2603:10a6:10:3c2::16) by PAXPR07MB7886.eurprd07.prod.outlook.com (2603:10a6:102:13a::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.20; Mon, 12 Aug 2024 12:59:03 +0000 Received: from DU2PEPF00028D03.eurprd03.prod.outlook.com (2603:10a6:10:3c2:cafe::d1) by DUZPR01CA0071.outlook.office365.com (2603:10a6:10:3c2::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.20 via Frontend Transport; Mon, 12 Aug 2024 12:59:03 +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 DU2PEPF00028D03.mail.protection.outlook.com (10.167.242.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.8 via Frontend Transport; Mon, 12 Aug 2024 12:59:03 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.64) with Microsoft SMTP Server id 15.2.1544.11; Mon, 12 Aug 2024 14:59:02 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id D4B6E380061; Mon, 12 Aug 2024 14:59:02 +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?= , Jack Bond-Preston , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Subject: [PATCH v3 0/5] Improve EAL bit operations API Date: Mon, 12 Aug 2024 14:49:25 +0200 Message-ID: <20240812124930.604796-1-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240809095829.589396-2-mattias.ronnblom@ericsson.com> References: <20240809095829.589396-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: DU2PEPF00028D03:EE_|PAXPR07MB7886:EE_ X-MS-Office365-Filtering-Correlation-Id: 21036b98-0ed9-47e8-23e0-08dcbace8acb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|376014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?B?QXlSRXQ2ZFdtbWt3Yk5pWTQ2c3crSnNLditwUFp5Q3dsRTF4V1BIWWFlaXI0?= =?utf-8?B?d2ZoQnBOd0ZCK2F0bXcxaGJZK1FkekE3cmt6bFlGbkRRQko4dVhackFSRGJI?= =?utf-8?B?TzdzWFY4d3NHOXg2YjNBNDY1dXo1eXlmN1FIWkRNcVdHR0FTc3p4SHhuYkJ3?= =?utf-8?B?emR5NzIrVFRPTlk3L1huenBJRVBONVg2MlBJeDhocmZSUGU1bU1NQ2htdDRO?= =?utf-8?B?US9oWkYxSklzVzQ3MXpuVG1uZDlWdHNOUWlKS3VNWTdqMERNVWhyb0pjWWY3?= =?utf-8?B?N1BlQkdiR3dCaDdKY29RaG1YOXBSQmdGcktocHRCeW40K1JISmU2Z3NDNlor?= =?utf-8?B?QUZ2dHl0c0I2Zlh5K1U3K1FpaUZOdlluNDRBSzVNOW1HVDFjZllET2VQY3FR?= =?utf-8?B?SjhTR2NrMzF5STM4bGNrSFZVc3h5K1ZqK1lXck1HNEVXd0NPZ1VnOTZnU21Z?= =?utf-8?B?L0c1N3EvUGltUjRaeTBDcUlxOHJxZFhpdmxjWm9EWFF4VG1qeWFPdlVOWSsy?= =?utf-8?B?YUlpRW55ZHh5RThKMWJ5RzRWVnE3aWVPYmkvdWl1RkxHVU5HTmw2cm1JdUQ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hqR2RMSklkTjhrQzVVZ3BX?= =?utf-8?B?OWlDcXh6bEFHZlZrYXAxcXdlOHd4Ri92T1p4N21EdGEyd1FXU2FueXFsaWoy?= =?utf-8?B?eDA0VGJESzJrWUtSdk9HYnV6OFY0V281bG9KbFZ1MGJjV3A5Y1o1ZmRVQ0Q4?= =?utf-8?B?eFlrb2puRXZGakVVS1lVUGIwNm9QMXU2UGRrNWJnK3cxK0RvTFlzUFlEVElv?= =?utf-8?B?V1JFem8wcUh4V3NxaXo5VGpIY1BXRU9rRzA4RzRVTkE0UzJKOXdqMG10bVRN?= =?utf-8?B?YmNxb3NtZDFWc2tQa0hnQ082Qkp1WXdydFBMWTcxKzJjbmY1dTFlZEx3R010?= =?utf-8?B?UWtwd1YrTm5KSlpwVTZ1YjdSSEVnK2hMSVNSeVF0TnNmNG9WMWtRY0hNZVd0?= =?utf-8?B?ZkN2Vis1Z3RkdkZ6SE91NFVwWERTYStUOHB1RWpYYnE4MlE9PQ==?= 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)(376014)(82310400026)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2024 12:59:03.3428 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 21036b98-0ed9-47e8-23e0-08dcbace8acb 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: DU2PEPF00028D03.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR07MB7886 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 | 416 +++++++++++++- doc/guides/rel_notes/release_24_11.rst | 17 + lib/eal/include/rte_bitops.h | 768 ++++++++++++++++++++++++- 3 files changed, 1183 insertions(+), 18 deletions(-) -- 2.34.1