From patchwork Sat Mar 2 13:53:27 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: 137806 X-Patchwork-Delegate: thomas@monjalon.net 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 9E8E243C3A; Sat, 2 Mar 2024 15:03:03 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3A34442DD0; Sat, 2 Mar 2024 15:02:25 +0100 (CET) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2050.outbound.protection.outlook.com [40.107.104.50]) by mails.dpdk.org (Postfix) with ESMTP id 3233442DB1 for ; Sat, 2 Mar 2024 15:02:20 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eaJWIrPiyAydpno8MsDLWUzJaq16Qpd4Y0DzMgW673qyz1LH6DQkFUgr0mlMUONhsm6eVKDsrLdgbCDea+D6L0ng3g+TyL4xIj5DC1sge5TIQO55VMF1KohogFIdssq1vdVDp6/CztHYCOSvQLnOPDomhFZvj7Plp50EMmFQ3kDDHqzvOQs3iVNDFpmWCL8YICgKZPn8Mwahn3Xc0ib6MYrsjjWcsCDd47Op7nQCSsQzyHb39wxxf3zu3GrDmuNA5/ZxDRMsHPYHZkA1lryY+SJJT2BV3CQ4IJB86/j5+nCnHePbRdTu4diFEGLgnu+A6ugiIW0TgR5RiTdtJh3hwQ== 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=FTvQZ77SCYs9OU2uyZYRE6OakPKdcGExXqaWXV/AEsM=; b=Z2oWH6nspqThr6qn+SPKk1UX2FgJo0dtNGbDz3S7LzSlB036FWNjq74jUdzpbyU0exPmDXj/ey9hZnN90QzrwNjH1pHhudlsbmp65xlFtjd2HDDzX9y/o/K1j8/JVWXRn8a7zY8IFS5+sRLmj9rIArmaH4usHUCEFxzI0dEH/wCHj5Y4+Gxtm7CZ8kWVPsB3fWdGenLkle/636XLQdAOExk8GrJkSSqyiNy+JxtuvfnbLsb9aVptR53c8OezNTJQLAsDwnHq+pKzeps+UYOnH2xk7Zi6lMKpWeSKmQPPIohTVfShbHdRmf7WGyKSGXASAeGve5oJeV1c1u8CavYDpQ== 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=FTvQZ77SCYs9OU2uyZYRE6OakPKdcGExXqaWXV/AEsM=; b=WQ83tReaB9aJSQ6YBUBYrovmlJCKn+VG1GYE+q/TwaehmxLALt4BCgKyUTjK6YomCw+MA84pvWl//FyZZh5+tNUFYhg19n+QxOv2VX20hEiQFNv3ZRy2zqJDCCD5XRiPmIjBQRAer1mxyLqSdQdwPc8LhColMqZ4Kijuwa0Riyzx1155RROp/m5Qt3OopbBotP5DHPP+tfbtoUAULiO8Z/gVL8nsaElh2MinLko+Y3JMgGGUuTQDDY65Dhdb9RgV+cqA6A7B7yhipChZddyKcjaBXr7XtqzTrLxZlsd0CzUgKbMOSz1PkcBlwxLQRk8wMp9gnqPwhrWeFbDaTgdV1A== Received: from DU2PR04CA0299.eurprd04.prod.outlook.com (2603:10a6:10:28c::34) by PAXPR07MB8354.eurprd07.prod.outlook.com (2603:10a6:102:231::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.39; Sat, 2 Mar 2024 14:02:18 +0000 Received: from DB1PEPF000509E9.eurprd03.prod.outlook.com (2603:10a6:10:28c:cafe::b6) by DU2PR04CA0299.outlook.office365.com (2603:10a6:10:28c::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.36 via Frontend Transport; Sat, 2 Mar 2024 14:02: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 DB1PEPF000509E9.mail.protection.outlook.com (10.167.242.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Sat, 2 Mar 2024 14:02:18 +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.1258.12; Sat, 2 Mar 2024 15:02:17 +0100 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id B15261C006A; Sat, 2 Mar 2024 15:02:17 +0100 (CET) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , Heng Wang , =?utf-8?q?M?= =?utf-8?q?attias_R=C3=B6nnblom?= Subject: [RFC 6/7] eal: add generic atomic bit operations Date: Sat, 2 Mar 2024 14:53:27 +0100 Message-ID: <20240302135328.531940-7-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240302135328.531940-1-mattias.ronnblom@ericsson.com> References: <20240302135328.531940-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB1PEPF000509E9:EE_|PAXPR07MB8354:EE_ X-MS-Office365-Filtering-Correlation-Id: 813b511e-e7aa-419a-447d-08dc3ac15f73 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nLuM9Q3j6+x9LybW1nfIPYm2HuDXCBtHuE8HxVHBOU7kPimvdG5APdqp+NIkjo0Qb8QiNKnliUTbHfzcxKRN/Rx925P8IOf7RcBWBvuvSseGNPeXHraBMivGp95wGWtkeeUdTTGj8AMLaBYrcqNobEj+/pchgXGm5T7k78HTEN/FIyTFubD1dRedvBJbSfEmqII3uaXjD13byTIZeJfCCF0ff5RAmt+1XjnGZvY+aOx3Uq79K6vVsq5aPPtQc+ijmJPQGB1w7zADS/h/M5GnU9P4S4hCvspYf0s2LTuMdDfqNT2JOmFY8LfKOE3GioFyuuydVlDhydL9g0gSs9ZE7f1USrSXYVoLagYbBd930eNa5tkidPl2U5qKjF0N1uqz8wzqW97RQtFZDrzQ2wpeyhorS5U167unqebOnefORLrT5QL/geJW9h1yCtirKrhTRMPtY60+nx4RH8qbsHHIm7LSkHvG6slKIZLL7O+NTgz9nV1WuVOZmC14psVpgQEnjcx7VL0jdImpgPh/7nn+FfbMBuFfhnuIXwlBN+4b6QRRzoI16lkc58pmo1kFLlLtnSlw7iGeMze1DrvclC8vhF4WoZ3tWMxz7bQWqA718EwDrRT5r1yHM9B9XdDIn4/Yxsk2omrkjP7XOv5kbXEpcxlr4Vnsp5FyO9H7u98jlWDbio9Ra4wZbmchsPNld4uwrg290Rs/LOhTArFlPwRnny06uirK1tmfesRJgqrIhw8xUHSl7Hl/CDyt42hPn1mv 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)(376005)(36860700004)(82310400014); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2024 14:02:18.3475 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 813b511e-e7aa-419a-447d-08dc3ac15f73 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: DB1PEPF000509E9.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR07MB8354 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 Add atomic bit-level test/set/clear/assign macros operating on both 32-bit and 64-bit words by means of C11 generic selection. Signed-off-by: Mattias Rönnblom --- lib/eal/include/rte_bitops.h | 125 +++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/lib/eal/include/rte_bitops.h b/lib/eal/include/rte_bitops.h index 7eb08bc768..b5a9df5930 100644 --- a/lib/eal/include/rte_bitops.h +++ b/lib/eal/include/rte_bitops.h @@ -290,6 +290,131 @@ extern "C" { uint32_t *: rte_bit_once_assign32, \ uint64_t *: rte_bit_once_assign64)(addr, nr, value) +/** + * Test if a particular bit in a word is set with a particular memory + * order. + * + * Test a bit with the resulting memory load ordered as per the + * specified memory order. + * + * @param addr + * A pointer to the word to query. + * @param nr + * The index of the bit. + * @param memory_order + * The memory order to use. See for details. + * @return + * Returns true if the bit is set, and false otherwise. + */ +#define rte_bit_atomic_test(addr, nr, memory_order) \ + _Generic((addr), \ + uint32_t *: rte_bit_atomic_test32, \ + uint64_t *: rte_bit_atomic_test64)(addr, nr, memory_order) + +/** + * Atomically set bit in word. + * + * Atomically set bit specified by @c nr in the word pointed to by @c + * addr to '1', with the memory ordering as specified by @c + * memory_order. + * + * @param addr + * A pointer to the word to modify. + * @param nr + * The index of the bit. + * @param memory_order + * The memory order to use. See for details. + */ +#define rte_bit_atomic_set(addr, nr, memory_order) \ + _Generic((addr), \ + uint32_t *: rte_bit_atomic_set32, \ + uint64_t *: rte_bit_atomic_set64)(addr, nr, memory_order) + +/** + * Atomically clear bit in word. + * + * Atomically set bit specified by @c nr in the word pointed to by @c + * addr to '0', with the memory ordering as specified by @c + * memory_order. + * + * @param addr + * A pointer to the word to modify. + * @param nr + * The index of the bit. + * @param memory_order + * The memory order to use. See for details. + */ +#define rte_bit_atomic_clear(addr, nr, memory_order) \ + _Generic((addr), \ + uint32_t *: rte_bit_atomic_clear32, \ + uint64_t *: rte_bit_atomic_clear64)(addr, nr, memory_order) + +/** + * Atomically assign a value to bit in word. + * + * Atomically set bit specified by @c nr in the word pointed to by @c + * addr to the value indicated by @c value, with the memory ordering + * as specified with @c memory_order. + * + * @param addr + * A pointer to the word to modify. + * @param nr + * The index of the bit. + * @param value + * The new value of the bit - true for '1', or false for '0'. + * @param memory_order + * The memory order to use. See for details. + */ +#define rte_bit_atomic_assign(addr, nr, value, memory_order) \ + _Generic((addr), \ + uint32_t *: rte_bit_atomic_assign32, \ + uint64_t *: rte_bit_atomic_assign64)(addr, nr, value, \ + memory_order) + +/** + * Atomically test and set a bit in word. + * + * Atomically test and set bit specified by @c nr in the word pointed + * to by @c addr to '1', with the memory ordering as specified with @c + * memory_order. + * + * @param addr + * A pointer to the word to modify. + * @param nr + * The index of the bit. + * @param memory_order + * The memory order to use. See for details. + * @return + * Returns true if the bit was set, and false otherwise. + */ +#define rte_bit_atomic_test_and_set(addr, nr, memory_order) \ + _Generic((addr), \ + uint32_t *: rte_bit_atomic_test_and_set32, \ + uint64_t *: rte_bit_atomic_test_and_set64)(addr, nr, \ + memory_order)) + +/** + * Atomically test and clear a bit in word. + * + * Atomically test and clear bit specified by @c nr in the word + * pointed to by @c addr to '0', with the memory ordering as specified + * with @c memory_order. + * + * @param addr + * A pointer to the word to modify. + * @param nr + * The index of the bit. + * @param memory_order + * The memory order to use. See for details. + * @return + * Returns true if the bit was set, and false otherwise. + */ +#define rte_bit_atomic_test_and_clear(addr, nr, memory_order) \ + _Generic((addr), \ + uint32_t *: rte_bit_atomic_test_and_clear32, \ + uint64_t *: rte_bit_atomic_test_and_clear64)(addr, nr, \ + memory_order)) + /** * Test if a particular bit in a 32-bit word is set. *