From patchwork Mon Aug 12 12:49:25 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: 1227 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 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_R=C3=B6nnblom?= To: CC: , Heng Wang , "Stephen Hemminger" , Tyler Retzlaff , =?utf-8?q?Morten_Br=C3=B8rup?= , Jack Bond-Preston , =?utf-8?q?Mattias_R?= =?utf-8?q?=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 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?q?AyREt6dWmmkwbNiY46sw+JsKv+pPZyC?= =?utf-8?q?wlE1xWPHYaeir4wfhBpNwFB+atmw1hbY+QdzA7rkzlYFnDQBJ8uXZrARDbHO7sXV8?= =?utf-8?q?wsG9x6b3A465uz5yyf7QHZDMqWGGASszxHxnbBwzdy72+TTONY7/XnzpIEPN5X62P?= =?utf-8?q?Ix8hrfRPe5mMMChmt4NQ/hZF1JIsW471znTmnd9VtsNQiJKuMY7j0DMUhroJcYf77?= =?utf-8?q?PeBGbGwBh7JcoQhmX9pRBgFrKhptByn4+RHJe6gsC6Z+AFvtytsB6fXy+U7+QiiFN?= =?utf-8?q?vYn44AK5M9mGT1cfYDOePcqQJ8SGck31yI38lckHVUsxy+Vj+YWrMG4EWwCOgUg96?= =?utf-8?q?gSmY/G57q/PimR4Zy0CqIq8rqdXivlcZoDXQxTmjyaOvUNY+2aIiEnydxyE8J1byG?= =?utf-8?q?4VVq7ieObi/uiuFLGUNGNl6rmIuD1wbNEVYDNT5Kb3CAh5ghM4ANiHPOCgvM+0gKg?= =?utf-8?q?fCC7FAa5QVaRwt7DjPy+5iaPS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jXbq82Q=3D=3D?= 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(-)