From patchwork Wed Oct 16 13:19:10 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: 146085 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 6DAF445B50; Wed, 16 Oct 2024 15:29:05 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D55AD4066C; Wed, 16 Oct 2024 15:28:35 +0200 (CEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2061.outbound.protection.outlook.com [40.107.20.61]) by mails.dpdk.org (Postfix) with ESMTP id 78BCB40611 for ; Wed, 16 Oct 2024 15:28:27 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iSc0PL0uIBt9dr6fx84AX9FVJiTrir6cqnYca0oForTo6/Z9ClwCmYD5taCkJunZpSsFzmf/URUKjZnJ3UejpuYXqnDgaCuwCR4i62CYZ0Cj8Z1NrmxFgtQCGrHyi0HUl0OAKMURh7tatYbG6GWFtzYXxXLuH29iKia7WGtWGx7gzlH1eOzx/5QqlZYGQIu1R9SNKgGIPZOlptGrk2pG8GZOxRKFpc9ncPF6Ne238L0bugx7vc7ysRuSl1q9J5tn+2RC0XWBa5HG6s8dsT7q2TWnP5xcxdCkyJZkoxkEPJai+vLJxzLG5PeGua2sJcz2bUNMJjSNK65ARbDGZUosSA== 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=nEGLX5Bc5w10a56utLDpwoCs1qQHm7GXJ9VyEGv8sFQ=; b=NrU4eiwbTsFr00R8W5IL4y0N7wOcb+kA8S0HBVZklaR/XtWJfKLhsbefJ3rSrgLVqxn31jZJ1ZWSiwwc1oXh1mkKX1mDqkPQ47fb+1vAL9koMH3Oy7z6+IvO9hOtSj5HjhhO03/1+yyNS/EukQTESFEMjpcLympjIGctEvwlMMUo8X7slWeYZVjiqxvhgFOFA5/O+SHDcQo8fuAh9clchjYAZ9L/zpIw/Oqt8cSUc13rmh+uyfLrrgp/m342gtqdTXUL6/3FtakJDArmc2GLp4bE1akL3yqzJemIYYyUABAu03KN2HA/mUGLW2vQpFN39eueqTKwL/ufA0MkAwUbmw== 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=nEGLX5Bc5w10a56utLDpwoCs1qQHm7GXJ9VyEGv8sFQ=; b=idpEDo27sOvZin5e4o/lmSDGBxmq/WPuCBDyMxMsnD4bny4vm6SYvJ8nFBk4lHl4C34HUBSXH6892D9+VCprDePiIo/L5CYgxEj9e+4p/1KcibflNNgdHrKBFQ1msbXRgo6Im1/RHZ4bPApbYftNxK2ljjsUVsrvR0Xd3Yt1A/f8sLqQJ2VjtZO/y5KWs/GKEyELsSoIsm91iHb0E47gZap9XZRtKZlqOrXFTeVVBUUw37TNFKa7mWdFCCGzQw4JYSX4vbXCN0V+dFiR+jS9gkAXiXYeHdpHjUK2IBpuFkqcEDrajfIVBeHgyB7vO3tBnBDeTfgxlpytFqCuLFT0lQ== Received: from DU6P191CA0020.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:540::27) by PR3PR07MB7051.eurprd07.prod.outlook.com (2603:10a6:102:70::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Wed, 16 Oct 2024 13:28:21 +0000 Received: from DB1PEPF000509F9.eurprd02.prod.outlook.com (2603:10a6:10:540:cafe::6a) by DU6P191CA0020.outlook.office365.com (2603:10a6:10:540::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.18 via Frontend Transport; Wed, 16 Oct 2024 13:28:21 +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 DB1PEPF000509F9.mail.protection.outlook.com (10.167.242.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.17 via Frontend Transport; Wed, 16 Oct 2024 13:28:21 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.63) with Microsoft SMTP Server id 15.2.1544.11; Wed, 16 Oct 2024 15:28:20 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id A437E1C006D; Wed, 16 Oct 2024 15:28:20 +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 , Jerin Jacob , Luka Jankovic , =?utf-8?q?Mattias_R=C3=B6nnblom?= , Konstantin Ananyev , Chengwen Feng Subject: [PATCH v14 1/7] eal: add static per-lcore memory allocation facility Date: Wed, 16 Oct 2024 15:19:10 +0200 Message-ID: <20241016131916.827788-2-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241016131916.827788-1-mattias.ronnblom@ericsson.com> References: <20241015093344.824073-2-mattias.ronnblom@ericsson.com> <20241016131916.827788-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB1PEPF000509F9:EE_|PR3PR07MB7051:EE_ X-MS-Office365-Filtering-Correlation-Id: 79e32ff3-bd53-4c83-126f-08dcede6677c 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?A+GqVbV7Qc1AieO1yU+qnsCLuKAf2I7?= =?utf-8?q?ash1UwkDs+gYgcgFoIiAAy0ZzWd5SoSuWMTQIUXIbyCEQjUsMrjPE+/ex9zEu/IDd?= =?utf-8?q?GDG3Y44Sm6mex7QNL0QZ/bbCwKpcd+la/OUyyeewCKxAOf2hvYLZsMUqaxLRVFsxg?= =?utf-8?q?KXdnqBWfJqpUziApmBSLQSBH/L8sr62hiSLklu0QvzoW9GflEQWh9Gu8CS1xu7Plb?= =?utf-8?q?ZGS4eAXgXXFmTICMQBR1EaHBf0DDf1WL0gdgectPHXcKVzI1SM0812jvUhzkAFfOf?= =?utf-8?q?8mXU2f8HkQqdFcYvo8T08gKJAGN486GEGI5z0UWynVSOYiT/nvvTxJgGjIFW463Pj?= =?utf-8?q?+NsEXegfO7vuHunmm4cLXOaIXtyOQsLegsM+JtAnZsQP26kZ53j6Hv7bcX50QJJsW?= =?utf-8?q?GRlg5kD4KfPyGbv3Sx87APmOazKN4zmhfijIPZ/YmkUqiEKXP1yGCKUlwW+pC+7zC?= =?utf-8?q?ynIYIc/QXYK81kdQIZi1YEASBHe2WEi24dbXaViTCHhpjqil+BOfLeEzHfr82GwOc?= =?utf-8?q?FBqziR419RqrZIXdXAaxHZAyJndzA7BfI2f1c8og3ASE4FNFPG7xtJYtVoKmAVe0H?= =?utf-8?q?OYcu+WnzQas7OA+wHdAngVmNLSTKbF7t1guCXxzWdXi4HjQQrAGZPIyopANkQJnLp?= =?utf-8?q?6rSCDI6f9Kdsh28ZMJ6r2rIG956WXwUezP0q13SsiVAUio05HKCfWtl1iCQx7BeZo?= =?utf-8?q?o+kmUacQxQz7gT9FiRQYYjI6pJ1ro5nSRmmlN+xOthjWahdSb58Uegp1vhc1VgVL9?= =?utf-8?q?v8nUQItRktIfFGWRVuUHW4g78pKhwlPaNTkpi2dWcyKORu6VzaTxfL+w8jM8VHuOB?= =?utf-8?q?SPNnMmeXFT53VrJstVXQ1tcSkg74XB3rqZmmjsCp6h1oXQSYZ7JPqoxizMQOYJyJL?= =?utf-8?q?J06i7e9TVwcFqLqB5iCSm0BuDxJvL3tEuqd92McvLkETZ96YAy1g5i00Rl0EMVuyZ?= =?utf-8?q?N73o2Kv36ts1zAnjaQro5AlWUcOaEarzaf5tYHZLd3v2t9KPIYfbY3PeAWtuDxPUR?= =?utf-8?q?raoTkuwQVxB3dphPmqj3aJxg59372sqxniq8ZCo4Y+hcrxMg79PVYx9VIJ8tNjYvg?= =?utf-8?q?XFhS8EX0l8skjiIj6Lz4kyyNmQwds2iReIp6r0B6nOG6/a2Mj4y/s0oco2SuMMT6V?= =?utf-8?q?xeAppqz8wly6pcOc0ghBhhhirAGRKH2AxakAXvHoYYFE1qB1fILpK4HWvpugKaKnm?= =?utf-8?q?u+B6s+GmEcO8Clua8lDWKwFdIvH0EToJBFocH6AJAN+kMbUJvsU9/gkjRArkP3WBI?= =?utf-8?q?ikkRGZw8TdJvZAyr8m6Nzq4vHCHHeWPGZU2Fkpa9Y3rtsAsvHu+6n4Es=3D?= X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230040)(376014)(36860700013)(82310400026)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2024 13:28:21.3432 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 79e32ff3-bd53-4c83-126f-08dcede6677c 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: DB1PEPF000509F9.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR07MB7051 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 Acked-by: Konstantin Ananyev Acked-by: Chengwen Feng Acked-by: Stephen Hemminger --- PATCH v14: * Add note in rte_lcore_var_alloc() that the memory cannot be freed. (Stephen Hemminger) * Hint the compiler rte_lcore_var_alloc() is a memory allocation facility. (Stephen Hemminger) PATCH v13: * Remove _VALUE() suffix from value lookup and iterator macros. (Morten Brørup and Thomas Monjalon) * Remove the _ptr() suffix from the value lookup function. PATCH v12: * Replace RTE_ASSERT() with RTE_VERIFY(), since performance is not a concern. (Morten Brørup) * Fix issue (introduced in v11) where aligned_malloc() was provided an object size which wasn't an even number of the alignment. (Stephen Hemminger) PATCH v11: * Add a note in the API docs on lcore variables and huge page memory. (Stephen Hemminger) * Free lcore var buffers at EAL cleanup. (Thomas Monjalon) * Tweak naming and include short lcore var buffer use overview in eal_common_lcore_var.c. PATCH v10: * Improve documentation grammar and spelling. (Stephen Hemminger, Thomas Monjalon) * Add version.map DPDK version comment. (Thomas Monjalon) PATCH v9: * Fixed merge conflicts in release notes. PATCH v8: * Work around missing max_align_t definition in MSVC. (Morten Brørup) PATCH v7: * Add () to the FOREACH lcore id macro parameter, to allow arbitrary expression, not just a simple variable name, being passed. (Konstantin Ananyev) PATCH v6: * Have API user provide the loop variable in the FOREACH macro, to avoid subtle bugs where the loop variable name clashes with some other user-defined variable. (Konstantin Ananyev) PATCH v5: * Update EAL programming guide. PATCH v2: * Add Windows support. (Morten Brørup) * Fix lcore variables API index reference. (Morten Brørup) * Various improvements of the API documentation. (Morten Brørup) * Elimination of unused symbol in version.map. (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 + .../prog_guide/env_abstraction_layer.rst | 43 +- doc/guides/rel_notes/release_24_11.rst | 14 + lib/eal/common/eal_common_lcore_var.c | 138 ++++++ lib/eal/common/eal_lcore_var.h | 11 + lib/eal/common/meson.build | 1 + lib/eal/freebsd/eal.c | 2 + lib/eal/include/meson.build | 1 + lib/eal/include/rte_lcore_var.h | 394 ++++++++++++++++++ lib/eal/linux/eal.c | 2 + lib/eal/version.map | 1 + 13 files changed, 609 insertions(+), 6 deletions(-) create mode 100644 lib/eal/common/eal_common_lcore_var.c create mode 100644 lib/eal/common/eal_lcore_var.h create mode 100644 lib/eal/include/rte_lcore_var.h diff --git a/MAINTAINERS b/MAINTAINERS index 6814991735..84fe62d339 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -289,6 +289,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 fd6f8a2f1a..498d509244 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 abd44b1861..6306636357 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 variables](@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/prog_guide/env_abstraction_layer.rst b/doc/guides/prog_guide/env_abstraction_layer.rst index b9fac1839d..b659a1d085 100644 --- a/doc/guides/prog_guide/env_abstraction_layer.rst +++ b/doc/guides/prog_guide/env_abstraction_layer.rst @@ -429,12 +429,43 @@ with them once they're registered. Per-lcore and Shared Variables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. note:: - - lcore refers to a logical execution unit of the processor, sometimes called a hardware *thread*. - -Shared variables are the default behavior. -Per-lcore variables are implemented using *Thread Local Storage* (TLS) to provide per-thread local storage. +By default, static variables, memory blocks allocated on the DPDK +heap, and other types of memory are shared by all DPDK threads. + +An application, a DPDK library, or a PMD may opt to keep per-thread state. + +Per-thread data can be maintained using either *lcore variables* (see +``rte_lcore_var.h``), *thread-local storage (TLS)* (see +``rte_per_lcore.h``), or a static array of ``RTE_MAX_LCORE`` elements, +indexed by ``rte_lcore_id()``. These methods allow per-lcore data to be +largely internal to the module and not directly exposed in its +API. Another approach is to explicitly handle per-thread aspects in +the API (e.g., the ports in the Eventdev API). + +Lcore variables are suitable for small objects that are statically +allocated at the time of module or application initialization. An +lcore variable takes on one value for each lcore ID-equipped thread +(i.e., for both EAL threads and registered non-EAL threads, in total +``RTE_MAX_LCORE`` instances). The lifetime of lcore variables is +independent of the owning threads and can, therefore, be initialized +before the threads are created. + +Variables with thread-local storage are allocated when the thread is +created and exist until the thread terminates. These are applicable +for every thread in the process. Only very small objects should be +allocated in TLS, as large TLS objects can significantly slow down +thread creation and may unnecessarily increase the memory footprint of +applications that extensively use unregistered threads. + +A common but now largely obsolete DPDK pattern is to use a static +array sized according to the maximum number of lcore ID-equipped +threads (i.e., with ``RTE_MAX_LCORE`` elements). To avoid *false +sharing*, each element must be both cache-aligned and include an +``RTE_CACHE_GUARD``. This extensive use of padding causes internal +fragmentation (i.e., unused space) and reduces cache hit rates. + +For more discussions on per-lcore state, refer to the +``rte_lcore_var.h`` API documentation. Logs ~~~~ diff --git a/doc/guides/rel_notes/release_24_11.rst b/doc/guides/rel_notes/release_24_11.rst index 5a6502820d..ba11ccc97e 100644 --- a/doc/guides/rel_notes/release_24_11.rst +++ b/doc/guides/rel_notes/release_24_11.rst @@ -212,6 +212,20 @@ New Features Added ability for node to advertise and update multiple xstat counters, that can be retrieved using ``rte_graph_cluster_stats_get``. +* **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 EAL thread and registered non-EAL thread. + + With lcore variables, data is organized spatially on a per-lcore id + 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..f4dd5b1a82 --- /dev/null +++ b/lib/eal/common/eal_common_lcore_var.c @@ -0,0 +1,138 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 Ericsson AB + */ + +#include +#include + +#ifdef RTE_EXEC_ENV_WINDOWS +#include +#endif + +#include +#include +#include + +#include + +#include "eal_private.h" +#include "eal_lcore_var.h" + +/* + * An lcore var buffer stores at a minimum one, but usually many, + * lcore variables. The value instances for all lcore ids are stored + * in the same buffer. + * + * The address of the value of a particular lcore variable associated + * with a particular lcore id is: + * buffer->data + offset + lcore_id * RTE_MAX_LCORE_VAR. + * + * In this way, the values associated with a particular lcore id are + * grouped spatially close (in the data array), and no padding is + * required to prevent false sharing. + * + * The (buffer->data + offset) base pointer is what is being returned + * to the API user as an opaque handle. The handle is a pointer to the + * value for lcore id 0, for that lcore variable. + * + * The implementation maintains a current lcore var buffer (being + * allocated from), and an offset representing the amount of data + * already allocated (in bytes) in that buffer. + * + * The offset is progressively incremented (by the size of the + * just-allocated lcore variable), as lcore variables are being + * allocated. + * + * When one lcore var buffer is full, a new is allocated off the heap. + * + * The lcore var buffers are arranged in a single-link list, to allow + * freeing them at the point of rte_eal_cleanup(), and thereby avoid + * false positives from tools like valgrind memcheck. + */ +struct lcore_var_buffer { + char data[RTE_MAX_LCORE_VAR * RTE_MAX_LCORE]; + struct lcore_var_buffer *prev; +}; + +static struct lcore_var_buffer *current_buffer; + +/* initialized to trigger buffer allocation on first allocation */ +static size_t offset = RTE_MAX_LCORE_VAR; + +static void * +lcore_var_alloc(size_t size, size_t align) +{ + void *handle; + unsigned int lcore_id; + void *value; + + offset = RTE_ALIGN_CEIL(offset, align); + + if (offset + size > RTE_MAX_LCORE_VAR) { + struct lcore_var_buffer *prev = current_buffer; + size_t alloc_size = + RTE_ALIGN_CEIL(sizeof(struct lcore_var_buffer), + RTE_CACHE_LINE_SIZE); +#ifdef RTE_EXEC_ENV_WINDOWS + current_buffer = _aligned_malloc(alloc_size, RTE_CACHE_LINE_SIZE); +#else + current_buffer = aligned_alloc(RTE_CACHE_LINE_SIZE, alloc_size); + +#endif + RTE_VERIFY(current_buffer != NULL); + + current_buffer->prev = prev; + + offset = 0; + } + + handle = ¤t_buffer->data[offset]; + + offset += size; + + RTE_LCORE_VAR_FOREACH(lcore_id, 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_VERIFY(align <= RTE_CACHE_LINE_SIZE); + RTE_VERIFY(size <= RTE_MAX_LCORE_VAR); + + /* '0' means asking for worst-case alignment requirements */ + if (align == 0) +#ifdef RTE_TOOLCHAIN_MSVC + /* MSVC is missing the max_align_t typedef */ + align = alignof(double); +#else + align = alignof(max_align_t); +#endif + + RTE_VERIFY(rte_is_power_of_2(align)); + + return lcore_var_alloc(size, align); +} + +void +eal_lcore_var_cleanup(void) +{ + while (current_buffer != NULL) { + struct lcore_var_buffer *prev = current_buffer->prev; + + free(current_buffer); + + current_buffer = prev; + } +} diff --git a/lib/eal/common/eal_lcore_var.h b/lib/eal/common/eal_lcore_var.h new file mode 100644 index 0000000000..de2c4e44a0 --- /dev/null +++ b/lib/eal/common/eal_lcore_var.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2024 Ericsson AB. + */ + +#ifndef EAL_LCORE_VAR_H +#define EAL_LCORE_VAR_H + +void +eal_lcore_var_cleanup(void); + +#endif diff --git a/lib/eal/common/meson.build b/lib/eal/common/meson.build index c1bbf26654..e273745e93 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/freebsd/eal.c b/lib/eal/freebsd/eal.c index 1229230063..796c9dbf2d 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -47,6 +47,7 @@ #include "eal_private.h" #include "eal_thread.h" +#include "eal_lcore_var.h" #include "eal_internal_cfg.h" #include "eal_filesystem.h" #include "eal_hugepages.h" @@ -941,6 +942,7 @@ rte_eal_cleanup(void) /* after this point, any DPDK pointers will become dangling */ rte_eal_memory_detach(); eal_cleanup_config(internal_conf); + eal_lcore_var_cleanup(); return 0; } diff --git a/lib/eal/include/meson.build b/lib/eal/include/meson.build index 474097f211..d903577caa 100644 --- a/lib/eal/include/meson.build +++ b/lib/eal/include/meson.build @@ -28,6 +28,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..3f5ae500bc --- /dev/null +++ b/lib/eal/include/rte_lcore_var.h @@ -0,0 +1,394 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 Ericsson AB + */ + +#ifndef _RTE_LCORE_VAR_H_ +#define _RTE_LCORE_VAR_H_ + +/** + * @file + * + * Lcore 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) holds a + * unique value for each EAL thread and registered non-EAL + * thread. There is one instance for each current and future lcore + * id-equipped thread, with a total of @c RTE_MAX_LCORE instances. The + * value of the lcore variable for one lcore id is independent from + * the values assigned to other lcore ids within the same 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 an @c uint32_t lcore variable, the handle is a + * uint32_t *). The handle type is used to inform the + * access macros of 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 an opaque identifier. An allocated handle never + * has the value NULL. + * + * @b Creation + * + * An lcore variable is created in two steps: + * 1. Define an 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 at the time + * of module initialization, but may be done at any time. + * + * The lifetime of an lcore variable is not tied to the thread that + * created it. Its per lcore id values (up to @c RTE_MAX_LCORE) are + * available from the moment the lcore variable is created and + * continue to exist throughout the entire lifetime of the EAL, + * whether or not the lcore id is currently in use. + * + * 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, associated with different lcore + * ids may be frequently read or written by their respective owners + * without risking false sharing. + * + * An appropriate synchronization mechanism (e.g., atomic loads and + * stores) should be employed to prevent data races between the owning + * thread and any other thread accessing the same value instance. + * + * The value of the lcore variable for a particular lcore id is + * accessed using @ref RTE_LCORE_VAR_LCORE. + * + * 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 + * shorthand exists as @ref RTE_LCORE_VAR. + * + * 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 be 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 define an lcore variable handle without ever + * allocating it. + * + * The size of an lcore variable's value must be less than the DPDK + * build-time constant @c RTE_MAX_LCORE_VAR. + * + * Lcore variables 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 be the lcore + * variable's owner. Adding padding will increase the effective memory + * working set size, potentially reducing performance. + * + * Lcore variable values are initialized to zero by default. + * + * Lcore variables are not stored in huge page memory. + * + * @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(lcore_states); + * + * return state->a + state->b; + * } + * + * RTE_INIT(rte_foo_init) + * { + * RTE_LCORE_VAR_ALLOC(lcore_states); + * + * unsigned int lcore_id; + * struct foo_lcore_state *state; + * RTE_LCORE_VAR_FOREACH(lcore_id, 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 are kept close in memory. At a bare minimum, this requires + * sizing data structures (e.g., using `__rte_cache_aligned`) to an + * even number of cache lines 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 + * and prevent false sharing. + * + * Lcore variables offer the advantage of working with, rather than + * against, the CPU's assumptions. A next-line hardware prefetcher, + * for example, may function as 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 makes 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 lifecycle of a thread-local variable instance is tied to + * that of the thread. The data cannot be accessed before the + * thread has been created, nor after it has exited. As a result, + * thread-local variables must be 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 occur + * before 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 specifics of the TLS implementation. With GCC __thread and + * GCC _Thread_local, data sharing between threads is supported. + * In the C11 standard, 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 an lcore variable handle. + * + * This macro defines a variable which is used as a handle to access + * the various instances of a per-lcore id variable. + * + * This macro clarifies that the declaration is an lcore handle, not a + * regular pointer. + * + * Add @b static as a prefix in case the lcore variable is 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 handle 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(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(lcore_id, handle) \ + ((typeof(handle))rte_lcore_var_lcore(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(handle) \ + RTE_LCORE_VAR_LCORE(rte_lcore_id(), handle) + +/** + * Iterate over each lcore id's value for an lcore variable. + * + * @param lcore_id + * An unsigned int variable successively set to the + * lcore id of every valid lcore id (up to @c RTE_MAX_LCORE). + * @param value + * A pointer variable successively set to point to lcore variable + * value instance of the current lcore id being processed. + * @param handle + * The lcore variable handle. + */ +#define RTE_LCORE_VAR_FOREACH(lcore_id, value, handle) \ + for ((lcore_id) = \ + (((value) = RTE_LCORE_VAR_LCORE(0, handle)), 0); \ + (lcore_id) < RTE_MAX_LCORE; \ + (lcore_id)++, (value) = RTE_LCORE_VAR_LCORE(lcore_id, \ + handle)) + +/** + * Allocate space in the per-lcore id buffers for an lcore variable. + * + * The pointer returned is only an opaque identifier of the variable. To + * get an actual pointer to a particular instance of the variable use + * @ref RTE_LCORE_VAR or @ref RTE_LCORE_VAR_LCORE. + * + * 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. + * + * The allocated memory cannot be freed. + * + * @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 variable's handle, 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) + __rte_alloc_size(2); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_LCORE_VAR_H_ */ diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 54577b7718..d0f27315b9 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -45,6 +45,7 @@ #include #include "eal_private.h" #include "eal_thread.h" +#include "eal_lcore_var.h" #include "eal_internal_cfg.h" #include "eal_filesystem.h" #include "eal_hugepages.h" @@ -1371,6 +1372,7 @@ rte_eal_cleanup(void) rte_eal_malloc_heap_cleanup(); eal_cleanup_config(internal_conf); rte_eal_log_cleanup(); + eal_lcore_var_cleanup(); return 0; } diff --git a/lib/eal/version.map b/lib/eal/version.map index f493cd1ca7..94dc5b17d6 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -399,6 +399,7 @@ EXPERIMENTAL { # added in 24.11 rte_bitset_to_str; + rte_lcore_var_alloc; }; INTERNAL { From patchwork Wed Oct 16 13:19:11 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: 146086 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 7226945B50; Wed, 16 Oct 2024 15:29:13 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1C17E40672; Wed, 16 Oct 2024 15:28:37 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2047.outbound.protection.outlook.com [40.107.22.47]) by mails.dpdk.org (Postfix) with ESMTP id 59E2E4060B for ; Wed, 16 Oct 2024 15:28:27 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JT0UFEZ4SUcGOooBSLLc4LmtKauCPdPUysFizSExdam0rib8sjPZ6WNe7x/OPMkGkJsCGiE0ngsO0ctiiQfVJnHBlKBgPFvKSbvxmFZpZ1xWpjUuw4kD8kv00w11aOb1KhVDbTbHkwcRMSS9OoGbTM+gmGNWZvtShOrYqj4JTyj67UlTXTfPrEIlpZBHJRa5Q5wDHlMpwDbbMWm31xO1CtAYP1TodRyDH25O0kMOxJhmIbWjCdsgNvrcVo9b+n0bk7Z4PLGH4iXO8cYfJsqX1EXhLkSKcJep+gx8Lh+LnTi9kSrvVmx4ifSsd5y1JwczyiAiAFiHQnBzHM2Fk/jk7w== 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=qeCwkc3UJZ2cf3/aQKFBEZk6mxDMOPd4/2W5Mok9DfY=; b=jZjqaYT+VrFxXjDeP6+nutR6Ze1Z49fy7j3I652PbCmcsld2KhOuIrT0jiailHRjXVP17+ylDBR+YceqhsRPXr/IgnEyGDpIk79LYi9cGmsN3CMPJP2acnHaLSg1u4dwMQlAarLyOOHpKTL/6ujb5FgWGwCcrO9YvR2E+jVxMB07myZWhjzSIVUy+4p6DEVz4Di5CluamVCj//4Z+dRnO9fuTMnaDxQPXR8Ir1ZQFtlU6A/UM3yBbp4SnWTfrFrO8EuDotL+wmb5JranaNDNcDVxTjTOeygNDNexE/d2yMVsQfehMIXBTJqG7LiF9SivQuIk7F4NCxxBc3IWsXXLMQ== 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=qeCwkc3UJZ2cf3/aQKFBEZk6mxDMOPd4/2W5Mok9DfY=; b=fjquU6YoHyb0rGD/vDDs0dsNlPKUOtUnCLYxKa6CStl5GKWxIRONKlENvh+jYikoOA22uvwhSOe0+1tt1LZRFDZ66cp6900ezig1FZiLkLtwgQnz1+cCBRDAVN6hPSbPqKLbBp4dpVpyEaNEJldwE6Ez2zIrmEsxbHuJDqByAnCpasWVAFJJp3StMoeYV6VbKzXySitjlG8i9VnMfLrxvJEbUZ4MSJzlxtZOjxbwmMoRYPge59Wl565ehKVHKCCXoBzunBxooZ0ywGH1QXyAtieCHL5v6DGnogsotzKNkLwM5U975N0Lm3JR7RehCjo+nd1SBWRevM/5BE6bbMGeYw== Received: from DU6P191CA0009.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:540::9) by GV1PR07MB8997.eurprd07.prod.outlook.com (2603:10a6:150:a2::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.26; Wed, 16 Oct 2024 13:28:22 +0000 Received: from DB1PEPF000509F9.eurprd02.prod.outlook.com (2603:10a6:10:540:cafe::2a) by DU6P191CA0009.outlook.office365.com (2603:10a6:10:540::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.18 via Frontend Transport; Wed, 16 Oct 2024 13:28:22 +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 DB1PEPF000509F9.mail.protection.outlook.com (10.167.242.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.17 via Frontend Transport; Wed, 16 Oct 2024 13:28:22 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.63) with Microsoft SMTP Server id 15.2.1544.11; Wed, 16 Oct 2024 15:28:20 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id BAD571C0070; Wed, 16 Oct 2024 15:28:20 +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 , Jerin Jacob , Luka Jankovic , =?utf-8?q?Mattias_R=C3=B6nnblom?= , Chengwen Feng Subject: [PATCH v14 2/7] eal: add lcore variable functional tests Date: Wed, 16 Oct 2024 15:19:11 +0200 Message-ID: <20241016131916.827788-3-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241016131916.827788-1-mattias.ronnblom@ericsson.com> References: <20241015093344.824073-2-mattias.ronnblom@ericsson.com> <20241016131916.827788-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB1PEPF000509F9:EE_|GV1PR07MB8997:EE_ X-MS-Office365-Filtering-Correlation-Id: 84224a8b-2372-4bc8-9624-08dcede66801 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|36860700013|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?q?SJpEZAhBMw/SQzLALHnIuz1SMOBW7Gk?= =?utf-8?q?e1K6ELGezOsI0cMcUKA4azyzwNj3Y9GMZMKv6sEV5mgjPQGjB/U4GS55nvR0KvQx+?= =?utf-8?q?jWZEl5JEff9Bz38vqFje+Y0rCOKeh6YEf3dnZ8SdjUgr4OLqJjS9gtkfz+Bu9jVmL?= =?utf-8?q?QsL9w8c3PQ1ZYdz4kr6wGkRLOi9i7o2Mrg0d9mqO0YSGbnTtmZ+6dg4RKAYpU8CUB?= =?utf-8?q?HqEI9i1wb4D7Ti/x0D0iXH0tTp5Tr2IdMDatO3V0S9yNJbCWPB9Qefbknb0o0/n37?= =?utf-8?q?MQvbLnhb+iH6WsI0qGlx9XMYGR4tyfHlKnfUuoOZ+9WXBl94D4KqEPeNo+q7Jc4+r?= =?utf-8?q?reuzHM5TS59zwY+3PG+WC5W+OVh23AymQMbX4e8mjEnjt/OEDr0ycwUyvaXRmS2Q+?= =?utf-8?q?c1fG8uhCG94xgyCNbyJz5GnypsSm2xo9lVZItr8qPkZlobKPUVVI1nQg2pnNoQ7oy?= =?utf-8?q?BHgYv142zblaFCa06CekzIQ8RplE+Npw6XL0lGbQZoGq499ZhYM3vD+9qoq7dgeX8?= =?utf-8?q?ineP2QMuZ7TbVhxqEiQ5TuxxsWhG+8gbBjJpJzJKYVwjXxd4GiU3s5S4dnXxMjylH?= =?utf-8?q?D+ipXGgTvpuSfjA8aS/vQA0kYnsGh50aQUZXJ0rxE+4EsG6B8D+BYFL9H8UeESkWi?= =?utf-8?q?LhzdRN3q4l6kF2p8cvyWxhWCfAVW/XerIYcO9Xe1PtJOkIia9U54fX0B3ZuETOZXE?= =?utf-8?q?pxRBKSXHzwwFOHx3IM/Cj8KjylXh2fvTGJ83huhCTH3vRZmQ/bpLA2IraeBpTlh84?= =?utf-8?q?1c0Iw+c7eQhKbe6SHL0esIRQcOblqBlSzy+9LoK1RWmf8UP1jeapSP1NSzA1c63w8?= =?utf-8?q?CZ1mIdVDbN2uX7EO11AX3qBzga5GKdoNh3Q22tfvvm3R7yooE1yUc6LCt49GuNVKw?= =?utf-8?q?Y0uNc1XkA2zmG62VSdVLzyB4iaXIOdWkxDMYJtzmyPNAhbu2Cj4wmqURRIlgwaLw9?= =?utf-8?q?HW8NUOAOvzdy1In/9q8e/eeKsd6/Xpon5UKSRGTNW8KX0FsyZhRvEXzG6IbfmfjXL?= =?utf-8?q?LCr6x8wI85adiMaZomxpUoZXru920+uYK67R03giNJdxFZWmJHucpN4+mRp/YJUou?= =?utf-8?q?AqITl36ybvcHApdMgxEiGEccKccyhYvvXRhm+9yqT/CtMoxDwF86j4yCbySoGyHvn?= =?utf-8?q?ZjQHfVEfdumDqXOpuRyncvn03965fiTR6f/OEyIDqBT66HNcWoQp4g8VK2S3bC7DK?= =?utf-8?q?1GCsM3ownxHhz6KqxBmaKTEOkUCCjdvLb9408oRbBp0Q2u5z0FBMxfT21jI8LH8Dq?= =?utf-8?q?xGWjq4gWXt5VOdXh86IASAURAyLwLP48ZN1SSKJjjIov0Lzz9+6YR1bg=3D?= X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230040)(376014)(36860700013)(1800799024)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2024 13:28:22.2182 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 84224a8b-2372-4bc8-9624-08dcede66801 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: DB1PEPF000509F9.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR07MB8997 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 functional test suite to exercise the API. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup Acked-by: Chengwen Feng Acked-by: Stephen Hemminger --- PATCH v6: * Update FOREACH invocations to match new API. 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 fe248b786c..9060cfeb7a 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -104,6 +104,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..ddf70b03a0 --- /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(test_int); + + bool naturally_aligned = is_ptr_aligned(ptr, sizeof(int)); + + bool equal = *(RTE_LCORE_VAR(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(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(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; + unsigned int i = 0; + RTE_LCORE_VAR_FOREACH(lcore_id, v, test_int) { + TEST_ASSERT_EQUAL(i, lcore_id, "Encountered lcore id %d " + "while expecting %d during iteration", + lcore_id, i); + TEST_ASSERT_EQUAL(states[lcore_id].new_value, *v, + "Unexpected value on lcore %d during " + "iteration", lcore_id); + i++; + } + + return TEST_SUCCESS; +} + +static int +test_sized_alignment(void) +{ + unsigned int lcore_id; + long *v; + + RTE_LCORE_VAR_FOREACH(lcore_id, v, test_long_sized) { + TEST_ASSERT(is_ptr_aligned(v, alignof(long)), + "Type-derived alignment failed"); + } + + RTE_LCORE_VAR_FOREACH(lcore_id, 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(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(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(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(lcore_id, before_struct); + char after = + *RTE_LCORE_VAR_LCORE(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(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(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(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(lcore_id, before_array); + char after = + *RTE_LCORE_VAR_LCORE(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(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(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(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(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 Wed Oct 16 13:19:12 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: 146081 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 A60C945B50; Wed, 16 Oct 2024 15:28:30 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 70CDE402DD; Wed, 16 Oct 2024 15:28:26 +0200 (CEST) Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2063.outbound.protection.outlook.com [40.107.247.63]) by mails.dpdk.org (Postfix) with ESMTP id 1B51B40264 for ; Wed, 16 Oct 2024 15:28:24 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OG400bRbqN0ZO/g+X/1mBaarrPWoYuQzw/E+5l5U/v6hUEy+95TXWzHAzMc3EyLcZxA7Q3+iAGkP1d5jtGU3ZHTR65tIIsRu7IjfKOL7zknLFtQxqpulzljmYBhBQeNdcje0sDsG1q57aUDK3cRE/Q4ha+scwaIAfv5jWoyT5rjQDmvcT9lOhuxZC36Pf+6Ix+KHfC5jrksi+Y/tEX9ZtgLhlc6av7TN2Few5Z0KV0DPdD7MMhRpG5gXrXY1t3AJ1yu3vZNsutZkl51quI2ZQbmmTBLCfJUAjUCfrsAANIK4DTQTdb9aK4CWJipA+Px+v08W0/qgMiRSZQTSO3rDFw== 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=Fuu6j6hbwgy3sNnieKhxiheiV+fLzKrYeHZEIArggf0=; b=hiZ4nNJCg8yb3NERvG2LxwnLxQ4K9kFI0PFE8zoUZGrmHOYiB1WgGzFgxq4VyFTTo2HmKOx4zNzLL8on8C0wTS8cLSJLp09/k3G2IbsEltjOJN/uJY/tR10nAzwS3gXlb0EppI4mOKZytCBVU+Q78iegmU4NYyF2PMOlT4diL+UpK982aj9nvU/dgmMy/sKFlT16bTv3BSuuFSYm0Z8ypzqgqX41tud/oIvdF/JkUZMnrKMFrJ8n/NaIjwLPnzjgsHiO0PmtZrRbiXMUDXeTfvA50LyfZUb7W3jYu7POZlbTTiHqwXPa2tPrv2tKSMP7CWNa/ZUno53QZSm53bWTEw== 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=Fuu6j6hbwgy3sNnieKhxiheiV+fLzKrYeHZEIArggf0=; b=jOgAZNbBcG5aMV2d3Pvpn3HbAHUfJUVSmOf1TdUnUXzwNUutYqeuMMua/C7Bw0F0qXY0hV32vAQJfkscE8QUX/n9Bb5nDNCfHEsy4Ecae3Yvy+BMUaRB+9KyTTB6hp+78Bb0nGBjHAuzUxCcEALnWtIePBz4Qg0tGMbxixGJgQtIl/BrPtmxinl+Vc3OvcbNuqK/ClauYZ+G/rb5tgi4oIYzOR4x9fFpqtfPhvSBf8l47Xp1dIK7Hcbb5r5ICRNVUDyQuJg3gRJCUhTJzHI7OcMCOOJiHso3yhMxlFaPX6FSOCDPe4Ugb4C5CfMDDMF+44VpR1Zvu9ZdmenWHmRYYA== Received: from DU6P191CA0021.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:540::26) by DBBPR07MB7545.eurprd07.prod.outlook.com (2603:10a6:10:1f2::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.17; Wed, 16 Oct 2024 13:28:21 +0000 Received: from DB1PEPF000509F9.eurprd02.prod.outlook.com (2603:10a6:10:540:cafe::b6) by DU6P191CA0021.outlook.office365.com (2603:10a6:10:540::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.18 via Frontend Transport; Wed, 16 Oct 2024 13:28:21 +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 DB1PEPF000509F9.mail.protection.outlook.com (10.167.242.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.17 via Frontend Transport; Wed, 16 Oct 2024 13:28:21 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.63) with Microsoft SMTP Server id 15.2.1544.11; Wed, 16 Oct 2024 15:28:20 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id CDE621C006B; Wed, 16 Oct 2024 15:28:20 +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 , Jerin Jacob , Luka Jankovic , =?utf-8?q?Mattias_R=C3=B6nnblom?= , Chengwen Feng Subject: [PATCH v14 3/7] eal: add lcore variable performance test Date: Wed, 16 Oct 2024 15:19:12 +0200 Message-ID: <20241016131916.827788-4-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241016131916.827788-1-mattias.ronnblom@ericsson.com> References: <20241015093344.824073-2-mattias.ronnblom@ericsson.com> <20241016131916.827788-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB1PEPF000509F9:EE_|DBBPR07MB7545:EE_ X-MS-Office365-Filtering-Correlation-Id: a1442400-cff7-4f14-e71b-08dcede667d1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|376014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?q?s27q9asZqzflyBG7aHe3ViHj60UJC4I?= =?utf-8?q?hfgcwZDLiHDoVNfKLsjqpX6Ox9ATtiyRt5HJ0TydUkmzcsCyiPG6W+Kpao4+dvegX?= =?utf-8?q?rBZz0iUg1cozidOn+BLk8b0WosnjjIVecKDWcdlfUNlx1m5ovcprfLB+T3KX+VsGh?= =?utf-8?q?4R5op685POnt5BZUnJNINBce4VGu+w6Bx78OpqausdbkBhfoBJ1HsI18RrMg/FAdw?= =?utf-8?q?fvirAFDbehDMIczXTQxu1LjYoDP9picYChV4XgoSSfO4VOXjjznMEwTRIzNpGzY5c?= =?utf-8?q?2W9CatoYnllB9xJScSXKOAFUHFx6cQGbHv4BTmiCkume2a44nTNH9p2Kpw52HV+G1?= =?utf-8?q?+eIz3KJgQ6/r2QGoRLjlMBnQg5IgyexHesKLnBe6l5vzQ7osoBhAadf14RZVaiQoS?= =?utf-8?q?OdkDgQsD7wRfDY2XftXq1iqnhW0b9/+gscLQvxuBQ5NecgIgVEQLSYYAJdHCyMABy?= =?utf-8?q?UY/6OprHnHYU6Ade6cFvYmNjD+baRXzuX70e2Kebc+RJ4WA+i+P3M/y3gAu8xjzup?= =?utf-8?q?wNo4FoAd3CUgNDwfOb4kPbxd/HrSU4kL/mu0sqsxoWrIVZQbUzBYvMt26PXKBEtlP?= =?utf-8?q?+rM/jbt/ANd7Tm2aCk6COhraidrxJcclVh4LBXDPxFx30HWWt4UPj3QXghaSIkbmg?= =?utf-8?q?zKFgqvqd9rAWUaSxroGJ4IaKEm3l1Fwea5MFmPlp/rbSd660kbUbLF5CBuiYTw45E?= =?utf-8?q?H1+b7OH6YGBw0d2IGAULixEd/1LLFxMS18Vd7PV2k/udJ2nqtFWJtOYd2YDOzYsG6?= =?utf-8?q?PRtSUNotQmCydHheRnQRVlDhYbnOzFZm/uuENeA22wHASLkpEHEjYXGNxOI8jcx+Y?= =?utf-8?q?iUU9s3s0vS3zbP3WiKJwHf3mc6OHZusx50jCSdW9Veq5KZT7Uv73ltkY0DyXnGXQy?= =?utf-8?q?2wFDvjmZBcvVpkYQYnMI6x2SOWs+HZDHO6bW0kNaKCoQOkkAOsYNjnZpfvmbXEfFj?= =?utf-8?q?texSqqs2kuligniwfbSNo+SBPlLiCYItTCMfqt7LdN6jl5KUsiRbjyMWIBBh+n8Gj?= =?utf-8?q?AGZFjsc1Mex3p1diHIej9LZKC/1w7Hfjfw0GAsBU7VvGhANk4BAqRl7H5wslRrbpK?= =?utf-8?q?V/5xucxSf+R+SRu0lsEnySVWp50o3I2ysOBwoRaO+FciBGVNGPqrchax+Ovc4RxmW?= =?utf-8?q?kDJAJgufSJHeg6v+NZPEmCAXc/cRwJumVAFJov1BKLV4UQ7tHWcZpi5Rs83CJCWtS?= =?utf-8?q?IV18Spin0GDTiq/4/QQXOSHO8wy7VmF6Y4IQ/YoQbVude4g6ymvivUJe4GT7FxBnO?= =?utf-8?q?nv5I/4lypn4XII81qmT6Rtgs6HDLwURtdj3A1PEGpIc0WWKAbMxkMSDLIK3GPvBc5?= =?utf-8?q?L92HL3yTm5I0?= 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)(376014)(36860700013)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2024 13:28:21.9057 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a1442400-cff7-4f14-e71b-08dcede667d1 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: DB1PEPF000509F9.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR07MB7545 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 basic micro benchmark for lcore variables, in an attempt to assure that the overhead isn't significantly greater than alternative approaches, in scenarios where the benefits aren't expected to show up (i.e., when plenty of cache is available compared to the working set size of the per-lcore data). Signed-off-by: Mattias Rönnblom Acked-by: Chengwen Feng Acked-by: Stephen Hemminger Acked-by: Morten Brørup --- PATCH v8: * Fix spelling. (Morten Brørup) PATCH v6: * Use floating point math when calculating per-update latency. (Morten Brørup) PATCH v5: * Add variant of thread-local storage with initialization performed at the time of thread creation to the benchmark scenarios. (Morten Brørup) PATCH v4: * Rework the tests to be a little less unrealistic. Instead of a single dummy module using a single variable, use a number of variables/modules. In this way, differences in cache effects may show up. * Add RTE_CACHE_GUARD to better mimic that static array pattern. (Morten Brørup) * Show latencies as TSC cycles. (Morten Brørup) --- app/test/meson.build | 1 + app/test/test_lcore_var_perf.c | 256 +++++++++++++++++++++++++++++++++ 2 files changed, 257 insertions(+) create mode 100644 app/test/test_lcore_var_perf.c diff --git a/app/test/meson.build b/app/test/meson.build index 9060cfeb7a..cf4908de5a 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -105,6 +105,7 @@ source_file_deps = { 'test_kvargs.c': ['kvargs'], 'test_latencystats.c': ['ethdev', 'latencystats', 'metrics'] + sample_packet_forward_deps, 'test_lcore_var.c': [], + 'test_lcore_var_perf.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_perf.c b/app/test/test_lcore_var_perf.c new file mode 100644 index 0000000000..6d9869f873 --- /dev/null +++ b/app/test/test_lcore_var_perf.c @@ -0,0 +1,256 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 Ericsson AB + */ + +#define MAX_MODS 1024 + +#include + +#include +#include +#include +#include +#include + +#include "test.h" + +struct mod_lcore_state { + uint64_t a; + uint64_t b; + uint64_t sum; +}; + +static void +mod_init(struct mod_lcore_state *state) +{ + state->a = rte_rand(); + state->b = rte_rand(); + state->sum = 0; +} + +static __rte_always_inline void +mod_update(volatile struct mod_lcore_state *state) +{ + state->sum += state->a * state->b; +} + +struct __rte_cache_aligned mod_lcore_state_aligned { + struct mod_lcore_state mod_state; + + RTE_CACHE_GUARD; +}; + +static struct mod_lcore_state_aligned +sarray_lcore_state[MAX_MODS][RTE_MAX_LCORE]; + +static void +sarray_init(void) +{ + unsigned int lcore_id = rte_lcore_id(); + int mod; + + for (mod = 0; mod < MAX_MODS; mod++) { + struct mod_lcore_state *mod_state = + &sarray_lcore_state[mod][lcore_id].mod_state; + + mod_init(mod_state); + } +} + +static __rte_noinline void +sarray_update(unsigned int mod) +{ + unsigned int lcore_id = rte_lcore_id(); + struct mod_lcore_state *mod_state = + &sarray_lcore_state[mod][lcore_id].mod_state; + + mod_update(mod_state); +} + +struct mod_lcore_state_lazy { + struct mod_lcore_state mod_state; + bool initialized; +}; + +/* + * Note: it's usually a bad idea have this much thread-local storage + * allocated in a real application, since it will incur a cost on + * thread creation and non-lcore thread memory usage. + */ +static RTE_DEFINE_PER_LCORE(struct mod_lcore_state_lazy, + tls_lcore_state)[MAX_MODS]; + +static inline void +tls_init(struct mod_lcore_state_lazy *state) +{ + mod_init(&state->mod_state); + + state->initialized = true; +} + +static __rte_noinline void +tls_lazy_update(unsigned int mod) +{ + struct mod_lcore_state_lazy *state = + &RTE_PER_LCORE(tls_lcore_state[mod]); + + /* With thread-local storage, initialization must usually be lazy */ + if (!state->initialized) + tls_init(state); + + mod_update(&state->mod_state); +} + +static __rte_noinline void +tls_update(unsigned int mod) +{ + struct mod_lcore_state_lazy *state = + &RTE_PER_LCORE(tls_lcore_state[mod]); + + mod_update(&state->mod_state); +} + +RTE_LCORE_VAR_HANDLE(struct mod_lcore_state, lvar_lcore_state)[MAX_MODS]; + +static void +lvar_init(void) +{ + unsigned int mod; + + for (mod = 0; mod < MAX_MODS; mod++) { + RTE_LCORE_VAR_ALLOC(lvar_lcore_state[mod]); + + struct mod_lcore_state *state = + RTE_LCORE_VAR(lvar_lcore_state[mod]); + + mod_init(state); + } +} + +static __rte_noinline void +lvar_update(unsigned int mod) +{ + struct mod_lcore_state *state = RTE_LCORE_VAR(lvar_lcore_state[mod]); + + mod_update(state); +} + +static void +shuffle(unsigned int *elems, size_t len) +{ + size_t i; + + for (i = len - 1; i > 0; i--) { + unsigned int other = rte_rand_max(i + 1); + + unsigned int tmp = elems[other]; + elems[other] = elems[i]; + elems[i] = tmp; + } +} + +#define ITERATIONS UINT64_C(10000000) + +static inline double +benchmark_access(const unsigned int *mods, unsigned int num_mods, + void (*init_fun)(void), void (*update_fun)(unsigned int)) +{ + unsigned int i; + double start; + double end; + double latency; + unsigned int num_mods_mask = num_mods - 1; + + RTE_VERIFY(rte_is_power_of_2(num_mods)); + + if (init_fun != NULL) + init_fun(); + + /* Warm up cache and make sure TLS variables are initialized */ + for (i = 0; i < num_mods; i++) + update_fun(i); + + start = rte_rdtsc(); + + for (i = 0; i < ITERATIONS; i++) + update_fun(mods[i & num_mods_mask]); + + end = rte_rdtsc(); + + latency = (end - start) / (double)ITERATIONS; + + return latency; +} + +static void +test_lcore_var_access_n(unsigned int num_mods) +{ + double sarray_latency; + double tls_latency; + double lazy_tls_latency; + double lvar_latency; + unsigned int mods[num_mods]; + unsigned int i; + + for (i = 0; i < num_mods; i++) + mods[i] = i; + + shuffle(mods, num_mods); + + sarray_latency = + benchmark_access(mods, num_mods, sarray_init, sarray_update); + + tls_latency = + benchmark_access(mods, num_mods, NULL, tls_update); + + lazy_tls_latency = + benchmark_access(mods, num_mods, NULL, tls_lazy_update); + + lvar_latency = + benchmark_access(mods, num_mods, lvar_init, lvar_update); + + printf("%17u %8.1f %14.1f %15.1f %10.1f\n", num_mods, sarray_latency, + tls_latency, lazy_tls_latency, lvar_latency); +} + +/* + * The potential performance benefit of lcore variables compared to + * the use of statically sized, lcore id-indexed arrays is not + * shorter latencies in a scenario with low cache pressure, but rather + * fewer cache misses in a real-world scenario, with extensive cache + * usage. These tests are a crude simulation of such, using dummy + * modules, each with a small, per-lcore state. Note however that + * these tests have very little non-lcore/thread local state, which is + * unrealistic. + */ + +static int +test_lcore_var_access(void) +{ + unsigned int num_mods = 1; + + printf("- Latencies [TSC cycles/update] -\n"); + printf("Number of Static Thread-local Thread-local Lcore\n"); + printf("Modules/Variables Array Storage Storage (Lazy) Variables\n"); + + for (num_mods = 1; num_mods <= MAX_MODS; num_mods *= 2) + test_lcore_var_access_n(num_mods); + + return TEST_SUCCESS; +} + +static struct unit_test_suite lcore_var_testsuite = { + .suite_name = "lcore variable perf autotest", + .unit_test_cases = { + TEST_CASE(test_lcore_var_access), + TEST_CASES_END() + }, +}; + +static int +test_lcore_var_perf(void) +{ + return unit_test_suite_runner(&lcore_var_testsuite); +} + +REGISTER_PERF_TEST(lcore_var_perf_autotest, test_lcore_var_perf); From patchwork Wed Oct 16 13:19:13 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: 146087 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 8EFA945B50; Wed, 16 Oct 2024 15:29:26 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 12F4840663; Wed, 16 Oct 2024 15:28:43 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2060.outbound.protection.outlook.com [40.107.22.60]) by mails.dpdk.org (Postfix) with ESMTP id 3A0F840430 for ; Wed, 16 Oct 2024 15:28:27 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uPANcrArx4vzJJNfiYzAsbADZAYHJ9VBV++Pdpe8psVigAKBTe9NIB7xBZw3px9Dp3YHKDnszC8rxBOTiXt/Zd2Q4rbNGrQcL/g5irbpKrqsAS7NpWvvfmL4YLxdECiDmDq8Wcj109Z0anq4l3Fd2hV5Pfp9aTF0pWvKaOchbZ4BT/r5onQ4zQurn5qlG5sHekeASsPDZaSGg+ORR9ZJsFcQUFApAYGTr1BDHyiaIibQr1lsWBs1R+ZpIqwm/aBljwZLoqd9Yz+mH56vEHb/lH72kAQyjlYOEEYO0TlOgwrZDvy/urllXD8eGuMa4R52HxJVCdgMTPzw+M/m7n24ZQ== 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=DESL2qFVuTQWm/n9l4enH+FDESyNnVazkJ0Sbs+rOpQ=; b=lMh7IE+iRAodUfwrvzJDWi6LzpekxJR6R7y6dmqa5jWGrZ8t7K9nsEfjry8jECTlVqk7zQ7re9Y2gN0wysPT8Sjdu/BXL2/W9xAnGFRRAaQ+W8a1HdTuzBRDi5OD1o71d+Ac7K+NonaAPhKFo5s1q9zT69gbpHm6cO1q1rcAWH7FMSGah7zGoxvqVRxQbwZAeGLP+LcKqM1jg+UX0OCAg1sBvxAtjfTWWtwQZyH3+lRsZLQqlKyhkG6e9OEaU9jOtezxrOxi7FyTmwTlN5MzavuaFCgD9s8u2fCFlqnXf39owyscSPRIqQwUB768D5FrgHNTEGhqSR0Qpm0OMGnjww== 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=DESL2qFVuTQWm/n9l4enH+FDESyNnVazkJ0Sbs+rOpQ=; b=RsDjvYDIlIbb6UbK3rfBqIo7+Dii3p2SrQ9+Df80Gw7yUpM4vgVv4X0SSDZpAWro7Sf7pnUe3DEBknZH/pMhjMcw1LwgZzx4I1O5tWKMeOL2fJWg7RcP6CPtTAiz3UQnHZK+Sv2qDcm4ZDPSNozx/+T9Jl9YjLo6tt+sBRBMlexN1PMiq71YzPa5TuzCF1tba2fzgznxS0c/EzvvE1KACmOYFACzs/RtBSG0gAmvF2wlgSsxvbmbRsYchP4nkSHfm8O3vRwcKAaKFjDwHPXDeL2RqBDUs4nCpclnKBei7RW8QxJJ2pRddFdAg+HKQWdH4bCxlryzd3kXVCUY22b5Mw== Received: from AM0PR01CA0090.eurprd01.prod.exchangelabs.com (2603:10a6:208:10e::31) by GVXPR07MB9677.eurprd07.prod.outlook.com (2603:10a6:150:111::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.17; Wed, 16 Oct 2024 13:28:22 +0000 Received: from AM3PEPF0000A795.eurprd04.prod.outlook.com (2603:10a6:208:10e:cafe::d7) by AM0PR01CA0090.outlook.office365.com (2603:10a6:208:10e::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.18 via Frontend Transport; Wed, 16 Oct 2024 13:28:21 +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 AM3PEPF0000A795.mail.protection.outlook.com (10.167.16.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.17 via Frontend Transport; Wed, 16 Oct 2024 13:28:21 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.62) with Microsoft SMTP Server id 15.2.1544.11; Wed, 16 Oct 2024 15:28:21 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id DF8E61C006D; Wed, 16 Oct 2024 15:28:20 +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 , Jerin Jacob , Luka Jankovic , =?utf-8?q?Mattias_R=C3=B6nnblom?= , Konstantin Ananyev , Chengwen Feng Subject: [PATCH v14 4/7] random: keep PRNG state in lcore variable Date: Wed, 16 Oct 2024 15:19:13 +0200 Message-ID: <20241016131916.827788-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241016131916.827788-1-mattias.ronnblom@ericsson.com> References: <20241015093344.824073-2-mattias.ronnblom@ericsson.com> <20241016131916.827788-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM3PEPF0000A795:EE_|GVXPR07MB9677:EE_ X-MS-Office365-Filtering-Correlation-Id: 8a684f69-e24f-4ee5-cc21-08dcede6676d 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?Af1yN98NW0Y4ozpMQVamXUJEZGz/GwB?= =?utf-8?q?cx9p7XhgLgahdod2J3hwUYo30yrE6Sa9Od3SGbzCqIBqCsy+Jr2WLT+3jF3exTYmS?= =?utf-8?q?gcUNUHl5WRifEU8YatoKWaqzQIbLrhWfUK5Y1k2ZHdxcNeANSHYHvUGkLf1iNDzgD?= =?utf-8?q?zNaksIRrIXg2cWtY4z+HkiNeNRloD3MmHX/IXm4UXzGYT4wOKELV5R292LqzASh/c?= =?utf-8?q?k4SBTk/dBXgI7mWdZdJUgKsJp2YNceL6ho6Vrrm42JVUbGHzFSvmgebSyuT3Y/gmV?= =?utf-8?q?B+ZX2oQ+4Z2xotNnIi8fWo9blc9Z5VEhLt9pCBO7TlvqjuNn6RyysC2kFKodEv82T?= =?utf-8?q?ztBXoOdv1vKbm53+kgop0uNWe6KH7a07z8GucRHVaaGO9ul4M6J1WJ9JX3m2Y6Eqs?= =?utf-8?q?xzdzPDUrP1cOl4gVIL/uWC6nms8qc2G9JR9WedlpqjgDXwdCo2XPhEPpkX/jVP8sM?= =?utf-8?q?HK8oySGSLxk33ILyMyHB2WqnTPNIRGjM+GfDoqtjFczRTtobVnVQ/chC89M6jhcqA?= =?utf-8?q?J73wjFkUAaRqNkcdJBZBNdWXf32b8TmJepKw/uVVQH/vpOKtNqJeNfAQkFQ5SZAnr?= =?utf-8?q?HCz3xS4Cis+W/pKcKyUpAIaVOueOXdNEMaL/Q19nyrAWlakUxGk9zk0Km/IB87ICd?= =?utf-8?q?3c1haIu0YBbPdKdFSpkitKiCZYnl3hF7sHbonMXiqNalAWKRw/cLVO1ViwWgNwM8W?= =?utf-8?q?thThWlIHh5rRfiNhlN6yPjwIXbLYMmnoUavASQWUXLmyqggK4ax9TBrKq1Emg67JN?= =?utf-8?q?Pj97RgV7wUtEjtO/fWQkhCacxkyY3DkuwlpKSc5WiUplRdoWnng3p562NmpPWR4Tr?= =?utf-8?q?LrXjXLY7cy23iJTgVzx6QlfUL3K1dFUjYG/120kTNvXWkemL535SOUnB+pLB+1ZcX?= =?utf-8?q?T7JWPXuTErm3xrfqXJsxr0pY5Y41RoG5q7O6QI91xdqv/6QG/AxfpvfP6KZtR8sBd?= =?utf-8?q?M1o9MvIz1EgHrpQMtURJWyuf0XHA3h/aauC7eVI2XFZrTYKgZGbjccJajEmRmqb+v?= =?utf-8?q?TURj1h+2jHctdC8gODfxaEPmZDnDK2liB/yWScO9I0J5EuBdVWqpAZNaEulN7Wpu8?= =?utf-8?q?ADbE2aM3etwYdF97DNpS7rStQA9FjuSkzImp6dFhrG931/1jfP2Pr9mh/Si16DEDP?= =?utf-8?q?6f7Q3QVXq7vX/FW2KUWWpwa9YyIyqwuUv0WYBTNKFtc+A0yqX+SfxvSOCNfg9XEXh?= =?utf-8?q?2pi8Yvxq+hD3XKGGVLN1hFqBh1yzDUgzAav9BA61NLJ3Y98XMxVVXj3cUKIBIG3Eb?= =?utf-8?q?32nP9Y8CMB1AVGNoMUyw9qbPbagrCi6UyYkUSWOP+loxqpzCZ4JqYV+Q=3D?= X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230040)(1800799024)(376014)(36860700013)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2024 13:28:21.2808 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8a684f69-e24f-4ee5-cc21-08dcede6676d 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: AM3PEPF0000A795.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR07MB9677 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 Acked-by: Konstantin Ananyev Acked-by: Chengwen Feng Acked-by: Stephen Hemminger --- 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..cf0756f26a 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(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(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 Wed Oct 16 13:19:14 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: 146082 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 C0CE045B50; Wed, 16 Oct 2024 15:28:40 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 618A44064E; Wed, 16 Oct 2024 15:28:31 +0200 (CEST) Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03on2058.outbound.protection.outlook.com [40.107.103.58]) by mails.dpdk.org (Postfix) with ESMTP id 544914029C for ; Wed, 16 Oct 2024 15:28:25 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HMBkyGt4UlMAKcJLS2rI5pdvmnUBZlupjkFn93a69ZovTHdD2d+RQdDIEl0T1zYEcMBVQNkX3BhI0Rdnc6fkQoICeGIUmCiT+VRFTeitVJs0PUTA6vhR8K29JQPWdPKFgI8UK9kQult8551BXsCL119CvzZX/Kx63pFH+Yr0wWM4DRugKEUN/1294ELMJcLZ6OcqpUsLTszcCQZvqRiEBB3f2qoGB0X8yYpu4auQ6Kf0mPyGAXebL378Dd39fMkMOYHZ+KuLrjjNelvZA4HqW93/E0jJAmaY8qvQcu3dPIhtWc937wNWm1pUTBFZGlFhtHxII7yNdqKHrltMytZFOw== 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=fgGvEdU4oP2VvxxJBFw7rocIdfPCeSVcgUr69sGrc+Y=; b=Iy1FnPkWDh/ys0XP/DqSOdlj5eCGi0pPt5fR5HWED/RQj19FsEK5tHMEFwNaZHDzIzJZ9XNWK1lzG79GGgMGT3eu9UHhhuFutwdsiDoBfJEE55YEW3KD5ukm/gXY22OR9EaqtTuH35Nx9Eg2NoAJKQYZpasZBU5Z39G6gAA9UxnjyfDQ9BnQjkEGkcE1qg8wwq9YI6zhW211SGVjd/9uU8cYONzVfwcGuTMUfC6rlVIYeimlhk7e0fbuIN7t28uSZRaCAaWNqVmQIgRkQobTJ1N/tJQtos/kAB5TMiNpZifpVLR1Hz+8389BbCoYu4f2pYNpQUOnsiuedmm/hBs+Aw== 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=fgGvEdU4oP2VvxxJBFw7rocIdfPCeSVcgUr69sGrc+Y=; b=HAOk0yy0YzzKL1lZacbj7a9T4aA05OSKB0Alag09wiHyXlrCuRLba0shAxaK6n7nsfI/GEhJa6q212EtblZnQi/qe97n6vFmoNG3fBULnnp0mLPK/oKv9/Q3uSAFsvxm0jZa1N+/UEdhjQKhp5n/90lnDGuOJAV/yDVEEeHhVutnB3AK88TlKGWgp6+0K9CwSsoaUAD+aoAzJX1m/qHrpXfwX2jkmFEnE09/i3e8dqrrOZlI017U8XEOepqmntvwPf7zJLcBcfphHydQPZ1Mm2MmE1iXMygTVrnAA2YB2w97l5f0uZH2CsRdRrsxdSjMjtm0oWhtbB6My/SaLffvAg== Received: from AM0PR04CA0135.eurprd04.prod.outlook.com (2603:10a6:208:55::40) by AS5PR07MB9894.eurprd07.prod.outlook.com (2603:10a6:20b:683::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.27; Wed, 16 Oct 2024 13:28:22 +0000 Received: from AM4PEPF00027A6B.eurprd04.prod.outlook.com (2603:10a6:208:55:cafe::d) by AM0PR04CA0135.outlook.office365.com (2603:10a6:208:55::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.18 via Frontend Transport; Wed, 16 Oct 2024 13:28:22 +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 AM4PEPF00027A6B.mail.protection.outlook.com (10.167.16.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.17 via Frontend Transport; Wed, 16 Oct 2024 13:28:21 +0000 Received: from seliicinfr00050.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; Wed, 16 Oct 2024 15:28:21 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id F00CC1C0073; Wed, 16 Oct 2024 15:28:20 +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 , Jerin Jacob , Luka Jankovic , =?utf-8?q?Mattias_R=C3=B6nnblom?= , Konstantin Ananyev , Chengwen Feng Subject: [PATCH v14 5/7] power: keep per-lcore state in lcore variable Date: Wed, 16 Oct 2024 15:19:14 +0200 Message-ID: <20241016131916.827788-6-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241016131916.827788-1-mattias.ronnblom@ericsson.com> References: <20241015093344.824073-2-mattias.ronnblom@ericsson.com> <20241016131916.827788-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM4PEPF00027A6B:EE_|AS5PR07MB9894:EE_ X-MS-Office365-Filtering-Correlation-Id: e55de3c1-3807-48a1-b5c1-08dcede66799 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|376014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?q?nCfuHyfdvnX3d91icg/lNj/aobvqSYG?= =?utf-8?q?+PUZqBEU5A7IKIXFfKaK5N0SrVRhmtLTnZj5vZ5D49N3lqGTKjeSnY5fGOjRak77i?= =?utf-8?q?Uu4spbuWzLKwdTc98Hwl5iUZamvdmcJXgx5xHDPZBfPygOYmV1PakTbmBcBkqNoNP?= =?utf-8?q?u6GgrMpOzERmJqiooPvWA8AkgyUd4wtZxitFVF84yfTmOh2rPq2R6kCtvxpInr23W?= =?utf-8?q?blycG342ML3+//gbr9RUMA96cZFTrIoX8g1znorPw7d+tWmogU9X43ZBu3VeX2Z7D?= =?utf-8?q?08JYqltGoasxgKARRqjCVAXN8ZLGPWPrxHp3KbQy+pY919J+uKdD3/kwT/PUDOeA8?= =?utf-8?q?KvVKkxgf/IDxqJvFWfxlPIIdKdcMHXKN5QPZPgtfvBJGF0Y4W0jbHHwR3w/pDoRpz?= =?utf-8?q?/lSX/ANEabPvCzlFx3d8mCJyPn57ZVrX2IrzsEQWnLTFQWJHxaJZG8sjLKpmDh+Xz?= =?utf-8?q?kDTGYvmVIEzeymWcAfuPfTLExKCqz4z3e75SupYXL2PqK1wao7X9OVaIm9sax4VhJ?= =?utf-8?q?9SdJkPMJ03vDsgRYpgYiJ9DHXeb4ZawOvtobb+t4QFzyGye63nyykz4vyiOS58s4V?= =?utf-8?q?ePw090yPPjnJO5KafiwXZ32S/PYfKW2SAuS0PSXP/+slrj/V0d3mVKOq9K6W3Icbp?= =?utf-8?q?oFF2lFxBhATVPp55GC0PrXBt4kbP5A4qkOBX5JipT0qRAGXWXcQcq7nf0kb+RXSJK?= =?utf-8?q?SivPMxRy4dGSWNlFFAH5OvLVW5BasDUbL/RL27lIse9kKaI+31s9GI9UC5D1Hg/Rq?= =?utf-8?q?sdNec92+/z372+InfWWQKu6wt5mkFlUxT+45Xpk8GfYNxxgRy6P+TdQDwMdrsTWsp?= =?utf-8?q?fTjKLED5vJ16zf1Yxsp5k11E2j+Rr1xhoSfmL4ITqFkne1DqzYSAwgTR7/K3gjz6c?= =?utf-8?q?Woz06Mi0TfjJ+W4iirTlNYKgARmMDLyeTsIawf0FDb147upx4HOrTKklG8D2ue+F3?= =?utf-8?q?mRhncPhIKkBlQsTLRXovToR5xv7IV+EevCES3ubOjK7oST+YHyb90HMdujWzrnQy/?= =?utf-8?q?H+dqKkGu8AFY0V984HME031UyqWCkfAf/5w0J7m/enkZA2ix/Wgs9mkddvm0o5hm+?= =?utf-8?q?sy6rJJj4X3GLBElpjPkbW1fl8o88AizJYs7DETl6/N3OG5ev/9FlDciAdcV33HkEo?= =?utf-8?q?E2rAH8jHCb9l/aNNy/sXpdo6hm/XuvZez9zzYfgQw+tLYRqqR/0I6PZNkC7JCbwdM?= =?utf-8?q?0R7MbT9RyGk3HZPpIi/QKtYmB8nmw/Hn71irCHvt+ZnQFTcmIHiu40b/4URxxx6iN?= =?utf-8?q?ye3GnScD/xpl85uvK5yHQZ+xGWcoYmEW+E42GM3+CoJpe9M20WDsrXge6qHi2JfGt?= =?utf-8?q?Cvg8i0SjFtyG?= 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)(376014)(36860700013)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2024 13:28:21.5374 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e55de3c1-3807-48a1-b5c1-08dcede66799 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: AM4PEPF00027A6B.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS5PR07MB9894 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 Acked-by: Konstantin Ananyev Acked-by: Chengwen Feng Acked-by: Stephen Hemminger --- PATCH v6: * Update FOREACH invocation to match new API. RFC v3: * Replace for loop with FOREACH macro. --- lib/power/rte_power_pmd_mgmt.c | 35 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/power/rte_power_pmd_mgmt.c b/lib/power/rte_power_pmd_mgmt.c index 830a6c7a97..4bab2d5108 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(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(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(lcore_cfgs); struct queue_list_entry *queue_conf = arg; if (likely(!empty)) { @@ -519,7 +517,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(lcore_id, lcore_cfgs); /* check if other queues are stopped as well */ ret = cfg_queues_stopped(lcore_cfg); @@ -620,7 +618,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(lcore_id, lcore_cfgs); /* check if other queues are stopped as well */ ret = cfg_queues_stopped(lcore_cfg); @@ -770,21 +768,22 @@ rte_power_pmd_mgmt_get_scaling_freq_max(unsigned int lcore) } RTE_INIT(rte_power_ethdev_pmgmt_init) { - size_t i; - int j; + unsigned int lcore_id; + 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(lcore_id, 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 Wed Oct 16 13:19:15 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: 146083 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 0A0D945B50; Wed, 16 Oct 2024 15:28:49 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9964540656; Wed, 16 Oct 2024 15:28:33 +0200 (CEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2069.outbound.protection.outlook.com [40.107.20.69]) by mails.dpdk.org (Postfix) with ESMTP id 26E754042C for ; Wed, 16 Oct 2024 15:28:27 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nXIOMHc0BsfkgxzyyZitcKbdCTw5iv29SWPac2tLfkkSC4wP6Y4j/UN0EFH4BapXnL8BxQZN7BFHHHQOUl01sdeqV1Nq514SoSCi503w9yGvBakeiaC5zVDVH7Y+/hLwgD7LLMTb+H3L8174+mSuvtroW7cga7nH86u+wJVQHThdqmuDSU+G38yM/8xEmDhyAtjNegK5WZm+YWobNx/sMrBaLzbslB/TDuLMKEO+vwRQiVcvbBvNeQHy7pE4uDrjOA/znTHYanZ0mAtRs10mNE9aUe+2dY3E7DrFXf7zOm9WZGoDD6tvK5lvFSv3v2sO2atOc32JHxKDqVYnnl6n7Q== 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=bZe54tHV1BWuXkkOzb0KIXBGV4vegSrp2GI9ZzhuZjE=; b=AOYPY6/1UfeaZfgnn7pEeJkruk10Imx5b3eg459GhyJDCkS8lI73PuKHRf2B+FXOEC7L6UEc8NLv0IkhkhbVAFhW7uVEYYOIHf4hRcyICBXrTTiSr02DtTww+SwQTEJ73hMHrAXzRQOGO7bETIw7BF3oTCKjNhpQ//VkLqq7f6KXR6pyFE6BHQIp8K3cJcBm1L+Ui7bVRidj5PE+4Zqrq+TExDHuxwmaJWUt4+DTZRJgijxAEbYNzEX4fTcjwfbilS3V9tq+ALpx8UugHH5p44B+CI9RTCK89TO11QKiDZ1XIgWqiNi9LcIGbFTrLRnaIysnxkU5VgWBElTiMFIkLA== 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=bZe54tHV1BWuXkkOzb0KIXBGV4vegSrp2GI9ZzhuZjE=; b=Edh3LfVxvH93jlV1QYOCEGFoqBCTJMofcirpZM+olY2qTJMZTOgcOfO3LDCn23l/c6WxmYuJTImaz+XyK1iNdbBwV9Ji+9pGOydDEY4Qk4eYWV1CUXkamBVEPex3S+WwPOsHJgv19BFifSKUeEeY7s7fEJJ8ZBKqKOz1vv3bc7+oQcWpe3AdV0o0/zHry8bcnd9QfHUsG2UQJkwYKo6TLTbAuxq2MrRV0L1qiWDxAarybJHLeMW3oSPY13FXOvzeqn75zNGFICbjgkSJkQfkrtMyZ7mSM5pcqniPpscg4ID8MWEbcI9mJt3lpIcpUovOF3bbAtlzy8h1/DAxPzTeYA== Received: from AM0PR01CA0101.eurprd01.prod.exchangelabs.com (2603:10a6:208:10e::42) by DU2PR07MB9450.eurprd07.prod.outlook.com (2603:10a6:10:49c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.27; Wed, 16 Oct 2024 13:28:22 +0000 Received: from AM3PEPF0000A795.eurprd04.prod.outlook.com (2603:10a6:208:10e:cafe::9d) by AM0PR01CA0101.outlook.office365.com (2603:10a6:208:10e::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.18 via Frontend Transport; Wed, 16 Oct 2024 13:28:22 +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 AM3PEPF0000A795.mail.protection.outlook.com (10.167.16.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.17 via Frontend Transport; Wed, 16 Oct 2024 13:28:22 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.62) with Microsoft SMTP Server id 15.2.1544.11; Wed, 16 Oct 2024 15:28:21 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 0D0C81C0079; Wed, 16 Oct 2024 15:28:21 +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 , Jerin Jacob , Luka Jankovic , =?utf-8?q?Mattias_R=C3=B6nnblom?= , Konstantin Ananyev , Chengwen Feng Subject: [PATCH v14 6/7] service: keep per-lcore state in lcore variable Date: Wed, 16 Oct 2024 15:19:15 +0200 Message-ID: <20241016131916.827788-7-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241016131916.827788-1-mattias.ronnblom@ericsson.com> References: <20241015093344.824073-2-mattias.ronnblom@ericsson.com> <20241016131916.827788-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM3PEPF0000A795:EE_|DU2PR07MB9450:EE_ X-MS-Office365-Filtering-Correlation-Id: b48f34d4-3530-4cb8-4c0e-08dcede66850 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?utf-8?q?/Y0wD0bR/Dc1u6obQsJm1jDKneffCcd?= =?utf-8?q?HzjzYfhY6eGwIhcam3B3DKPbeuHBe15ghiQLEn3oTO/+Va22XQIJWJKX7hhKEqFxU?= =?utf-8?q?8L4uS5pQJ3VR1Gv6viJ5m+A5tZfthXGX2cWW4NVHVWaHciBTDG+dpQO3Jqgq/HTjS?= =?utf-8?q?lNe93W0sN47u99Rz9/k3vQJwhv2KH/zMCqQcXy+pETCQfWeqw//bLsfFd6OKI0tes?= =?utf-8?q?I2N7HwN9VeSbxPqT+w1OvqUqDMlOevKDcufYcHy7U/VjQiBgmXK4e4Wp/XD67xJP8?= =?utf-8?q?C+yDBBkfRhYaFJsRHWqVcCJ7Q69Jt/00D5OpHQ3YGGpwxMhU//V6b7+NpAxxjWP5s?= =?utf-8?q?akB7R0jZ+9O+XsvjjyUgaTqdpz1ML1D5YM9pzdYP6y9XQ44sgLU2fojHatuarEpx6?= =?utf-8?q?SN5LKrf/uzZ3nrcotiaEuecAXbeCyFGOFrMm7EI1f/fTFcWpa0dwKYY5KTjJSFCtz?= =?utf-8?q?pyZLDu+lIvjwm6EamEEReY2kk8+JR896pC2asgrW0yggeHspjCwaNB3sZiaYhSmWl?= =?utf-8?q?fTfg7OBrRVUW/N2G+OQ2vY4cWWtDQIbUa7LA2hABJuZcHy5XL8zm5oKecfvkfukA9?= =?utf-8?q?moZhS/7rO4rZQk4BDDbcqBBVaRmThNFFne5umltXHdksblkABAGcBHQbDQS6XCUQX?= =?utf-8?q?X9PFMT6yoJ1QP2Z0TqEhuUH/M9THQrUkCm4uBpK4tS+wmEnO/oAy7zjgONsv28pVQ?= =?utf-8?q?R3lgN56o4F4N8i9eEUP/8NtgufeCqXlSbvLpOClyjlxZtYIonK/3nfkLTcHcZvHDK?= =?utf-8?q?pNpRASllkGFkl5wp5C4N50xcla8FKSF6FbwE2zKetuq2zce4Zzsv17dYMaLRk9d6T?= =?utf-8?q?LCVEHR0LAt7H8eRJvOKoj0t3x+mPqptysvAprgZKpvZxi15iiDg2fsRUdxvMhio0O?= =?utf-8?q?ymJfIDcl05W5fO05VuEzn++OvhuITgbnZaMEeNSIbpyei69icDkZwsY31643lSb9X?= =?utf-8?q?+4pUUYpVj+joNyb10gMgaNhMh1Z88GYsr9ATQh5BG9EhReHXQYIdH/ubNR6JM6xyM?= =?utf-8?q?m1NA8RvZWhXlWCb7PEB3ZGTA6ZBYSXe8VvBY0oLzigTtBqxcN9TkhLGw4cZ8xcVSe?= =?utf-8?q?wtwiVGx//d9W5i3As120Mn10vLfVMOYOykeMPzaqpzBUA9+sCfFjWisNjlLIEe5Bb?= =?utf-8?q?905VMQTIJoYwuc7SwCzA2+sAp7Sn5vcVO3gZCOjbsO6z/iV96SSrYqMnWSCoFi00Y?= =?utf-8?q?rPaC8izLrg7FNlPuG/hyUe3cr74F0n/UctbPmGA3rxpym6VTSh23PToad2gilecOV?= =?utf-8?q?dSp6IEz+TlMZxxPNT/WmUwmqQLVSuZ0mJ+wNOe0CSW3sPdXmf9InvPByMshZPqpjU?= =?utf-8?q?rUNRgllYPGtq?= 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)(82310400026)(1800799024)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2024 13:28:22.7652 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b48f34d4-3530-4cb8-4c0e-08dcede66850 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: AM3PEPF0000A795.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR07MB9450 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 Acked-by: Konstantin Ananyev Acked-by: Chengwen Feng Acked-by: Stephen Hemminger --- PATCH v14: * Merge with bitset-related changes. PATCH v7: * Update to match new FOREACH API. 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 | 116 ++++++++++++++++++++--------------- 1 file changed, 65 insertions(+), 51 deletions(-) diff --git a/lib/eal/common/rte_service.c b/lib/eal/common/rte_service.c index 324471e897..dad3150df9 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 @@ -78,7 +79,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 @@ -99,12 +100,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(); @@ -120,7 +117,6 @@ rte_service_init(void) return 0; fail_mem: rte_free(rte_services); - rte_free(lcore_states); return -ENOMEM; } @@ -134,7 +130,6 @@ rte_service_finalize(void) rte_eal_mp_wait_lcore(); rte_free(rte_services); - rte_free(lcore_states); rte_service_library_initialized = 0; } @@ -284,7 +279,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); @@ -292,9 +286,11 @@ rte_service_component_unregister(uint32_t id) s->internal_flags &= ~(SERVICE_F_REGISTERED); + unsigned int lcore_id; + struct core_state *cs; /* clear the run-bit in all cores */ - for (i = 0; i < RTE_MAX_LCORE; i++) - rte_bitset_clear(lcore_states[i].mapped_services, id); + RTE_LCORE_VAR_FOREACH(lcore_id, cs, lcore_states) + rte_bitset_clear(cs->mapped_services, id); memset(&rte_services[id], 0, sizeof(struct rte_service_spec_impl)); @@ -463,7 +459,10 @@ rte_service_may_be_active(uint32_t id) return -EINVAL; for (i = 0; i < lcore_count; i++) { - if (rte_bitset_test(lcore_states[ids[i]].service_active_on_lcore, id)) + struct core_state *cs = + RTE_LCORE_VAR_LCORE(ids[i], lcore_states); + + if (rte_bitset_test(cs->service_active_on_lcore, id)) return 1; } @@ -473,7 +472,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(lcore_states); struct rte_service_spec_impl *s; SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL); @@ -496,8 +495,7 @@ static int32_t service_runner_func(void *arg) { RTE_SET_USED(arg); - const int lcore = rte_lcore_id(); - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR(lcore_states); rte_atomic_store_explicit(&cs->thread_active, 1, rte_memory_order_seq_cst); @@ -533,13 +531,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(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 +547,12 @@ 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; + + unsigned int lcore_id; + struct core_state *cs; + RTE_LCORE_VAR_FOREACH(lcore_id, cs, lcore_states) + count += cs->is_service_core; + return count; } @@ -566,7 +569,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(i, lcore_states); if (cs->is_service_core) { array[idx] = i; idx++; @@ -582,7 +586,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(lcore, lcore_states); if (!cs->is_service_core) return -ENOTSUP; @@ -634,28 +638,30 @@ 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(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; if (set) { - uint64_t lcore_mapped = rte_bitset_test(lcore_states[lcore].mapped_services, sid); + bool lcore_mapped = rte_bitset_test(cs->mapped_services, sid); if (*set && !lcore_mapped) { - rte_bitset_set(lcore_states[lcore].mapped_services, sid); + rte_bitset_set(cs->mapped_services, sid); rte_atomic_fetch_add_explicit(&rte_services[sid].num_mapped_cores, 1, rte_memory_order_relaxed); } if (!*set && lcore_mapped) { - rte_bitset_clear(lcore_states[lcore].mapped_services, sid); + rte_bitset_clear(cs->mapped_services, sid); rte_atomic_fetch_sub_explicit(&rte_services[sid].num_mapped_cores, 1, rte_memory_order_relaxed); } } if (enabled) - *enabled = rte_bitset_test(lcore_states[lcore].mapped_services, sid); + *enabled = rte_bitset_test(cs->mapped_services, sid); return 0; } @@ -683,13 +689,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(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); } @@ -700,14 +707,16 @@ rte_service_lcore_reset_all(void) /* loop over cores, reset all mapped services */ uint32_t i; for (i = 0; i < RTE_MAX_LCORE; i++) { - if (lcore_states[i].is_service_core) { - rte_bitset_clear_all(lcore_states[i].mapped_services, RTE_SERVICE_NUM_MAX); + struct core_state *cs = RTE_LCORE_VAR_LCORE(i, lcore_states); + + if (cs->is_service_core) { + rte_bitset_clear_all(cs->mapped_services, RTE_SERVICE_NUM_MAX); 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); } } @@ -723,17 +732,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(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 */ - rte_bitset_clear_all(lcore_states[lcore].mapped_services, RTE_SERVICE_NUM_MAX); + rte_bitset_clear_all(cs->mapped_services, RTE_SERVICE_NUM_MAX); /* 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); @@ -745,7 +756,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(lcore, lcore_states); if (!cs->is_service_core) return -EINVAL; @@ -769,7 +780,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(lcore, lcore_states); if (!cs->is_service_core) return -EINVAL; @@ -799,6 +810,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(lcore, lcore_states); + if (lcore >= RTE_MAX_LCORE) return -EINVAL; @@ -806,12 +819,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]; for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) { bool enabled = rte_bitset_test(cs->mapped_services, i); @@ -831,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); @@ -842,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(lcore, lcore_states); return rte_atomic_load_explicit(&cs->loops, rte_memory_order_relaxed); } @@ -850,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(lcore, lcore_states); return rte_atomic_load_explicit(&cs->cycles, rte_memory_order_relaxed); } @@ -858,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(lcore, lcore_states); return rte_atomic_load_explicit(&cs->service_stats[service_id].calls, rte_memory_order_relaxed); @@ -885,7 +897,7 @@ lcore_attr_get_service_error_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(lcore, lcore_states); return rte_atomic_load_explicit(&cs->service_stats[service_id].cycles, rte_memory_order_relaxed); @@ -901,7 +913,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(lcore, lcore_states); + + if (cs->is_service_core) sum += lcore_attr_get(id, lcore); } @@ -963,12 +978,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(lcore, lcore_states); if (lcore >= RTE_MAX_LCORE || !attr_value) return -EINVAL; - cs = &lcore_states[lcore]; if (!cs->is_service_core) return -ENOTSUP; @@ -993,7 +1007,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(lcore, lcore_states); cs->service_stats[id] = (struct service_stats) {}; } @@ -1004,12 +1019,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(lcore, lcore_states); if (lcore >= RTE_MAX_LCORE) return -EINVAL; - cs = &lcore_states[lcore]; if (!cs->is_service_core) return -ENOTSUP; @@ -1044,7 +1058,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(lcore, lcore_states); fprintf(f, "%02d\t", lcore); for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) { From patchwork Wed Oct 16 13:19:16 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: 146084 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 B60A445B50; Wed, 16 Oct 2024 15:28:56 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A5D464065F; Wed, 16 Oct 2024 15:28:34 +0200 (CEST) Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2082.outbound.protection.outlook.com [40.107.249.82]) by mails.dpdk.org (Postfix) with ESMTP id 322514042E for ; Wed, 16 Oct 2024 15:28:27 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=k2uKpZUJ+9MMGNXAuFJdodnuDBOwcDBik1K6NNnpfa4q94r8Ecz13Q1INwyECKgyYootoeQGJsyeOZmR4jQJ1eAxcVnw5ZQNW/WG+9xeKNQHpS4J7820uab44v5RUzA+un+XBV4QC7qafm+6JhAiY6/Zhu3JzL/MSuV3ZpbeWC3PZpIIRuV51Faqea+OKcSTKZ5gzOR6aAbeSPd3vpB94gs5T3CrqENDCEP+snatzCuEwT++H63TC06NhGuDiFGC1v5o0ENDrlOHU9dWnZFmbGsCQDahJct7QV1FWd4J7K5903iibo7jATRyBZLcd1vfHB9TJR4pE9zedS/PIElWNw== 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=cX4ufj1pN9MGR3XnbJ9151fWBNDYFHNFptwEX85LFw4=; b=Iyo6irUDBKjj/4zTCygS4HEyA/Pt2/Dq4TXsiWMKNWoghmYKLQ7tlO/SEVRHzLeBZsjcY9OB4xwPOx6PfqlzOIlM5yTmYlsZ9uW8au71vhU00bFhbE0F4OmfiyDrF3GJZYuvAKuEyAUchD7CcXILxVS+1KGfzGkbKmMOyBmSdaksNeDeiJULcURDzMj/NhJZXUvw8deHdK+K0CfK2qVVHXHmZydWlJqvIRdnFYFtw+g9+DvUnIVfnGnNZ+6D5wi8AnIqfJAYiG2JhJVyOr9UTbTqf4krHcFgXTTYDmguhwNV7z2MK7FcU5EjXPCZAgUesXZbDNeXWc6cdplPWIYI5A== 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=cX4ufj1pN9MGR3XnbJ9151fWBNDYFHNFptwEX85LFw4=; b=nrY+AQNscUBDghl8wGu0LvxcvCC7RQrOJrmthC7oVjOjSiPPgVrWWe1OPSJoW2MpJOjIC9i56VPjmKhh5JPRr2TTnsZUXO3PlcZG020vdngWE3fzaTy1epYBLuaq5WSnuftzmIvBX+UYlaEyNI/c3rMDoQ9QHKA4bvrZ2Z94wk4275HZfH2aMupTZwZYqqkoJaLgaUZVorODEqUdQYPsw7iMGPXsIGtuev64OTB7TyPPmjkHjTsHQOwHgUYr9yPvOWiuBbCEVnQFxfG81UUxfMZyl9lBtQzoL+cUIkt1H4M5gFcDamQcMMwiuCVdP53BSiQRsjivNULCN711VY8K3A== Received: from DU6P191CA0003.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:540::29) by DB8PR07MB6345.eurprd07.prod.outlook.com (2603:10a6:10:137::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.17; Wed, 16 Oct 2024 13:28:24 +0000 Received: from DB1PEPF000509F4.eurprd02.prod.outlook.com (2603:10a6:10:540:cafe::63) by DU6P191CA0003.outlook.office365.com (2603:10a6:10:540::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.18 via Frontend Transport; Wed, 16 Oct 2024 13:28:24 +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 DB1PEPF000509F4.mail.protection.outlook.com (10.167.242.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.17 via Frontend Transport; Wed, 16 Oct 2024 13:28:24 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.63) with Microsoft SMTP Server id 15.2.1544.11; Wed, 16 Oct 2024 15:28:21 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 1EEAD1C006B; Wed, 16 Oct 2024 15:28:21 +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 , Jerin Jacob , Luka Jankovic , =?utf-8?q?Mattias_R=C3=B6nnblom?= , Konstantin Ananyev , Chengwen Feng Subject: [PATCH v14 7/7] eal: keep per-lcore power intrinsics state in lcore variable Date: Wed, 16 Oct 2024 15:19:16 +0200 Message-ID: <20241016131916.827788-8-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241016131916.827788-1-mattias.ronnblom@ericsson.com> References: <20241015093344.824073-2-mattias.ronnblom@ericsson.com> <20241016131916.827788-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB1PEPF000509F4:EE_|DB8PR07MB6345:EE_ X-MS-Office365-Filtering-Correlation-Id: 929ad946-6c1f-4706-0def-08dcede66960 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?5Hawl+T8CoTOkLnxbCHjeqW7G927/k/?= =?utf-8?q?RGP6TFLjskfw3QHmNl4d+jRmQEz5eP0irj9ENiSFDN53Pg4ylL39T/tP2C8SJ130U?= =?utf-8?q?pD6mF5ejy33RKYv5BXJY6zUnOyvNs8fCQEdFeCz8WT6we14hW94Kg0+LlPeooK22q?= =?utf-8?q?IS0UibNPNusJOuLNCRT3mHDJGaJG29uInKY9TvH4GASo1iEyfgcF7pRJQqCx0/zvT?= =?utf-8?q?SsT+QNS8OpCGI37M4Id7AQ7rlU2QfrH6rI5vEXGuq2CI5MQjLay+mVXEAQQ7troAm?= =?utf-8?q?sFQOs4jE8PK8FfjeqdzfdvPW2BT3ykCjtBcqp9CCr/TBxsa+3tODmKZodkIm325vV?= =?utf-8?q?wa4lcsKw2Ngw2xBfgn6rG6GoAExuR9nDmPYpR8Z8C9PFVeuXBFDjPe2/j+je/3A+D?= =?utf-8?q?ksUpsKH5Ke2UKVHcv5qgaBla/cW2YRknjDwhnrAkM5lqr4C80cD1oMD7wrMBoDfqG?= =?utf-8?q?PIzFnjGuq68PZcYyGFI1X115zz0ZE+ohUjCD7/tWh0hHDNwLtHcC3oQitler87l/5?= =?utf-8?q?kqa4tVpYqOFsLbkvf0RMu8npL5q5CKCXyqFMNEojjs5En/DwfB4p2A9LGUzHpl5KX?= =?utf-8?q?v5ioVl7b/+jeetInGe0Zj7I8a6lAgPxoli20EdvzqwhDWRgJDL9hEs2t6VVZHODKf?= =?utf-8?q?4jCmsnspgbn0wij9G4DTTxmmPLft6c27dHBz3BDgkQTHmqdrYfTfw0wrm+iVAC9IY?= =?utf-8?q?J9xv9Pk5D8qe4A29ISmPjOrNqbXRISGOmROskZPY++MHEuG1Wc+xwg+fFvODxH4TU?= =?utf-8?q?idBQOJrZAGWuGzFgceSLsKu51zBqbkHTW55QmYP8TERvAZayozIUJ50l2t8vi4JeX?= =?utf-8?q?lkQzagX0618jBYRQVxAvApp2uVVHo3NtXzIcF0TWeE0MvyszthjeXuwQdzmUVno6/?= =?utf-8?q?XFkB+MeWMVAfSzLuhiVipzcutgmHSpBYyABO4KAz7WYXSC1aF4lzOAfS8k5ASx5me?= =?utf-8?q?h20huMM2OoZVpIiGC74yHBw3Hb0d5cIX3S1VVeZ9b5A0w4pnDzxRzDHgymqViaSLC?= =?utf-8?q?PmeQFDxnDrZ4lMJQCO+OjhQUMbIGAv/pKUuj+45H7vxpUinHYNFc3bwR0mo0PN7Jr?= =?utf-8?q?kHdA1E3w6voDx0KDcFyWOrE8zdCPP+Y7jterbai08bWfq428QemLdfoxnxzMuJfee?= =?utf-8?q?YNOf0mDaJER9W+Vs5EpjAACBxqL68Xk01BHlVKnKh87t+1sVSr6EiV7t9SggZiMzb?= =?utf-8?q?Ji2hbZUbUJM1uQnCWf2VxIUgSIvLVOxWHCGa0wmY6oFpPhQUxYVPuuzNZCyf7fHPb?= =?utf-8?q?AjWDMCwhgjjo6R/ofd1j6pYlbQSaOrj8gk6M5AGbCTFY/QQTQnBb2d7M=3D?= X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230040)(36860700013)(82310400026)(1800799024)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2024 13:28:24.5150 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 929ad946-6c1f-4706-0def-08dcede66960 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: DB1PEPF000509F4.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR07MB6345 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 Acked-by: Konstantin Ananyev Acked-by: Chengwen Feng Acked-by: Stephen Hemminger --- 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..98a2cbc611 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(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(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(wait_status); + uint32_t i, rc; /* check if supported */