From patchwork Fri Oct 11 08:18:55 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: 145742 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 8734845B12; Fri, 11 Oct 2024 10:28:56 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9145240656; Fri, 11 Oct 2024 10:28:30 +0200 (CEST) Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2076.outbound.protection.outlook.com [40.107.247.76]) by mails.dpdk.org (Postfix) with ESMTP id 653FD402DC for ; Fri, 11 Oct 2024 10:28:22 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wbAzwjagBiMKnjSX4cGbhay0uIj1pl1T+3bWmSiZMWIP+iJkK2ODEfDVvuAft5OC3hTCxXeRSnK6HLCwkfUke7YJc/0YANGRYwwCtnY7+iVP9MDTZPG7SMA4dDV2KwFhhF3E//4eZzoIgYuoXHo7Y0lohH454GNJNrBJkgDr7EDXtengogWIcNdWtlfrMTS8BYIICsT386Nn1wgzGsk0aITFH8jPMqUC4Xk8+IEbqpsUuo4Hf3NwX+cRLFXIIqcqjLIUiKh+JCzgbgCtNONpQNN3PMqTSMdXKFmyzVNvyybvpQdE6hV4ayJN1Ug3saec8aHElGFQcEcRqzbJA8SmPw== 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=3tYpJQP20AiX4iMAXnvMJtBPeQxMZ4rD8bcbDz8Kibs=; b=czw/mzWL2WSuqdNYyqNVXLDyNz6XNq+oSgKdRyTRb5A3BgNO5+n9iH9Yd9lv6SqhA24ripGfCY60QMv2yxafzmVzbmUwlwLx4cw4e1U9VQcZUlc8+CkfRUKd4mWNgpPpOOZJw/A9f3x1lQdjIKlIsT0JS2hAuYD/L6SsDJToq65rPkNR0rHyKlxlrpw+GfNUJOThwfycO5Pxwh+R/guZH+kPsCf+EOsDewrJlOLnwXqOvWCaigBUb1AU4f6GXb1eq0vhEebeLA/B4MKZufsCKKcS5Mm0Lh6830ENB9yXuxYQLvzYyn3G1lwUKzaseGBYW4NqZznWe7GNe3XOWnx5ng== 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=3tYpJQP20AiX4iMAXnvMJtBPeQxMZ4rD8bcbDz8Kibs=; b=TiCzH6OzTqP2OwbfJ4pb4E3eRgT/AFx2DRrNkTG5DgCIZWcbnaaBAw5uofm6BDekcpPxMuh3675lcP/0a+s3d4Qc6Ck+q0fZFTCxQRKzSFCTXtolnuKmZ1Js4XzwCKM1wobBzLvE0EPE51h0XQGBfj9TVzP2rDgb8kK4KZmpWx+TFRCHC66HmcQytCX8qfsm+jFI0rRFWTq82pggiCal3dnLNjzp+yoJRugKPKBcjrBaDPnHuHFd5cBOgcJh/jFwpHvUH0Kqrr8JxCGXw8NI+W6Znrqm4QOwlZVZpKZKq2pjFUn/U8q6NmmSwp/5/xF6nGS4uNYAgS1hvLEpMS3xBA== Received: from AS9PR05CA0009.eurprd05.prod.outlook.com (2603:10a6:20b:488::10) by DB9PR07MB8960.eurprd07.prod.outlook.com (2603:10a6:10:3c4::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.20; Fri, 11 Oct 2024 08:28:17 +0000 Received: from AMS0EPF000001A5.eurprd05.prod.outlook.com (2603:10a6:20b:488:cafe::ba) by AS9PR05CA0009.outlook.office365.com (2603:10a6:20b:488::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.34 via Frontend Transport; Fri, 11 Oct 2024 08:28:17 +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 AMS0EPF000001A5.mail.protection.outlook.com (10.167.16.232) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Fri, 11 Oct 2024 08:28:17 +0000 Received: from seliicinfr00049.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; Fri, 11 Oct 2024 10:28:15 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id B6A0B38007A; Fri, 11 Oct 2024 10:28:15 +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 v10 1/7] eal: add static per-lcore memory allocation facility Date: Fri, 11 Oct 2024 10:18:55 +0200 Message-ID: <20241011081901.816211-2-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241011081901.816211-1-mattias.ronnblom@ericsson.com> References: <20241010142205.813134-2-mattias.ronnblom@ericsson.com> <20241011081901.816211-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AMS0EPF000001A5:EE_|DB9PR07MB8960:EE_ X-MS-Office365-Filtering-Correlation-Id: 2155709b-012b-43cc-c514-08dce9cea7fb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|376014|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?q?fUlnBkGcxsb2eArmTM/JBlYJLmN4v2s?= =?utf-8?q?ywlOH0TaDeNmtH2AQeAZ+oQGZ4isN2ppZQGlWT4+mqtamvJVf+qIBINDdTVUZaLz0?= =?utf-8?q?T/DOGdgiyNOxbPbKDvPGiY+c9sbBfDX2ZnDKibP9iHoq9EHtEhBoJ25uHc2FuwASt?= =?utf-8?q?6vYg05KNVXuoBXFuQ+qmHs9YyzTORF+nheXrUsirb2oIRQalV7nDUXVM81PFIkyBb?= =?utf-8?q?8MEuyrLXK5dmFYFhLYUL9BCz4Exmcs8iaMmU4a7aW0E8b6TQlk2aDtJyWlaWpdQf9?= =?utf-8?q?4dNjL4xNdVMjztlkbAqFhH3Va/Xp8Yk9GWQaNVdqkia5hpfIY0PWivhbBEYw7KbF1?= =?utf-8?q?0vMWmzc2/9oYNMcDRaMKILRAqSArr1hqgMk5kYTGNVcjKR9QOc6KjMovqy6w5vtjG?= =?utf-8?q?YR9KbWFs7bYfHglGvRMo8cAi/OeNI9GviLULMySjBV40BQ1BaXtWVVCjFMhMaO0Wa?= =?utf-8?q?83Wen7DTUpEi68zy+m2H7vP3OEcHESn1+UdsuGsyOw+JlQyuBvKIS6rshMYgFrQUp?= =?utf-8?q?2eyuR/TnUJyamvIEiLMI5Rdx7nlU4znVps7FXWEODgX5W2e0OC8RkjGK8oDRWOFHh?= =?utf-8?q?GU9kP0O3lvtCW/uFrLKMB24JQTPof9F+Vp56ORmPIV7bTvSDqwZXjEpaqf3y7LHJP?= =?utf-8?q?aNlY1eKXApunUmDmT5EyZdzRrWzgAHBT2IbIj2nMyvk3r+AvGXgde8YgYNDSFytkU?= =?utf-8?q?b2d8+KZMjQDPWA+tmFSQlkUdzPF97l/1+ARINysmiXwYbolNlCW4BQ846ChLjY1nI?= =?utf-8?q?Im6Jv0J1YlwON8DCkgB/QZqbwpfh8yHNx45STSlci3xbXkefwKv79XDhZveiQUQXn?= =?utf-8?q?eskgQae6ZMEScpniO58BDN/WcxlKIzvOHOkxXoSh2JcDXAJb2bAdDPgT3nmkqSl30?= =?utf-8?q?ZcjsNYto3K4+mBxUTADj6fiOd/kExzSK3efHnhBO/9BA3HKFrVvo0tjQDPU0Fto/B?= =?utf-8?q?9O5iXrukwbdQtumDpo/ItNfMGsjuB7EkvSxbpymj7Az8SUW1E9f8/DIwe/n71CxfC?= =?utf-8?q?Vy67Tosr4hWeErAlMFfpce+2fhcU9/zf7Own6m7ZWonzsK97RhZutfeFpDW57qxzN?= =?utf-8?q?9gy4N2LdNzQCbELvE2q9zytHCZE38k6OZzfBGbjkO2Oi+AoiP9QbOcdyC07ld+6DT?= =?utf-8?q?jJrxQIRClQxm0WdjVx6I99nig1T7WvSgwfuzOV4C0Tyz45tzrmc7/a1v4mfRhQSDK?= =?utf-8?q?18iI7pby2mMCUrAHk8+6h5tjB8QNhd2I3gPDB/B2L2N1ZBMDbuPXVE2uG1dgS18kY?= =?utf-8?q?UmRF5WcMX69mZZsAJOOMAYg5RzR9wTES3L9bV1dIxHFsIauRgp3TqSxjl99IyvgBr?= =?utf-8?q?JWoU7BgqKhyP?= X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230040)(36860700013)(376014)(1800799024)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2024 08:28:17.0128 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2155709b-012b-43cc-c514-08dce9cea7fb 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: AMS0EPF000001A5.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR07MB8960 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 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 | 85 ++++ lib/eal/common/meson.build | 1 + lib/eal/include/meson.build | 1 + lib/eal/include/rte_lcore_var.h | 389 ++++++++++++++++++ lib/eal/version.map | 3 + 10 files changed, 538 insertions(+), 6 deletions(-) create mode 100644 lib/eal/common/eal_common_lcore_var.c create mode 100644 lib/eal/include/rte_lcore_var.h diff --git a/MAINTAINERS b/MAINTAINERS index 812463fe9f..61e5907fb5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -282,6 +282,12 @@ F: lib/eal/include/rte_random.h F: lib/eal/common/rte_random.c F: app/test/test_rand_perf.c +Lcore Variables +M: Mattias Rönnblom +F: lib/eal/include/rte_lcore_var.h +F: lib/eal/common/eal_common_lcore_var.c +F: app/test/test_lcore_var.c + ARM v7 M: Wathsala Vithanage F: config/arm/ diff --git a/config/rte_config.h b/config/rte_config.h index 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 f9f0300126..ed577f14ee 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 915065a6f9..0e15767d41 100644 --- a/doc/guides/rel_notes/release_24_11.rst +++ b/doc/guides/rel_notes/release_24_11.rst @@ -113,6 +113,20 @@ New Features * Added independent enqueue feature. +* **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..fac6ab52b0 --- /dev/null +++ b/lib/eal/common/eal_common_lcore_var.c @@ -0,0 +1,85 @@ +/* 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" + +#define LCORE_BUFFER_SIZE (RTE_MAX_LCORE_VAR * RTE_MAX_LCORE) + +static void *lcore_buffer; +/* initialized to trigger buffer allocation on first lcore_var_alloc() call */ +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) { +#ifdef RTE_EXEC_ENV_WINDOWS + lcore_buffer = _aligned_malloc(LCORE_BUFFER_SIZE, + RTE_CACHE_LINE_SIZE); +#else + lcore_buffer = aligned_alloc(RTE_CACHE_LINE_SIZE, + LCORE_BUFFER_SIZE); +#endif + RTE_VERIFY(lcore_buffer != NULL); + + offset = 0; + } + + handle = RTE_PTR_ADD(lcore_buffer, offset); + + offset += size; + + RTE_LCORE_VAR_FOREACH_VALUE(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_ASSERT(align <= RTE_CACHE_LINE_SIZE); + RTE_ASSERT(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_ASSERT(rte_is_power_of_2(align)); + + return lcore_var_alloc(size, align); +} diff --git a/lib/eal/common/meson.build b/lib/eal/common/meson.build index 22a626ba6f..d41403680b 100644 --- a/lib/eal/common/meson.build +++ b/lib/eal/common/meson.build @@ -18,6 +18,7 @@ sources += files( 'eal_common_interrupts.c', 'eal_common_launch.c', 'eal_common_lcore.c', + 'eal_common_lcore_var.c', 'eal_common_mcfg.c', 'eal_common_memalloc.c', 'eal_common_memory.c', diff --git a/lib/eal/include/meson.build b/lib/eal/include/meson.build index e94b056d46..9449253e23 100644 --- a/lib/eal/include/meson.build +++ b/lib/eal/include/meson.build @@ -27,6 +27,7 @@ headers += files( 'rte_keepalive.h', 'rte_launch.h', 'rte_lcore.h', + 'rte_lcore_var.h', 'rte_lock_annotations.h', 'rte_malloc.h', 'rte_mcslock.h', diff --git a/lib/eal/include/rte_lcore_var.h b/lib/eal/include/rte_lcore_var.h new file mode 100644 index 0000000000..2f4d388732 --- /dev/null +++ b/lib/eal/include/rte_lcore_var.h @@ -0,0 +1,389 @@ +/* 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_VALUE. + * + * A common pattern is for an EAL thread or a registered non-EAL + * thread to access its own lcore variable value. For this purpose, a + * shorthand exists as @ref RTE_LCORE_VAR_VALUE. + * + * Although the handle (as defined by @ref RTE_LCORE_VAR_HANDLE) is a + * pointer with the same type as the value, it may not be directly + * dereferenced and must be treated as an opaque identifier. + * + * Lcore variable handles and value pointers may be freely passed + * between different threads. + * + * @b Storage + * + * An lcore variable's values may 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. + * + * @b Example + * + * Below is an example of the use of an lcore variable: + * + * @code{.c} + * struct foo_lcore_state { + * int a; + * long b; + * }; + * + * static RTE_LCORE_VAR_HANDLE(struct foo_lcore_state, lcore_states); + * + * long foo_get_a_plus_b(void) + * { + * struct foo_lcore_state *state = RTE_LCORE_VAR_VALUE(lcore_states); + * + * return state->a + state->b; + * } + * + * RTE_INIT(rte_foo_init) + * { + * RTE_LCORE_VAR_ALLOC(lcore_states); + * + * unsigned int lcore_id; + * struct foo_lcore_state *state; + * RTE_LCORE_VAR_FOREACH_VALUE(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_ptr(unsigned int lcore_id, void *handle) +{ + return RTE_PTR_ADD(handle, lcore_id * RTE_MAX_LCORE_VAR); +} + +/** + * Get pointer to lcore variable instance with the specified lcore id. + * + * @param lcore_id + * The lcore id specifying which of the @c RTE_MAX_LCORE value + * instances should be accessed. The lcore id need not be valid + * (e.g., may be @ref LCORE_ID_ANY), but in such a case, the pointer + * is also not valid (and thus should not be dereferenced). + * @param handle + * The lcore variable handle. + */ +#define RTE_LCORE_VAR_LCORE_VALUE(lcore_id, handle) \ + ((typeof(handle))rte_lcore_var_lcore_ptr(lcore_id, handle)) + +/** + * Get pointer to lcore variable instance of the current thread. + * + * May only be used by EAL threads and registered non-EAL threads. + */ +#define RTE_LCORE_VAR_VALUE(handle) \ + RTE_LCORE_VAR_LCORE_VALUE(rte_lcore_id(), handle) + +/** + * Iterate over each lcore id's value for 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_VALUE(lcore_id, value, handle) \ + for ((lcore_id) = \ + (((value) = RTE_LCORE_VAR_LCORE_VALUE(0, handle)), 0); \ + (lcore_id) < RTE_MAX_LCORE; \ + (lcore_id)++, (value) = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, \ + handle)) + +/** + * Allocate space in the per-lcore id buffers for 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_VALUE or @ref RTE_LCORE_VAR_LCORE_VALUE. + * + * The lcore variable values' memory is set to zero. + * + * The allocation is always successful, barring a fatal exhaustion of + * the per-lcore id buffer space. + * + * rte_lcore_var_alloc() is not multi-thread safe. + * + * @param size + * The size (in bytes) of the variable's per-lcore id value. Must be > 0. + * @param align + * If 0, the values will be suitably aligned for any kind of type + * (i.e., alignof(max_align_t)). Otherwise, the values will be aligned + * on a multiple of *align*, which must be a power of 2 and equal or + * less than @c RTE_CACHE_LINE_SIZE. + * @return + * The 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); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_LCORE_VAR_H_ */ diff --git a/lib/eal/version.map b/lib/eal/version.map index e3ff412683..77d3181087 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -396,6 +396,9 @@ EXPERIMENTAL { # added in 24.03 rte_vfio_get_device_info; # WINDOWS_NO_EXPORT + + # added in 24.11 + rte_lcore_var_alloc; }; INTERNAL { From patchwork Fri Oct 11 08:18:56 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: 145739 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 AB81745B12; Fri, 11 Oct 2024 10:28:35 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 70AED4060B; Fri, 11 Oct 2024 10:28:26 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2071.outbound.protection.outlook.com [40.107.22.71]) by mails.dpdk.org (Postfix) with ESMTP id C586A402ED for ; Fri, 11 Oct 2024 10:28:21 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=T4tpobOzR4H2uPp8BJDoWg6kzdJl0mcu8pWj48uAbYlpxmGXqeqIwf1ePYmxHFARFG0zGSHlQt0HogySuoIyMg4MVLHrwG7oYIfaQYkn5uMyMOYlDecBZRPhorve9/DAfeffUY5vmDGEliokIJVTA2Rlj7CYdOODjmLyJFdZ/Jyug+kZjMSiBiW5LQ3RLLSPk+m/iMkNNxc4H+PIUQZFnAZE/9ZXLfSuapCIgFEJnaXfIErByCUPecKPR4JVeTtopTu5wOr+pWL9+HnqhVvtBOLE8BSZjuPlWd2Ifj0MagtyHIh40Vz33HiYg3QYahDMlNKedYI/NSoWaiOKhuNseQ== 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=6QRj+7ZhWDJmUZHiZM2sNB1rRz6GYGmqpf/UvIl3/24=; b=iy+/z+0Ar4tDHwzmyECSy/QBDriWMI/eMWNX48dCI3TUxmPOuukr56TmfQ0P/QcAqFkPCKyA3jPehyZI9CO6zpzIxy1GQrEoeSSE7UKbrJCH/EYDubbuZLIkJQNfiqz8Xj1TqtfAxvw6hw2SUJPOw6GVpbEe/WV1gjHM/eOPVhxJ/8zoIdSJVu7nNfm3X3sLXxRqAme6C7xVa6YhcHWf+aebP6mijib3/nC4KwlTv4WX6DHSji9DWkfaIb78u9WsDmNOgwExOpxtGuhZhHrp9Q0yFTX8zpHiAizbUCyx20PYRxCHwDOz4U+1zDMVi3pESnYVNtWfmbFabwExyZR61Q== 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=6QRj+7ZhWDJmUZHiZM2sNB1rRz6GYGmqpf/UvIl3/24=; b=w5Oda6drHkwlpW0e8KI3c3C1g8XI2IZQkH8PGTO/zuRAhdWwk/pHx5mDZTzW76Xc3CeMkBVOJqjn5XlMZrjWj7fSuIOibYwjH3YCQqG3qzH2/p2eYqqaFG70EabC3/0xCYzpbvz/b3c8KD+gubpUCIar8DZVAZMYerz/RAbzMD+0lZhzGL8B5jt/+Hi0T+yfSiTW/2catUsgjkUYV6uPgbrGRfGLXaOvpThi5P71VYa1mCdue6jh6n2cYxOYXxtE30j7d/3W7DfIEqQuB8ZkderKj1jx510o8c/3NJQSic3baKGS9KTaHuzH31lSKAhmB4ED0RsGDV0oOJpOQVTK+g== Received: from DU7P189CA0010.EURP189.PROD.OUTLOOK.COM (2603:10a6:10:552::12) by PR3PR07MB7049.eurprd07.prod.outlook.com (2603:10a6:102:7c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Fri, 11 Oct 2024 08:28:18 +0000 Received: from DB5PEPF00014B88.eurprd02.prod.outlook.com (2603:10a6:10:552:cafe::35) by DU7P189CA0010.outlook.office365.com (2603:10a6:10:552::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.24 via Frontend Transport; Fri, 11 Oct 2024 08:28:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 192.176.1.74) smtp.mailfrom=ericsson.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ericsson.com; Received-SPF: Pass (protection.outlook.com: domain of ericsson.com designates 192.176.1.74 as permitted sender) receiver=protection.outlook.com; client-ip=192.176.1.74; helo=oa.msg.ericsson.com; pr=C Received: from oa.msg.ericsson.com (192.176.1.74) by DB5PEPF00014B88.mail.protection.outlook.com (10.167.8.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.13 via Frontend Transport; Fri, 11 Oct 2024 08:28:16 +0000 Received: from seliicinfr00049.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; Fri, 11 Oct 2024 10:28:15 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id CC6D638007D; Fri, 11 Oct 2024 10:28:15 +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 v10 2/7] eal: add lcore variable functional tests Date: Fri, 11 Oct 2024 10:18:56 +0200 Message-ID: <20241011081901.816211-3-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241011081901.816211-1-mattias.ronnblom@ericsson.com> References: <20241010142205.813134-2-mattias.ronnblom@ericsson.com> <20241011081901.816211-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB5PEPF00014B88:EE_|PR3PR07MB7049:EE_ X-MS-Office365-Filtering-Correlation-Id: 51fb4c1f-2ae0-4555-2b5e-08dce9cea7a6 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?LkJSFxlN3LyqPySlV+ndS9MuYjRAKbR?= =?utf-8?q?yXsQJAoXAtiwFqY/35VKBNHGVpiCa4clGwPT9tk8xLTqIBTr3VruxjcucoQnZF8JN?= =?utf-8?q?z+a7jHpLghJ81m+UIjXyYh8shTwk8mMP2bjYeZE/QtPWrcGJC9GoZPCVqV6EnQf3Z?= =?utf-8?q?NQtEePOqc2WTWbWwAuWKfJwGFvZC5vLiQy7PN2lVzd0LyDjCed0/qxo5ldyQcOTAi?= =?utf-8?q?WFsqoORgIaTQbufZZOjHXEpICnnJ6qcdZapjbqmRaeet3Uy71STOaqhiqezvdY7V+?= =?utf-8?q?1ZO5q1+ty6vKhG4eX5IyVxOkD0ZfeSJDpcI8ta6Silu3o06uHvbofzJOnTY1sB+nL?= =?utf-8?q?mHRVcbWKEeQOY5WWwAD5m98LEzn+2izLeB36M1I22xaPaxOVfrJUaafHT0r8SlFtF?= =?utf-8?q?l9NymQQN/QuZeJqtl3NGYHAGekYfjFPc43ngzCMEdBBPCVy4St/XYnWiJRv7yDTbV?= =?utf-8?q?FaYGJqxvpbjj7dPYhaldXtLnCvac5S6OUSZluDKB9kzAwg1negEieSAXBF3vucnAe?= =?utf-8?q?q2tJYBYsH5Y6MLXj5zC8rwv9CDrvMXIqS2bM6TsprOmv0TP1q4T6CnUcNq3e4z6f+?= =?utf-8?q?7JYU75EWkiUmi+FqJtvMeSguKprvA/8xgukLcp6aOvnooq/sPDwSmubpljQaRirPf?= =?utf-8?q?7o9noPY0NLVMETeAie3o/Maip6W2EkKUcv/XR8VY8B0PQBhgzoH+kkIG5efiLG8XX?= =?utf-8?q?GoHDoww9LPYAkIBTiDlMz9P8IBPQV1NPZiQahD0yapn+wbC6m5mZNAi9Yq0ignS9i?= =?utf-8?q?an4N2CQE9DlSOBTZ/A+Cd5HrHfxfGmGcQuX9+n2Plkm9VpK5uxxXKNd762qO59820?= =?utf-8?q?XrsZ3VQSFeXAdlIALBmA+htyVzzhmvgfiybwv3Ai/KFz2yXm0sLn5U1HkICjb9XoW?= =?utf-8?q?Mkvwt/RzPMeMIyZ/eFgD6xM2M7gqJrggDFhIes8VribaShoeake2I1EIb8gNWsZj9?= =?utf-8?q?G+fgkhuisg+EX3seSHNguU3/2v2/5NV5YV9CmusdJ0UmICXLzBtCiCfaHVTZaAj+t?= =?utf-8?q?D7nY9y5RLMyEwvH21uqixqMsLIU6cwoLEoFfIvUO5+Sgos/178+jyVhyLPiqjB3Gx?= =?utf-8?q?3LUsAB25WQGDz738aNyHhSnutVtj6qtfNkuitkJB6aV4gfYXif0xDfQtuHP3zfSJt?= =?utf-8?q?AZDbiE0oYnbkInVGTixCH3Vor2FtLP2gNWjMOmTmh+tw+kWdE80gr6/njN0EvnBwk?= =?utf-8?q?AlRbRE2qotNwX+qVPdy4ExrIg0oBj0pi8v059cEozdu9xS0AJQpRAy2tLySHjBgYs?= =?utf-8?q?emvY7fTEOtvSFAyRR4HswChfuI7AHdeqHACd6q1CUrYoHDvtGUr4TXeY=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:ErrorRetry; CAT:NONE; SFS:(13230040)(376014)(36860700013)(82310400026)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2024 08:28:16.4206 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 51fb4c1f-2ae0-4555-2b5e-08dce9cea7a6 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: DB5PEPF00014B88.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR07MB7049 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 | 436 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 437 insertions(+) create mode 100644 app/test/test_lcore_var.c diff --git a/app/test/meson.build b/app/test/meson.build index e29258e6ec..48279522f0 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -103,6 +103,7 @@ source_file_deps = { 'test_ipsec_sad.c': ['ipsec'], 'test_kvargs.c': ['kvargs'], 'test_latencystats.c': ['ethdev', 'latencystats', 'metrics'] + sample_packet_forward_deps, + 'test_lcore_var.c': [], 'test_lcores.c': [], 'test_link_bonding.c': ['ethdev', 'net_bond', 'net'] + packet_burst_generator_deps + virtual_pmd_deps, diff --git a/app/test/test_lcore_var.c b/app/test/test_lcore_var.c new file mode 100644 index 0000000000..2a1f258548 --- /dev/null +++ b/app/test/test_lcore_var.c @@ -0,0 +1,436 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 Ericsson AB + */ + +#include +#include +#include + +#include +#include +#include + +#include "test.h" + +#define MIN_LCORES 2 + +RTE_LCORE_VAR_HANDLE(int, test_int); +RTE_LCORE_VAR_HANDLE(char, test_char); +RTE_LCORE_VAR_HANDLE(long, test_long_sized); +RTE_LCORE_VAR_HANDLE(short, test_short); +RTE_LCORE_VAR_HANDLE(long, test_long_sized_aligned); + +struct int_checker_state { + int old_value; + int new_value; + bool success; +}; + +static void +rand_blk(void *blk, size_t size) +{ + size_t i; + + for (i = 0; i < size; i++) + ((unsigned char *)blk)[i] = (unsigned char)rte_rand(); +} + +static bool +is_ptr_aligned(const void *ptr, size_t align) +{ + return ptr != NULL ? (uintptr_t)ptr % align == 0 : false; +} + +static int +check_int(void *arg) +{ + struct int_checker_state *state = arg; + + int *ptr = RTE_LCORE_VAR_VALUE(test_int); + + bool naturally_aligned = is_ptr_aligned(ptr, sizeof(int)); + + bool equal = *(RTE_LCORE_VAR_VALUE(test_int)) == state->old_value; + + state->success = equal && naturally_aligned; + + *ptr = state->new_value; + + return 0; +} + +RTE_LCORE_VAR_INIT(test_int); +RTE_LCORE_VAR_INIT(test_char); +RTE_LCORE_VAR_INIT_SIZE(test_long_sized, 32); +RTE_LCORE_VAR_INIT(test_short); +RTE_LCORE_VAR_INIT_SIZE_ALIGN(test_long_sized_aligned, sizeof(long), + RTE_CACHE_LINE_SIZE); + +static int +test_int_lvar(void) +{ + unsigned int lcore_id; + + struct int_checker_state states[RTE_MAX_LCORE] = {}; + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + struct int_checker_state *state = &states[lcore_id]; + + state->old_value = (int)rte_rand(); + state->new_value = (int)rte_rand(); + + *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, test_int) = + state->old_value; + } + + RTE_LCORE_FOREACH_WORKER(lcore_id) + rte_eal_remote_launch(check_int, &states[lcore_id], lcore_id); + + rte_eal_mp_wait_lcore(); + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + struct int_checker_state *state = &states[lcore_id]; + int value; + + TEST_ASSERT(state->success, "Unexpected value " + "encountered on lcore %d", lcore_id); + + value = *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, test_int); + TEST_ASSERT_EQUAL(state->new_value, value, + "Lcore %d failed to update int", lcore_id); + } + + /* take the opportunity to test the foreach macro */ + int *v; + unsigned int i = 0; + RTE_LCORE_VAR_FOREACH_VALUE(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_VALUE(lcore_id, v, test_long_sized) { + TEST_ASSERT(is_ptr_aligned(v, alignof(long)), + "Type-derived alignment failed"); + } + + RTE_LCORE_VAR_FOREACH_VALUE(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_VALUE(test_struct); + + bool properly_aligned = + is_ptr_aligned(test_struct, alignof(struct test_struct)); + + bool equal = memcmp(lcore_struct->data, state->old_value.data, + TEST_STRUCT_DATA_SIZE) == 0; + + state->success = equal && properly_aligned; + + memcpy(lcore_struct->data, state->new_value.data, + TEST_STRUCT_DATA_SIZE); + + return 0; +} + +static int +test_struct_lvar(void) +{ + unsigned int lcore_id; + + RTE_LCORE_VAR_ALLOC(before_struct); + RTE_LCORE_VAR_ALLOC(test_struct); + RTE_LCORE_VAR_ALLOC(after_struct); + + struct struct_checker_state states[RTE_MAX_LCORE]; + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + struct struct_checker_state *state = &states[lcore_id]; + + rand_blk(state->old_value.data, TEST_STRUCT_DATA_SIZE); + rand_blk(state->new_value.data, TEST_STRUCT_DATA_SIZE); + + memcpy(RTE_LCORE_VAR_LCORE_VALUE(lcore_id, test_struct)->data, + state->old_value.data, TEST_STRUCT_DATA_SIZE); + } + + RTE_LCORE_FOREACH_WORKER(lcore_id) + rte_eal_remote_launch(check_struct, &states[lcore_id], + lcore_id); + + rte_eal_mp_wait_lcore(); + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + struct struct_checker_state *state = &states[lcore_id]; + struct test_struct *lstruct = + RTE_LCORE_VAR_LCORE_VALUE(lcore_id, test_struct); + + TEST_ASSERT(state->success, "Unexpected value encountered on " + "lcore %d", lcore_id); + + bool equal = memcmp(lstruct->data, state->new_value.data, + TEST_STRUCT_DATA_SIZE) == 0; + + TEST_ASSERT(equal, "Lcore %d failed to update struct", + lcore_id); + } + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + char before = + *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, before_struct); + char after = + *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, after_struct); + + TEST_ASSERT_EQUAL(before, 0, "Lcore variable before test " + "struct was modified on lcore %d", lcore_id); + TEST_ASSERT_EQUAL(after, 0, "Lcore variable after test " + "struct was modified on lcore %d", lcore_id); + } + + return TEST_SUCCESS; +} + +#define TEST_ARRAY_SIZE 99 + +typedef uint16_t test_array_t[TEST_ARRAY_SIZE]; + +static void test_array_init_rand(test_array_t a) +{ + size_t i; + for (i = 0; i < TEST_ARRAY_SIZE; i++) + a[i] = (uint16_t)rte_rand(); +} + +static bool test_array_equal(test_array_t a, test_array_t b) +{ + size_t i; + for (i = 0; i < TEST_ARRAY_SIZE; i++) { + if (a[i] != b[i]) + return false; + } + return true; +} + +static void test_array_copy(test_array_t dst, const test_array_t src) +{ + size_t i; + for (i = 0; i < TEST_ARRAY_SIZE; i++) + dst[i] = src[i]; +} + +static RTE_LCORE_VAR_HANDLE(char, before_array); +static RTE_LCORE_VAR_HANDLE(test_array_t, test_array); +static RTE_LCORE_VAR_HANDLE(char, after_array); + +struct array_checker_state { + test_array_t old_value; + test_array_t new_value; + bool success; +}; + +static int check_array(void *arg) +{ + struct array_checker_state *state = arg; + + test_array_t *lcore_array = RTE_LCORE_VAR_VALUE(test_array); + + bool properly_aligned = + is_ptr_aligned(lcore_array, alignof(test_array_t)); + + bool equal = test_array_equal(*lcore_array, state->old_value); + + state->success = equal && properly_aligned; + + test_array_copy(*lcore_array, state->new_value); + + return 0; +} + +static int +test_array_lvar(void) +{ + unsigned int lcore_id; + + RTE_LCORE_VAR_ALLOC(before_array); + RTE_LCORE_VAR_ALLOC(test_array); + RTE_LCORE_VAR_ALLOC(after_array); + + struct array_checker_state states[RTE_MAX_LCORE]; + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + struct array_checker_state *state = &states[lcore_id]; + + test_array_init_rand(state->new_value); + test_array_init_rand(state->old_value); + + test_array_copy(*RTE_LCORE_VAR_LCORE_VALUE(lcore_id, + test_array), + state->old_value); + } + + RTE_LCORE_FOREACH_WORKER(lcore_id) + rte_eal_remote_launch(check_array, &states[lcore_id], + lcore_id); + + rte_eal_mp_wait_lcore(); + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + struct array_checker_state *state = &states[lcore_id]; + test_array_t *larray = + RTE_LCORE_VAR_LCORE_VALUE(lcore_id, test_array); + + TEST_ASSERT(state->success, "Unexpected value encountered on " + "lcore %d", lcore_id); + + bool equal = test_array_equal(*larray, state->new_value); + + TEST_ASSERT(equal, "Lcore %d failed to update array", + lcore_id); + } + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + char before = + *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, before_array); + char after = + *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, after_array); + + TEST_ASSERT_EQUAL(before, 0, "Lcore variable before test " + "array was modified on lcore %d", lcore_id); + TEST_ASSERT_EQUAL(after, 0, "Lcore variable after test " + "array was modified on lcore %d", lcore_id); + } + + return TEST_SUCCESS; +} + +#define MANY_LVARS (2 * RTE_MAX_LCORE_VAR / sizeof(uint32_t)) + +static int +test_many_lvars(void) +{ + uint32_t **handlers = malloc(sizeof(uint32_t *) * MANY_LVARS); + unsigned int i; + + TEST_ASSERT(handlers != NULL, "Unable to allocate memory"); + + for (i = 0; i < MANY_LVARS; i++) { + unsigned int lcore_id; + + RTE_LCORE_VAR_ALLOC(handlers[i]); + + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { + uint32_t *v = + RTE_LCORE_VAR_LCORE_VALUE(lcore_id, handlers[i]); + *v = (uint32_t)(i * lcore_id); + } + } + + for (i = 0; i < MANY_LVARS; i++) { + unsigned int lcore_id; + + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { + uint32_t v = *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, + handlers[i]); + TEST_ASSERT_EQUAL((uint32_t)(i * lcore_id), v, + "Unexpected lcore variable value on " + "lcore %d", lcore_id); + } + } + + free(handlers); + + return TEST_SUCCESS; +} + +static int +test_large_lvar(void) +{ + RTE_LCORE_VAR_HANDLE(unsigned char, large); + unsigned int lcore_id; + + RTE_LCORE_VAR_ALLOC_SIZE(large, RTE_MAX_LCORE_VAR); + + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { + unsigned char *ptr = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, large); + + memset(ptr, (unsigned char)lcore_id, RTE_MAX_LCORE_VAR); + } + + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { + unsigned char *ptr = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, large); + size_t i; + + for (i = 0; i < RTE_MAX_LCORE_VAR; i++) + TEST_ASSERT_EQUAL(ptr[i], (unsigned char)lcore_id, + "Large lcore variable value is " + "corrupted on lcore %d.", + lcore_id); + } + + return TEST_SUCCESS; +} + +static struct unit_test_suite lcore_var_testsuite = { + .suite_name = "lcore variable autotest", + .unit_test_cases = { + TEST_CASE(test_int_lvar), + TEST_CASE(test_sized_alignment), + TEST_CASE(test_struct_lvar), + TEST_CASE(test_array_lvar), + TEST_CASE(test_many_lvars), + TEST_CASE(test_large_lvar), + TEST_CASES_END() + }, +}; + +static int test_lcore_var(void) +{ + if (rte_lcore_count() < MIN_LCORES) { + printf("Not enough cores for lcore_var_autotest; expecting at " + "least %d.\n", MIN_LCORES); + return TEST_SKIPPED; + } + + return unit_test_suite_runner(&lcore_var_testsuite); +} + +REGISTER_FAST_TEST(lcore_var_autotest, true, false, test_lcore_var); From patchwork Fri Oct 11 08:18:57 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: 145741 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 1AF3845B12; Fri, 11 Oct 2024 10:28:50 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1E65240611; Fri, 11 Oct 2024 10:28:29 +0200 (CEST) Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03on2066.outbound.protection.outlook.com [40.107.103.66]) by mails.dpdk.org (Postfix) with ESMTP id 2405B400D5 for ; Fri, 11 Oct 2024 10:28:22 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iEkBsFnQtTrFqTcghNV8kXQyiWFu10p4syTN2NuhBIPQ9P8LUtdD1GlASzX88y6d/a0VeyHm6ANafIdcX56rQICSTYxR6Ea7CN+G4OdEK+XP4o3PxMDO3rFpn9Cp7MJn3McFJjLRYJriZhoIy4Vuhmgqq2jFMpB+P0FFVBd5BKAq1+KeEPV2XLZ954DZI3UzHGIN6C86xaJcJ5hvRMDXWAoE03nTk0WaPkNw4RC2ylTsPaFobnwDTkiOH7MiuTPxDolWPsNERrBsEjZT1MCaBnJcaloRQcg0D+mXFrYiZCkJ3v6teYOHJ3dLkimFgFedtFR9erS96zvvyYPREhdgtw== 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=3SE7ek+/krDICvlTVpg7t/7m7wAOxBjgLDNI2xEB+jk=; b=SGzQ6r77h8A9OffE3hW2eg3z7x1JAKJiZtCJvxaInxJla6YfoEHTIyUGP0QGa5jfQK/kVjcAP8GqtUmF2Y3utnbNa1C+mys0XY/bab6tbpcjF0xMiCsnMxLLFXoz6AWiunKIEQ1we6bkeamIm7+vooDZDjDmKIJgg97tFtZizUkmSsimI0TBTEcf3kSV4HRsTBfYOC9IJVD+mqwBBf17cO8lkoWA0M14TP5/qTYDLxjzDMW1M7Y8vFcwdUact/9/Xxkl3hs9TO3H+qZQtmjdHlzhm2i2QxBWkrf1W07ghocxCChPBM1AMp3oOVI3QLtDn275azgXuEeaiCn1f8jx5g== 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=3SE7ek+/krDICvlTVpg7t/7m7wAOxBjgLDNI2xEB+jk=; b=FhVuXIUsxpEyspdIPV1qznj2ZI4+LFXDq5GFbn9AgrM4mqLQnhtM57VaSHMmMdOUxO+szaIyICDkdbP0Hu8KcuC2EaFmJZRSF1mUUnwqCc/cDiRrw+s1gm4Z2A9+xRG0hnT+Uu1ReF68P9j8E/pNzQRs4zcE8gpXE4cQu007G7Fi/kY7/+Z/dqDUZQdcs8wqXQsmZkxwytnUfWG2G8ilif4otxTvLt3WYsyJWKex7edQqeRqxNWQn10UX0PJeq8JDlGJqDsuyCjUIe+GrdpV9Ag0QPGns0ju73PD/knmNKwth9jXoqrOmZBCWq5RUVgmwrZUjChXKQulc7XUNe5Cug== Received: from AM4PR0302CA0032.eurprd03.prod.outlook.com (2603:10a6:205:2::45) by PAXPR07MB7952.eurprd07.prod.outlook.com (2603:10a6:102:15f::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18; Fri, 11 Oct 2024 08:28:18 +0000 Received: from AMS0EPF000001AE.eurprd05.prod.outlook.com (2603:10a6:205:2:cafe::4) by AM4PR0302CA0032.outlook.office365.com (2603:10a6:205:2::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.20 via Frontend Transport; Fri, 11 Oct 2024 08:28:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 192.176.1.74) smtp.mailfrom=ericsson.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ericsson.com; Received-SPF: Pass (protection.outlook.com: domain of ericsson.com designates 192.176.1.74 as permitted sender) receiver=protection.outlook.com; client-ip=192.176.1.74; helo=oa.msg.ericsson.com; pr=C Received: from oa.msg.ericsson.com (192.176.1.74) by AMS0EPF000001AE.mail.protection.outlook.com (10.167.16.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Fri, 11 Oct 2024 08:28:17 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.61) with Microsoft SMTP Server id 15.2.1544.11; Fri, 11 Oct 2024 10:28:16 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id E0CEC380070; Fri, 11 Oct 2024 10:28:15 +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 v10 3/7] eal: add lcore variable performance test Date: Fri, 11 Oct 2024 10:18:57 +0200 Message-ID: <20241011081901.816211-4-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241011081901.816211-1-mattias.ronnblom@ericsson.com> References: <20241010142205.813134-2-mattias.ronnblom@ericsson.com> <20241011081901.816211-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AMS0EPF000001AE:EE_|PAXPR07MB7952:EE_ X-MS-Office365-Filtering-Correlation-Id: 9b12695a-951a-47cc-8080-08dce9cea874 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|36860700013|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?DVppSkDvhDQmYmu3NelgVjMr3z4PHy2?= =?utf-8?q?nsOv/mW33DdQnyRD9sCIYX7iFOoa/4BujZrKc4Pw5TxRtPWwDauNv2AM1YAVW5EaK?= =?utf-8?q?Z0emyGIDr3LczJOOPnd+vz5gDYJPxV+nV4lC/Rtt9BDzsh2fpwTZi4demAnemGAD+?= =?utf-8?q?RGI+kIbRjNCnuZDtynEjw4bG7tUe2RwgA9E4wwHeAQ+bYAqwT73d7y7IqDQHBMkwa?= =?utf-8?q?CeIt1z8LtwSCabKggHFGL8/vWZJJfAA+O+79p4QRtxygCvNdpDy1D2sh14+zYb3d7?= =?utf-8?q?bVh+5LmhCAAF/eZaBrRUfAA/PaY9a17olILtKLmQVVA2XIiCAYerQ/6Xn5B2nmZ77?= =?utf-8?q?yMi5Ff8N05CBylrBWEpJ65dQg2tTvclCV7dhW+t8OjPnUOchxuMqqUL8nyZr34V4D?= =?utf-8?q?uIFbJRZmaB/tCASn5Jq4lJWrxEcy8fKkYkOUY+KeZGl7cYT6eWgrClEpcwKP0h7pB?= =?utf-8?q?jL3i0Zq//92/IRVrP5OwZ23DYBojTiE1+rYc0j+ZscPoQLTbPtMWOuUsqxucmhw+7?= =?utf-8?q?Fxt/7a2e/lOQrNqMOnz0iZzXqHWtON3nlg7p+trnuGVwazMoAe8oo0SBDsAYgbjsv?= =?utf-8?q?j9rMKGrblX+jvYhb1EqQ/MeWlgRTihEWxeK9DEZ/JZM2MYXCqA8oVwsITo7EoPXDC?= =?utf-8?q?LXgf1Zj/HmPfktSniAToVXloOgZYKRjz1uIem8/S/maoAP98yQlTxRw6eGVLraMYe?= =?utf-8?q?EMpblrJfOnGQMkwVvaIpHxMRb/eeO8xgZYKSbAmMp8iddPt53xk09wbN2wkmixZph?= =?utf-8?q?tciPKx1GeZUL8Pqy4VqkJghA+zdIHlYnUS0zDnjr4up2mNLbZamNFnaQzvDvj04r6?= =?utf-8?q?pzwsZ3dgu9xXQnIs/BmGIdcWCIHYff7OW3ObiILAwEHWDUiazcCmDqLiF1t9eK2uN?= =?utf-8?q?Pwp5hEQYfoMuIWA2xp5DfVXZMeo2xo/8wl96EL6L9CycJazZ9RwMgXkzI26vovRRd?= =?utf-8?q?v73QCYrgUKvqciGoMbRJJIsuUWTtIYZGMKTTwsV3iR9y3zRml6hzVRzBo4z+JLoql?= =?utf-8?q?7HsTNPrz6bC9nFyiCBg+qiIMDJr+7JvGq0WlLkhvuT5QFOT8LIjXYrcxbs8pW2waI?= =?utf-8?q?lkFgX9pWbzn+cauHGFB32PMN/cKpsnVyUDxmh1OYtR/0Q4Rb7+du/YZs/WFEAwbbJ?= =?utf-8?q?oF690rMTVShOjA4wNXdrcP4U3kS5rrNPYDH9j3m4J8b75Z/bUyuxXSYy4ZgoxO+yZ?= =?utf-8?q?uwmKGiVL6RsQ1MbSWqb0goSrG4BFZi85Fo2GOeihfIY2yhx/Aa8dO36kodMyYjr7I?= =?utf-8?q?uWVdo5dMExi7jD9FKjkemuoAa1SI6BlgT4qQlGmuoI3Di2FaX5i9GwTtA4yxi3zyk?= =?utf-8?q?KHeJPKfoeiZP?= X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2024 08:28:17.8041 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9b12695a-951a-47cc-8080-08dce9cea874 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: AMS0EPF000001AE.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR07MB7952 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 | 257 +++++++++++++++++++++++++++++++++ 2 files changed, 258 insertions(+) create mode 100644 app/test/test_lcore_var_perf.c diff --git a/app/test/meson.build b/app/test/meson.build index 48279522f0..d4e0c59900 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -104,6 +104,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..2efb8342d1 --- /dev/null +++ b/app/test/test_lcore_var_perf.c @@ -0,0 +1,257 @@ +/* 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_VALUE(lvar_lcore_state[mod]); + + mod_init(state); + } +} + +static __rte_noinline void +lvar_update(unsigned int mod) +{ + struct mod_lcore_state *state = + RTE_LCORE_VAR_VALUE(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 Fri Oct 11 08:18:58 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: 145740 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 70D4545B12; Fri, 11 Oct 2024 10:28:43 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B39A140648; Fri, 11 Oct 2024 10:28:27 +0200 (CEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2085.outbound.protection.outlook.com [40.107.20.85]) by mails.dpdk.org (Postfix) with ESMTP id EBFC7402EE for ; Fri, 11 Oct 2024 10:28:21 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TaHLPmkLc0x/zFiw+ph6v5l8dpzvH9RYzpt78aOOxrwyLnNpUCC4wk+L3C69FSIsPdamePIvUDKPbks6VewrQAsEr5WquI3TPVocdVY45zojtJl7/U0coCVa13VOJJwL8OaK+yMu3cXspD3Lmymbbmg3okqvRXRkVr9ahLXCv21HsD3fDZT0/2jmcJVAxACB2u1omuFJYPhsebCtenWPEhZjXmNme2it6vB+jTW2U7jkkAoUY8iX7ZnhA5g6w5Okk8ZXV0lHWTuLDnOcsSIU+bgqNc84R/fw4jxE7i5UMi6f5Di1GMHCEnLzS9hLAK8mmgjm+e6jLC8EkqNx9w+C9g== 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=ZcrIxsUczn3eEQ4B3j0n5Yi5yrD0dIPqXBBskKRbBbI=; b=sVB2vNvuNxq9ELObqMr2z+lAkGS8lmItmnAF5Z7aBtv8Rpxe+ULQ93yK09aJIIq+9N4W38qqJfT/30HaGr6gYqMs+AIFnHf0BGh4Up513GbtKY4Eq0INiIDFg5oXXMcsl353e2A5ZZ0z2iY2OBrSkehARmOhelaMFQNsn74DnjBGdY0Adur9iLLAalDgI+8IOw+FCjTYl75/I2U2trKp0YWGokXlyJl39te5xinnpo2Qga8KIOedT6kTbk9vOdHvO0fYj/PAaXFOrbLg7MQsM3R4YExYvA3HQlucKpmS1xluHG3PMzwc32jjZWP/7BJqEc0LZvisCJ1R5r6eQ4Sk1Q== 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=ZcrIxsUczn3eEQ4B3j0n5Yi5yrD0dIPqXBBskKRbBbI=; b=BfT/pSBSpA53LCAbk+CY94XgDxUaQeHFvYkgNSkfTmYp9/eeeVj6gRicBI4q7iqZkY7suqVMALXZVFM6OlmbD2HeQBqyzMvlXcF+icrdvHDygd+YqmaXED66Rd5lon7qrw1WicMgNOvjnaw8LJT/K/VBcpiIhcbtJoc7MK9sG3l2AvK8FUIcIbRHymtIAcWUjxxvIyBPPOYrsKHxyi8WOIvDTPq9jJ8iY2EaOzljY4zrAjHBkh892Tk1OnP5pKF3W2mj140QLP2br9Xy5QhNqraiYrgaVrjfBdTL50eqpv/5XmXiTKe5n36xXzhLeyTyd6c4qrrI5VNn6aQZVXJCNA== Received: from DU7P189CA0016.EURP189.PROD.OUTLOOK.COM (2603:10a6:10:552::28) by AS1PR07MB8568.eurprd07.prod.outlook.com (2603:10a6:20b:470::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18; Fri, 11 Oct 2024 08:28:18 +0000 Received: from DB5PEPF00014B88.eurprd02.prod.outlook.com (2603:10a6:10:552:cafe::f5) by DU7P189CA0016.outlook.office365.com (2603:10a6:10:552::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.17 via Frontend Transport; Fri, 11 Oct 2024 08:28:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 192.176.1.74) smtp.mailfrom=ericsson.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ericsson.com; Received-SPF: Pass (protection.outlook.com: domain of ericsson.com designates 192.176.1.74 as permitted sender) receiver=protection.outlook.com; client-ip=192.176.1.74; helo=oa.msg.ericsson.com; pr=C Received: from oa.msg.ericsson.com (192.176.1.74) by DB5PEPF00014B88.mail.protection.outlook.com (10.167.8.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.13 via Frontend Transport; Fri, 11 Oct 2024 08:28:18 +0000 Received: from seliicinfr00049.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; Fri, 11 Oct 2024 10:28:16 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id F2EEA38007A; Fri, 11 Oct 2024 10:28:15 +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 v10 4/7] random: keep PRNG state in lcore variable Date: Fri, 11 Oct 2024 10:18:58 +0200 Message-ID: <20241011081901.816211-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241011081901.816211-1-mattias.ronnblom@ericsson.com> References: <20241010142205.813134-2-mattias.ronnblom@ericsson.com> <20241011081901.816211-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB5PEPF00014B88:EE_|AS1PR07MB8568:EE_ X-MS-Office365-Filtering-Correlation-Id: 72231348-b182-464e-bb70-08dce9cea8d9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: =?utf-8?q?cEFEXjaeWtUpYqYpvRYxRWIF6igD5EY?= =?utf-8?q?Y1X1qavc3ivDZOcFZUl5GdLT6rvj6g4rfMCsO41yUncn5X0MnnPpc/eTOr1WwID/b?= =?utf-8?q?lL2//5z92ex1YSBlOsVu4MzzqWBNMBK3pNIxJ8zoRpyqmXUghveofzz5T9ak8Bu9h?= =?utf-8?q?u7NohfD5/CSRC8peDr8yqMyDopq8tVrmaQ6LjXWIoEQuB2VCZ/bn6Xsh+WgUpSd9Z?= =?utf-8?q?atjNUcl92IVEfYdvZbqmLtr+6+AKlqX7EJhoR/ZqQ64Ed0sd/NTbV3KqRV01e19M4?= =?utf-8?q?R4t3U32sFh5Q2Vu4OVeTwr9xvLSC93nhsfHYTohVt0G1NJY7ZzN67rVnyMmXjLpmx?= =?utf-8?q?T1VBYKx/n89Ex8zlmHQvSUp28bb4g/Xs5P5CTTnx//uVmPtRuTqns3wKN7VaSlp6W?= =?utf-8?q?rZLE+Q5yXtJX4kExBKqk1Z85vFgo26oKXn75iPHJI5L83CQu+Pk1DcP5JvM+f1T9R?= =?utf-8?q?EIf6M1KFqqd8aY/71natHwSTnuiTOdIlH8J2wrvwD6XLWU1WqUtKMgKeWLu/xFc97?= =?utf-8?q?flHXH3HcaeaAZveoiGTfbX/e/qHRdJE4MQrFtITRyHV41Ehy6I8WvyWkgOme1edDC?= =?utf-8?q?LhN8b9y930moZpGxY7B4QqTwSIXGI2LUKnYmcA2YepqVcXs5M/e7GUdcCgtAPUOtY?= =?utf-8?q?4ZDjRK7RmWuSzIY6d69xee8PBWoeZvpVQ0ZykxZ6me8E5WVNNQu6isDaiMkuTSBvi?= =?utf-8?q?cblOokuFra7qA1e6TPdOPbYM6Tev6ZbWJ4wYCjxqdhKEdg5ldY/U8RH6hhsE+t3+j?= =?utf-8?q?GRrOkKq2ShSUDHjJVWUWYGYf0JdkRodfll2vQwAH5+w6r1AeUWjuX2SLU8n0i6nOH?= =?utf-8?q?Eo0uIxo82ClQQZyj010WFyvpR2oERSs8yF1EjoltEDkL+/7lSwiKnCsgO/YvAC5Ka?= =?utf-8?q?GQfrNfn7/Ck5Uocj/Gi08Ye4Q/y3sg9SIRXgx9zkteV14xI4IU0BdJnJavm/3nfkK?= =?utf-8?q?gwdO+CKUcBWLpnpCfyjzJ/wHeKvitnJJbWS+EIPJDSrxh41d6ulOjuUXwx4TUHHO9?= =?utf-8?q?Rzgg8EuC1JPjMAP/ZDtlZVvLt/KDFlg9I41kk/AIt0JZA9pRvYnf+MmveW5uUjrLJ?= =?utf-8?q?ym04Yr/wg9bAe7ygyKdgKnCJjgZpc1fTY0PMMuVOBfv4IUw0OLa6dyUiv4d/o30KQ?= =?utf-8?q?jtAx/hVcddmQvFtnhCs2RQQuxJhfXg5ThGHkqo767H5u1V658Vvk5I59NCXdXP22a?= =?utf-8?q?JNfm7Ps8I8QDoS4oBgbILnYZ5Ovhg488f0Eyb6oZXATQO0Vpk2FAWI/XpyarrLUfH?= =?utf-8?q?ifXLQ2O9JCqooRXdr5APQWt1xqW3pPE3Vrmfl9ZAc4gsZ0kL3N6iXrtg=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)(1800799024)(82310400026)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2024 08:28:18.3737 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 72231348-b182-464e-bb70-08dce9cea8d9 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: DB5PEPF00014B88.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR07MB8568 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..a8d00308dd 100644 --- a/lib/eal/common/rte_random.c +++ b/lib/eal/common/rte_random.c @@ -11,6 +11,7 @@ #include #include #include +#include #include struct __rte_cache_aligned rte_rand_state { @@ -19,14 +20,12 @@ struct __rte_cache_aligned rte_rand_state { uint64_t z3; uint64_t z4; uint64_t z5; - RTE_CACHE_GUARD; }; -/* One instance each for every lcore id-equipped thread, and one - * additional instance to be shared by all others threads (i.e., all - * unregistered non-EAL threads). - */ -static struct rte_rand_state rand_states[RTE_MAX_LCORE + 1]; +RTE_LCORE_VAR_HANDLE(struct rte_rand_state, rand_state); + +/* instance to be shared by all unregistered non-EAL threads */ +static struct rte_rand_state unregistered_rand_state; static uint32_t __rte_rand_lcg32(uint32_t *seed) @@ -85,8 +84,14 @@ rte_srand(uint64_t seed) unsigned int lcore_id; /* add lcore_id to seed to avoid having the same sequence */ - for (lcore_id = 0; lcore_id < RTE_DIM(rand_states); lcore_id++) - __rte_srand_lfsr258(seed + lcore_id, &rand_states[lcore_id]); + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { + struct rte_rand_state *lcore_state = + RTE_LCORE_VAR_LCORE_VALUE(lcore_id, rand_state); + + __rte_srand_lfsr258(seed + lcore_id, lcore_state); + } + + __rte_srand_lfsr258(seed + lcore_id, &unregistered_rand_state); } static __rte_always_inline uint64_t @@ -124,11 +129,10 @@ struct rte_rand_state *__rte_rand_get_state(void) idx = rte_lcore_id(); - /* last instance reserved for unregistered non-EAL threads */ if (unlikely(idx == LCORE_ID_ANY)) - idx = RTE_MAX_LCORE; + return &unregistered_rand_state; - return &rand_states[idx]; + return RTE_LCORE_VAR_VALUE(rand_state); } uint64_t @@ -228,6 +232,8 @@ RTE_INIT(rte_rand_init) { uint64_t seed; + RTE_LCORE_VAR_ALLOC(rand_state); + seed = __rte_random_initial_seed(); rte_srand(seed); From patchwork Fri Oct 11 08:18:59 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: 145737 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 146A645B12; Fri, 11 Oct 2024 10:28:20 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CF5AC4028B; Fri, 11 Oct 2024 10:28:19 +0200 (CEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2079.outbound.protection.outlook.com [40.107.20.79]) by mails.dpdk.org (Postfix) with ESMTP id BC9A7400D5 for ; Fri, 11 Oct 2024 10:28:18 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RlG6/pfDmXYLm59qsXZLNyuQ3LZp4V7VjjWdKfMlSgbJ7oRblshgju3NY31h0gr5OdhFt7Qv9Yrn4cXGFUSfe3oJc1WFmU3aFXdCImaL5BXAsim2g9R3X1SuKXd6QCv6UU2bkFM4/21ASLbY8v11ZwqbMUL+Jcaw0IcUGZ9O/0V7/4g5WBYs8QUwu8NbClsO6FSkbdpJqfV2EHiDqWecAsj/pfoqrtLEOHMmeVxzArgKdlG3wmm1fus52STd+Lx5+0YWoYCyXWAwzkEHt73TpPpWc8dcD869zmCUwF3tFaxjF7/7pdbIDxeUi37TcjJmtkd2d5lj7Bsx0KclWRqJNA== 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=BqPcb0CZHAMsN7CS7hVMSqhGJidwIIpSIHOdrawrTEM=; b=I6eBdVj6TTREPl1adE/ZI6LdfXkc5+v20xTIc56iI5BOnVSxYON/XoHXN40K7V1BHC9dB0rtg4m9FcARhCx5W7SfY1kvJIeEqJzLSdaVwZGXSczhinwk8x8q+cR3oeKkm6SXJxT3X0TSdpwmceWhZ2pG1jOKx9Wys48ChgeGDARnrxSwc7nl4hAxNLlUUH7dbyg27CrLtefHJGKctKg7q+aYGHC4Aab2VZZLHVsxmBFCOyPYb4G1uTDPI/pNJ17DoYLO83uN5a00KrdrqR8birP6FHmKwCs1BDmMyoGokFsPXxxGnsTB9m/ZPMuyzi6r7Jj15OekZcsTqHw4HaeU/Q== 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=BqPcb0CZHAMsN7CS7hVMSqhGJidwIIpSIHOdrawrTEM=; b=WjKFNL3C21HtO6NniCEy78h6GR3qe6Si9KsHlcF6YVgIEBVMWebIQWwsU709H9X3vq7Ebylq4kaccS2czTH/7t1LrD1aw2Z5GAlzA/dJKheCXjhL/gv2fcuE+UkRqfmBL2/XpJuWRTL1zinTwJ3OwVxngSBkW1adCi4q+iNf0g8o5XsY/PC+jl7chu/eVLh6OM0mRMOY+W0LTAeWWDuVnzPQDbiu2mcEDkCVdljsyWN6u91zuZwTlrsbDiehtuk3BuywKJ2/LY6DZ8JitNkbqU9+Pwxez0TBJCbQxIDt9A7kUx3OT3GmFZw1da87CR7J5I/5w4sBi5MJjeyRrtZqNA== Received: from DUZPR01CA0281.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b9::9) by AS8PR07MB7944.eurprd07.prod.outlook.com (2603:10a6:20b:393::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18; Fri, 11 Oct 2024 08:28:17 +0000 Received: from DB1PEPF000509F4.eurprd02.prod.outlook.com (2603:10a6:10:4b9:cafe::5c) by DUZPR01CA0281.outlook.office365.com (2603:10a6:10:4b9::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.20 via Frontend Transport; Fri, 11 Oct 2024 08:28:17 +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.8048.13 via Frontend Transport; Fri, 11 Oct 2024 08:28:16 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.69) with Microsoft SMTP Server id 15.2.1544.11; Fri, 11 Oct 2024 10:28:16 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 0F99A38007D; Fri, 11 Oct 2024 10:28:16 +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 v10 5/7] power: keep per-lcore state in lcore variable Date: Fri, 11 Oct 2024 10:18:59 +0200 Message-ID: <20241011081901.816211-6-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241011081901.816211-1-mattias.ronnblom@ericsson.com> References: <20241010142205.813134-2-mattias.ronnblom@ericsson.com> <20241011081901.816211-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB1PEPF000509F4:EE_|AS8PR07MB7944:EE_ X-MS-Office365-Filtering-Correlation-Id: c5efe31f-ffdc-4f99-44fd-08dce9cea7c2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|376014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?q?L3gqq4dtm6uwf2EtDCJOaIYaapKHM4s?= =?utf-8?q?gjQvQMFUjUua7BTAVRFTUZSVaA8QHMWbbZKdpDfgmHO2ygdg7WIiQNbNQjs805u+7?= =?utf-8?q?xyjiKJQyApTh0eMzvSLABhNjoVDLUl3Uysap/ujyW9ycTdqMlDtEQ/yYqP66eltwp?= =?utf-8?q?89SaNTLq8y5vgEgK8SgaS0OM568lpESEj4J3ms87WPjMN0GLYkYXIahH/90Wul3fE?= =?utf-8?q?kzKE/ryJG8kraGgNTODhlqa9eQTsmiTiWlS0ezK1A00AqJ59uYyigTPVWfl08PZVe?= =?utf-8?q?EEv+Qm8nE3UTc9nh4BW837kaeP5MDDsixBm1Ts4dZu0mTyz0Hj+ChjINgh6DDoUwV?= =?utf-8?q?EJn7gXnjcHHB5aR5j7hAv5AZXwWV1ZHG5hr2xvXp1BNSpGk2FlnFz5Ssbuz8qLguX?= =?utf-8?q?em+L4RiFRrNA+12ztbagTfGVwS1RW2r+PaBo0JEe/jek7mPU3eS7LKnFtDx8tUhHf?= =?utf-8?q?g+5wvvfzJcOZp5duc3EiBYDZU0EOPeMHKUUnVc3d4trI1HpuVotrRhfME0Rets1Tp?= =?utf-8?q?MXvExn2GpmIHMLjairANA7qS5T5TevzdxtVcRJUuoT8kTl3yR8D5QXDquyW26NM7c?= =?utf-8?q?7c/tYnzuIXElkYxJCAThMZLdScUW7S46y5oNSoKjKbPjbPOkXn8oxmVaRbwz1y94k?= =?utf-8?q?BaDc5lRTmPFBkFnU1x8PgkXqHZRsysfhvT3GA3rWE1IsNWUmNgpG8wVGBgJ36zPed?= =?utf-8?q?pokkDByrg+/8qVvk7nGbPLl9SjkpKEsO75PXKecfoFwxmAI5LSNgWf6/0CIs58dVN?= =?utf-8?q?Oj9xHHXi40QVhUwZTgNfAkaI4b1PVJDAAWvpnfFAMqjE+odSS4u33yPRJV/tFtheS?= =?utf-8?q?HkHkkfn6rM1F0vgWn8exHVdciMVryMAc+K1ug4VS7cdH6w6Te7sFiRWG54E6JdZRh?= =?utf-8?q?0DXcQcmH7M8h6Karkm9LivwtX/5GlqYXN+VjK9df+xPOFOkZA3f2g4QodOzCgap8Y?= =?utf-8?q?ftloLSxWUl3OnByeNlBk3oMHHXTJ6DzbflF9ZGgQwbTEW+4K89pxlos6NQiHxcyFb?= =?utf-8?q?iSb3o3Rd7HY8T0vK2c9xdX+6zsRRAYF97ljFXHkVE3FPNdk4s0qmiy9w8kk09Az7p?= =?utf-8?q?LNry8jlo3rPq5QsufUyWgvOpl10f7d+Mv8/JnydJgpT4G+C6vezCKFhvoxf+OOGuB?= =?utf-8?q?bO3w7MiJl2IpZT/3sgZrDv3bMc7gtlmldfOIMQF6Q4l1wDoGPIpCBfNi0hPSB1D+n?= =?utf-8?q?pwjkNzDRz7wnNgYXnX7n/ehRfI01ueaXeLq/EMSYzS4f62I6MLiPFLpGcxJ9ScQ0p?= =?utf-8?q?dp8vFcjlaUQBw5FotcE9Y4kOdUFeAG1KgPJ6xNATDJUqt84ytvclLlUC9V+cNrU/D?= =?utf-8?q?B4qglZqCuHxm?= X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230040)(36860700013)(376014)(82310400026)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2024 08:28:16.6048 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c5efe31f-ffdc-4f99-44fd-08dce9cea7c2 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: AS8PR07MB7944 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 b1c18a5f56..a981db4b39 100644 --- a/lib/power/rte_power_pmd_mgmt.c +++ b/lib/power/rte_power_pmd_mgmt.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -69,7 +70,7 @@ struct __rte_cache_aligned pmd_core_cfg { uint64_t sleep_target; /**< Prevent a queue from triggering sleep multiple times */ }; -static struct pmd_core_cfg lcore_cfgs[RTE_MAX_LCORE]; +static RTE_LCORE_VAR_HANDLE(struct pmd_core_cfg, lcore_cfgs); static inline bool queue_equal(const union queue *l, const union queue *r) @@ -252,12 +253,11 @@ clb_multiwait(uint16_t port_id __rte_unused, uint16_t qidx __rte_unused, struct rte_mbuf **pkts __rte_unused, uint16_t nb_rx, uint16_t max_pkts __rte_unused, void *arg) { - const unsigned int lcore = rte_lcore_id(); struct queue_list_entry *queue_conf = arg; struct pmd_core_cfg *lcore_conf; const bool empty = nb_rx == 0; - lcore_conf = &lcore_cfgs[lcore]; + lcore_conf = RTE_LCORE_VAR_VALUE(lcore_cfgs); /* early exit */ if (likely(!empty)) @@ -317,13 +317,12 @@ clb_pause(uint16_t port_id __rte_unused, uint16_t qidx __rte_unused, struct rte_mbuf **pkts __rte_unused, uint16_t nb_rx, uint16_t max_pkts __rte_unused, void *arg) { - const unsigned int lcore = rte_lcore_id(); struct queue_list_entry *queue_conf = arg; struct pmd_core_cfg *lcore_conf; const bool empty = nb_rx == 0; uint32_t pause_duration = rte_power_pmd_mgmt_get_pause_duration(); - lcore_conf = &lcore_cfgs[lcore]; + lcore_conf = RTE_LCORE_VAR_VALUE(lcore_cfgs); if (likely(!empty)) /* early exit */ @@ -358,9 +357,8 @@ clb_scale_freq(uint16_t port_id __rte_unused, uint16_t qidx __rte_unused, struct rte_mbuf **pkts __rte_unused, uint16_t nb_rx, uint16_t max_pkts __rte_unused, void *arg) { - const unsigned int lcore = rte_lcore_id(); const bool empty = nb_rx == 0; - struct pmd_core_cfg *lcore_conf = &lcore_cfgs[lcore]; + struct pmd_core_cfg *lcore_conf = RTE_LCORE_VAR_VALUE(lcore_cfgs); struct queue_list_entry *queue_conf = arg; if (likely(!empty)) { @@ -518,7 +516,7 @@ rte_power_ethdev_pmgmt_queue_enable(unsigned int lcore_id, uint16_t port_id, goto end; } - lcore_cfg = &lcore_cfgs[lcore_id]; + lcore_cfg = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, lcore_cfgs); /* check if other queues are stopped as well */ ret = cfg_queues_stopped(lcore_cfg); @@ -619,7 +617,7 @@ rte_power_ethdev_pmgmt_queue_disable(unsigned int lcore_id, } /* no need to check queue id as wrong queue id would not be enabled */ - lcore_cfg = &lcore_cfgs[lcore_id]; + lcore_cfg = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, lcore_cfgs); /* check if other queues are stopped as well */ ret = cfg_queues_stopped(lcore_cfg); @@ -769,21 +767,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_VALUE(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 Fri Oct 11 08:19:00 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: 145743 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 A233C45B12; Fri, 11 Oct 2024 10:29:02 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 21DC44065D; Fri, 11 Oct 2024 10:28:32 +0200 (CEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2067.outbound.protection.outlook.com [40.107.20.67]) by mails.dpdk.org (Postfix) with ESMTP id 2822A402DC for ; Fri, 11 Oct 2024 10:28:23 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IgS7Q3xpwUJbEW+jSk61WBaXwRpSIjXPPgT7VJcxdNdo5BS7MAj43mGPYWSJkx+EHcLKX7HJA2FincBQ91sodpzTVyzp6DtdkEJO7rN7QiIfxZZ5aez+G1tOgMpJ46djlbf9GUHljJsABgVsdeyqaCEwhgj+wyouxcgOazKQOxS+Ex6Qg6wUk2MMcsIdGODyt+bCneKk/5PSGIE3fmtHRCGUMdfzOgQ1l2b7+np7GFOrc4Gne2yTeb2jJq3A7TU4cbExTxrZImT7RL6J43eSZiWkr2jEp+//E2G2WNcCUirGumUiwPm67YmtEjQ136oIx99+tyvPO/4OeYSWgdB6Vw== 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=ZkIKv5i0ytANi2Qv4NhA4vS3QvO0U4Y3yKKe5bexizg=; b=RjyaSXJH3blCPDsCB0iWiIsrNTONCf28IA9kCHyRjpRA+nxfNDxr20Yrke9fAQ6hBJnR41L5/Rttf2UPhzWo5eytA1NXr6/TA0JNQQusihy0/2af5aQieZkgQzq95EP/XCa6eAuexlCx6YddkXrOhd3mzcqf7gaXRACoY4kGS7vsBkWn3zoO36Q9K3rF+1WJoNe9WRL+3GL7gzcvc7UC5cDXZBc6ncd0YjbPl6drM5YPG15RwLqscv9DvRPVUD4j9Wzs70cpEMu9u+uYtO2xb1cYFMHaaUr6fQ8ICAv+7GYlBuovjCJUptB4RzSOVdaG4ykGkgMjMlrNiE9rfu6kIA== 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=ZkIKv5i0ytANi2Qv4NhA4vS3QvO0U4Y3yKKe5bexizg=; b=kN30ZxRgJ1i7AxADxmFHjHq2abQkNdDHP+yVWsMO7fJw5YGdZBJz4RZej4fE5mADI3aJqGIEPBs0yCamel2WBFsO0rUmFmSmokDWmpLKyONWokEjCVFgwcGld/gUAtDCU3hWdtXFfs0mlPSo3WZqR4byui6O2Sp6Fo4J7niHGiXavz+188BoMmqzLgpZuONUGsNlJJYY45hF7Z8tJhJuNcr6ExkJvAQriDxfCmKy1W74qQSe0dIcMIWzfdShOvAKCyqvGYMN6yfDbLvDgbQsUGykrCv8Ju3E54Nq9HSsr5b2IfQhmMbzMEXybzX3698BoYxICMgkUOHsKpHREFeLgw== Received: from AM4PR0302CA0013.eurprd03.prod.outlook.com (2603:10a6:205:2::26) by VI1PR07MB6399.eurprd07.prod.outlook.com (2603:10a6:800:137::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18; Fri, 11 Oct 2024 08:28:18 +0000 Received: from AMS0EPF000001AE.eurprd05.prod.outlook.com (2603:10a6:205:2:cafe::e8) by AM4PR0302CA0013.outlook.office365.com (2603:10a6:205:2::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.20 via Frontend Transport; Fri, 11 Oct 2024 08:28:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 192.176.1.74) smtp.mailfrom=ericsson.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ericsson.com; Received-SPF: Pass (protection.outlook.com: domain of ericsson.com designates 192.176.1.74 as permitted sender) receiver=protection.outlook.com; client-ip=192.176.1.74; helo=oa.msg.ericsson.com; pr=C Received: from oa.msg.ericsson.com (192.176.1.74) by AMS0EPF000001AE.mail.protection.outlook.com (10.167.16.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Fri, 11 Oct 2024 08:28:18 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.61) with Microsoft SMTP Server id 15.2.1544.11; Fri, 11 Oct 2024 10:28:16 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 21B5838007F; Fri, 11 Oct 2024 10:28:16 +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 v10 6/7] service: keep per-lcore state in lcore variable Date: Fri, 11 Oct 2024 10:19:00 +0200 Message-ID: <20241011081901.816211-7-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241011081901.816211-1-mattias.ronnblom@ericsson.com> References: <20241010142205.813134-2-mattias.ronnblom@ericsson.com> <20241011081901.816211-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AMS0EPF000001AE:EE_|VI1PR07MB6399:EE_ X-MS-Office365-Filtering-Correlation-Id: 3e07e4ed-b935-49ff-ca9f-08dce9cea8df X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?q?eY7l9VxKBL0gjStBoB4hlEuOvMyZXw0?= =?utf-8?q?5a3vf4lzGIO4bfE6xLY+v0Ii+BKB1Q5ttZbqEYZyqLH+FUXeE1Y7RBUjz9hrmAAFQ?= =?utf-8?q?YlvkA3swNT2MVe+HngMzBoIbiSBtVgqS9/EPip2EAcwjW6kpl/o2ARfHE+A9CdIuO?= =?utf-8?q?9chlvPLrfreyJ1CrcYoTKrrs08GAJZC45aF8FNGYEt+bv9M8U9f85ZYJxLaR1lKKS?= =?utf-8?q?6U+yv0hKSxwVK5lyCqPyut5Xg78Ao3qzyQL8A5J4C5XRnAtzNXKOi5K4oxY924Kec?= =?utf-8?q?QVNCXM5KliSEVCHwTqctf0K9SvmUFnn5xOn/QzIOQVT9iQxBNpLOdK9X81hvHLDbN?= =?utf-8?q?jGjfbWFB7D4MQ1bYnm9i+CtpfoYUs42BHlmtF2ANP8qLPzwfoNPbPS/OJ/zTS3HIL?= =?utf-8?q?/MIQdCMsymxaHD/co9PxnIUza+hAVS/ubYda805/469A/uX6myu7GlGEAfob3ogBG?= =?utf-8?q?Z9txOnnxkD4Inao9I0w4m+x6O1KVUuUw1CA9hq7zF4CoZhY3S2eb8HmLT181e7oT5?= =?utf-8?q?z0hWTcBAjLbVjNEPIur1afvxf6zmxmEDTUikwPyepNRbxdQ3G1VgoBRmB5+6fPuss?= =?utf-8?q?VqqS1+c5lv4Wb0tXIJMNJSigl485MuCqrGoecTJCdwwfpHQi2cBSv/BuTeRbSECT3?= =?utf-8?q?kPvN+XmXgUASw1XhaV4NHGrs5aJLN1Qh+0fdr0bfwP+x38DLlqc6fPGKlbFxqXLA/?= =?utf-8?q?V/HsxRdojZJbELdhZpD/vA5w8+nUG+k1veNYoDWaAfJ9RybG4i4RChOor4eDlnAiv?= =?utf-8?q?XfGeMBFNT/XjNADpOrSa1graQv/PIu1uT3xwCsUPQOFJ/ILvUyB8tXx4jXCQaAT68?= =?utf-8?q?QXSexJdLgGCrD0U3XASnICMLQgPrVtxVO16UOgfrqagOOVq4+i0uxfUhZhbsTlQ+B?= =?utf-8?q?7UWSoza0eTmgApDZi9x1HLqaXXC49U4K4b07aZXC399dQhSUk9gFVIWjtczX+xV97?= =?utf-8?q?XktcxiqoSuVPnP9LULKihKs0JebRx2ECdVc1Rs0XUVJAohVrDZ6zeNYCtsExqdwYg?= =?utf-8?q?ChdhIcldbHNCy/O/oO+dMe/5SFa4DEFlOsG3mTo9+tGt0Eh1Q98y14kX9hi69hOng?= =?utf-8?q?1g4hQK4eKUkZMAZxK2KTgDvNZZz+hZJk33AxIpj90oCKkrkIlCSFp43urLPDlExwH?= =?utf-8?q?yaW33dguPzFUZZ/PKbhcwi9ue+76ofYAzrjHqVKPKz5RaxttmCvYKLShNqmj469vr?= =?utf-8?q?ADa+Sh1S//RjGeVpcR7fJpPL9msdbqGSIWNC0gowkpMIhqEKYJUF95Jv6P029uOa7?= =?utf-8?q?IfvXzQ/nJaCf6lPFBAI0ztdAXb1C7HK5RTUz7VstLUcrRGPEACb0dA/Jomk98tVoE?= =?utf-8?q?MnqYSoC+qEc1?= 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)(36860700013)(376014)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2024 08:28:18.4759 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3e07e4ed-b935-49ff-ca9f-08dce9cea8df 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: AMS0EPF000001AE.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB6399 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 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 | 117 +++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 52 deletions(-) diff --git a/lib/eal/common/rte_service.c b/lib/eal/common/rte_service.c index a38c594ce4..3d2c12c39b 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 @@ -77,7 +78,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 @@ -103,12 +104,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(); @@ -124,7 +121,6 @@ rte_service_init(void) return 0; fail_mem: rte_free(rte_services); - rte_free(lcore_states); return -ENOMEM; } @@ -138,7 +134,6 @@ rte_service_finalize(void) rte_eal_mp_wait_lcore(); rte_free(rte_services); - rte_free(lcore_states); rte_service_library_initialized = 0; } @@ -288,7 +283,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); @@ -296,9 +290,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++) - lcore_states[i].service_mask &= ~(UINT64_C(1) << id); + RTE_LCORE_VAR_FOREACH_VALUE(lcore_id, cs, lcore_states) + cs->service_mask &= ~(UINT64_C(1) << id); memset(&rte_services[id], 0, sizeof(struct rte_service_spec_impl)); @@ -467,7 +463,10 @@ rte_service_may_be_active(uint32_t id) return -EINVAL; for (i = 0; i < lcore_count; i++) { - if (lcore_states[ids[i]].service_active_on_lcore[id]) + struct core_state *cs = + RTE_LCORE_VAR_LCORE_VALUE(ids[i], lcore_states); + + if (cs->service_active_on_lcore[id]) return 1; } @@ -477,7 +476,7 @@ rte_service_may_be_active(uint32_t id) int32_t rte_service_run_iter_on_app_lcore(uint32_t id, uint32_t serialize_mt_unsafe) { - struct core_state *cs = &lcore_states[rte_lcore_id()]; + struct core_state *cs = RTE_LCORE_VAR_VALUE(lcore_states); struct rte_service_spec_impl *s; SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL); @@ -499,8 +498,7 @@ service_runner_func(void *arg) { RTE_SET_USED(arg); uint8_t i; - const int lcore = rte_lcore_id(); - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_VALUE(lcore_states); rte_atomic_store_explicit(&cs->thread_active, 1, rte_memory_order_seq_cst); @@ -546,13 +544,15 @@ service_runner_func(void *arg) int32_t rte_service_lcore_may_be_active(uint32_t lcore) { - if (lcore >= RTE_MAX_LCORE || !lcore_states[lcore].is_service_core) + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); + + if (lcore >= RTE_MAX_LCORE || !cs->is_service_core) return -EINVAL; /* Load thread_active using ACQUIRE to avoid instructions dependent on * the result being re-ordered before this load completes. */ - return rte_atomic_load_explicit(&lcore_states[lcore].thread_active, + return rte_atomic_load_explicit(&cs->thread_active, rte_memory_order_acquire); } @@ -560,9 +560,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_VALUE(lcore_id, cs, lcore_states) + count += cs->is_service_core; + return count; } @@ -579,7 +582,8 @@ rte_service_lcore_list(uint32_t array[], uint32_t n) uint32_t i; uint32_t idx = 0; for (i = 0; i < RTE_MAX_LCORE; i++) { - struct core_state *cs = &lcore_states[i]; + struct core_state *cs = + RTE_LCORE_VAR_LCORE_VALUE(i, lcore_states); if (cs->is_service_core) { array[idx] = i; idx++; @@ -595,7 +599,7 @@ rte_service_lcore_count_services(uint32_t lcore) if (lcore >= RTE_MAX_LCORE) return -EINVAL; - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); if (!cs->is_service_core) return -ENOTSUP; @@ -647,30 +651,31 @@ rte_service_start_with_defaults(void) static int32_t service_update(uint32_t sid, uint32_t lcore, uint32_t *set, uint32_t *enabled) { + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); + /* validate ID, or return error value */ if (!service_valid(sid) || lcore >= RTE_MAX_LCORE || - !lcore_states[lcore].is_service_core) + !cs->is_service_core) return -EINVAL; uint64_t sid_mask = UINT64_C(1) << sid; if (set) { - uint64_t lcore_mapped = lcore_states[lcore].service_mask & - sid_mask; + uint64_t lcore_mapped = cs->service_mask & sid_mask; if (*set && !lcore_mapped) { - lcore_states[lcore].service_mask |= sid_mask; + cs->service_mask |= sid_mask; rte_atomic_fetch_add_explicit(&rte_services[sid].num_mapped_cores, 1, rte_memory_order_relaxed); } if (!*set && lcore_mapped) { - lcore_states[lcore].service_mask &= ~(sid_mask); + cs->service_mask &= ~(sid_mask); rte_atomic_fetch_sub_explicit(&rte_services[sid].num_mapped_cores, 1, rte_memory_order_relaxed); } } if (enabled) - *enabled = !!(lcore_states[lcore].service_mask & (sid_mask)); + *enabled = !!(cs->service_mask & (sid_mask)); return 0; } @@ -698,13 +703,14 @@ set_lcore_state(uint32_t lcore, int32_t state) { /* mark core state in hugepage backed config */ struct rte_config *cfg = rte_eal_get_configuration(); + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); cfg->lcore_role[lcore] = state; /* mark state in process local lcore_config */ lcore_config[lcore].core_role = state; /* update per-lcore optimized state tracking */ - lcore_states[lcore].is_service_core = (state == ROLE_SERVICE); + cs->is_service_core = (state == ROLE_SERVICE); rte_eal_trace_service_lcore_state_change(lcore, state); } @@ -715,14 +721,16 @@ rte_service_lcore_reset_all(void) /* loop over cores, reset all to mask 0 */ uint32_t i; for (i = 0; i < RTE_MAX_LCORE; i++) { - if (lcore_states[i].is_service_core) { - lcore_states[i].service_mask = 0; + struct core_state *cs = + RTE_LCORE_VAR_LCORE_VALUE(i, lcore_states); + if (cs->is_service_core) { + cs->service_mask = 0; set_lcore_state(i, ROLE_RTE); /* runstate act as guard variable Use * store-release memory order here to synchronize * with load-acquire in runstate read functions. */ - rte_atomic_store_explicit(&lcore_states[i].runstate, + rte_atomic_store_explicit(&cs->runstate, RUNSTATE_STOPPED, rte_memory_order_release); } } @@ -738,17 +746,19 @@ rte_service_lcore_add(uint32_t lcore) { if (lcore >= RTE_MAX_LCORE) return -EINVAL; - if (lcore_states[lcore].is_service_core) + + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); + if (cs->is_service_core) return -EALREADY; set_lcore_state(lcore, ROLE_SERVICE); /* ensure that after adding a core the mask and state are defaults */ - lcore_states[lcore].service_mask = 0; + cs->service_mask = 0; /* Use store-release memory order here to synchronize with * load-acquire in runstate read functions. */ - rte_atomic_store_explicit(&lcore_states[lcore].runstate, RUNSTATE_STOPPED, + rte_atomic_store_explicit(&cs->runstate, RUNSTATE_STOPPED, rte_memory_order_release); return rte_eal_wait_lcore(lcore); @@ -760,7 +770,7 @@ rte_service_lcore_del(uint32_t lcore) if (lcore >= RTE_MAX_LCORE) return -EINVAL; - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); if (!cs->is_service_core) return -EINVAL; @@ -784,7 +794,7 @@ rte_service_lcore_start(uint32_t lcore) if (lcore >= RTE_MAX_LCORE) return -EINVAL; - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); if (!cs->is_service_core) return -EINVAL; @@ -814,6 +824,8 @@ rte_service_lcore_start(uint32_t lcore) int32_t rte_service_lcore_stop(uint32_t lcore) { + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); + if (lcore >= RTE_MAX_LCORE) return -EINVAL; @@ -821,12 +833,11 @@ rte_service_lcore_stop(uint32_t lcore) * memory order here to synchronize with store-release * in runstate update functions. */ - if (rte_atomic_load_explicit(&lcore_states[lcore].runstate, rte_memory_order_acquire) == + if (rte_atomic_load_explicit(&cs->runstate, rte_memory_order_acquire) == RUNSTATE_STOPPED) return -EALREADY; uint32_t i; - struct core_state *cs = &lcore_states[lcore]; uint64_t service_mask = cs->service_mask; for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) { @@ -847,7 +858,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); @@ -858,7 +869,7 @@ rte_service_lcore_stop(uint32_t lcore) static uint64_t lcore_attr_get_loops(unsigned int lcore) { - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); return rte_atomic_load_explicit(&cs->loops, rte_memory_order_relaxed); } @@ -866,7 +877,7 @@ lcore_attr_get_loops(unsigned int lcore) static uint64_t lcore_attr_get_cycles(unsigned int lcore) { - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); return rte_atomic_load_explicit(&cs->cycles, rte_memory_order_relaxed); } @@ -874,7 +885,7 @@ lcore_attr_get_cycles(unsigned int lcore) static uint64_t lcore_attr_get_service_calls(uint32_t service_id, unsigned int lcore) { - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); return rte_atomic_load_explicit(&cs->service_stats[service_id].calls, rte_memory_order_relaxed); @@ -901,7 +912,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_VALUE(lcore, lcore_states); return rte_atomic_load_explicit(&cs->service_stats[service_id].cycles, rte_memory_order_relaxed); @@ -917,7 +928,10 @@ attr_get(uint32_t id, lcore_attr_get_fun lcore_attr_get) uint64_t sum = 0; for (lcore = 0; lcore < RTE_MAX_LCORE; lcore++) { - if (lcore_states[lcore].is_service_core) + struct core_state *cs = + RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); + + if (cs->is_service_core) sum += lcore_attr_get(id, lcore); } @@ -979,12 +993,11 @@ int32_t rte_service_lcore_attr_get(uint32_t lcore, uint32_t attr_id, uint64_t *attr_value) { - struct core_state *cs; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); if (lcore >= RTE_MAX_LCORE || !attr_value) return -EINVAL; - cs = &lcore_states[lcore]; if (!cs->is_service_core) return -ENOTSUP; @@ -1009,7 +1022,8 @@ rte_service_attr_reset_all(uint32_t id) return -EINVAL; for (lcore = 0; lcore < RTE_MAX_LCORE; lcore++) { - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = + RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); cs->service_stats[id] = (struct service_stats) {}; } @@ -1020,12 +1034,11 @@ rte_service_attr_reset_all(uint32_t id) int32_t rte_service_lcore_attr_reset_all(uint32_t lcore) { - struct core_state *cs; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); if (lcore >= RTE_MAX_LCORE) return -EINVAL; - cs = &lcore_states[lcore]; if (!cs->is_service_core) return -ENOTSUP; @@ -1060,7 +1073,7 @@ static void service_dump_calls_per_lcore(FILE *f, uint32_t lcore) { uint32_t i; - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); fprintf(f, "%02d\t", lcore); for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) { From patchwork Fri Oct 11 08:19:01 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: 145738 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 B04A445B12; Fri, 11 Oct 2024 10:28:29 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 29B1A40395; Fri, 11 Oct 2024 10:28:25 +0200 (CEST) Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03on2042.outbound.protection.outlook.com [40.107.103.42]) by mails.dpdk.org (Postfix) with ESMTP id BBD8F402E2 for ; Fri, 11 Oct 2024 10:28:20 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=i2GaPyzV5xm6saaFNuiDcrcMC5BfD3tW0y4hzzzmH7U0smkbKETRnU0Wiw0MNtaGebTtdExLWSUh1EmNJ476R5NiGl6NYrFURUULYSR81AhPwhsDy7K0YBC72/oca+AESQbBEMc38k8E81KAKWDPd0ZrrWJNzLhyt8Vw8hr1kvOLMpkKM1gcIZJ+ULwsaGv8jSisWK6d/9xOUBBYo98m0cLpf+dgCRZ5lsj5x1f1jeCU2uGVZ8r+GmcqBqvRizqXeOXDkqF6b5E+Bd53KJ39S0JexqZJM9ltfV93sIAv41CVPFqUQ6sZ0g4g7MX4L5qOZtJCt5YEiXBI68YeWN15mw== 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=PTgJESNpXPAbYyilhrJD+JxRLMhMHZz2uCopWS6Fc6Y=; b=F1/3SuDwW2rl0HFjonfpL39DIJIcfR+IKkmZUpj8121yFw0pdj+lQO+p65Wad3demAgdKytOoL6eYsuCYV38fy5+DhHAMVSJYeISK6cCCOBiWa2mBMFG7vJ4b7RoiyVDftjJ1dWL0OxKfapEQ7QYxCnxeCGySwqksfEvnY2O0XPqe/J9j1DtSqjLPkKfKWt6vsmaDZvGqHhvS1O49eDAUX4Q0Z7oSqRZ+BOPfrREg6a+8mgymy0kFcpzplj03pzzP/aZZXqHp5bcrUkwaq/X91AVRS+TznD/oq/0Os3wXWHObW20C4v89WxYy8sV9rtqhkxs+ZV4E/c7oBQzKtjL6Q== 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=PTgJESNpXPAbYyilhrJD+JxRLMhMHZz2uCopWS6Fc6Y=; b=NQziRtGOfWdACkI7xUtUD/tbEppXHNNzwLTe/U3ZGWOIFzpaN9Kzn7psFS1pDZiNvjH7sKaTrSgeXfZKDTOjgl29JELzFmNzsDjpaLJLs4XAo+CVRZBi5zYWLzBKZVZ45OVp6FIua6gcSrg7p/XhhZ8400ugmHSMtX503tzsAm+1Q2md++643oaATBdiYSiTtErK4ikBEl4EH64+eYzbgHHymTkjrtfw6uTa4+NPmcFyykTb+BVFXQsbN6jBjOHua4voLxgpqq+CBSy6Ns5gkj6dPfIVTT2y380JUYGSi9xCdLLAU2z/AkKmeKrWTPkLrussKTywp9z6hY9+DEM7+A== Received: from DUZPR01CA0275.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b9::6) by DUZPR07MB9980.eurprd07.prod.outlook.com (2603:10a6:10:4af::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18; Fri, 11 Oct 2024 08:28:17 +0000 Received: from DB1PEPF000509F4.eurprd02.prod.outlook.com (2603:10a6:10:4b9:cafe::2a) by DUZPR01CA0275.outlook.office365.com (2603:10a6:10:4b9::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.20 via Frontend Transport; Fri, 11 Oct 2024 08:28:17 +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.8048.13 via Frontend Transport; Fri, 11 Oct 2024 08:28:17 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.69) with Microsoft SMTP Server id 15.2.1544.11; Fri, 11 Oct 2024 10:28:16 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 35ADA380070; Fri, 11 Oct 2024 10:28:16 +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 v10 7/7] eal: keep per-lcore power intrinsics state in lcore variable Date: Fri, 11 Oct 2024 10:19:01 +0200 Message-ID: <20241011081901.816211-8-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241011081901.816211-1-mattias.ronnblom@ericsson.com> References: <20241010142205.813134-2-mattias.ronnblom@ericsson.com> <20241011081901.816211-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB1PEPF000509F4:EE_|DUZPR07MB9980:EE_ X-MS-Office365-Filtering-Correlation-Id: f8c7f828-0e49-44fd-a163-08dce9cea840 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|36860700013|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?q?KQzKxCY2gYUk9ZO0xWWS001btPvgJ9l?= =?utf-8?q?sfohpxHVrPdsaRXgn7uEI8H1jx7GC5bJ4ezBZpMDx+tZ6KoOunb9Ipf2LvlgCFxnP?= =?utf-8?q?dPqtAazIdcQQGQgsVzZRMu//TlFsbgOCuKqYfBV2b/ZrUh9jX4924T8fDSYS2tOsU?= =?utf-8?q?rPJn5XWMxuXlV55a4PIhPHs6xu4lBuuxZvvSdhJQmrWtnWLYvLDqaDqGSiLaOnerw?= =?utf-8?q?kX0+xodeVwr9hFmXgoZOw2PX3+9klvNKr0RAM6Jik52ObPK0O94fHX0EydLgu34BU?= =?utf-8?q?mo/gjaGtRKUTiDEnngWJ6bL3B9IFN2Tnz7LlYAwvvKwbo4ec5isGgbn6n/1nz6UP2?= =?utf-8?q?SRMlX0YVzbnz515jYh8YUYYawBj/+R876LQidBbRDusxwNXH7DiiRMEevA23uJMBp?= =?utf-8?q?ZbaWqY+uUq3qOpZ3WM349Yth3bzSR4doPD9gKS+QQ2nW6uBnsFcIawBhyZGKshsMk?= =?utf-8?q?xYPF7H9f9GBiyg9JrvoDC5Pwm6eitr1LhCpYj73N4E/WLU1+K2cCpPkr4HvVnhoDp?= =?utf-8?q?U/IaTHFA93a3cPuNVEEqlwMBZYeXI8XNYdWHO7w5YiLMG73dSA0RUrmBFCwkLBweo?= =?utf-8?q?kHRO8cIOVp1VEweoOoWdyRzdzBgw2PA0sIFdhZenFARlPqhGYXClb+U+90qQ65Aop?= =?utf-8?q?AtuQ1Znp/a1cpAwQqNMr3u/a3oGdNRM6PRd7zKtp0H9wTGYZlWklOcaIJYQ+LiCXn?= =?utf-8?q?bUTEitUJS6jKR7qi9jNILd8MtJX1tx1Hx6OYl6qcycxUsXc2iXU+CpbAF6HGOT2Yv?= =?utf-8?q?9WjRHNHLy97pcCHSGjADy7MtwZvUb/ZK4ukB2+5DqQSonhnEQvjPHj3RniSMkWg/f?= =?utf-8?q?gZokfe4FpwzbxrBF3jbC1irp0OudL1/8j9Z+7gKvldVE8jX4KNgxTzGBfwLXf+cNM?= =?utf-8?q?5sE+BpFPouPK3gubL46dR1Djo/N5/qE6cQlyXQF83I6FUqj48ATaGJ3lDnFtVw/d/?= =?utf-8?q?C92PTkNmwJNmlT1TKMjKmHrFqRZZkcAw7mOgkXeRaYqdsDC6AyE13ur0iO3L8/y6D?= =?utf-8?q?VoWPgYjVAhsjLPhN1mI8j5zPt3Lvh7Vc49gy52GZ41fxAtAw7t/HN5Rl0PxbIhWQK?= =?utf-8?q?S/EYmht34osP01hcUyND+Q3NsuF0zPKNVoCD/KcJVzKOBybxZlEr0Hmcely54pc2a?= =?utf-8?q?EQJ0c6/YjlIJQabGbqjOUWj8ldJ7lu9ZsAsiSGpohBVz9tcCjr8C1GlNpVoENc3Ff?= =?utf-8?q?plPLrxBvCX7N2fyoHgsD8QEOn24PhzTcnGM0pTKpxMdIJ42ma375/7G4MWCVEd698?= =?utf-8?q?AeRb67oalmjeEUIgXix/9RDaz9YC0ayiOhMVIimlacDmpO6LXilPNJ9s=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)(82310400026)(36860700013)(376014)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2024 08:28:17.4329 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f8c7f828-0e49-44fd-a163-08dce9cea840 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: DUZPR07MB9980 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..f4ba2c8ecb 100644 --- a/lib/eal/x86/rte_power_intrinsics.c +++ b/lib/eal/x86/rte_power_intrinsics.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -14,10 +15,14 @@ /* * Per-lcore structure holding current status of C0.2 sleeps. */ -static alignas(RTE_CACHE_LINE_SIZE) struct power_wait_status { +struct power_wait_status { rte_spinlock_t lock; volatile void *monitor_addr; /**< NULL if not currently sleeping */ -} wait_status[RTE_MAX_LCORE]; +}; + +RTE_LCORE_VAR_HANDLE(struct power_wait_status, wait_status); + +RTE_LCORE_VAR_INIT(wait_status); /* * This function uses UMONITOR/UMWAIT instructions and will enter C0.2 state. @@ -172,7 +177,7 @@ rte_power_monitor(const struct rte_power_monitor_cond *pmc, if (pmc->fn == NULL) return -EINVAL; - s = &wait_status[lcore_id]; + s = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, wait_status); /* update sleep address */ rte_spinlock_lock(&s->lock); @@ -264,7 +269,7 @@ rte_power_monitor_wakeup(const unsigned int lcore_id) if (lcore_id >= RTE_MAX_LCORE) return -EINVAL; - s = &wait_status[lcore_id]; + s = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, wait_status); /* * There is a race condition between sleep, wakeup and locking, but we @@ -303,8 +308,8 @@ int rte_power_monitor_multi(const struct rte_power_monitor_cond pmc[], const uint32_t num, const uint64_t tsc_timestamp) { - const unsigned int lcore_id = rte_lcore_id(); - struct power_wait_status *s = &wait_status[lcore_id]; + struct power_wait_status *s = RTE_LCORE_VAR_VALUE(wait_status); + uint32_t i, rc; /* check if supported */