From patchwork Tue Sep 10 07:03:39 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: 143845 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 34D3345952; Tue, 10 Sep 2024 09:13:56 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 24CD8427C0; Tue, 10 Sep 2024 09:13:18 +0200 (CEST) Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03on2049.outbound.protection.outlook.com [40.107.103.49]) by mails.dpdk.org (Postfix) with ESMTP id 24DA840151 for ; Tue, 10 Sep 2024 09:13:13 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iWKKsQ2XFE9l+gmh97MSn5TUooaXjcZ4JiYrY0hW5i7Xj8klt9lK/pBAaCZjcU3GkTg60ZSHybkPsF4Xwf1pbWAn3zgspiRIkQNiIah01cgSSWLU3gK/xzw57mibYk5AUB6nfrdh0BC0KW82E2A/w+zN7KN66PGAVH0jVmloza3GaDYSttK/2D3ly6ytI9vA+uu677ypXzdR+pGwzuPSz5+kGJWLFOPGd4lhfDB/J3ZLax5/KcY+ZpVLEXewI10avDfNlokPE9kz5OIpNOPeZyFHLfLezCTsNEKYRy2EWjQmEmv4AgKIMPtYXJ2GHCDiKlCUbLV2ad2TU6ojwOSuyw== 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=fzcQRgXE1KnF1AAbU1yogv0s4wNukVlfomiJVeN0fN4=; b=IbAqkSSvKiZxucbaWifl5Mvhy3X5LH4GSg4nKTX1mC8//tFLry+VDI+nBdj4koeetH0MjuVwegECUcYtfhA1pHUTt/n0NwZqKjdSjqzYuo5fMDq83N7QWfrDPgA884Mmprv6nhIhDN0BsuJS/YExS9ZouU9ihSB0B9aqPxcJuQPmwffj3VxJNv5iXz2h5ZDUZcpWcYlXfJhEYkw9LCii4P4FSstWS4QkcnekhkzjChROIVednqaLp3VY0kZYGokGd619nlB+J3xvqmHppUcrTHex+XB4iEhYQtH4zPh+oWmrGwmqgtve3lx8SwDbTDvMPjt1aFlHdX8eokhHDP6e0A== 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=fzcQRgXE1KnF1AAbU1yogv0s4wNukVlfomiJVeN0fN4=; b=Z61eyebnfyc4HnM9RNGV2hd4GpiytwdWU0n3WNtygrgRyHLVgDCmdeROkqrhzp4r3xjWtpB/Ea8i59AWg1CJODNJwXlgg5oWJX/6sL4h7kp9t8IcLvDlWXCWgdLq71b4FnwRWIs7HkMZ84t5MW35qHwgxnOmb2IHmx0o3L/0snXOhpg8CEYGmjDReAyULD/BSUDKhXJHkNYzMKawoawDbAHRh36+Z66UiL4wXPmVEdRiCD9ChpofLvp9Xe2edHh1medQg1j5UvtM+58Tlfi2Ai7LadYLqAxQWDe+fqr9GQPuByIUsky2S0SIbPNuXDVzxyyVenja2fi7lERjA66dqw== Received: from AS8PR07CA0055.eurprd07.prod.outlook.com (2603:10a6:20b:459::26) by VI1PR07MB6479.eurprd07.prod.outlook.com (2603:10a6:800:136::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.23; Tue, 10 Sep 2024 07:13:06 +0000 Received: from AMS0EPF000001A0.eurprd05.prod.outlook.com (2603:10a6:20b:459:cafe::e5) by AS8PR07CA0055.outlook.office365.com (2603:10a6:20b:459::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.25 via Frontend Transport; Tue, 10 Sep 2024 07:13:06 +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 AMS0EPF000001A0.mail.protection.outlook.com (10.167.16.230) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Tue, 10 Sep 2024 07:13:05 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.65) with Microsoft SMTP Server id 15.2.1544.11; Tue, 10 Sep 2024 09:13:05 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 6EC81380070; Tue, 10 Sep 2024 09:13:05 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , =?utf-8?q?Morten_Br=C3=B8rup?= , Stephen Hemminger , Konstantin Ananyev , David Marchand , =?utf-8?q?Mattias_R=C3=B6nnblom?= Subject: [PATCH 1/6] eal: add static per-lcore memory allocation facility Date: Tue, 10 Sep 2024 09:03:39 +0200 Message-ID: <20240910070344.699183-2-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910070344.699183-1-mattias.ronnblom@ericsson.com> References: <20240506082721.120666-2-mattias.ronnblom@ericsson.com> <20240910070344.699183-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AMS0EPF000001A0:EE_|VI1PR07MB6479:EE_ X-MS-Office365-Filtering-Correlation-Id: 19f9adf9-4087-47c3-44fc-08dcd1680463 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?q?9n7muMFII8w7/QZCqbWmnaXkioLQIQY?= =?utf-8?q?00C17Hj3L1q1D/ZGWMmNXFx0Zop6giJ2IzwIY9zZznHegGeoCnhVxGyTSHpuyW3Ce?= =?utf-8?q?6zd6W7XMDtloXMGVBUsG4NOdDqyBGoUr9eHd0hGqckLduzrNc1DF4tS2Y2gYeRqas?= =?utf-8?q?9iv3eZUr9Uuxka44JiVpGcdEZYDlkleIuhrN5wI8A+Wc5Mg8Z3Na8wiOsa0TEiHd5?= =?utf-8?q?MvnzSzD502XOR/oi+fF0c+ViWuMbWBOUE8So7Ee8vLlpA9wLMGRCsVjQNGS7AUhbj?= =?utf-8?q?MxGlYKpcvEUFChnx3JiYaaPmKL9dnx+Tt+OE4OuMR+blM/bBWYu+lteVHu2lH2HiP?= =?utf-8?q?w5qKXjQr4g45Sy136H7Wz3eXNaHzdKlKUPUT5laH8IFH6+4bqxLiiBoStBI+wjhwv?= =?utf-8?q?fttjw1o8WC0V6IeAfLg//Q/iKiDAFF2a1RwSGPepsENp+bTg70QvOsM0P4Ge6uVal?= =?utf-8?q?Z0NU+BQtpJaRoJyF3rj7gM/CiLzhSjwc3/CZIsTTdRNm83DaY23PPhKUg2PBVSypO?= =?utf-8?q?4rvzeZGnFgS7M+iOc71Mt1Ro8pMeH7vaEDUWc/pZeXtDeAGcoV9RsoVBcVg4A86hF?= =?utf-8?q?ecDa9Fi2/s+V0pe+3/kgmK4FugX2IyJUflWmkVCtXy87khoaaZSPbNxsAWcJb03me?= =?utf-8?q?bPyHNnzTQVtBXpQwadevfS0zzHcBPvhsuE9FJFYQtI7yUw2MXhaRkPKot50k2Asdg?= =?utf-8?q?9yiGTp1Q7JRrT8uvQGBfSuWd1dBdjZs09G+nEZdZIsHYHbe86YOSRRXXiYv8STSz4?= =?utf-8?q?3P0JyifZAgtOG/dtZFss1X9lYkLzJHxMlqMtFBkkQ0XP6XVo/KoSlBS7Kec+Z965b?= =?utf-8?q?EanAXq760w8Iizqjg89eppC+1gHaIAUT3qD/5t3e3PXDn1N4VWJz8I3VjpE0TX/p2?= =?utf-8?q?0CRsCpQsB2CH8dWIt42YK9rZS00rdfS7kAhClqmO9gekgQZvi2THQTN4IG8Wor/t3?= =?utf-8?q?bn9vDm5mFVGNiMXKwi/BZdMlJx59jM+L1cj1HzQW8LFdoJCB+oKl0met5tE07lVyS?= =?utf-8?q?9pAdAp9lB5bRTN4PhiWeEogNeHam6Y7Ly1dF/mb/LrY6SLJvZpdliUmc5toabW1Ud?= =?utf-8?q?cXQ71eRlkr+dMqjasZJABLBYL8/4vNMucNFos3tzLQofTiQQlO1kKUstjloJSPj26?= =?utf-8?q?uzYz2cvLKElSkNVz0AuV2vmtOpvaYUhv5K3EGZwwRE4SR4PzV0n4mMMOXAtvWrBW3?= =?utf-8?q?NAQc3wklDLXPsbDzC3jCdtlLfqZx+m2Iq3MfIhVEMS0QVdWsnFB2LFLG/PCuqeodE?= =?utf-8?q?Ewla1hACSKdvA03oz6s/TLXOBfXqbpd1lIc8Kcc8I5ZdzfAEQhdEZc0g/UyQreymq?= =?utf-8?q?Lr47mQzmvb8S1vIhQY+xtLHjs6QDOkqA4FcbJ773Bb+HBRrglzlMkmsdGDT6JDtpu?= =?utf-8?q?/Jcpu1rSvZs?= 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)(376014)(36860700013)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 07:13:05.9561 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 19f9adf9-4087-47c3-44fc-08dcd1680463 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: AMS0EPF000001A0.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB6479 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 Introduce DPDK per-lcore id variables, or lcore variables for short. An lcore variable has one value for every current and future lcore id-equipped thread. The primary use case is for statically allocating small, frequently-accessed data structures, for which one instance should exist for each lcore. Lcore variables are similar to thread-local storage (TLS, e.g., C11 _Thread_local), but decoupling the values' life time with that of the threads. Lcore variables are also similar in terms of functionality provided by FreeBSD kernel's DPCPU_*() family of macros and the associated build-time machinery. DPCPU uses linker scripts, which effectively prevents the reuse of its, otherwise seemingly viable, approach. The currently-prevailing way to solve the same problem as lcore variables is to keep a module's per-lcore data as RTE_MAX_LCORE-sized array of cache-aligned, RTE_CACHE_GUARDed structs. The benefit of lcore variables over this approach is that data related to the same lcore now is close (spatially, in memory), rather than data used by the same module, which in turn avoid excessive use of padding, polluting caches with unused data. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup --- PATCH: * Update MAINTAINERS and release notes. * Stop covering included files in extern "C" {}. RFC v6: * Include to get aligned_alloc(). * Tweak documentation (grammar). * Provide API-level guarantees that lcore variable values take on an initial value of zero. * Fix misplaced __rte_cache_aligned in the API doc example. RFC v5: * In Doxygen, consistenly use @ (and not \). * The RTE_LCORE_VAR_GET() and SET() convience access macros covered an uncommon use case, where the lcore value is of a primitive type, rather than a struct, and is thus eliminated from the API. (Morten Brørup) * In the wake up GET()/SET() removeal, rename RTE_LCORE_VAR_PTR() RTE_LCORE_VAR_VALUE(). * The underscores are removed from __rte_lcore_var_lcore_ptr() to signal that this function is a part of the public API. * Macro arguments are documented. RFV v4: * Replace large static array with libc heap-allocated memory. One implication of this change is there no longer exists a fixed upper bound for the total amount of memory used by lcore variables. RTE_MAX_LCORE_VAR has changed meaning, and now represent the maximum size of any individual lcore variable value. * Fix issues in example. (Morten Brørup) * Improve access macro type checking. (Morten Brørup) * Refer to the lcore variable handle as "handle" and not "name" in various macros. * Document lack of thread safety in rte_lcore_var_alloc(). * Provide API-level assurance the lcore variable handle is always non-NULL, to all applications to use NULL to mean "not yet allocated". * Note zero-sized allocations are not allowed. * Give API-level guarantee the lcore variable values are zeroed. RFC v3: * Replace use of GCC-specific alignof() with alignof(). * Update example to reflect FOREACH macro name change (in RFC v2). RFC v2: * Use alignof to derive alignment requirements. (Morten Brørup) * Change name of FOREACH to make it distinct from 's *per-EAL-thread* RTE_LCORE_FOREACH(). (Morten Brørup) * Allow user-specified alignment, but limit max to cache line size. --- MAINTAINERS | 6 + config/rte_config.h | 1 + doc/api/doxy-api-index.md | 1 + doc/guides/rel_notes/release_24_11.rst | 14 + lib/eal/common/eal_common_lcore_var.c | 69 +++++ lib/eal/common/meson.build | 1 + lib/eal/include/meson.build | 1 + lib/eal/include/rte_lcore_var.h | 384 +++++++++++++++++++++++++ lib/eal/version.map | 3 + 9 files changed, 480 insertions(+) create mode 100644 lib/eal/common/eal_common_lcore_var.c create mode 100644 lib/eal/include/rte_lcore_var.h diff --git a/MAINTAINERS b/MAINTAINERS index c5a703b5c0..362d9a3f28 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -282,6 +282,12 @@ F: lib/eal/include/rte_random.h F: lib/eal/common/rte_random.c F: app/test/test_rand_perf.c +Lcore Variables +M: Mattias Rönnblom +F: lib/eal/include/rte_lcore_var.h +F: lib/eal/common/eal_common_lcore_var.c +F: app/test/test_lcore_var.c + ARM v7 M: Wathsala Vithanage F: config/arm/ diff --git a/config/rte_config.h b/config/rte_config.h index dd7bb0d35b..311692e498 100644 --- a/config/rte_config.h +++ b/config/rte_config.h @@ -41,6 +41,7 @@ /* EAL defines */ #define RTE_CACHE_GUARD_LINES 1 #define RTE_MAX_HEAPS 32 +#define RTE_MAX_LCORE_VAR 1048576 #define RTE_MAX_MEMSEG_LISTS 128 #define RTE_MAX_MEMSEG_PER_LIST 8192 #define RTE_MAX_MEM_MB_PER_LIST 32768 diff --git a/doc/api/doxy-api-index.md b/doc/api/doxy-api-index.md index f9f0300126..07d7cbc66c 100644 --- a/doc/api/doxy-api-index.md +++ b/doc/api/doxy-api-index.md @@ -99,6 +99,7 @@ The public API headers are grouped by topics: [interrupts](@ref rte_interrupts.h), [launch](@ref rte_launch.h), [lcore](@ref rte_lcore.h), + [lcore-varible](@ref rte_lcore_var.h), [per-lcore](@ref rte_per_lcore.h), [service cores](@ref rte_service.h), [keepalive](@ref rte_keepalive.h), diff --git a/doc/guides/rel_notes/release_24_11.rst b/doc/guides/rel_notes/release_24_11.rst index 0ff70d9057..adb8eb404d 100644 --- a/doc/guides/rel_notes/release_24_11.rst +++ b/doc/guides/rel_notes/release_24_11.rst @@ -55,6 +55,20 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Added EAL per-lcore static memory allocation facility.** + + Added EAL API for statically allocating small, + frequently-accessed data structures, for which one instance should + exist for each lcore. + + With lcore variables, data is organized spatially on a per-lcore + basis, rather than per library or PMD, avoiding the need for cache + aligning (or RTE_CACHE_GUARDing) data structures, which in turn + reduces CPU cache internal fragmentation, improving performance. + + Lcore variables are similar to thread-local storage (TLS, e.g., + C11 _Thread_local), but decoupling the values' life time from that + of the threads. Removed Items ------------- diff --git a/lib/eal/common/eal_common_lcore_var.c b/lib/eal/common/eal_common_lcore_var.c new file mode 100644 index 0000000000..74ad8272ec --- /dev/null +++ b/lib/eal/common/eal_common_lcore_var.c @@ -0,0 +1,69 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 Ericsson AB + */ + +#include +#include + +#include +#include +#include + +#include + +#include "eal_private.h" + +#define LCORE_BUFFER_SIZE (RTE_MAX_LCORE_VAR * RTE_MAX_LCORE) + +static void *lcore_buffer; +static size_t offset = RTE_MAX_LCORE_VAR; + +static void * +lcore_var_alloc(size_t size, size_t align) +{ + void *handle; + void *value; + + offset = RTE_ALIGN_CEIL(offset, align); + + if (offset + size > RTE_MAX_LCORE_VAR) { + lcore_buffer = aligned_alloc(RTE_CACHE_LINE_SIZE, + LCORE_BUFFER_SIZE); + RTE_VERIFY(lcore_buffer != NULL); + + offset = 0; + } + + handle = RTE_PTR_ADD(lcore_buffer, offset); + + offset += size; + + RTE_LCORE_VAR_FOREACH_VALUE(value, handle) + memset(value, 0, size); + + EAL_LOG(DEBUG, "Allocated %"PRIuPTR" bytes of per-lcore data with a " + "%"PRIuPTR"-byte alignment", size, align); + + return handle; +} + +void * +rte_lcore_var_alloc(size_t size, size_t align) +{ + /* Having the per-lcore buffer size aligned on cache lines + * assures as well as having the base pointer aligned on cache + * size assures that aligned offsets also translate to alipgned + * pointers across all values. + */ + RTE_BUILD_BUG_ON(RTE_MAX_LCORE_VAR % RTE_CACHE_LINE_SIZE != 0); + RTE_ASSERT(align <= RTE_CACHE_LINE_SIZE); + RTE_ASSERT(size <= RTE_MAX_LCORE_VAR); + + /* '0' means asking for worst-case alignment requirements */ + if (align == 0) + align = alignof(max_align_t); + + RTE_ASSERT(rte_is_power_of_2(align)); + + return lcore_var_alloc(size, align); +} diff --git a/lib/eal/common/meson.build b/lib/eal/common/meson.build index 22a626ba6f..d41403680b 100644 --- a/lib/eal/common/meson.build +++ b/lib/eal/common/meson.build @@ -18,6 +18,7 @@ sources += files( 'eal_common_interrupts.c', 'eal_common_launch.c', 'eal_common_lcore.c', + 'eal_common_lcore_var.c', 'eal_common_mcfg.c', 'eal_common_memalloc.c', 'eal_common_memory.c', diff --git a/lib/eal/include/meson.build b/lib/eal/include/meson.build index e94b056d46..9449253e23 100644 --- a/lib/eal/include/meson.build +++ b/lib/eal/include/meson.build @@ -27,6 +27,7 @@ headers += files( 'rte_keepalive.h', 'rte_launch.h', 'rte_lcore.h', + 'rte_lcore_var.h', 'rte_lock_annotations.h', 'rte_malloc.h', 'rte_mcslock.h', diff --git a/lib/eal/include/rte_lcore_var.h b/lib/eal/include/rte_lcore_var.h new file mode 100644 index 0000000000..7d3178c424 --- /dev/null +++ b/lib/eal/include/rte_lcore_var.h @@ -0,0 +1,384 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 Ericsson AB + */ + +#ifndef _RTE_LCORE_VAR_H_ +#define _RTE_LCORE_VAR_H_ + +/** + * @file + * + * RTE Per-lcore id variables + * + * This API provides a mechanism to create and access per-lcore id + * variables in a space- and cycle-efficient manner. + * + * A per-lcore id variable (or lcore variable for short) has one value + * for each EAL thread and registered non-EAL thread. There is one + * copy for each current and future lcore id-equipped thread, with the + * total number of copies amounting to @c RTE_MAX_LCORE. The value of + * an lcore variable for a particular lcore id is independent from + * other values (for other lcore ids) within the same lcore variable. + * + * In order to access the values of an lcore variable, a handle is + * used. The type of the handle is a pointer to the value's type + * (e.g., for @c uint32_t lcore variable, the handle is a + * uint32_t *. The handler type is used to inform the + * access macros the type of the values. A handle may be passed + * between modules and threads just like any pointer, but its value + * must be treated as a an opaque identifier. An allocated handle + * never has the value NULL. + * + * @b Creation + * + * An lcore variable is created in two steps: + * 1. Define a lcore variable handle by using @ref RTE_LCORE_VAR_HANDLE. + * 2. Allocate lcore variable storage and initialize the handle with + * a unique identifier by @ref RTE_LCORE_VAR_ALLOC or + * @ref RTE_LCORE_VAR_INIT. Allocation generally occurs the time of + * module initialization, but may be done at any time. + * + * An lcore variable is not tied to the owning thread's lifetime. It's + * available for use by any thread immediately after having been + * allocated, and continues to be available throughout the lifetime of + * the EAL. + * + * Lcore variables cannot and need not be freed. + * + * @b Access + * + * The value of any lcore variable for any lcore id may be accessed + * from any thread (including unregistered threads), but it should + * only be *frequently* read from or written to by the owner. + * + * Values of the same lcore variable but owned by to different lcore + * ids may be frequently read or written by the owners without risking + * false sharing. + * + * An appropriate synchronization mechanism (e.g., atomic loads and + * stores) should employed to assure there are no data races between + * the owning thread and any non-owner threads accessing the same + * lcore variable instance. + * + * The value of the lcore variable for a particular lcore id is + * accessed using @ref RTE_LCORE_VAR_LCORE_VALUE. + * + * A common pattern is for an EAL thread or a registered non-EAL + * thread to access its own lcore variable value. For this purpose, a + * short-hand exists in the form of @ref RTE_LCORE_VAR_VALUE. + * + * Although the handle (as defined by @ref RTE_LCORE_VAR_HANDLE) is a + * pointer with the same type as the value, it may not be directly + * dereferenced and must be treated as an opaque identifier. + * + * Lcore variable handles and value pointers may be freely passed + * between different threads. + * + * @b Storage + * + * An lcore variable's values may by of a primitive type like @c int, + * but would more typically be a @c struct. + * + * The lcore variable handle introduces a per-variable (not + * per-value/per-lcore id) overhead of @c sizeof(void *) bytes, so + * there are some memory footprint gains to be made by organizing all + * per-lcore id data for a particular module as one lcore variable + * (e.g., as a struct). + * + * An application may choose to define an lcore variable handle, which + * it then it goes on to never allocate. + * + * The size of a lcore variable's value must be less than the DPDK + * build-time constant @c RTE_MAX_LCORE_VAR. + * + * The lcore variable are stored in a series of lcore buffers, which + * are allocated from the libc heap. Heap allocation failures are + * treated as fatal. + * + * Lcore variables should generally *not* be @ref __rte_cache_aligned + * and need *not* include a @ref RTE_CACHE_GUARD field, since the use + * of these constructs are designed to avoid false sharing. In the + * case of an lcore variable instance, the thread most recently + * accessing nearby data structures should almost-always the lcore + * variables' owner. Adding padding will increase the effective memory + * working set size, potentially reducing performance. + * + * Lcore variable values take on an initial value of zero. + * + * @b Example + * + * Below is an example of the use of an lcore variable: + * + * @code{.c} + * struct foo_lcore_state { + * int a; + * long b; + * }; + * + * static RTE_LCORE_VAR_HANDLE(struct foo_lcore_state, lcore_states); + * + * long foo_get_a_plus_b(void) + * { + * struct foo_lcore_state *state = RTE_LCORE_VAR_VALUE(lcore_states); + * + * return state->a + state->b; + * } + * + * RTE_INIT(rte_foo_init) + * { + * RTE_LCORE_VAR_ALLOC(lcore_states); + * + * struct foo_lcore_state *state; + * RTE_LCORE_VAR_FOREACH_VALUE(state, lcore_states) { + * (initialize 'state') + * } + * + * (other initialization) + * } + * @endcode + * + * + * @b Alternatives + * + * Lcore variables are designed to replace a pattern exemplified below: + * @code{.c} + * struct __rte_cache_aligned foo_lcore_state { + * int a; + * long b; + * RTE_CACHE_GUARD; + * }; + * + * static struct foo_lcore_state lcore_states[RTE_MAX_LCORE]; + * @endcode + * + * This scheme is simple and effective, but has one drawback: the data + * is organized so that objects related to all lcores for a particular + * module is kept close in memory. At a bare minimum, this forces the + * use of cache-line alignment to avoid false sharing. With CPU + * hardware prefetching and memory loads resulting from speculative + * execution (functions which seemingly are getting more eager faster + * than they are getting more intelligent), one or more "guard" cache + * lines may be required to separate one lcore's data from another's. + * + * Lcore variables has the upside of working with, not against, the + * CPU's assumptions and for example next-line prefetchers may well + * work the way its designers intended (i.e., to the benefit, not + * detriment, of system performance). + * + * Another alternative to @ref rte_lcore_var.h is the @ref + * rte_per_lcore.h API, which make use of thread-local storage (TLS, + * e.g., GCC __thread or C11 _Thread_local). The main differences + * between by using the various forms of TLS (e.g., @ref + * RTE_DEFINE_PER_LCORE or _Thread_local) and the use of lcore + * variables are: + * + * * The existence and non-existence of a thread-local variable + * instance follow that of particular thread's. The data cannot be + * accessed before the thread has been created, nor after it has + * exited. As a result, thread-local variables must initialized in + * a "lazy" manner (e.g., at the point of thread creation). Lcore + * variables may be accessed immediately after having been + * allocated (which may be prior any thread beyond the main + * thread is running). + * * A thread-local variable is duplicated across all threads in the + * process, including unregistered non-EAL threads (i.e., + * "regular" threads). For DPDK applications heavily relying on + * multi-threading (in conjunction to DPDK's "one thread per core" + * pattern), either by having many concurrent threads or + * creating/destroying threads at a high rate, an excessive use of + * thread-local variables may cause inefficiencies (e.g., + * increased thread creation overhead due to thread-local storage + * initialization or increased total RAM footprint usage). Lcore + * variables *only* exist for threads with an lcore id. + * * If data in thread-local storage may be shared between threads + * (i.e., can a pointer to a thread-local variable be passed to + * and successfully dereferenced by non-owning thread) depends on + * the details of the TLS implementation. With GCC __thread and + * GCC _Thread_local, such data sharing is supported. In the C11 + * standard, the result of accessing another thread's + * _Thread_local object is implementation-defined. Lcore variable + * instances may be accessed reliably by any thread. + */ + +#include +#include + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Given the lcore variable type, produces the type of the lcore + * variable handle. + */ +#define RTE_LCORE_VAR_HANDLE_TYPE(type) \ + type * + +/** + * Define a lcore variable handle. + * + * This macro defines a variable which is used as a handle to access + * the various per-lcore id instances of a per-lcore id variable. + * + * The aim with this macro is to make clear at the point of + * declaration that this is an lcore handler, rather than a regular + * pointer. + * + * Add @b static as a prefix in case the lcore variable are only to be + * accessed from a particular translation unit. + */ +#define RTE_LCORE_VAR_HANDLE(type, name) \ + RTE_LCORE_VAR_HANDLE_TYPE(type) name + +/** + * Allocate space for an lcore variable, and initialize its handle. + * + * The values of the lcore variable are initialized to zero. + */ +#define RTE_LCORE_VAR_ALLOC_SIZE_ALIGN(handle, size, align) \ + handle = rte_lcore_var_alloc(size, align) + +/** + * Allocate space for an lcore variable, and initialize its handle, + * with values aligned for any type of object. + * + * The values of the lcore variable are initialized to zero. + */ +#define RTE_LCORE_VAR_ALLOC_SIZE(handle, size) \ + RTE_LCORE_VAR_ALLOC_SIZE_ALIGN(handle, size, 0) + +/** + * Allocate space for an lcore variable of the size and alignment requirements + * suggested by the handler pointer type, and initialize its handle. + * + * The values of the lcore variable are initialized to zero. + */ +#define RTE_LCORE_VAR_ALLOC(handle) \ + RTE_LCORE_VAR_ALLOC_SIZE_ALIGN(handle, sizeof(*(handle)), \ + alignof(typeof(*(handle)))) + +/** + * Allocate an explicitly-sized, explicitly-aligned lcore variable by + * means of a @ref RTE_INIT constructor. + * + * The values of the lcore variable are initialized to zero. + */ +#define RTE_LCORE_VAR_INIT_SIZE_ALIGN(name, size, align) \ + RTE_INIT(rte_lcore_var_init_ ## name) \ + { \ + RTE_LCORE_VAR_ALLOC_SIZE_ALIGN(name, size, align); \ + } + +/** + * Allocate an explicitly-sized lcore variable by means of a @ref + * RTE_INIT constructor. + * + * The values of the lcore variable are initialized to zero. + */ +#define RTE_LCORE_VAR_INIT_SIZE(name, size) \ + RTE_LCORE_VAR_INIT_SIZE_ALIGN(name, size, 0) + +/** + * Allocate an lcore variable by means of a @ref RTE_INIT constructor. + * + * The values of the lcore variable are initialized to zero. + */ +#define RTE_LCORE_VAR_INIT(name) \ + RTE_INIT(rte_lcore_var_init_ ## name) \ + { \ + RTE_LCORE_VAR_ALLOC(name); \ + } + +/** + * Get void pointer to lcore variable instance with the specified + * lcore id. + * + * @param lcore_id + * The lcore id specifying which of the @c RTE_MAX_LCORE value + * instances should be accessed. The lcore id need not be valid + * (e.g., may be @ref LCORE_ID_ANY), but in such a case, the pointer + * is also not valid (and thus should not be dereferenced). + * @param handle + * The lcore variable handle. + */ +static inline void * +rte_lcore_var_lcore_ptr(unsigned int lcore_id, void *handle) +{ + return RTE_PTR_ADD(handle, lcore_id * RTE_MAX_LCORE_VAR); +} + +/** + * Get pointer to lcore variable instance with the specified lcore id. + * + * @param lcore_id + * The lcore id specifying which of the @c RTE_MAX_LCORE value + * instances should be accessed. The lcore id need not be valid + * (e.g., may be @ref LCORE_ID_ANY), but in such a case, the pointer + * is also not valid (and thus should not be dereferenced). + * @param handle + * The lcore variable handle. + */ +#define RTE_LCORE_VAR_LCORE_VALUE(lcore_id, handle) \ + ((typeof(handle))rte_lcore_var_lcore_ptr(lcore_id, handle)) + +/** + * Get pointer to lcore variable instance of the current thread. + * + * May only be used by EAL threads and registered non-EAL threads. + */ +#define RTE_LCORE_VAR_VALUE(handle) \ + RTE_LCORE_VAR_LCORE_VALUE(rte_lcore_id(), handle) + +/** + * Iterate over each lcore id's value for a lcore variable. + * + * @param value + * A pointer set successivly set to point to lcore variable value + * corresponding to every lcore id (up to @c RTE_MAX_LCORE). + * @param handle + * The lcore variable handle. + */ +#define RTE_LCORE_VAR_FOREACH_VALUE(value, handle) \ + for (unsigned int lcore_id = \ + (((value) = RTE_LCORE_VAR_LCORE_VALUE(0, handle)), 0); \ + lcore_id < RTE_MAX_LCORE; \ + lcore_id++, (value) = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, handle)) + +/** + * Allocate space in the per-lcore id buffers for a lcore variable. + * + * The pointer returned is only an opaque identifer of the variable. To + * get an actual pointer to a particular instance of the variable use + * @ref RTE_LCORE_VAR_VALUE or @ref RTE_LCORE_VAR_LCORE_VALUE. + * + * The lcore variable values' memory is set to zero. + * + * The allocation is always successful, barring a fatal exhaustion of + * the per-lcore id buffer space. + * + * rte_lcore_var_alloc() is not multi-thread safe. + * + * @param size + * The size (in bytes) of the variable's per-lcore id value. Must be > 0. + * @param align + * If 0, the values will be suitably aligned for any kind of type + * (i.e., alignof(max_align_t)). Otherwise, the values will be aligned + * on a multiple of *align*, which must be a power of 2 and equal or + * less than @c RTE_CACHE_LINE_SIZE. + * @return + * The id of the variable, stored in a void pointer value. The value + * is always non-NULL. + */ +__rte_experimental +void * +rte_lcore_var_alloc(size_t size, size_t align); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_LCORE_VAR_H_ */ diff --git a/lib/eal/version.map b/lib/eal/version.map index e3ff412683..5f5a3522c0 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -396,6 +396,9 @@ EXPERIMENTAL { # added in 24.03 rte_vfio_get_device_info; # WINDOWS_NO_EXPORT + + rte_lcore_var_alloc; + rte_lcore_var; }; INTERNAL { From patchwork Tue Sep 10 07:03:40 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: 143842 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 5A7FF45952; Tue, 10 Sep 2024 09:13:31 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9075540151; Tue, 10 Sep 2024 09:13:13 +0200 (CEST) Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2076.outbound.protection.outlook.com [40.107.105.76]) by mails.dpdk.org (Postfix) with ESMTP id 100D64278C for ; Tue, 10 Sep 2024 09:13:11 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tirgR3S8vwn10VNZ5qWhfTTp9AiyHEzxXmvEav8HwFPTZDGD8efY2z4bPEF/8kuRPcH+8Ogq0N6jTkqzygPIjnZN02MHHp5EpsdsdaM5oZOVQMwWrDHQKjwd2A0qYTSRv6gvEmH9Ou77FchPT7xlnWugO6dx8bbs3zwymlAawF3pKwNJgFedQ5MlWu7Ou9DEgEkkoxHxwE8fvTcsilqy5dmGhTcQDxlNzC+23saPfUkw1gM0Unux7udQEagixigaxKtBolhWYcwRK26CpD2iEQEIbpZYJLHek/qZrLe0S0xhw2Omz1w9oitQKv/cPDu5WgCY08H5x6adxSP4hie+cg== 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=75z+lMU0W9MYrOZSbeH4OIEGHZjSiMo6/I9oUTCcslU=; b=j2iqS5KSEw2TTilCrhV/s9EIrmH0Rrd71R15smXpyHQR6vyegf+ekQ76eDw8PiIqw3cjmLRcTbyBiW5xv4TMvMd73QDY0LbUxUfoWGOrtiyITMCAqdZfNozeX5FNZ57O+vIicDHhKBrVvqpTW/5G5y+05ml6FQrAXHx4ajzSGlT/ELr2RBJmhorXPjfUH7RZlelDCjpc0/eu1vA60QH5TH3E3QbS5+ZdDAyJtmUJ9De9EMqSwc2R5RHGlPToqKOMC+MhBalEo7R0d1WlkAUlAC4JNdqbOnsksDHUQmCEjdlUHu0jKGtxGDHqGHIsvZvu8dZzBLluVaPi3W/AiW99tg== 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=75z+lMU0W9MYrOZSbeH4OIEGHZjSiMo6/I9oUTCcslU=; b=u+5bBaZ/s3kcIu9PADyFn37g63CKiZAGnkQGtreugvM6nq4zHeViAIBSiIRJvDxlLMy39/2xiyfLc2nGHNobntqLQllRAF5wfMgg5t9BfJu9eoWXciLKzRvwpdCq86BY90OeF/lQlgJS9eU1eBUdHYigltYU/u9/GSjuHM86TdeJUYs2g9AjTJVkkrGd7hqcqKRM0S7Z7eNRQ3OP1QYZ+O0FQn71nNbZNFwv2n0ZD3Qcbb+ATUO3/8hgerplVWt2b+t/m5as4aECIiw8zdEG54oMIRMJg4yUCE4IFS2u0Ws1Sc70QAHnPp9Bn9H4KMTSg6J3vmKYQ6WGuYOhzw2mcQ== Received: from DU7PR01CA0003.eurprd01.prod.exchangelabs.com (2603:10a6:10:50f::17) by AM9PR07MB7202.eurprd07.prod.outlook.com (2603:10a6:20b:2d3::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24; Tue, 10 Sep 2024 07:13:06 +0000 Received: from DU6PEPF00009524.eurprd02.prod.outlook.com (2603:10a6:10:50f:cafe::4d) by DU7PR01CA0003.outlook.office365.com (2603:10a6:10:50f::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.25 via Frontend Transport; Tue, 10 Sep 2024 07:13:06 +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 DU6PEPF00009524.mail.protection.outlook.com (10.167.8.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Tue, 10 Sep 2024 07:13:06 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.69) with Microsoft SMTP Server id 15.2.1544.11; Tue, 10 Sep 2024 09:13:05 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 82A0938007A; Tue, 10 Sep 2024 09:13:05 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , =?utf-8?q?Morten_Br=C3=B8rup?= , Stephen Hemminger , Konstantin Ananyev , David Marchand , =?utf-8?q?Mattias_R=C3=B6nnblom?= Subject: [PATCH 2/6] eal: add lcore variable test suite Date: Tue, 10 Sep 2024 09:03:40 +0200 Message-ID: <20240910070344.699183-3-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910070344.699183-1-mattias.ronnblom@ericsson.com> References: <20240506082721.120666-2-mattias.ronnblom@ericsson.com> <20240910070344.699183-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU6PEPF00009524:EE_|AM9PR07MB7202:EE_ X-MS-Office365-Filtering-Correlation-Id: ac94b390-9244-44b1-4d30-08dcd1680491 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|36860700013|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?q?ykkAKEQce9gPU1hZ/iNF2XuMj5DuoVF?= =?utf-8?q?s6zOcowVnGYCnrq/qDXH8fmTManmuURgeE5BrlZiPcWlLL5gli3WpwlMbD75gzefG?= =?utf-8?q?gRuRy1unJ7WP5SYCmnGuQtpkf6HEJxSE591YrOcBKX0FFLQrAoqe6oLX7nor5WBAZ?= =?utf-8?q?Ew+RwN9eorLqOuds+CkhHWGXSsTjqlBXXbHt1RhmxvOO/GxjtfkAzTZSh4r1iKtWX?= =?utf-8?q?WGzjxCQoQyuajJCEC6sfkWshhR+uB3PATJ9tRxiDyRR9PKb6Fkog+zIng5iX3JtZt?= =?utf-8?q?BIBJ0nna83o32q4NpF0SsKihT5tNRn6zatXpvyVRduwG/Vs00kQL7xetaw/OIycnR?= =?utf-8?q?HGz3O1Ffmdfc9jZc6r7lgzOs6hoD2aQLQgFk8JrceC2/yyf/UYxR0B4HuCyC12rNq?= =?utf-8?q?GnLdf1eE3ksRE2qPwhJbpcuLg8rCtf036yDi+0zp6n51/EjriN8C+kZUpmPdaKIb5?= =?utf-8?q?LkQu71QzcFFFnfY3QOqroFZOMBL8EGpYIpDik24vJc7s7B+tYfJgzbV/HFte/IRhy?= =?utf-8?q?PbHGzxykEqP2YImp70sIf6Aftskge3qgHbyGUIBzwEjextvyRw8nwHSLnFP3N/crH?= =?utf-8?q?znOu0P4Iv0HFUB4ddQVH9QstcmodFKYs7fTik2EoNqUSMMcNaHD54jHV53Macsnmd?= =?utf-8?q?WpNVikCcv2TRttsEebHMQ6iSn9VEc3udXWgDfHaz2faaIeN98HH35Z38Wmd4sq+a1?= =?utf-8?q?sIv8Malx/pHfAXzRyHjhYl6gCREmfIzX/kLGd5vD1omz5Y1f5qaLagnOKCwi8kD2k?= =?utf-8?q?vZIuBHNsd6icFDoWm4R22WPb+X/LIZGg+BMK9HRz5Em6L8xy8jduGtfh37q5fnifD?= =?utf-8?q?BIdfG3bX8Ul8goinK4BcuBxUPJpxuSy6vCCnWhBu+1JPa9wP03o5YJHoP4kDV0xPG?= =?utf-8?q?/10tlnZN8NdXc1fU0MhpldYDtcYqHZflMxKU29omvsKTb8Zagta6HZqIORAjsR4md?= =?utf-8?q?6V2WNDF+Ae73H6ypp3NetNSc2DmDZb5gKpyrnQeFj0wPfbbylgdMhBPwkmaSt/Q9N?= =?utf-8?q?EDd00D06dWsHa+DeMk/yRsizwCqqEkXdGu4R1+LsZ9Az5hr99J2U2A9tX+WUfyQKc?= =?utf-8?q?xJ8193GkkaXSRio5cxzPhhd+zxbdldqYx4BBfcOrmkXaze4Eja5kUhOzY51BK9VqE?= =?utf-8?q?dBFPRxRX/EpqaoOgfka0ITGznL4sjheWSxPMXODK3HWKPsLwPs9v3aLjkcUzl52M7?= =?utf-8?q?9FZBsZVvGj03ZxlXrQNJc65e4sIpTpOyZfMke9HxR8VYgHL3nZy1jO8j25dEFyW+Q?= =?utf-8?q?0yKZ73s96lUU1QLEK6OiGVDryN4moHyXaN0qiewL+pI0ea0ctHk4vnC6KG+h8jFEB?= =?utf-8?q?pS4M2uCbizA9qEmboZ7/kjs/qzwxu+2upQKfcaNERjoSHNo4GmxOox4W9r9fNWxQ7?= =?utf-8?q?Cx7pqYh2Rmx?= 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)(376014)(36860700013)(82310400026)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 07:13:06.2421 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ac94b390-9244-44b1-4d30-08dcd1680491 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: DU6PEPF00009524.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR07MB7202 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 test suite to exercise the API. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup --- RFC v5: * Adapt tests to reflect the removal of the GET() and SET() macros. RFC v4: * Check all lcore id's values for all variables in the many variables test case. * Introduce test case for max-sized lcore variables. RFC v2: * Improve alignment-related test coverage. --- app/test/meson.build | 1 + app/test/test_lcore_var.c | 432 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 433 insertions(+) create mode 100644 app/test/test_lcore_var.c diff --git a/app/test/meson.build b/app/test/meson.build index e29258e6ec..48279522f0 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -103,6 +103,7 @@ source_file_deps = { 'test_ipsec_sad.c': ['ipsec'], 'test_kvargs.c': ['kvargs'], 'test_latencystats.c': ['ethdev', 'latencystats', 'metrics'] + sample_packet_forward_deps, + 'test_lcore_var.c': [], 'test_lcores.c': [], 'test_link_bonding.c': ['ethdev', 'net_bond', 'net'] + packet_burst_generator_deps + virtual_pmd_deps, diff --git a/app/test/test_lcore_var.c b/app/test/test_lcore_var.c new file mode 100644 index 0000000000..e07d13460f --- /dev/null +++ b/app/test/test_lcore_var.c @@ -0,0 +1,432 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 Ericsson AB + */ + +#include +#include +#include + +#include +#include +#include + +#include "test.h" + +#define MIN_LCORES 2 + +RTE_LCORE_VAR_HANDLE(int, test_int); +RTE_LCORE_VAR_HANDLE(char, test_char); +RTE_LCORE_VAR_HANDLE(long, test_long_sized); +RTE_LCORE_VAR_HANDLE(short, test_short); +RTE_LCORE_VAR_HANDLE(long, test_long_sized_aligned); + +struct int_checker_state { + int old_value; + int new_value; + bool success; +}; + +static void +rand_blk(void *blk, size_t size) +{ + size_t i; + + for (i = 0; i < size; i++) + ((unsigned char *)blk)[i] = (unsigned char)rte_rand(); +} + +static bool +is_ptr_aligned(const void *ptr, size_t align) +{ + return ptr != NULL ? (uintptr_t)ptr % align == 0 : false; +} + +static int +check_int(void *arg) +{ + struct int_checker_state *state = arg; + + int *ptr = RTE_LCORE_VAR_VALUE(test_int); + + bool naturally_aligned = is_ptr_aligned(ptr, sizeof(int)); + + bool equal = *(RTE_LCORE_VAR_VALUE(test_int)) == state->old_value; + + state->success = equal && naturally_aligned; + + *ptr = state->new_value; + + return 0; +} + +RTE_LCORE_VAR_INIT(test_int); +RTE_LCORE_VAR_INIT(test_char); +RTE_LCORE_VAR_INIT_SIZE(test_long_sized, 32); +RTE_LCORE_VAR_INIT(test_short); +RTE_LCORE_VAR_INIT_SIZE_ALIGN(test_long_sized_aligned, sizeof(long), + RTE_CACHE_LINE_SIZE); + +static int +test_int_lvar(void) +{ + unsigned int lcore_id; + + struct int_checker_state states[RTE_MAX_LCORE] = {}; + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + struct int_checker_state *state = &states[lcore_id]; + + state->old_value = (int)rte_rand(); + state->new_value = (int)rte_rand(); + + *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, test_int) = + state->old_value; + } + + RTE_LCORE_FOREACH_WORKER(lcore_id) + rte_eal_remote_launch(check_int, &states[lcore_id], lcore_id); + + rte_eal_mp_wait_lcore(); + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + struct int_checker_state *state = &states[lcore_id]; + int value; + + TEST_ASSERT(state->success, "Unexpected value " + "encountered on lcore %d", lcore_id); + + value = *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, test_int); + TEST_ASSERT_EQUAL(state->new_value, value, + "Lcore %d failed to update int", lcore_id); + } + + /* take the opportunity to test the foreach macro */ + int *v; + lcore_id = 0; + RTE_LCORE_VAR_FOREACH_VALUE(v, test_int) { + TEST_ASSERT_EQUAL(states[lcore_id].new_value, *v, + "Unexpected value on lcore %d during " + "iteration", lcore_id); + lcore_id++; + } + + return TEST_SUCCESS; +} + +static int +test_sized_alignment(void) +{ + long *v; + + RTE_LCORE_VAR_FOREACH_VALUE(v, test_long_sized) { + TEST_ASSERT(is_ptr_aligned(v, alignof(long)), + "Type-derived alignment failed"); + } + + RTE_LCORE_VAR_FOREACH_VALUE(v, test_long_sized_aligned) { + TEST_ASSERT(is_ptr_aligned(v, RTE_CACHE_LINE_SIZE), + "Explicit alignment failed"); + } + + return TEST_SUCCESS; +} + +/* private, larger, struct */ +#define TEST_STRUCT_DATA_SIZE 1234 + +struct test_struct { + uint8_t data[TEST_STRUCT_DATA_SIZE]; +}; + +static RTE_LCORE_VAR_HANDLE(char, before_struct); +static RTE_LCORE_VAR_HANDLE(struct test_struct, test_struct); +static RTE_LCORE_VAR_HANDLE(char, after_struct); + +struct struct_checker_state { + struct test_struct old_value; + struct test_struct new_value; + bool success; +}; + +static int check_struct(void *arg) +{ + struct struct_checker_state *state = arg; + + struct test_struct *lcore_struct = RTE_LCORE_VAR_VALUE(test_struct); + + bool properly_aligned = + is_ptr_aligned(test_struct, alignof(struct test_struct)); + + bool equal = memcmp(lcore_struct->data, state->old_value.data, + TEST_STRUCT_DATA_SIZE) == 0; + + state->success = equal && properly_aligned; + + memcpy(lcore_struct->data, state->new_value.data, + TEST_STRUCT_DATA_SIZE); + + return 0; +} + +static int +test_struct_lvar(void) +{ + unsigned int lcore_id; + + RTE_LCORE_VAR_ALLOC(before_struct); + RTE_LCORE_VAR_ALLOC(test_struct); + RTE_LCORE_VAR_ALLOC(after_struct); + + struct struct_checker_state states[RTE_MAX_LCORE]; + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + struct struct_checker_state *state = &states[lcore_id]; + + rand_blk(state->old_value.data, TEST_STRUCT_DATA_SIZE); + rand_blk(state->new_value.data, TEST_STRUCT_DATA_SIZE); + + memcpy(RTE_LCORE_VAR_LCORE_VALUE(lcore_id, test_struct)->data, + state->old_value.data, TEST_STRUCT_DATA_SIZE); + } + + RTE_LCORE_FOREACH_WORKER(lcore_id) + rte_eal_remote_launch(check_struct, &states[lcore_id], + lcore_id); + + rte_eal_mp_wait_lcore(); + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + struct struct_checker_state *state = &states[lcore_id]; + struct test_struct *lstruct = + RTE_LCORE_VAR_LCORE_VALUE(lcore_id, test_struct); + + TEST_ASSERT(state->success, "Unexpected value encountered on " + "lcore %d", lcore_id); + + bool equal = memcmp(lstruct->data, state->new_value.data, + TEST_STRUCT_DATA_SIZE) == 0; + + TEST_ASSERT(equal, "Lcore %d failed to update struct", + lcore_id); + } + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + char before = + *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, before_struct); + char after = + *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, after_struct); + + TEST_ASSERT_EQUAL(before, 0, "Lcore variable before test " + "struct was modified on lcore %d", lcore_id); + TEST_ASSERT_EQUAL(after, 0, "Lcore variable after test " + "struct was modified on lcore %d", lcore_id); + } + + return TEST_SUCCESS; +} + +#define TEST_ARRAY_SIZE 99 + +typedef uint16_t test_array_t[TEST_ARRAY_SIZE]; + +static void test_array_init_rand(test_array_t a) +{ + size_t i; + for (i = 0; i < TEST_ARRAY_SIZE; i++) + a[i] = (uint16_t)rte_rand(); +} + +static bool test_array_equal(test_array_t a, test_array_t b) +{ + size_t i; + for (i = 0; i < TEST_ARRAY_SIZE; i++) { + if (a[i] != b[i]) + return false; + } + return true; +} + +static void test_array_copy(test_array_t dst, const test_array_t src) +{ + size_t i; + for (i = 0; i < TEST_ARRAY_SIZE; i++) + dst[i] = src[i]; +} + +static RTE_LCORE_VAR_HANDLE(char, before_array); +static RTE_LCORE_VAR_HANDLE(test_array_t, test_array); +static RTE_LCORE_VAR_HANDLE(char, after_array); + +struct array_checker_state { + test_array_t old_value; + test_array_t new_value; + bool success; +}; + +static int check_array(void *arg) +{ + struct array_checker_state *state = arg; + + test_array_t *lcore_array = RTE_LCORE_VAR_VALUE(test_array); + + bool properly_aligned = + is_ptr_aligned(lcore_array, alignof(test_array_t)); + + bool equal = test_array_equal(*lcore_array, state->old_value); + + state->success = equal && properly_aligned; + + test_array_copy(*lcore_array, state->new_value); + + return 0; +} + +static int +test_array_lvar(void) +{ + unsigned int lcore_id; + + RTE_LCORE_VAR_ALLOC(before_array); + RTE_LCORE_VAR_ALLOC(test_array); + RTE_LCORE_VAR_ALLOC(after_array); + + struct array_checker_state states[RTE_MAX_LCORE]; + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + struct array_checker_state *state = &states[lcore_id]; + + test_array_init_rand(state->new_value); + test_array_init_rand(state->old_value); + + test_array_copy(*RTE_LCORE_VAR_LCORE_VALUE(lcore_id, + test_array), + state->old_value); + } + + RTE_LCORE_FOREACH_WORKER(lcore_id) + rte_eal_remote_launch(check_array, &states[lcore_id], + lcore_id); + + rte_eal_mp_wait_lcore(); + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + struct array_checker_state *state = &states[lcore_id]; + test_array_t *larray = + RTE_LCORE_VAR_LCORE_VALUE(lcore_id, test_array); + + TEST_ASSERT(state->success, "Unexpected value encountered on " + "lcore %d", lcore_id); + + bool equal = test_array_equal(*larray, state->new_value); + + TEST_ASSERT(equal, "Lcore %d failed to update array", + lcore_id); + } + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + char before = + *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, before_array); + char after = + *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, after_array); + + TEST_ASSERT_EQUAL(before, 0, "Lcore variable before test " + "array was modified on lcore %d", lcore_id); + TEST_ASSERT_EQUAL(after, 0, "Lcore variable after test " + "array was modified on lcore %d", lcore_id); + } + + return TEST_SUCCESS; +} + +#define MANY_LVARS (2 * RTE_MAX_LCORE_VAR / sizeof(uint32_t)) + +static int +test_many_lvars(void) +{ + uint32_t **handlers = malloc(sizeof(uint32_t *) * MANY_LVARS); + unsigned int i; + + TEST_ASSERT(handlers != NULL, "Unable to allocate memory"); + + for (i = 0; i < MANY_LVARS; i++) { + unsigned int lcore_id; + + RTE_LCORE_VAR_ALLOC(handlers[i]); + + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { + uint32_t *v = + RTE_LCORE_VAR_LCORE_VALUE(lcore_id, handlers[i]); + *v = (uint32_t)(i * lcore_id); + } + } + + for (i = 0; i < MANY_LVARS; i++) { + unsigned int lcore_id; + + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { + uint32_t v = *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, + handlers[i]); + TEST_ASSERT_EQUAL((uint32_t)(i * lcore_id), v, + "Unexpected lcore variable value on " + "lcore %d", lcore_id); + } + } + + free(handlers); + + return TEST_SUCCESS; +} + +static int +test_large_lvar(void) +{ + RTE_LCORE_VAR_HANDLE(unsigned char, large); + unsigned int lcore_id; + + RTE_LCORE_VAR_ALLOC_SIZE(large, RTE_MAX_LCORE_VAR); + + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { + unsigned char *ptr = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, large); + + memset(ptr, (unsigned char)lcore_id, RTE_MAX_LCORE_VAR); + } + + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { + unsigned char *ptr = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, large); + size_t i; + + for (i = 0; i < RTE_MAX_LCORE_VAR; i++) + TEST_ASSERT_EQUAL(ptr[i], (unsigned char)lcore_id, + "Large lcore variable value is " + "corrupted on lcore %d.", + lcore_id); + } + + return TEST_SUCCESS; +} + +static struct unit_test_suite lcore_var_testsuite = { + .suite_name = "lcore variable autotest", + .unit_test_cases = { + TEST_CASE(test_int_lvar), + TEST_CASE(test_sized_alignment), + TEST_CASE(test_struct_lvar), + TEST_CASE(test_array_lvar), + TEST_CASE(test_many_lvars), + TEST_CASE(test_large_lvar), + TEST_CASES_END() + }, +}; + +static int test_lcore_var(void) +{ + if (rte_lcore_count() < MIN_LCORES) { + printf("Not enough cores for lcore_var_autotest; expecting at " + "least %d.\n", MIN_LCORES); + return TEST_SKIPPED; + } + + return unit_test_suite_runner(&lcore_var_testsuite); +} + +REGISTER_FAST_TEST(lcore_var_autotest, true, false, test_lcore_var); From patchwork Tue Sep 10 07:03:41 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: 143844 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 BE5C545952; Tue, 10 Sep 2024 09:13:49 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EF977427BB; Tue, 10 Sep 2024 09:13:16 +0200 (CEST) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2050.outbound.protection.outlook.com [40.107.21.50]) by mails.dpdk.org (Postfix) with ESMTP id 525D442793 for ; Tue, 10 Sep 2024 09:13:12 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KYClWTMPvU5D4wRUwJQCCMyEv+v0JiW88M3yXBHaAYm8qL1ZHGIePlFMPIfs2Q5XmvTbfrrFNJDN7SStwR4uzOAhVPC0Pmlh18IOBK+twmZKNRXLiPs5/909yVrqSHoxxZBpT/6AQImgI32pWie6k/xZJcMfI1XkQYEUrRZuPn+E1YzMWmGTmRHugU1ZC0eTi64ikwSBlPypPHLOVcUapbbAZxjdfJBIRWrWm7FoN5hMjXphLfmCJDVrcnt3cyBZ/F65al42ZVlvtcvTOo/wZt/nbuDQeB5omXelHGuagLqU1Az6SxfxNBNdZNc9O6qRFxZnA/0vRPTNV/RHY5sLEw== 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=zISDW1GBkEsa6ggWGIfXJzOVRhTUGIhGxNJ8LygZRHo=; b=c/MOS/+dRG0z0gX8jh99c5Nd4VS3n485K/iuO/clLFMzoQoBil+ZvqiArB8Jm/fRnbrB4FZc2QEA6mhaoZuaGLm4AawnVMIx4OpQgnApGd+BQBj4TqJ0iuxI1dglOU7h+7uhlPpCkDNHKyjPSj/bi4jhgpJ5MLnwe8z4KiiDcR0/GRS4LUpWMNFko8sLEfBUjzmzUC1k9sIgau3Rn7eGcmN0oYzBJYWIfrdu+q/WNMlPqmVEcI9Y6Cj0rqqZp1M1sKtFbWszA6IlULebGkE0ASZcYBvP3TYl3uJquc6EwzsIYbxijqpEHhk2alTqCJCjKxu2tZ1L4HfN4xvrOw78oQ== 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=zISDW1GBkEsa6ggWGIfXJzOVRhTUGIhGxNJ8LygZRHo=; b=X1NFwLd2Ikc1nfmn+fiwjFXa1ZHjIXfrEIaDw24ZWEl/n/EtmOFyZ4B46YMP3xvbfSs8Cjq40LzJ3zrCunn+7nbUtTgg0kBRVWq6QQnVsNAaVM2x/ZU2WsDn5yq14+nc4x+RqR283bwXbrVx6sh0aAzU4aAb8Wxa8aXBpaACAC8kqnteei/fEdbjxkocsmLH0n5fR1ERH37C0IZuQxh7GDjfnTBe/CnKxMxLZWfF2TP6ekbRjmzPNrPuAeF4FuIY54oDRA/JQ3T35c2fpz4cA50/HyUvs+VeOce3+gELlxv9l1XRIJ9c9MbD7Uzv5dvi0iDEFDg+rv/rGakZwdPrVg== Received: from AS8PR07CA0043.eurprd07.prod.outlook.com (2603:10a6:20b:459::12) by AM9PR07MB7841.eurprd07.prod.outlook.com (2603:10a6:20b:305::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24; Tue, 10 Sep 2024 07:13:07 +0000 Received: from AMS0EPF000001A0.eurprd05.prod.outlook.com (2603:10a6:20b:459:cafe::30) by AS8PR07CA0043.outlook.office365.com (2603:10a6:20b:459::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24 via Frontend Transport; Tue, 10 Sep 2024 07:13:07 +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 AMS0EPF000001A0.mail.protection.outlook.com (10.167.16.230) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Tue, 10 Sep 2024 07:13:07 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.65) with Microsoft SMTP Server id 15.2.1544.11; Tue, 10 Sep 2024 09:13:05 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 9482F380061; Tue, 10 Sep 2024 09:13:05 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , =?utf-8?q?Morten_Br=C3=B8rup?= , Stephen Hemminger , Konstantin Ananyev , David Marchand , =?utf-8?q?Mattias_R=C3=B6nnblom?= Subject: [PATCH 3/6] random: keep PRNG state in lcore variable Date: Tue, 10 Sep 2024 09:03:41 +0200 Message-ID: <20240910070344.699183-4-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910070344.699183-1-mattias.ronnblom@ericsson.com> References: <20240506082721.120666-2-mattias.ronnblom@ericsson.com> <20240910070344.699183-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AMS0EPF000001A0:EE_|AM9PR07MB7841:EE_ X-MS-Office365-Filtering-Correlation-Id: e2975098-811a-46d3-50b1-08dcd1680511 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?q?1oqJBlymlG2JQo+y+lluNMKFu7bttb+?= =?utf-8?q?i1X5bzJ+CFkRpPtN++WittTf06l3J9cx3I26EuqmRSJGHEXcDz4+wNnJRk0G2GFzM?= =?utf-8?q?+THr/IisOb8Ba6VwSd2w+BMzC96y49QEO4TLUo48amrSUhPdJKjhbeRxiGAikXED/?= =?utf-8?q?QJYMm55lvnFzw0pxKmSgvuSOpX6/bF8AMOQ7DerVE6rIN5wqv6JUYXCw0lkfr9mql?= =?utf-8?q?TNwAzCqrkFb53wX2qeb3A+VN4+lD/hsKmqEue6foS3ar6Dp/u4q3BWqQkT47gYma3?= =?utf-8?q?0ZeduMWOh19mT5WW1eI5pQ2JwEhT+WD7jTRqL1k+QDeA4GvdF4KNHSt2whE2mb5m0?= =?utf-8?q?iyYqZ6D2CZuYR18niJL4jjbZPTcgxvGz9ywltlGUlEnuHssdpT1GpHKMWcMnRp67Q?= =?utf-8?q?opv22RE5j3nMP3YL+0ffEBRgUeHrpwu1Rgk19RLfx+2oVgJkzZYH8xlqpVaOcTw84?= =?utf-8?q?GdOat7ioPx2kc8v4yJuV1kYuUjEtZ9dmkcuyb80FmRbB/BMPv3QlNvCNz/kM/lQ2W?= =?utf-8?q?kpDqfkugbG1hDAooaJU336CXUwQko8e3l7kmE3Zwegu9Z4m7IYxaIiIDAUypYku6i?= =?utf-8?q?v3c88KYMy3cXT1m4spRoMMgrct0INc9bI52aLPcQVhbdZd8HGD37L67/D/Z2kJ69l?= =?utf-8?q?hPKCy80WllFbIT/SpfDKbvy8XDj1biuv0lr0dDvnIbSrlxh2vPII6m6h8R/vdHCoG?= =?utf-8?q?Lgn67HG9xvnEweFhB/meadoXWvIbAypBZiaEz8bmv/TbWCjNc75vVUyhMUTMEPcBw?= =?utf-8?q?Dhk0yNJXDz7qCgsJQ/zkZiqcrE7W2igTEfAWSa93RZkE3ogAN9XwTMHl223uXPWy4?= =?utf-8?q?OqiPXmAGpiaM4Qj3wcoq+tUQSOPPasyjN3WwIV1BX2xd4ytD1saoX5sjmfBxmuI6v?= =?utf-8?q?77G6aOInB7cO4HBEeotLLAhh/mEbMBfi7UjT7OC1G20NN8cHjMvl+S3qKJ37+nPHB?= =?utf-8?q?2+0xI1M3lFuGoZJnX4I4REDLaO+eK+xk+ZXyKIn537AZ/xYg7PVFYYLWTTvxm54Ko?= =?utf-8?q?E6mEYT4cC8le5D5P0ZPjzHOfxMaSf6EEzN3fRafWj+mFiD3yLjxk/TiYL4nnV3R5m?= =?utf-8?q?Gn8RMEWVvJE8Qyxqdb4rdV0BMla+26icWLAKRyTI9NT5csgrUXPtzCeaR/SRC9qZi?= =?utf-8?q?St6y11lH1QLPFuW1xHB/aF2IZ3pQn3wYsaQjLRRCUqCIbhAZUwE3KDnVuWA7xxUuW?= =?utf-8?q?TE88lt3KBFpVyCpIa3MuDoovaPFBT/hS0ilpW1lnDHmYcW1mE+s8Iue4C/HBCM1ww?= =?utf-8?q?x2oUln1uzF/iQIPwM5u2OVEJjlfNuqPpP6imh6S2ZXTUTizAsZO0kVKbH2KHWbh1e?= =?utf-8?q?czSJYih4W4HuoNhX9xv+MalBF7CQuGwG2DzdcFfj8J6nVQa4aTtkYQA7T2yVp1gsL?= =?utf-8?q?9CnOP3etmeS?= 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)(376014)(36860700013)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 07:13:07.0342 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e2975098-811a-46d3-50b1-08dcd1680511 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: AMS0EPF000001A0.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR07MB7841 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 Replace keeping PRNG state in a RTE_MAX_LCORE-sized static array of cache-aligned and RTE_CACHE_GUARDed struct instances with keeping the same state in a more cache-friendly lcore variable. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup --- RFC v3: * Remove cache alignment on unregistered threads' rte_rand_state. (Morten Brørup) --- lib/eal/common/rte_random.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/eal/common/rte_random.c b/lib/eal/common/rte_random.c index 90e91b3c4f..a8d00308dd 100644 --- a/lib/eal/common/rte_random.c +++ b/lib/eal/common/rte_random.c @@ -11,6 +11,7 @@ #include #include #include +#include #include struct __rte_cache_aligned rte_rand_state { @@ -19,14 +20,12 @@ struct __rte_cache_aligned rte_rand_state { uint64_t z3; uint64_t z4; uint64_t z5; - RTE_CACHE_GUARD; }; -/* One instance each for every lcore id-equipped thread, and one - * additional instance to be shared by all others threads (i.e., all - * unregistered non-EAL threads). - */ -static struct rte_rand_state rand_states[RTE_MAX_LCORE + 1]; +RTE_LCORE_VAR_HANDLE(struct rte_rand_state, rand_state); + +/* instance to be shared by all unregistered non-EAL threads */ +static struct rte_rand_state unregistered_rand_state; static uint32_t __rte_rand_lcg32(uint32_t *seed) @@ -85,8 +84,14 @@ rte_srand(uint64_t seed) unsigned int lcore_id; /* add lcore_id to seed to avoid having the same sequence */ - for (lcore_id = 0; lcore_id < RTE_DIM(rand_states); lcore_id++) - __rte_srand_lfsr258(seed + lcore_id, &rand_states[lcore_id]); + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { + struct rte_rand_state *lcore_state = + RTE_LCORE_VAR_LCORE_VALUE(lcore_id, rand_state); + + __rte_srand_lfsr258(seed + lcore_id, lcore_state); + } + + __rte_srand_lfsr258(seed + lcore_id, &unregistered_rand_state); } static __rte_always_inline uint64_t @@ -124,11 +129,10 @@ struct rte_rand_state *__rte_rand_get_state(void) idx = rte_lcore_id(); - /* last instance reserved for unregistered non-EAL threads */ if (unlikely(idx == LCORE_ID_ANY)) - idx = RTE_MAX_LCORE; + return &unregistered_rand_state; - return &rand_states[idx]; + return RTE_LCORE_VAR_VALUE(rand_state); } uint64_t @@ -228,6 +232,8 @@ RTE_INIT(rte_rand_init) { uint64_t seed; + RTE_LCORE_VAR_ALLOC(rand_state); + seed = __rte_random_initial_seed(); rte_srand(seed); From patchwork Tue Sep 10 07:03:42 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: 143841 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 E59E245952; Tue, 10 Sep 2024 09:13:23 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6798842798; Tue, 10 Sep 2024 09:13:12 +0200 (CEST) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2064.outbound.protection.outlook.com [40.107.104.64]) by mails.dpdk.org (Postfix) with ESMTP id DAF8342789 for ; Tue, 10 Sep 2024 09:13:10 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=v3CE3ELjbILKt66aK/ZfZCBo55mcN6dFTuIo1dwOEEI0QmcrYDUfTlyvJH22+TnkZx0CSszdSuOU+FM+f2zUoTwGmMmXQospse9/Fk8ysSZqVprEtStqg+XtQ+UJ6W5TRaFutY8Emm3bG/9XkPgSUn14hrtYM6wfNWGHrNuwBnbv3Pt354z6hI/pM0+dKMes0JSqZpA3mpyVH1v8JPkPRvVBtrxr+7fHpQgT1TOg/tSCyDthU9zi8zs3FB1XZeovl1ryJrcnO39kG0fEDG7ZYSvH6Fg20bskC61f9eWSrSCtsmbCh9gH+QM3ixjjzE5N5sYqNlsfCZ/kr/gAZAVupg== 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=kBpxqgX85DWxmyTJGvSPz7yoWBkPj6gMBWw5io8Onaw=; b=Bnv3fhEigfCjgXR3N50oul4L77+ZhQGs+jI0FbcYFAUMaDLuLblh9dxYup+Nydm3K/GUIh0ESB85dGCI42vkYZtIQf8w1ydGm3CCRQryMvmVbqhkIcqm+lQswttduegrjmd/Yb3tq91NQ7EGryhXGFXRj1/Hq8eVVzgtWtZn2zvQjB3hyGYZg3GUVDPKpcBIsw0lYxEjZgkJpH/dlWVYvl+hcBHVwHkpO2OZCtLcWFi01M2RwatPTb57t786OIPhVXnOL+yRL776GDO+GNtOQ8himMk+gmGWn56F0+U4nYi33sqCxWTnWOMZrLc2pXYDRFSKv8MhN4zzBAo5ETWUCQ== 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=kBpxqgX85DWxmyTJGvSPz7yoWBkPj6gMBWw5io8Onaw=; b=gOIzyotvxFaqSWs6SCmURa1VK9/kMRq8HjKPFPma+SVeeGxVT0kprf9PD91P6Umbl+lmhUhvf/G4g5IROrY3C1q+VfATCqjN+hK9SMpYI4RyUWnFaOdmJDCgGXtDHFTxCrJCwwTkqzDrYSVwihu02qpNbR9liJlyXlIamynXF2beq5T3RgUQrXsZhFkphbg5T3y89rSNQxQCmbRgL+qdLjaS2QdFSE1IXpuURNe72Nnaj423a7AM7rdXGBSrDjupAbne2RphuhPPs5CEtkf813HM4zPYDvrgsy2H9Mcym/W9X1dOgg+BcXIg+bpJh13zKTKoTLV5I76L5VLt/Zssaw== Received: from DB7PR02CA0013.eurprd02.prod.outlook.com (2603:10a6:10:52::26) by AS2PR07MB9278.eurprd07.prod.outlook.com (2603:10a6:20b:60e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.28; Tue, 10 Sep 2024 07:13:06 +0000 Received: from DU2PEPF00028CFF.eurprd03.prod.outlook.com (2603:10a6:10:52:cafe::c5) by DB7PR02CA0013.outlook.office365.com (2603:10a6:10:52::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.23 via Frontend Transport; Tue, 10 Sep 2024 07:13:06 +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 DU2PEPF00028CFF.mail.protection.outlook.com (10.167.242.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Tue, 10 Sep 2024 07:13:06 +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.11; Tue, 10 Sep 2024 09:13:05 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id A39D838007D; Tue, 10 Sep 2024 09:13:05 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , =?utf-8?q?Morten_Br=C3=B8rup?= , Stephen Hemminger , Konstantin Ananyev , David Marchand , =?utf-8?q?Mattias_R=C3=B6nnblom?= Subject: [PATCH 4/6] power: keep per-lcore state in lcore variable Date: Tue, 10 Sep 2024 09:03:42 +0200 Message-ID: <20240910070344.699183-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910070344.699183-1-mattias.ronnblom@ericsson.com> References: <20240506082721.120666-2-mattias.ronnblom@ericsson.com> <20240910070344.699183-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PEPF00028CFF:EE_|AS2PR07MB9278:EE_ X-MS-Office365-Filtering-Correlation-Id: 7bd3716e-99bf-4e74-97bf-08dcd1680484 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|36860700013|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?A0wt4RTLuqwNkhXC7PHqZPrP8alP7Tb?= =?utf-8?q?GA4bfRpqoxFhhr2pYwYiMJG4NSVFDBOBhIxVRpsfBRzpQZdL3D1q/FVS4XInFvdZA?= =?utf-8?q?nE1gfC5CbJQ9DvxJStlKU3YfOFV/PSUs2wXirrbWJK3D/eeREQPeD9hfNx/roBiNf?= =?utf-8?q?y0jpZ3tCaygkXYixsbC1OZyQXjSH1ySIFl4cnEuh2Uyg7JJbVVd3LK/KaOMflox8X?= =?utf-8?q?cnGiL124iyLz/fvRabk3dCBc/q3Cvi9hIqqQDwyo5tc6qaRXiZN12tTqGJU3M7XQq?= =?utf-8?q?6e994/HC67EgXsCVXMvL6iQjl1Dlo6lUXpRi2xTIEufSa1DeYuzWQMmDuxU9nfc6r?= =?utf-8?q?tLOOdAQOo+M5fkabI8ns1aTK+W41Cni40uisQivEX9yZbIYTrELFS8m1o3POOY83L?= =?utf-8?q?9VvvSOdIBH4Z1Gm7JGAMno7Vqr07E40dWoFG95TEYEWplQojt5x9PVjc+bgO96XrW?= =?utf-8?q?cL5qZ+u0ye58GLYIleQpye8JBDHWLKkOJ+hGQfz20hk9Z6epbxMZKysI1d2LNQh5+?= =?utf-8?q?MY2qfZa4FsIE0LcEf5Z52cNKxQB9DQzipliXao+XK8fOWbLt/I5VseuHVJ45wHcVO?= =?utf-8?q?fKyZhbsE/esneKRCNLxhCac0D8l9LJfa5w2Qpgx3X4mopkOHk2G6YEit6nE+X72vD?= =?utf-8?q?8pEo/h57XO5brlKavHt4hoGr/HbUt4crlt4S10cpirWf8SIRotgGEO/kmBjARdQ4Z?= =?utf-8?q?aCg4B8XykPDoUPQe15loKiB4quQsUDfO8GN6y/s418sUwcKJxuF/jnSCPFxh9O6Lr?= =?utf-8?q?QI+F2yz/v3jhCJCPeAFPQ+eza1Qz9xcBp1WsEg0Oz7psm39+nQa9sV56g7l0hwGMm?= =?utf-8?q?d/g2YOGXNcn8B9FluKYfLdosWCZ9Lkf1OGu+7XNO6hD/VwLT2NfPBGSihYVWgFJ07?= =?utf-8?q?PIWrndjC4Wl7dzCgbOBj1KE5k3UxjZDpWzlPvHatKyHEiN/j6ZZmXhBghf2pPH3+P?= =?utf-8?q?qqKIB3+bVuwkBBXLJ9hBPVpyP4CRn4rbKdH3mphy4QRzcvuqHLj4OIasnmnjZZYgF?= =?utf-8?q?+5Rz3jbZrY6uX1xJcpYEHX4fY0VVc05TdBkZt2cKEmTDzK0K2au2I/3s7Pn0AYqkH?= =?utf-8?q?FGfwuhmSr0ISeqGowI8aKp31NeuAejl9hLbmQLN5LJ41eQlq1EYtrfZAuLnz+leg4?= =?utf-8?q?bd7D+LPSt9ZZgYJ83epIqNL4m0OHRVuWzX3IgdTrqUgkJcykarRURdgVVmQHR+9cQ?= =?utf-8?q?4JJBLPTj2zGOzqXfqEZLLqEJVS9+JCamQz8y/49KJEw4eK/Jej1T0KTCdQZhiwZd4?= =?utf-8?q?zrQ3Q4xN5nVQ9goPWAPxGR7FMchG7yqqmiOho3ex4WLwVe2SS+llmkQlDOjQM8Jfk?= =?utf-8?q?JYkzyAz2dDe0KML3cP3qC5BGuaTeCQ0nI8ieOiG76gQPZfFo53nNRi3URHbeVXICE?= =?utf-8?q?ehxGjz6+7Dr?= 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)(82310400026)(36860700013)(1800799024)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 07:13:06.1588 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7bd3716e-99bf-4e74-97bf-08dcd1680484 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: DU2PEPF00028CFF.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR07MB9278 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 Replace static array of cache-aligned structs with an lcore variable, to slightly benefit code simplicity and performance. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup --- RFC v3: * Replace for loop with FOREACH macro. --- lib/power/rte_power_pmd_mgmt.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/power/rte_power_pmd_mgmt.c b/lib/power/rte_power_pmd_mgmt.c index b1c18a5f56..a5139dd4f7 100644 --- a/lib/power/rte_power_pmd_mgmt.c +++ b/lib/power/rte_power_pmd_mgmt.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -69,7 +70,7 @@ struct __rte_cache_aligned pmd_core_cfg { uint64_t sleep_target; /**< Prevent a queue from triggering sleep multiple times */ }; -static struct pmd_core_cfg lcore_cfgs[RTE_MAX_LCORE]; +static RTE_LCORE_VAR_HANDLE(struct pmd_core_cfg, lcore_cfgs); static inline bool queue_equal(const union queue *l, const union queue *r) @@ -252,12 +253,11 @@ clb_multiwait(uint16_t port_id __rte_unused, uint16_t qidx __rte_unused, struct rte_mbuf **pkts __rte_unused, uint16_t nb_rx, uint16_t max_pkts __rte_unused, void *arg) { - const unsigned int lcore = rte_lcore_id(); struct queue_list_entry *queue_conf = arg; struct pmd_core_cfg *lcore_conf; const bool empty = nb_rx == 0; - lcore_conf = &lcore_cfgs[lcore]; + lcore_conf = RTE_LCORE_VAR_VALUE(lcore_cfgs); /* early exit */ if (likely(!empty)) @@ -317,13 +317,12 @@ clb_pause(uint16_t port_id __rte_unused, uint16_t qidx __rte_unused, struct rte_mbuf **pkts __rte_unused, uint16_t nb_rx, uint16_t max_pkts __rte_unused, void *arg) { - const unsigned int lcore = rte_lcore_id(); struct queue_list_entry *queue_conf = arg; struct pmd_core_cfg *lcore_conf; const bool empty = nb_rx == 0; uint32_t pause_duration = rte_power_pmd_mgmt_get_pause_duration(); - lcore_conf = &lcore_cfgs[lcore]; + lcore_conf = RTE_LCORE_VAR_VALUE(lcore_cfgs); if (likely(!empty)) /* early exit */ @@ -358,9 +357,8 @@ clb_scale_freq(uint16_t port_id __rte_unused, uint16_t qidx __rte_unused, struct rte_mbuf **pkts __rte_unused, uint16_t nb_rx, uint16_t max_pkts __rte_unused, void *arg) { - const unsigned int lcore = rte_lcore_id(); const bool empty = nb_rx == 0; - struct pmd_core_cfg *lcore_conf = &lcore_cfgs[lcore]; + struct pmd_core_cfg *lcore_conf = RTE_LCORE_VAR_VALUE(lcore_cfgs); struct queue_list_entry *queue_conf = arg; if (likely(!empty)) { @@ -518,7 +516,7 @@ rte_power_ethdev_pmgmt_queue_enable(unsigned int lcore_id, uint16_t port_id, goto end; } - lcore_cfg = &lcore_cfgs[lcore_id]; + lcore_cfg = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, lcore_cfgs); /* check if other queues are stopped as well */ ret = cfg_queues_stopped(lcore_cfg); @@ -619,7 +617,7 @@ rte_power_ethdev_pmgmt_queue_disable(unsigned int lcore_id, } /* no need to check queue id as wrong queue id would not be enabled */ - lcore_cfg = &lcore_cfgs[lcore_id]; + lcore_cfg = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, lcore_cfgs); /* check if other queues are stopped as well */ ret = cfg_queues_stopped(lcore_cfg); @@ -769,21 +767,21 @@ rte_power_pmd_mgmt_get_scaling_freq_max(unsigned int lcore) } RTE_INIT(rte_power_ethdev_pmgmt_init) { - size_t i; - int j; + struct pmd_core_cfg *lcore_cfg; + int i; + + RTE_LCORE_VAR_ALLOC(lcore_cfgs); /* initialize all tailqs */ - for (i = 0; i < RTE_DIM(lcore_cfgs); i++) { - struct pmd_core_cfg *cfg = &lcore_cfgs[i]; - TAILQ_INIT(&cfg->head); - } + RTE_LCORE_VAR_FOREACH_VALUE(lcore_cfg, lcore_cfgs) + TAILQ_INIT(&lcore_cfg->head); /* initialize config defaults */ emptypoll_max = 512; pause_duration = 1; /* scaling defaults out of range to ensure not used unless set by user or app */ - for (j = 0; j < RTE_MAX_LCORE; j++) { - scale_freq_min[j] = 0; - scale_freq_max[j] = UINT32_MAX; + for (i = 0; i < RTE_MAX_LCORE; i++) { + scale_freq_min[i] = 0; + scale_freq_max[i] = UINT32_MAX; } } From patchwork Tue Sep 10 07:03:43 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: 143843 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 EF54E45952; Tue, 10 Sep 2024 09:13:37 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B6475427A1; Tue, 10 Sep 2024 09:13:14 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2045.outbound.protection.outlook.com [40.107.22.45]) by mails.dpdk.org (Postfix) with ESMTP id 46AB14278E for ; Tue, 10 Sep 2024 09:13:11 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZPUSh8Hst2p77RpvTG9WzVyWXqj1DslK4opGgUrulTlfgOUrGfFWyJU70PYxTX8HeMwQ7gZPsDg8S+njg6yVgS+iHPOoXbgErgqPq2zCKyPJpGBdeWc0rW3UwuDPCw151yiP9Q0BOrw0ZoOr/+dlTk5YlrEsFwUeDcimw08/swWgWCt5wR9spOoNHHgtMFRkIKW6dKA9LKf5d5SQ8SiOEHPCxXX9LIjxFjkUoC9hYtjk+srCTOYhBYvEkN18wyL5Ba3Y7QvO3meRc0xX+/4J8fQqNmYMn0Cu/QPEU7ETC4XUqdvqJcGdTBuiSK6STvDabUCMjvHsNxmRu7U+mgKacA== 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=K5hoNFuDZxse7acgv9FO6Esrxy002pzpeLdNSPgJRpI=; b=S5q9RBu9rHRUZXiF1ebDKCQM9xuTU/cIbSvZkP+zn95a45gHxFnKw/AWZKmPCHg6aFGNEZoVIjJRUSIuQ8uTPa9Ayy80GNLNibQaUXctS82BrAkVd02wrPcWa+B0a7/nGQO8thmw1wZu+egJzgkLemYvxahM3e8C3W8ZxfjxTjbCO4Nn5mQTOKhX3QQeHMWVkmWL/D6l7Nrs0bsmV5YqNu2yk8x6pdiHBErB13vv2ZpFiVrWBGditl/rn3J2/xDoeF103Voe6kIFhZ4qYkbU78kjRrseTgU6a7tHVDAMPoXTuvZMF7W4nYU3Dv9y0KTQZIB4r+9Ot3Rl0Xvf6I9qlg== 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=K5hoNFuDZxse7acgv9FO6Esrxy002pzpeLdNSPgJRpI=; b=MdnoWkDCe63TpNXPppz7E8qgb8Sb6UG6aI0vfbMduGJpZ1TWe2RhMSTVS+2pH8aN7xql4cyNF1hhEqHiiyPXTozVqixe7nx55biHY3gswiLVKhDqoHipDmUOZp0R+z5vFz4DChnCypmiwZLQvS1yj1OnLvk/gU64LahoWMGWe+kE/HuuwReJ114hgwdz6ddCrib3VCdHsU1jui3DBNNR7UUTOuSz+xbn/3RYuKxGtnTdO9rIxOkS3mhhzoHMzrimRReyvVYw/WLP1rZ8MP5Gvw1xxTxMFYxvckj6hGP/c2PsJVPJyIS3Sp7XsMqguSkUfa+mjG70I8r4kC4PdO0+HQ== Received: from DUZPR01CA0108.eurprd01.prod.exchangelabs.com (2603:10a6:10:4bb::23) by DB8PR07MB6330.eurprd07.prod.outlook.com (2603:10a6:10:13c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24; Tue, 10 Sep 2024 07:13:06 +0000 Received: from DU2PEPF00028D0C.eurprd03.prod.outlook.com (2603:10a6:10:4bb:cafe::82) by DUZPR01CA0108.outlook.office365.com (2603:10a6:10:4bb::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.25 via Frontend Transport; Tue, 10 Sep 2024 07:13:06 +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 DU2PEPF00028D0C.mail.protection.outlook.com (10.167.242.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Tue, 10 Sep 2024 07:13:06 +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; Tue, 10 Sep 2024 09:13:05 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id B36FB380070; Tue, 10 Sep 2024 09:13:05 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , =?utf-8?q?Morten_Br=C3=B8rup?= , Stephen Hemminger , Konstantin Ananyev , David Marchand , =?utf-8?q?Mattias_R=C3=B6nnblom?= Subject: [PATCH 5/6] service: keep per-lcore state in lcore variable Date: Tue, 10 Sep 2024 09:03:43 +0200 Message-ID: <20240910070344.699183-6-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910070344.699183-1-mattias.ronnblom@ericsson.com> References: <20240506082721.120666-2-mattias.ronnblom@ericsson.com> <20240910070344.699183-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PEPF00028D0C:EE_|DB8PR07MB6330:EE_ X-MS-Office365-Filtering-Correlation-Id: 36778823-e077-45df-17eb-08dcd16804a4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|82310400026|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?IX5p/D5xTr7tbZoTzRqlbjRvsuu8Tn1?= =?utf-8?q?iqrvPmAgDjc0OEeqioBl+hHZqNCkGVnGLY1fCeFFNnaSsq4ulO9X8qnZ3IgIyn3yd?= =?utf-8?q?1PBWLV8v6RXymDj37WritAIiVXXykTXTzHDHZbuquyxMimF1H+2tghxpxjiYirUU8?= =?utf-8?q?smlxWBQrNr4m915rFCYE8vCr8hhwdDcoi4Ir4bEIbMqYqOh7jA+c7KqehciEa79qA?= =?utf-8?q?Eh8eE71B8jAe4/orOo9t05QPW02H+mxTRi3bnuS5qJBbgo0bUg5DMLxFPejjz7fjl?= =?utf-8?q?vp2PfEvQeUMi9nR3Zw6tIcgJzaEHHbUpRSDc4fDaxFAJXSM6j8bU9Bca+TU+r9oWu?= =?utf-8?q?fVECxNxIF6VIaQShNHKSpJJ2yQ+gcQuBrOiFgoyir2TopkU2P2My2ZWwTVGNWu4KK?= =?utf-8?q?4qHsIcBl/KNJzTIDNxGwKOhxSelRtyaEh/PRZX1OLl8naFQbxQXTgvZ2avMsBzDS4?= =?utf-8?q?7NNAeAbpAZmwXXkj1+UtDqOlMgYBSOeWNeL7SYue4bPzMbU+GN4I9IcDUXLu/Gjjr?= =?utf-8?q?wdhC0i3ii2b9v2Kw/HioFfyg/DaRTRFb/5/RtZBaRYyrn7NaoIzsZFk1ut1bXp7DX?= =?utf-8?q?lOwUYR9M7cMX5rmhx15jEyfJWu4DUL5cu5hoReW3Cw1cgEiwO4a9hpHZI3t3d//zd?= =?utf-8?q?OxmMvmrGW9NzyPoUAdo5fxUCeTY56qlFnli7boBfE0z1ndkbHaCbO3WSZECKEKSWW?= =?utf-8?q?rH7h6YPW3NmAYZM9c8mF1T2Rhz0LLLNQW+OILGIQFIqhbGFOnJ/LtEDfeuuImgGpx?= =?utf-8?q?tp3xzIP8/Komv6KXdyn4Udg/AukHLUo9OVN4+Ul5gI97ZRCH76sHNPs6X8rvuymO0?= =?utf-8?q?9iMsLjVex7Jua+oR5urWK5xxteMthbLK+VQ5xxB7y0klZ/pLPLyAHt9uyDvnASH7V?= =?utf-8?q?OFMtSGYVPCoWqXwie5iUw5ZP2x487pKEpn2r74Eo4/se0Ci3kemSyq+d6uaGxu93e?= =?utf-8?q?VH7jTIR5HhDfiVM9izjBr2MSEnYVxrLFqn63HNfEQAh+E2I+QcQa6v8fadcAhPk0l?= =?utf-8?q?rdQq2AvKgMYJrpuiyQSLz9RX+2Rpqvl5WUpGmO58gjLYNXuhULiopfk+vXzp8tGr2?= =?utf-8?q?PITfA5Jk1uqDyjyMQe99PiKS+dM0LrCsUjFxFwj8ZP5Bjp5mMr/BTJvfFvY8fToJV?= =?utf-8?q?AraTY7htskJMZyI7WxXNkLP+nDP4zuqfLrn6BX4DNPtIWoazMI6S3UkyhXOrBj6z5?= =?utf-8?q?t81GrEbcOMmoIvZcwwAs33imPCHeeea7RwKSXvPwkj4/1lls3m2uMLsFGRD7K7G0j?= =?utf-8?q?uYw9UtX6VwqJSMeELtacpXre5OarVm0po1yRJK7ZYZFMUoS7uT7CVuiwfAR/l3TuF?= =?utf-8?q?htZhv10pvkMLN3hVzoiGZu/NUvprNLyQfyzb92yRhQH1S/6yKSNAiyfeFZBWOKrZo?= =?utf-8?q?EMZy1abIhcb?= 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)(82310400026)(1800799024)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 07:13:06.3653 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 36778823-e077-45df-17eb-08dcd16804a4 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: DU2PEPF00028D0C.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR07MB6330 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 Replace static array of cache-aligned structs with an lcore variable, to slightly benefit code simplicity and performance. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup --- RFC v6: * Remove a now-redundant lcore variable value memset(). RFC v5: * Fix lcore value pointer bug introduced by RFC v4. RFC v4: * Remove strange-looking lcore value lookup potentially containing invalid lcore id. (Morten Brørup) * Replace misplaced tab with space. (Morten Brørup) --- lib/eal/common/rte_service.c | 115 +++++++++++++++++++---------------- 1 file changed, 63 insertions(+), 52 deletions(-) diff --git a/lib/eal/common/rte_service.c b/lib/eal/common/rte_service.c index 56379930b6..03379f1588 100644 --- a/lib/eal/common/rte_service.c +++ b/lib/eal/common/rte_service.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -75,7 +76,7 @@ struct __rte_cache_aligned core_state { static uint32_t rte_service_count; static struct rte_service_spec_impl *rte_services; -static struct core_state *lcore_states; +static RTE_LCORE_VAR_HANDLE(struct core_state, lcore_states); static uint32_t rte_service_library_initialized; int32_t @@ -101,12 +102,8 @@ rte_service_init(void) goto fail_mem; } - lcore_states = rte_calloc("rte_service_core_states", RTE_MAX_LCORE, - sizeof(struct core_state), RTE_CACHE_LINE_SIZE); - if (!lcore_states) { - EAL_LOG(ERR, "error allocating core states array"); - goto fail_mem; - } + if (lcore_states == NULL) + RTE_LCORE_VAR_ALLOC(lcore_states); int i; struct rte_config *cfg = rte_eal_get_configuration(); @@ -122,7 +119,6 @@ rte_service_init(void) return 0; fail_mem: rte_free(rte_services); - rte_free(lcore_states); return -ENOMEM; } @@ -136,7 +132,6 @@ rte_service_finalize(void) rte_eal_mp_wait_lcore(); rte_free(rte_services); - rte_free(lcore_states); rte_service_library_initialized = 0; } @@ -286,7 +281,6 @@ rte_service_component_register(const struct rte_service_spec *spec, int32_t rte_service_component_unregister(uint32_t id) { - uint32_t i; struct rte_service_spec_impl *s; SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL); @@ -294,9 +288,10 @@ rte_service_component_unregister(uint32_t id) s->internal_flags &= ~(SERVICE_F_REGISTERED); + struct core_state *cs; /* clear the run-bit in all cores */ - for (i = 0; i < RTE_MAX_LCORE; i++) - lcore_states[i].service_mask &= ~(UINT64_C(1) << id); + RTE_LCORE_VAR_FOREACH_VALUE(cs, lcore_states) + cs->service_mask &= ~(UINT64_C(1) << id); memset(&rte_services[id], 0, sizeof(struct rte_service_spec_impl)); @@ -454,7 +449,10 @@ rte_service_may_be_active(uint32_t id) return -EINVAL; for (i = 0; i < lcore_count; i++) { - if (lcore_states[ids[i]].service_active_on_lcore[id]) + struct core_state *cs = + RTE_LCORE_VAR_LCORE_VALUE(ids[i], lcore_states); + + if (cs->service_active_on_lcore[id]) return 1; } @@ -464,7 +462,7 @@ rte_service_may_be_active(uint32_t id) int32_t rte_service_run_iter_on_app_lcore(uint32_t id, uint32_t serialize_mt_unsafe) { - struct core_state *cs = &lcore_states[rte_lcore_id()]; + struct core_state *cs = RTE_LCORE_VAR_VALUE(lcore_states); struct rte_service_spec_impl *s; SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL); @@ -486,8 +484,7 @@ service_runner_func(void *arg) { RTE_SET_USED(arg); uint8_t i; - const int lcore = rte_lcore_id(); - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_VALUE(lcore_states); rte_atomic_store_explicit(&cs->thread_active, 1, rte_memory_order_seq_cst); @@ -533,13 +530,15 @@ service_runner_func(void *arg) int32_t rte_service_lcore_may_be_active(uint32_t lcore) { - if (lcore >= RTE_MAX_LCORE || !lcore_states[lcore].is_service_core) + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); + + if (lcore >= RTE_MAX_LCORE || !cs->is_service_core) return -EINVAL; /* Load thread_active using ACQUIRE to avoid instructions dependent on * the result being re-ordered before this load completes. */ - return rte_atomic_load_explicit(&lcore_states[lcore].thread_active, + return rte_atomic_load_explicit(&cs->thread_active, rte_memory_order_acquire); } @@ -547,9 +546,11 @@ int32_t rte_service_lcore_count(void) { int32_t count = 0; - uint32_t i; - for (i = 0; i < RTE_MAX_LCORE; i++) - count += lcore_states[i].is_service_core; + + struct core_state *cs; + RTE_LCORE_VAR_FOREACH_VALUE(cs, lcore_states) + count += cs->is_service_core; + return count; } @@ -566,7 +567,8 @@ rte_service_lcore_list(uint32_t array[], uint32_t n) uint32_t i; uint32_t idx = 0; for (i = 0; i < RTE_MAX_LCORE; i++) { - struct core_state *cs = &lcore_states[i]; + struct core_state *cs = + RTE_LCORE_VAR_LCORE_VALUE(i, lcore_states); if (cs->is_service_core) { array[idx] = i; idx++; @@ -582,7 +584,7 @@ rte_service_lcore_count_services(uint32_t lcore) if (lcore >= RTE_MAX_LCORE) return -EINVAL; - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); if (!cs->is_service_core) return -ENOTSUP; @@ -634,30 +636,31 @@ rte_service_start_with_defaults(void) static int32_t service_update(uint32_t sid, uint32_t lcore, uint32_t *set, uint32_t *enabled) { + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); + /* validate ID, or return error value */ if (!service_valid(sid) || lcore >= RTE_MAX_LCORE || - !lcore_states[lcore].is_service_core) + !cs->is_service_core) return -EINVAL; uint64_t sid_mask = UINT64_C(1) << sid; if (set) { - uint64_t lcore_mapped = lcore_states[lcore].service_mask & - sid_mask; + uint64_t lcore_mapped = cs->service_mask & sid_mask; if (*set && !lcore_mapped) { - lcore_states[lcore].service_mask |= sid_mask; + cs->service_mask |= sid_mask; rte_atomic_fetch_add_explicit(&rte_services[sid].num_mapped_cores, 1, rte_memory_order_relaxed); } if (!*set && lcore_mapped) { - lcore_states[lcore].service_mask &= ~(sid_mask); + cs->service_mask &= ~(sid_mask); rte_atomic_fetch_sub_explicit(&rte_services[sid].num_mapped_cores, 1, rte_memory_order_relaxed); } } if (enabled) - *enabled = !!(lcore_states[lcore].service_mask & (sid_mask)); + *enabled = !!(cs->service_mask & (sid_mask)); return 0; } @@ -685,13 +688,14 @@ set_lcore_state(uint32_t lcore, int32_t state) { /* mark core state in hugepage backed config */ struct rte_config *cfg = rte_eal_get_configuration(); + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); cfg->lcore_role[lcore] = state; /* mark state in process local lcore_config */ lcore_config[lcore].core_role = state; /* update per-lcore optimized state tracking */ - lcore_states[lcore].is_service_core = (state == ROLE_SERVICE); + cs->is_service_core = (state == ROLE_SERVICE); rte_eal_trace_service_lcore_state_change(lcore, state); } @@ -702,14 +706,16 @@ rte_service_lcore_reset_all(void) /* loop over cores, reset all to mask 0 */ uint32_t i; for (i = 0; i < RTE_MAX_LCORE; i++) { - if (lcore_states[i].is_service_core) { - lcore_states[i].service_mask = 0; + struct core_state *cs = + RTE_LCORE_VAR_LCORE_VALUE(i, lcore_states); + if (cs->is_service_core) { + cs->service_mask = 0; set_lcore_state(i, ROLE_RTE); /* runstate act as guard variable Use * store-release memory order here to synchronize * with load-acquire in runstate read functions. */ - rte_atomic_store_explicit(&lcore_states[i].runstate, + rte_atomic_store_explicit(&cs->runstate, RUNSTATE_STOPPED, rte_memory_order_release); } } @@ -725,17 +731,19 @@ rte_service_lcore_add(uint32_t lcore) { if (lcore >= RTE_MAX_LCORE) return -EINVAL; - if (lcore_states[lcore].is_service_core) + + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); + if (cs->is_service_core) return -EALREADY; set_lcore_state(lcore, ROLE_SERVICE); /* ensure that after adding a core the mask and state are defaults */ - lcore_states[lcore].service_mask = 0; + cs->service_mask = 0; /* Use store-release memory order here to synchronize with * load-acquire in runstate read functions. */ - rte_atomic_store_explicit(&lcore_states[lcore].runstate, RUNSTATE_STOPPED, + rte_atomic_store_explicit(&cs->runstate, RUNSTATE_STOPPED, rte_memory_order_release); return rte_eal_wait_lcore(lcore); @@ -747,7 +755,7 @@ rte_service_lcore_del(uint32_t lcore) if (lcore >= RTE_MAX_LCORE) return -EINVAL; - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); if (!cs->is_service_core) return -EINVAL; @@ -771,7 +779,7 @@ rte_service_lcore_start(uint32_t lcore) if (lcore >= RTE_MAX_LCORE) return -EINVAL; - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); if (!cs->is_service_core) return -EINVAL; @@ -801,6 +809,8 @@ rte_service_lcore_start(uint32_t lcore) int32_t rte_service_lcore_stop(uint32_t lcore) { + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); + if (lcore >= RTE_MAX_LCORE) return -EINVAL; @@ -808,12 +818,11 @@ rte_service_lcore_stop(uint32_t lcore) * memory order here to synchronize with store-release * in runstate update functions. */ - if (rte_atomic_load_explicit(&lcore_states[lcore].runstate, rte_memory_order_acquire) == + if (rte_atomic_load_explicit(&cs->runstate, rte_memory_order_acquire) == RUNSTATE_STOPPED) return -EALREADY; uint32_t i; - struct core_state *cs = &lcore_states[lcore]; uint64_t service_mask = cs->service_mask; for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) { @@ -834,7 +843,7 @@ rte_service_lcore_stop(uint32_t lcore) /* Use store-release memory order here to synchronize with * load-acquire in runstate read functions. */ - rte_atomic_store_explicit(&lcore_states[lcore].runstate, RUNSTATE_STOPPED, + rte_atomic_store_explicit(&cs->runstate, RUNSTATE_STOPPED, rte_memory_order_release); rte_eal_trace_service_lcore_stop(lcore); @@ -845,7 +854,7 @@ rte_service_lcore_stop(uint32_t lcore) static uint64_t lcore_attr_get_loops(unsigned int lcore) { - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); return rte_atomic_load_explicit(&cs->loops, rte_memory_order_relaxed); } @@ -853,7 +862,7 @@ lcore_attr_get_loops(unsigned int lcore) static uint64_t lcore_attr_get_cycles(unsigned int lcore) { - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); return rte_atomic_load_explicit(&cs->cycles, rte_memory_order_relaxed); } @@ -861,7 +870,7 @@ lcore_attr_get_cycles(unsigned int lcore) static uint64_t lcore_attr_get_service_calls(uint32_t service_id, unsigned int lcore) { - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); return rte_atomic_load_explicit(&cs->service_stats[service_id].calls, rte_memory_order_relaxed); @@ -870,7 +879,7 @@ lcore_attr_get_service_calls(uint32_t service_id, unsigned int lcore) static uint64_t lcore_attr_get_service_cycles(uint32_t service_id, unsigned int lcore) { - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); return rte_atomic_load_explicit(&cs->service_stats[service_id].cycles, rte_memory_order_relaxed); @@ -886,7 +895,10 @@ attr_get(uint32_t id, lcore_attr_get_fun lcore_attr_get) uint64_t sum = 0; for (lcore = 0; lcore < RTE_MAX_LCORE; lcore++) { - if (lcore_states[lcore].is_service_core) + struct core_state *cs = + RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); + + if (cs->is_service_core) sum += lcore_attr_get(id, lcore); } @@ -930,12 +942,11 @@ int32_t rte_service_lcore_attr_get(uint32_t lcore, uint32_t attr_id, uint64_t *attr_value) { - struct core_state *cs; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); if (lcore >= RTE_MAX_LCORE || !attr_value) return -EINVAL; - cs = &lcore_states[lcore]; if (!cs->is_service_core) return -ENOTSUP; @@ -960,7 +971,8 @@ rte_service_attr_reset_all(uint32_t id) return -EINVAL; for (lcore = 0; lcore < RTE_MAX_LCORE; lcore++) { - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = + RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); cs->service_stats[id] = (struct service_stats) {}; } @@ -971,12 +983,11 @@ rte_service_attr_reset_all(uint32_t id) int32_t rte_service_lcore_attr_reset_all(uint32_t lcore) { - struct core_state *cs; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); if (lcore >= RTE_MAX_LCORE) return -EINVAL; - cs = &lcore_states[lcore]; if (!cs->is_service_core) return -ENOTSUP; @@ -1011,7 +1022,7 @@ static void service_dump_calls_per_lcore(FILE *f, uint32_t lcore) { uint32_t i; - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); fprintf(f, "%02d\t", lcore); for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) { From patchwork Tue Sep 10 07:03:44 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: 143840 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 A23E045952; Tue, 10 Sep 2024 09:13:10 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3D3CA4021F; Tue, 10 Sep 2024 09:13:10 +0200 (CEST) Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2076.outbound.protection.outlook.com [40.107.249.76]) by mails.dpdk.org (Postfix) with ESMTP id C4FFB40151 for ; Tue, 10 Sep 2024 09:13:08 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=M/pRKUtS8GjsZYJ5o21H9DNhbC4OGZX1AePzf4SUYgduqLHWceAjq4Dg59I68D6WjtDooEmPU6EVsmfq1TvPLhnqsx5owS7S4sOHgXscRkz0R1MH4U05E9fNGfKmfHrecFriV8KjIX1lLA9NhUqdALF1bsy+8JZRmCjT9wZSdZGyKaELEVtGunE1ZWtrBqN05+Pd2imlRPI7BJSjudXe03ZuBVuRNWFlEcKYDl2yzRAl/SNMorH/cxRWLD4RTNL4dxc5ECz5ACpLvAozk2ItSS/bc25A/dP2pZdutekksqaq6nkAhGk1S4QtCbH0xE2tc28gmfIAK5Eti8RZ8wMHOQ== 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=5KgLIeJsoXsbjQgRv+axyk0s7Khi0OpcLSDJyLLTnRM=; b=hz2HBLmmAYkgskk82I8PbIVTGeNl8GChJgKaVGaHWYCrreFtAqxmWh2EeIi/SHrJnfINCUY2NxGuY6eiQKcn8FUtkDPKxPkLD3m1pbU6nK6PPSHZa5ogAD0KrUuubpZBn9Iof+iJHKfaCljHR/IWkRo01mj5pi4tlQEU45RXeUAObpbiRzZKx1+NGRnx1rtPB8jBXC4rjZjlJdBJTKIsNHZHyOQBDabvxiKpW603Se5jpl8PPujHKFm5CH4R5Tm0t6fuLY4qvwUaWu/Y5n1Pk2CX36RXIPL4yVc4SUeL6ePXSSK3t5VikDp6m16ryGjuxCag95Xb3/D5es++6tn6SQ== 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=5KgLIeJsoXsbjQgRv+axyk0s7Khi0OpcLSDJyLLTnRM=; b=Xp4M+bZKFrYmYN+WbVTX73Ie/bwGuVvn6PP4E2CvWiWnYCNOjyFD4aud7KOQn+w5r48Y6AK5px/77GMcK8Wl4CpcwbMayVTcKaz8g5tt7YjkxniIZOkLhaStXGIZ1UxYaTnm3VOloziXaUSWqKpjGPD+j8HGKT88lZpMa+0G42fJIUSoiTqUmx7nbxILZOUPf0YJpQecPAC7ECM9YlWMIwBFN4RNoG5qbtegIt/hdahnKsW3dxsKu+xewoh8+s9BWkM4K3u11TNEvGw9NZjd6CajCNwTb0xgLk1vTlz6suz254Xpc3NBfX39dLqt8c7PF0xyMBFI7NEvLOsz+qECFw== Received: from DU7PR01CA0004.eurprd01.prod.exchangelabs.com (2603:10a6:10:50f::18) by DB9PR07MB7771.eurprd07.prod.outlook.com (2603:10a6:10:2a6::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24; Tue, 10 Sep 2024 07:13:06 +0000 Received: from DU6PEPF00009524.eurprd02.prod.outlook.com (2603:10a6:10:50f:cafe::c2) by DU7PR01CA0004.outlook.office365.com (2603:10a6:10:50f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24 via Frontend Transport; Tue, 10 Sep 2024 07:13:06 +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 DU6PEPF00009524.mail.protection.outlook.com (10.167.8.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Tue, 10 Sep 2024 07:13:06 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.69) with Microsoft SMTP Server id 15.2.1544.11; Tue, 10 Sep 2024 09:13:05 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id BB57E38007F; Tue, 10 Sep 2024 09:13:05 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , =?utf-8?q?Morten_Br=C3=B8rup?= , Stephen Hemminger , Konstantin Ananyev , David Marchand , =?utf-8?q?Mattias_R=C3=B6nnblom?= Subject: [PATCH 6/6] eal: keep per-lcore power intrinsics state in lcore variable Date: Tue, 10 Sep 2024 09:03:44 +0200 Message-ID: <20240910070344.699183-7-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910070344.699183-1-mattias.ronnblom@ericsson.com> References: <20240506082721.120666-2-mattias.ronnblom@ericsson.com> <20240910070344.699183-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU6PEPF00009524:EE_|DB9PR07MB7771:EE_ X-MS-Office365-Filtering-Correlation-Id: c422bb20-7c5f-48e0-ab89-08dcd16804f0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|376014|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?q?Hb1wye8XgDfIKguHeUhlo7rStiac/la?= =?utf-8?q?WrRonVNcDFoG8BCdGrQiI88vop5CY6HwZYo0D+aEFjkZBjFriG3a3r+D9hL65k2TG?= =?utf-8?q?s/C6kNOYieTCKdNsV2MES+76IXbNICI44TJHAm3DgITqfWgvJoGId76hTv7hcBApN?= =?utf-8?q?dB+I9hQNoZSWxRDYXODJDnOD217JE3ty/WHE0D/1dO5aH/nTMUYJFCR/BSixU/BgJ?= =?utf-8?q?dN8fBC+OZEm0pPhNg2HQ7Y+2Yu9Z7rOLeJlQNh1zPF5cMMBsp21E6P4KBiPT1ZHON?= =?utf-8?q?D9HqFLKxN+872C1EuF9sQ+nR3A6WJqmlTdCc9WCsx4V7aZQVr0UA3eISDLHTXh+z9?= =?utf-8?q?ZeeOIGzJgjk2hlmjdtY4i/gUANVSZAJ7hpCP3lQD/c7npVqgZfyvReDbF1oZMoxgI?= =?utf-8?q?/6EkpjfISrBn5zKu42J90CLPhC5kGLcgNw/iL6lDH82qqDrceGu0mUNn2vTPOS5SP?= =?utf-8?q?QSz2Dz1bh6q5pHegBAcgoB84kmTm3mCXiqh8kEWRF1dcMS1l9OU10z9yPk9SfmFee?= =?utf-8?q?5g0tJROkUhT9ySs9n7b8Tf9QypaZMyi7KeaNr93LgrL1knN2sJPx/m/pdySkjH0UX?= =?utf-8?q?r/wgQLecMMjO3WVht7Pw6UTIOO/9S8WA5YOXxvh51hsLQskh6epdufdzxki4TsULl?= =?utf-8?q?W9r7/VHQ1r24Ihyv/vFfOybgmWkZh15JZcHaxij4gkEUkkJSA1JQ7wLizYtl+HcRR?= =?utf-8?q?1rk4LWCyNiJ+YPyWMvTvDsF7yDMqL2Ao+/SCILsIf9cXGodaEwCaPEjYSFsRtnLz7?= =?utf-8?q?JVVF4oEy9fsrOmMoDysfgNjG+12qSCvThH3BtRTfacCwmrM399yzPU05vjP5h8/xj?= =?utf-8?q?Kne0sek2kVl2sSLMZF6puc/2YmtHCYc/wnYCdg7g9U6y94PhmfNtnHGt5+ebPzw+U?= =?utf-8?q?5PEgXgp+/ticJgdfCkOiJDzqo0pWAC8TB1BNAJzT9t4thh78MoD2H7ew/ZH7jkKW0?= =?utf-8?q?Uib4R/e2GDvgyX+Pz7YJrI2J/ock74wcNZFx5hhhJQuutGJt1qNRGaAibrPYNCMn+?= =?utf-8?q?9BptBG8TLnf0B9mKgdJhynAhB09zVpIDq4X4QwBSkLB/zLhYF640wokHwKmVlWLqm?= =?utf-8?q?Y6UlvrQVH6lCf2dGywA/LPPynn+bKq7uHEIRWCP0FkeMd1vZn+1g8pyQEnQXBmEtw?= =?utf-8?q?lxhL5LxUVBwCWqdHEnfIvo30T+6Kf0A99R4z0UeZ7Oy2OqJqf2smiIan6ZyxzDdCy?= =?utf-8?q?wBC0XmUd6WEGSNxB3l5zOKwUDQgg/JqGjl13u13kI1iQEOxunsqdWmCtzeKt6Il6o?= =?utf-8?q?I29eXm/kFnwY1Gs+PSKrW2u4mPBG55ijaeReiYm6JeZ43SEAcbhQDX7ty5iIXCP2e?= =?utf-8?q?3msy1nQjv1A7pRu7vtfAZ0bXGQfyvuWUa2CPBv1/R21WPT1eqv7a83gXDBLiAa42i?= =?utf-8?q?ol/vXthPrSe?= 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)(1800799024)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 07:13:06.8671 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c422bb20-7c5f-48e0-ab89-08dcd16804f0 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: DU6PEPF00009524.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR07MB7771 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 Keep per-lcore power intrinsics state in a lcore variable to reduce cache working set size and avoid any CPU next-line-prefetching causing false sharing. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup --- lib/eal/x86/rte_power_intrinsics.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/eal/x86/rte_power_intrinsics.c b/lib/eal/x86/rte_power_intrinsics.c index 6d9b64240c..f4ba2c8ecb 100644 --- a/lib/eal/x86/rte_power_intrinsics.c +++ b/lib/eal/x86/rte_power_intrinsics.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -14,10 +15,14 @@ /* * Per-lcore structure holding current status of C0.2 sleeps. */ -static alignas(RTE_CACHE_LINE_SIZE) struct power_wait_status { +struct power_wait_status { rte_spinlock_t lock; volatile void *monitor_addr; /**< NULL if not currently sleeping */ -} wait_status[RTE_MAX_LCORE]; +}; + +RTE_LCORE_VAR_HANDLE(struct power_wait_status, wait_status); + +RTE_LCORE_VAR_INIT(wait_status); /* * This function uses UMONITOR/UMWAIT instructions and will enter C0.2 state. @@ -172,7 +177,7 @@ rte_power_monitor(const struct rte_power_monitor_cond *pmc, if (pmc->fn == NULL) return -EINVAL; - s = &wait_status[lcore_id]; + s = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, wait_status); /* update sleep address */ rte_spinlock_lock(&s->lock); @@ -264,7 +269,7 @@ rte_power_monitor_wakeup(const unsigned int lcore_id) if (lcore_id >= RTE_MAX_LCORE) return -EINVAL; - s = &wait_status[lcore_id]; + s = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, wait_status); /* * There is a race condition between sleep, wakeup and locking, but we @@ -303,8 +308,8 @@ int rte_power_monitor_multi(const struct rte_power_monitor_cond pmc[], const uint32_t num, const uint64_t tsc_timestamp) { - const unsigned int lcore_id = rte_lcore_id(); - struct power_wait_status *s = &wait_status[lcore_id]; + struct power_wait_status *s = RTE_LCORE_VAR_VALUE(wait_status); + uint32_t i, rc; /* check if supported */