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 443E245777; Fri, 9 Aug 2024 11:14:43 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7868942E8D; Fri, 9 Aug 2024 11:14:23 +0200 (CEST) Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03on2042.outbound.protection.outlook.com [40.107.103.42]) by mails.dpdk.org (Postfix) with ESMTP id 742D3427E3 for ; Fri, 9 Aug 2024 11:14:19 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=aAQnbSA8YUEz1dreQyszghXNMhtYqEdjw5Z3pAEDDP7uBUpplRwY2WbcU0ieQ1E+CY3tSh6T2JEbd0HuOOVvNh0YUORS9czzMY31j0Ur177OmhpHUPBLv0FIxYyg0gXH/U69TbDAMfmUI2C3gNHcAc7yTh335xcdtiQq/2Q9QCxRNhXhxN3MbEg8TTbGnA3P/rQUGvSxHoDY+UAZwV0kskXIg7sRyS7hdVDPw8z4Uj/nzOvO3UCA9bmW8zn8MjwTFa3N297O99s61yddHLYdl3Rmg0tcQyiC1L82plHAdr40cgzHPjidttVSdDl288kXMRHmit/I4EslR2Wrb9PrIw== 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=mfV0PuRHvGFS2wtRcZJIO+BbTfNrJByPCGUQ/M3caYc=; b=BmQTS8CLiT8wmnMbdFbO4iV22u+cmjwcEL0A5+blj6bptPh2o2EE5YumqybVto74FlKLxw6So/ufmSrzgjiYP+T4Yqk7qdcuKivFXmHjfl6YLHPjaUsVe16I9KZISINRgXUQsVCa9rbAsaB7Hu6Q98hzByTnhpkXzITo6XkiKIU/ewNtGh6kxuJXsibpbqcj589nlptMkI20KGqMHyXyw65qnjfFCm6gZP1C595CTH2PUWf8G3SNi8dc7zidXBzy1lnYwvGI0I5yjY3SZcBGh4TKCnJiovXoCPfMno9xHqIJSLR3RxV5Na8SpSMnMBGCYl+zxOAiBPgzu4wKpSESnw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 192.176.1.74) smtp.rcpttodomain=arm.com 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=mfV0PuRHvGFS2wtRcZJIO+BbTfNrJByPCGUQ/M3caYc=; b=G276N0TZevYSI5fTbAV6iBcD0Mm3nMKX38hyajDJeMTYHCMaiMpViIGnlwfHO155xkFdVih/RxLvWuVYdJ8RCk6BQp1MXENq81QmmJc/lrpvFmu5h4A7zJ0B7Q3YV989mOIsk7gAj6l6M1OEOOINhE583harUDAjC8KAADoM55yj62Xjd/p9YHfoMci7YRt0hrBqIZRmwwN9bK1Pb3kpQO+yyRpzKuIjXrOtZ6HblMtgRfm8RjNaqJhycIfjsuw/7WAjj4m+Tzg3v8mpegpfnvfd0E1YB+jusoZHSXNOOLUPKoYw7jMkp4jqSVaWMMAnabAaS/9WZVkd7P+7JNi0vQ== Received: from PR1P264CA0136.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:2ce::11) by DB8PR07MB6379.eurprd07.prod.outlook.com (2603:10a6:10:134::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.15; Fri, 9 Aug 2024 09:14:16 +0000 Received: from AM4PEPF00025F96.EURPRD83.prod.outlook.com (2603:10a6:102:2ce:cafe::77) by PR1P264CA0136.outlook.office365.com (2603:10a6:102:2ce::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.15 via Frontend Transport; Fri, 9 Aug 2024 09:14:16 +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 AM4PEPF00025F96.mail.protection.outlook.com (10.167.16.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.2 via Frontend Transport; Fri, 9 Aug 2024 09:14:15 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.67) with Microsoft SMTP Server id 15.2.1544.11; Fri, 9 Aug 2024 11:14:15 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 7D8BB1C006A; Fri, 9 Aug 2024 11:14:15 +0200 (CEST) From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= To: CC: , Heng Wang , "Stephen Hemminger" , Joyce Kong , Tyler Retzlaff , =?UTF-8?q?Morten=20Br=C3=B8rup?= , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Subject: [PATCH 0/5] Improve EAL bit operations API Date: Fri, 9 Aug 2024 11:04:34 +0200 Message-ID: <20240809090439.589295-1-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240505083737.118649-2-mattias.ronnblom@ericsson.com> References: <20240505083737.118649-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: AM4PEPF00025F96:EE_|DB8PR07MB6379:EE_ X-MS-Office365-Filtering-Correlation-Id: 9b84db5a-b891-4a4b-c53a-08dcb853a46b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|82310400026|376014|36860700013; X-Microsoft-Antispam-Message-Info: =?utf-8?B?NXVVWFJDUUYyY0IrTEd2UzJGWWgwQ0VMRmt2ZFhzNmloa2JtQXVTVjFRYnpz?= =?utf-8?B?WHNBdUwyTVFBSlFPeEs3QnlycTNtNlp1SDlBcjUyRGwwek5hQ0NxUDVLQUxt?= =?utf-8?B?N1pFMXl4dlJLVmhGOG5JNmZGanJLYjRIdnNPYndRSWgzRU9xcXozcFpxZG8v?= =?utf-8?B?RjFvcWhvNnVMS1lsR2loeHRSdUs2a3F6U0ZzejFqc3dnWjgwNGhURGhVdlg5?= =?utf-8?B?RjUzN2lkeFMxd0Z3eExDTmExcE5McjRnZ0hoeUpmQW9LcHJ1QXhsK3VmWUFG?= =?utf-8?B?TlA0cHRkWURWbDFsTnNYcEJKeVE1ZndRaHJCMk1hejYrS2hVWXpJNThRbUpW?= =?utf-8?B?MTRxdXc5OVUyRVhCWDVwOUF2U3FEaldtaVVqN1JmOUplV1pnMyt6U0VoQkh1?= =?utf-8?B?ejlBaUczbThoUVpvZUt6am43NCtPZ3pLUWMzV2JJY0dxSG5jTFhiTTc0cDds?= =?utf-8?B?WkdyLzR3dHJxLy92VCsxMWJNMVRnL0VVZW92cDFENkZGc0o5QW5XcGd3OGQ0?= =?utf-8?B?OXpEai80aVYxcEdLV1MyY2hJNWVVMmZXd3N6aDFpYnNQb0ZJVGgyTEtrcEJr?= =?utf-8?B?djBGTFcrbXFsRmRB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ZFUlZjYklEQkVKWnVwZ0hIOWJzT0FXYThJa0ZFOHFmaTRp?= =?utf-8?B?cnJKYklHSFJsLzV2NDhtRUlIa3pRc3YzQk1xNnp5cmt0TW5IUERJU3pUVldD?= =?utf-8?B?U1NPS1J4QTlmR0lub0c3R2l5dGk2aTMwZWdqb2xQZFcrVUJRQ3NPNGhOYk0w?= =?utf-8?B?cklVNnEya1E1NU8yVnNEVEJZVXlRKzdOeko3K3VDeWZuOGZqNUZNUlhWUTMy?= =?utf-8?B?eGxFa1dHTkZUdzJCb1QrN1pVbmRlL3ZPRkdWQWRmOFgrcHlJL1d4Mk1OeXdw?= =?utf-8?B?SFMreXdwd0pUemxWTHZEaXF1RnhScUhjOUsxeGxpY3RjM203c21TbzVvdlln?= =?utf-8?B?YkI2T3NNZUxxaDhUcFFOWXVQU3lTMEpDVm1oYS9ic3E2N1dtSVdkS0ZqWTdI?= =?utf-8?Q?ipdvLDyhO4+MYwZ6Ofk6UyutMKU5CKSI?= 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)(1800799024)(82310400026)(376014)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Aug 2024 09:14:15.9465 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9b84db5a-b891-4a4b-c53a-08dcb853a46b 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: AM4PEPF00025F96.EURPRD83.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR07MB6379 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 | 414 ++++++++++++++++++- lib/eal/include/rte_bitops.h | 778 ++++++++++++++++++++++++++++++++++- 2 files changed, 1174 insertions(+), 18 deletions(-) -- 2.34.1