From patchwork Mon May 6 08:27:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Mattias_R=C3=B6nnblom?= X-Patchwork-Id: 139875 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 8DEEE43FC4; Mon, 6 May 2024 10:38:39 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 614FB402DE; Mon, 6 May 2024 10:38:29 +0200 (CEST) Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2069.outbound.protection.outlook.com [40.107.105.69]) by mails.dpdk.org (Postfix) with ESMTP id A6FC4402E3 for ; Mon, 6 May 2024 10:38:24 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dS+C9u8m9W0JknwdUQp4DFGAq7qQFFxCFMsmRWZJq80On/+YRPATkBFVgtq1O55QPXPG+RY+e71aqy4Oij+sEb8Zvn7EUYAjvovWTCqWGTIMon+wz7QNNMsQY7ytSq/dX/8aPZ3iMxGI9H7CmK/oAt+jR4LpzTTWfra4kcDcNQq5eVUS49HzKuovEK9juYX4SI/PkAk5B9AhOEXz3EgST/+isTiwjxEEEstImZFw7iQmEv904RWu4e8Slpc626ictzY303Yo1YwaI0Bbwa5o5W3PtwVPD/TG4YPrvUxsNJTs9wTPS08OlltluGuQ/N/Qhlo4nw7RXUAmdADdOiatNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Pi0Be68i6HR4ePPvYDIqPdNgajcHLYV4RMNSHj2EC5k=; b=Tv6VbqNbCWQxNLGVbflBVwVGpRe2u8qWkpVBQTe24gCyh/co6J/uyyNO0M2F+DFehVimCe6VPLCclfa2gX9WrYBjjzM7eRIcteug5PzbnfGEyexwWhmaFPPpQvuKsiTf2hdkjY+f2a7FBB2XoC3NiIPkbOp1uQNw8lQtxCFTLrWYe96Qw811V3II38SFycMleldYlh6MXR7SlVfLrwdYDeBUs7c3S2hB+Z33iceQX9wMQgjjIY3d4dCmBy3IGJT0Z2Gd4pPYxDcx7B9BeIQjRAoDeDRfy3e2bYkdFmzjHjSiydzazT8kS6pc5/QVqKxsmDWUPVIQ7KWHTehTpn8AeA== 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=Pi0Be68i6HR4ePPvYDIqPdNgajcHLYV4RMNSHj2EC5k=; b=adjYzdBzUmu1jpjIvn1j7bYpHLCI8qvwHNp46Bp/a0LVFPFNEkLQvTxPGc7GFOh9pnFCq56cJw027bT+p2nE14Ax25q/f+zHyqkNfreH4uUIyLpA4pt6ZOOOGKlfCLy0Mo8WRqY2nDxMoKrsW1+QtdlftdG1n/beZnE6SDjhQMnvz353S0Vqw30gbZjbDA6Oi26RDSjErYa//nmHxa1C3rWs5c76NapWXsm38iS+yomBOhJebTlf4usU1H8ZuhUvCNSkPAQQjIw+O5Phi/GOIG+slCKNf55g3BxAbsQiTo18rGo6/XW9Hsi4Pn476bZ4fbkrC7uGuDwE8K9SZIlLZQ== Received: from DU6P191CA0033.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:53f::8) by VI1PR0701MB6816.eurprd07.prod.outlook.com (2603:10a6:800:19e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.42; Mon, 6 May 2024 08:38:22 +0000 Received: from DU2PEPF00028D04.eurprd03.prod.outlook.com (2603:10a6:10:53f:cafe::2c) by DU6P191CA0033.outlook.office365.com (2603:10a6:10:53f::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.42 via Frontend Transport; Mon, 6 May 2024 08:38:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 192.176.1.74) smtp.mailfrom=ericsson.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ericsson.com; Received-SPF: Pass (protection.outlook.com: domain of ericsson.com designates 192.176.1.74 as permitted sender) receiver=protection.outlook.com; client-ip=192.176.1.74; helo=oa.msg.ericsson.com; pr=C Received: from oa.msg.ericsson.com (192.176.1.74) by DU2PEPF00028D04.mail.protection.outlook.com (10.167.242.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.19 via Frontend Transport; Mon, 6 May 2024 08:38:22 +0000 Received: from seliicinfr00050.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.9; Mon, 6 May 2024 10:38:21 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 4EBE71C006A; Mon, 6 May 2024 10:38:21 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , =?utf-8?q?Morten_Br=C3=B8rup?= , Stephen Hemminger , Konstantin Ananyev , =?utf-8?q?Mattias_R?= =?utf-8?q?=C3=B6nnblom?= Subject: [RFC v6 1/6] eal: add static per-lcore memory allocation facility Date: Mon, 6 May 2024 10:27:16 +0200 Message-ID: <20240506082721.120666-2-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240506082721.120666-1-mattias.ronnblom@ericsson.com> References: <20240228100928.524277-2-mattias.ronnblom@ericsson.com> <20240506082721.120666-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PEPF00028D04:EE_|VI1PR0701MB6816:EE_ X-MS-Office365-Filtering-Correlation-Id: 74837f87-7b83-44f0-2ca7-08dc6da7e394 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|376005|1800799015|36860700004|82310400017; X-Microsoft-Antispam-Message-Info: =?utf-8?q?uIH+I4oEU53KkT4tgdkgJv2vRcURuc5?= =?utf-8?q?fEzq/WEEaJAOdARw3XqJiLUDpJHpvBfRR+FKawHFGyl4IexuVDE7IYWvkNlv0Z0qB?= =?utf-8?q?8tkIUlTGI+1uu+SxrDBQIX7G450M32BXdiLB9IMt8MeZSJabRA8QWOpqP8++tqFNU?= =?utf-8?q?DrgXvV33r9d7A8DNWBw/d/e+TQ6pOhlgMdV+ao9aZqmDBpyeeYwDqeah04Dx8LqFk?= =?utf-8?q?lzz77eTNj/F5LXUcaaANWjzKx+0ePh1OkE+MhmkYwaQ2Rw0eQ0PKgC1mtVUsNfrx7?= =?utf-8?q?Tow2NCBVr/VTSkdz/iKky2XZIQbkFt4I70LZ630foL5xnlt8ydpn0hgSQRYV0r5y4?= =?utf-8?q?Lo/8NXArsggjSVw0vW5AR/w2HIQCu9gztyZlsYpQi9cGrwJSftL5zLSLYZS8w6wqO?= =?utf-8?q?D71BUX4LZ36jUgCjoiO3nKkJqGLcUX3Tuo2C6e/HksTiGsCdY1y6i3yRkdq9KhR9d?= =?utf-8?q?it5Sj2VuFvGYwaLGRdodBpLHCLbaImNnP0ys+iTjIo7p8xCNol+nuFK9n3zy14OKt?= =?utf-8?q?w5CFG8+dwnFRJ1THJmhIgBiwnBX9rtZhRZToAgzQsYCDNMYGSHDPDr6R80u33+10d?= =?utf-8?q?YnPXYHCueyXwNVHSybmMV0M+K7ddG0tbJBXbSQwr1ZIBwcUTX+pJxU/XRF2hDYhyh?= =?utf-8?q?IIEu8ti63QIOhh+gDJ9C3pcXdED8KdqqoAwDaXZAWmQe7D60Rf9g/qzfNFA6/fzed?= =?utf-8?q?dhUC+fRIPDDRyvX7uMHKPUS4/VsIR4PEWpxhSgVMPeXup7Kum+dfojTBet1wvSPjS?= =?utf-8?q?QcNp7rOPa7Xp0P/wCYsffGq0F5U//yQM4l3FuZwC/1yOwlKO8/e6AS3KDNok9F83t?= =?utf-8?q?fy9zH5KF5jetzDbxJq25ezc9C/NF96uuZClDFtNQeZP0q9/59Biw1mP+HarRGDzsc?= =?utf-8?q?Yr8tPrA9Aw4KlxfvyFbOK4hvVkYKUstNjk0F4ZrjIHLx0bHBbTm1eLe7onTS+bYKb?= =?utf-8?q?9PfrJast+WVWxPaKg/6UyLy3OpIrzbBoDm5lZ6rXVGmiN6Kip+yglvyqCOT5CLNN3?= =?utf-8?q?AH5wOftPHhoyx2238AhJHM4EMGNFOzh7tYABtpORP2Tt6a+Y+nxYlfbHR+FVWDUzr?= =?utf-8?q?cWO202aplW1UvFxJO1uMzjNIOKFFNzafflnzEZC1DhG7K9LYBGo0NIDzGVTpVAQCI?= =?utf-8?q?BYnQd8UPpJ/pR3Z7jAGKJYC+JgGLxBbxM6AgdMSaGpSsyfHyG4Zt57Zhqu+mPd+cl?= =?utf-8?q?sIpW3inSFd4hu4VZkqLWsjaGijcwCGbsCYAYrYKPqwL0rS2cXZ1kqFFr8IHR/Tk9s?= =?utf-8?q?gqC3rf/2d14MEDNxj93vsJ4sH78JdcmkBjfknOSaVRXqhDFp+dOrjBmFBg6J3anAJ?= =?utf-8?q?mGT+2d+jNPkv?= X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230031)(376005)(1800799015)(36860700004)(82310400017); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 May 2024 08:38:22.4091 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 74837f87-7b83-44f0-2ca7-08dc6da7e394 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: DU2PEPF00028D04.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0701MB6816 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 chunks of often-used data, which is related logically, but where there are performance benefits to reap from having updates being local to an 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. 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. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup --- config/rte_config.h | 1 + doc/api/doxy-api-index.md | 1 + lib/eal/common/eal_common_lcore_var.c | 69 +++++ lib/eal/common/meson.build | 1 + lib/eal/include/meson.build | 1 + lib/eal/include/rte_lcore_var.h | 384 ++++++++++++++++++++++++++ lib/eal/version.map | 3 + 7 files changed, 460 insertions(+) create mode 100644 lib/eal/common/eal_common_lcore_var.c create mode 100644 lib/eal/include/rte_lcore_var.h diff --git a/config/rte_config.h b/config/rte_config.h index dd7bb0d35b..311692e498 100644 --- a/config/rte_config.h +++ b/config/rte_config.h @@ -41,6 +41,7 @@ /* EAL defines */ #define RTE_CACHE_GUARD_LINES 1 #define RTE_MAX_HEAPS 32 +#define RTE_MAX_LCORE_VAR 1048576 #define RTE_MAX_MEMSEG_LISTS 128 #define RTE_MAX_MEMSEG_PER_LIST 8192 #define RTE_MAX_MEM_MB_PER_LIST 32768 diff --git a/doc/api/doxy-api-index.md b/doc/api/doxy-api-index.md index 8c1eb8fafa..a3b8391570 100644 --- a/doc/api/doxy-api-index.md +++ b/doc/api/doxy-api-index.md @@ -99,6 +99,7 @@ The public API headers are grouped by topics: [interrupts](@ref rte_interrupts.h), [launch](@ref rte_launch.h), [lcore](@ref rte_lcore.h), + [lcore-varible](@ref rte_lcore_var.h), [per-lcore](@ref rte_per_lcore.h), [service cores](@ref rte_service.h), [keepalive](@ref rte_keepalive.h), diff --git a/lib/eal/common/eal_common_lcore_var.c b/lib/eal/common/eal_common_lcore_var.c new file mode 100644 index 0000000000..74ad8272ec --- /dev/null +++ b/lib/eal/common/eal_common_lcore_var.c @@ -0,0 +1,69 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 Ericsson AB + */ + +#include +#include + +#include +#include +#include + +#include + +#include "eal_private.h" + +#define LCORE_BUFFER_SIZE (RTE_MAX_LCORE_VAR * RTE_MAX_LCORE) + +static void *lcore_buffer; +static size_t offset = RTE_MAX_LCORE_VAR; + +static void * +lcore_var_alloc(size_t size, size_t align) +{ + void *handle; + void *value; + + offset = RTE_ALIGN_CEIL(offset, align); + + if (offset + size > RTE_MAX_LCORE_VAR) { + lcore_buffer = aligned_alloc(RTE_CACHE_LINE_SIZE, + LCORE_BUFFER_SIZE); + RTE_VERIFY(lcore_buffer != NULL); + + offset = 0; + } + + handle = RTE_PTR_ADD(lcore_buffer, offset); + + offset += size; + + RTE_LCORE_VAR_FOREACH_VALUE(value, handle) + memset(value, 0, size); + + EAL_LOG(DEBUG, "Allocated %"PRIuPTR" bytes of per-lcore data with a " + "%"PRIuPTR"-byte alignment", size, align); + + return handle; +} + +void * +rte_lcore_var_alloc(size_t size, size_t align) +{ + /* Having the per-lcore buffer size aligned on cache lines + * assures as well as having the base pointer aligned on cache + * size assures that aligned offsets also translate to alipgned + * pointers across all values. + */ + RTE_BUILD_BUG_ON(RTE_MAX_LCORE_VAR % RTE_CACHE_LINE_SIZE != 0); + RTE_ASSERT(align <= RTE_CACHE_LINE_SIZE); + RTE_ASSERT(size <= RTE_MAX_LCORE_VAR); + + /* '0' means asking for worst-case alignment requirements */ + if (align == 0) + align = alignof(max_align_t); + + RTE_ASSERT(rte_is_power_of_2(align)); + + return lcore_var_alloc(size, align); +} diff --git a/lib/eal/common/meson.build b/lib/eal/common/meson.build index 22a626ba6f..d41403680b 100644 --- a/lib/eal/common/meson.build +++ b/lib/eal/common/meson.build @@ -18,6 +18,7 @@ sources += files( 'eal_common_interrupts.c', 'eal_common_launch.c', 'eal_common_lcore.c', + 'eal_common_lcore_var.c', 'eal_common_mcfg.c', 'eal_common_memalloc.c', 'eal_common_memory.c', diff --git a/lib/eal/include/meson.build b/lib/eal/include/meson.build index e94b056d46..9449253e23 100644 --- a/lib/eal/include/meson.build +++ b/lib/eal/include/meson.build @@ -27,6 +27,7 @@ headers += files( 'rte_keepalive.h', 'rte_launch.h', 'rte_lcore.h', + 'rte_lcore_var.h', 'rte_lock_annotations.h', 'rte_malloc.h', 'rte_mcslock.h', diff --git a/lib/eal/include/rte_lcore_var.h b/lib/eal/include/rte_lcore_var.h new file mode 100644 index 0000000000..cfbcac41dd --- /dev/null +++ b/lib/eal/include/rte_lcore_var.h @@ -0,0 +1,384 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 Ericsson AB + */ + +#ifndef _RTE_LCORE_VAR_H_ +#define _RTE_LCORE_VAR_H_ + +/** + * @file + * + * RTE Per-lcore id variables + * + * This API provides a mechanism to create and access per-lcore id + * variables in a space- and cycle-efficient manner. + * + * A per-lcore id variable (or lcore variable for short) has one value + * for each EAL thread and registered non-EAL thread. There is one + * copy for each current and future lcore id-equipped thread, with the + * total number of copies amounting to @c RTE_MAX_LCORE. The value of + * an lcore variable for a particular lcore id is independent from + * other values (for other lcore ids) within the same lcore variable. + * + * In order to access the values of an lcore variable, a handle is + * used. The type of the handle is a pointer to the value's type + * (e.g., for @c uint32_t lcore variable, the handle is a + * uint32_t *. The handler type is used to inform the + * access macros the type of the values. A handle may be passed + * between modules and threads just like any pointer, but its value + * must be treated as a an opaque identifier. An allocated handle + * never has the value NULL. + * + * @b Creation + * + * An lcore variable is created in two steps: + * 1. Define a lcore variable handle by using @ref RTE_LCORE_VAR_HANDLE. + * 2. Allocate lcore variable storage and initialize the handle with + * a unique identifier by @ref RTE_LCORE_VAR_ALLOC or + * @ref RTE_LCORE_VAR_INIT. Allocation generally occurs the time of + * module initialization, but may be done at any time. + * + * An lcore variable is not tied to the owning thread's lifetime. It's + * available for use by any thread immediately after having been + * allocated, and continues to be available throughout the lifetime of + * the EAL. + * + * Lcore variables cannot and need not be freed. + * + * @b Access + * + * The value of any lcore variable for any lcore id may be accessed + * from any thread (including unregistered threads), but it should + * only be *frequently* read from or written to by the owner. + * + * Values of the same lcore variable but owned by to different lcore + * ids may be frequently read or written by the owners without risking + * false sharing. + * + * An appropriate synchronization mechanism (e.g., atomic loads and + * stores) should employed to assure there are no data races between + * the owning thread and any non-owner threads accessing the same + * lcore variable instance. + * + * The value of the lcore variable for a particular lcore id is + * accessed using @ref RTE_LCORE_VAR_LCORE_VALUE. + * + * A common pattern is for an EAL thread or a registered non-EAL + * thread to access its own lcore variable value. For this purpose, a + * short-hand exists in the form of @ref RTE_LCORE_VAR_VALUE. + * + * Although the handle (as defined by @ref RTE_LCORE_VAR_HANDLE) is a + * pointer with the same type as the value, it may not be directly + * dereferenced and must be treated as an opaque identifier. + * + * Lcore variable handles and value pointers may be freely passed + * between different threads. + * + * @b Storage + * + * An lcore variable's values may by of a primitive type like @c int, + * but would more typically be a @c struct. + * + * The lcore variable handle introduces a per-variable (not + * per-value/per-lcore id) overhead of @c sizeof(void *) bytes, so + * there are some memory footprint gains to be made by organizing all + * per-lcore id data for a particular module as one lcore variable + * (e.g., as a struct). + * + * An application may choose to define an lcore variable handle, which + * it then it goes on to never allocate. + * + * The size of a lcore variable's value must be less than the DPDK + * build-time constant @c RTE_MAX_LCORE_VAR. + * + * The lcore variable are stored in a series of lcore buffers, which + * are allocated from the libc heap. Heap allocation failures are + * treated as fatal. + * + * Lcore variables should generally *not* be @ref __rte_cache_aligned + * and need *not* include a @ref RTE_CACHE_GUARD field, since the use + * of these constructs are designed to avoid false sharing. In the + * case of an lcore variable instance, the thread most recently + * accessing nearby data structures should almost-always the lcore + * variables' owner. Adding padding will increase the effective memory + * working set size, potentially reducing performance. + * + * Lcore variable values take on an initial value of zero. + * + * @b Example + * + * Below is an example of the use of an lcore variable: + * + * @code{.c} + * struct foo_lcore_state { + * int a; + * long b; + * }; + * + * static RTE_LCORE_VAR_HANDLE(struct foo_lcore_state, lcore_states); + * + * long foo_get_a_plus_b(void) + * { + * struct foo_lcore_state *state = RTE_LCORE_VAR_VALUE(lcore_states); + * + * return state->a + state->b; + * } + * + * RTE_INIT(rte_foo_init) + * { + * RTE_LCORE_VAR_ALLOC(lcore_states); + * + * struct foo_lcore_state *state; + * RTE_LCORE_VAR_FOREACH_VALUE(state, lcore_states) { + * (initialize 'state') + * } + * + * (other initialization) + * } + * @endcode + * + * + * @b Alternatives + * + * Lcore variables are designed to replace a pattern exemplified below: + * @code{.c} + * struct __rte_cache_aligned foo_lcore_state { + * int a; + * long b; + * RTE_CACHE_GUARD; + * }; + * + * static struct foo_lcore_state lcore_states[RTE_MAX_LCORE]; + * @endcode + * + * This scheme is simple and effective, but has one drawback: the data + * is organized so that objects related to all lcores for a particular + * module is kept close in memory. At a bare minimum, this forces the + * use of cache-line alignment to avoid false sharing. With CPU + * hardware prefetching and memory loads resulting from speculative + * execution (functions which seemingly are getting more eager faster + * than they are getting more intelligent), one or more "guard" cache + * lines may be required to separate one lcore's data from another's. + * + * Lcore variables has the upside of working with, not against, the + * CPU's assumptions and for example next-line prefetchers may well + * work the way its designers intended (i.e., to the benefit, not + * detriment, of system performance). + * + * Another alternative to @ref rte_lcore_var.h is the @ref + * rte_per_lcore.h API, which make use of thread-local storage (TLS, + * e.g., GCC __thread or C11 _Thread_local). The main differences + * between by using the various forms of TLS (e.g., @ref + * RTE_DEFINE_PER_LCORE or _Thread_local) and the use of lcore + * variables are: + * + * * The existence and non-existence of a thread-local variable + * instance follow that of particular thread's. The data cannot be + * accessed before the thread has been created, nor after it has + * exited. As a result, thread-local variables must initialized in + * a "lazy" manner (e.g., at the point of thread creation). Lcore + * variables may be accessed immediately after having been + * allocated (which may be prior any thread beyond the main + * thread is running). + * * A thread-local variable is duplicated across all threads in the + * process, including unregistered non-EAL threads (i.e., + * "regular" threads). For DPDK applications heavily relying on + * multi-threading (in conjunction to DPDK's "one thread per core" + * pattern), either by having many concurrent threads or + * creating/destroying threads at a high rate, an excessive use of + * thread-local variables may cause inefficiencies (e.g., + * increased thread creation overhead due to thread-local storage + * initialization or increased total RAM footprint usage). Lcore + * variables *only* exist for threads with an lcore id. + * * If data in thread-local storage may be shared between threads + * (i.e., can a pointer to a thread-local variable be passed to + * and successfully dereferenced by non-owning thread) depends on + * the details of the TLS implementation. With GCC __thread and + * GCC _Thread_local, such data sharing is supported. In the C11 + * standard, the result of accessing another thread's + * _Thread_local object is implementation-defined. Lcore variable + * instances may be accessed reliably by any thread. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#include +#include +#include + +/** + * Given the lcore variable type, produces the type of the lcore + * variable handle. + */ +#define RTE_LCORE_VAR_HANDLE_TYPE(type) \ + type * + +/** + * Define a lcore variable handle. + * + * This macro defines a variable which is used as a handle to access + * the various per-lcore id instances of a per-lcore id variable. + * + * The aim with this macro is to make clear at the point of + * declaration that this is an lcore handler, rather than a regular + * pointer. + * + * Add @b static as a prefix in case the lcore variable are only to be + * accessed from a particular translation unit. + */ +#define RTE_LCORE_VAR_HANDLE(type, name) \ + RTE_LCORE_VAR_HANDLE_TYPE(type) name + +/** + * Allocate space for an lcore variable, and initialize its handle. + * + * The values of the lcore variable are initialized to zero. + */ +#define RTE_LCORE_VAR_ALLOC_SIZE_ALIGN(handle, size, align) \ + handle = rte_lcore_var_alloc(size, align) + +/** + * Allocate space for an lcore variable, and initialize its handle, + * with values aligned for any type of object. + * + * The values of the lcore variable are initialized to zero. + */ +#define RTE_LCORE_VAR_ALLOC_SIZE(handle, size) \ + RTE_LCORE_VAR_ALLOC_SIZE_ALIGN(handle, size, 0) + +/** + * Allocate space for an lcore variable of the size and alignment requirements + * suggested by the handler pointer type, and initialize its handle. + * + * The values of the lcore variable are initialized to zero. + */ +#define RTE_LCORE_VAR_ALLOC(handle) \ + RTE_LCORE_VAR_ALLOC_SIZE_ALIGN(handle, sizeof(*(handle)), \ + alignof(typeof(*(handle)))) + +/** + * Allocate an explicitly-sized, explicitly-aligned lcore variable by + * means of a @ref RTE_INIT constructor. + * + * The values of the lcore variable are initialized to zero. + */ +#define RTE_LCORE_VAR_INIT_SIZE_ALIGN(name, size, align) \ + RTE_INIT(rte_lcore_var_init_ ## name) \ + { \ + RTE_LCORE_VAR_ALLOC_SIZE_ALIGN(name, size, align); \ + } + +/** + * Allocate an explicitly-sized lcore variable by means of a @ref + * RTE_INIT constructor. + * + * The values of the lcore variable are initialized to zero. + */ +#define RTE_LCORE_VAR_INIT_SIZE(name, size) \ + RTE_LCORE_VAR_INIT_SIZE_ALIGN(name, size, 0) + +/** + * Allocate an lcore variable by means of a @ref RTE_INIT constructor. + * + * The values of the lcore variable are initialized to zero. + */ +#define RTE_LCORE_VAR_INIT(name) \ + RTE_INIT(rte_lcore_var_init_ ## name) \ + { \ + RTE_LCORE_VAR_ALLOC(name); \ + } + +/** + * Get void pointer to lcore variable instance with the specified + * lcore id. + * + * @param lcore_id + * The lcore id specifying which of the @c RTE_MAX_LCORE value + * instances should be accessed. The lcore id need not be valid + * (e.g., may be @ref LCORE_ID_ANY), but in such a case, the pointer + * is also not valid (and thus should not be dereferenced). + * @param handle + * The lcore variable handle. + */ +static inline void * +rte_lcore_var_lcore_ptr(unsigned int lcore_id, void *handle) +{ + return RTE_PTR_ADD(handle, lcore_id * RTE_MAX_LCORE_VAR); +} + +/** + * Get pointer to lcore variable instance with the specified lcore id. + * + * @param lcore_id + * The lcore id specifying which of the @c RTE_MAX_LCORE value + * instances should be accessed. The lcore id need not be valid + * (e.g., may be @ref LCORE_ID_ANY), but in such a case, the pointer + * is also not valid (and thus should not be dereferenced). + * @param handle + * The lcore variable handle. + */ +#define RTE_LCORE_VAR_LCORE_VALUE(lcore_id, handle) \ + ((typeof(handle))rte_lcore_var_lcore_ptr(lcore_id, handle)) + +/** + * Get pointer to lcore variable instance of the current thread. + * + * May only be used by EAL threads and registered non-EAL threads. + */ +#define RTE_LCORE_VAR_VALUE(handle) \ + RTE_LCORE_VAR_LCORE_VALUE(rte_lcore_id(), handle) + +/** + * Iterate over each lcore id's value for a lcore variable. + * + * @param value + * A pointer set successivly set to point to lcore variable value + * corresponding to every lcore id (up to @c RTE_MAX_LCORE). + * @param handle + * The lcore variable handle. + */ +#define RTE_LCORE_VAR_FOREACH_VALUE(value, handle) \ + for (unsigned int lcore_id = \ + (((value) = RTE_LCORE_VAR_LCORE_VALUE(0, handle)), 0); \ + lcore_id < RTE_MAX_LCORE; \ + lcore_id++, (value) = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, handle)) + +/** + * Allocate space in the per-lcore id buffers for a lcore variable. + * + * The pointer returned is only an opaque identifer of the variable. To + * get an actual pointer to a particular instance of the variable use + * @ref RTE_LCORE_VAR_VALUE or @ref RTE_LCORE_VAR_LCORE_VALUE. + * + * The lcore variable values' memory is set to zero. + * + * The allocation is always successful, barring a fatal exhaustion of + * the per-lcore id buffer space. + * + * rte_lcore_var_alloc() is not multi-thread safe. + * + * @param size + * The size (in bytes) of the variable's per-lcore id value. Must be > 0. + * @param align + * If 0, the values will be suitably aligned for any kind of type + * (i.e., alignof(max_align_t)). Otherwise, the values will be aligned + * on a multiple of *align*, which must be a power of 2 and equal or + * less than @c RTE_CACHE_LINE_SIZE. + * @return + * The id of the variable, stored in a void pointer value. The value + * is always non-NULL. + */ +__rte_experimental +void * +rte_lcore_var_alloc(size_t size, size_t align); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_LCORE_VAR_H_ */ diff --git a/lib/eal/version.map b/lib/eal/version.map index 3df50c3fbb..7702642785 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -396,6 +396,9 @@ EXPERIMENTAL { # added in 24.03 rte_vfio_get_device_info; # WINDOWS_NO_EXPORT + + rte_lcore_var_alloc; + rte_lcore_var; }; INTERNAL { From patchwork Mon May 6 08:27:17 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: 139874 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 1C9B343FC4; Mon, 6 May 2024 10:38:29 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DE909402E3; Mon, 6 May 2024 10:38:25 +0200 (CEST) Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2042.outbound.protection.outlook.com [40.107.105.42]) by mails.dpdk.org (Postfix) with ESMTP id 6D0D6402E1 for ; Mon, 6 May 2024 10:38:24 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XiY2mhI9y5ohzDAhZWwU0SmWH9RLojptptD4z+J5AugywmlTnsirBK2hYu+gxwZ1NJAd/pd6ZtALsOWn/tAn22gO1acISP91d+KhYxMSw89q9Gegl+869X6Dj+7Twpxc8kCl7V+rQ6fR6Ymnuk5TVTvvmnUVdoLKfCszA7Y2ZLmNoaesyya0pNHBSJ2GfakKxPtFZ9hEwa9r7Spd7FTo3eqSEqEfqHYl/aXAdomr4sobLFNF7bdTTKr4HiVVCeBmQoVr0QPBVuorkiiX3ZUvfN4Q2byf7P8RcDUPCckdOVbGP8hBr1sURxDEs3mg/v0lvu2rLkxBsoPTxmpyC7G8Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wy88gM49EvoC9uWorDMfxcXWJxsryZubX8VaSUoVskY=; b=WMTXtMAzM0SAtPr5Myxp0za1QBTUC3ZOft85M/U5Y5hHFnqE8Z2w0YqpxdQNmHNm5IsBKk+tZaZmnPfIgcK/Qskeekzqvr4sR1kCTyGYv504l9Hv4DlYzkAzfg71VnTl6i8weggxfqp5kismCc+CqMml9XH9iNpxgcAqMMOKh+sCQDVnlwHBOVh/NModsHqN6gfmpDGMxIQgxT3+rkNTij1rC8vDl/GaqYwwLK33YBAjjdmE4xjFsZzjMO/1SOOdqowMuMW41p5QCBOnkAaejaRpVdX5kkMDYzJP07GbepZUox/i7fn9nw05OlZfohlFomS2ZfLDpO2IQjJIMce9UA== 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=wy88gM49EvoC9uWorDMfxcXWJxsryZubX8VaSUoVskY=; b=R4ZN3wc7lQWWVFqFzsY+/HYsmnsrt0ywkHv6UWYd8UcVJNEsyoYp8bIkKBGHxFgVwYENdwJuTWOHJ5C+FqurjcBGWM/kqHlQwlo5iFc5LlIAEv+QHs6NWYuUsWeQA0STk8BH7i4FXcJ2QoAt3mi8UgG+lFZcAGZswsLqefzeQ9etJWznfso9HLQQYV735kGQhHPjMc87pjvgyymtiL2YcfO3wv8nQF6PeZCsArrepf+NDJMY4cznbMaIh+6ER7PCeT8qi7cxGRdI7U1oxYk+GBUbuhiG9wjZJnvh/lnUQj+pR9GBm8x/6ogr4aVeQr7UgrCTV28goMacobiDW0U4ug== Received: from DBBPR09CA0046.eurprd09.prod.outlook.com (2603:10a6:10:d4::34) by DBAPR07MB6967.eurprd07.prod.outlook.com (2603:10a6:10:192::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.41; Mon, 6 May 2024 08:38:22 +0000 Received: from DB1PEPF000509F7.eurprd02.prod.outlook.com (2603:10a6:10:d4:cafe::d4) by DBBPR09CA0046.outlook.office365.com (2603:10a6:10:d4::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.42 via Frontend Transport; Mon, 6 May 2024 08:38:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 192.176.1.74) smtp.mailfrom=ericsson.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ericsson.com; Received-SPF: Pass (protection.outlook.com: domain of ericsson.com designates 192.176.1.74 as permitted sender) receiver=protection.outlook.com; client-ip=192.176.1.74; helo=oa.msg.ericsson.com; pr=C Received: from oa.msg.ericsson.com (192.176.1.74) by DB1PEPF000509F7.mail.protection.outlook.com (10.167.242.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.18 via Frontend Transport; Mon, 6 May 2024 08:38:22 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.66) with Microsoft SMTP Server id 15.2.1544.9; Mon, 6 May 2024 10:38:22 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id E79E71C006A; Mon, 6 May 2024 10:38:21 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , =?utf-8?q?Morten_Br=C3=B8rup?= , Stephen Hemminger , Konstantin Ananyev , =?utf-8?q?Mattias_R?= =?utf-8?q?=C3=B6nnblom?= Subject: [RFC v6 2/6] eal: add lcore variable test suite Date: Mon, 6 May 2024 10:27:17 +0200 Message-ID: <20240506082721.120666-3-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240506082721.120666-1-mattias.ronnblom@ericsson.com> References: <20240228100928.524277-2-mattias.ronnblom@ericsson.com> <20240506082721.120666-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB1PEPF000509F7:EE_|DBAPR07MB6967:EE_ X-MS-Office365-Filtering-Correlation-Id: 93006c6e-65e8-4378-4bb2-08dc6da7e3ab X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|36860700004|82310400017|1800799015|376005; X-Microsoft-Antispam-Message-Info: =?utf-8?q?/ycmqOksmucEsJ2HDghpO6CKHFcxpgM?= =?utf-8?q?Dz28DPRZdZdTxBkk5CHDZK/K7Hmc8nvJPNBy0alfW12aqWK/UGE3iNpBeUeIwKYIb?= =?utf-8?q?lYWKinZ37uzvlhr4za/w0/zjmcJH/r2yrujULaLfiH/dVdKNkQK5mUPlrC1mRAzBl?= =?utf-8?q?5q58k3bRViKu09slDXnjTlTGtJi+muFOftUyEFpU42vv6mb5b3GEDVBU+Ll+Z4Qzn?= =?utf-8?q?7VbmnpSv/1ygNZWjuy+W6D/vRkWeWCssiCV137rLq5QDXnHHtYfUy0qED35SEusTR?= =?utf-8?q?CkFseW5ooIaX0fes/5uJzzgJaaR1OUb8rQS/D90MwgEg2IvOdJPDq95xPq1ClRGmH?= =?utf-8?q?BQqxgW+z9xnONtMod8b0Z7optrBOc4x+u4lXNIEyOSriUOriczvj1wAnluo87euck?= =?utf-8?q?D7xgQjAZkXgqFDjjoAmK6IJ04LdWbQDtur/gXs5snGto8D2/4V4jZty2/UFWnLqSz?= =?utf-8?q?MlCOKvCqhVjDhE5ctGvjjBRVRpzZ6LDG/518aeFClsooB/oYF2mBvRwSLfko6XL83?= =?utf-8?q?Qpv+SSnpOUgfWqbirj1z439OeECGL76RgUcw24R1sl+TjnDsvo13bWKDshAJLwjdn?= =?utf-8?q?uiXGg07K5Dy3nOoJi+Pyo6LxTB/MxCNU3h5j5gbOspkyztTsLZfk8xZvB0hRc7ID/?= =?utf-8?q?ROapGO2atmVP3tyo6H2/BbYjZpkrYdNVXXJnF2ITtfI0H0LQvP7oNGnIkFOllMIZe?= =?utf-8?q?U6fAznK1hBP3QkwCf4K1rSRgJ6SkM/UnYYAuol/5EJmiSQ6FISqHwyRkTPOfcTmvl?= =?utf-8?q?qqLduoYk9c1HeTXJIfEz4/vZy+6KsceosBwmE/iQB+ANWOmYwC5JvD4Ob8mtn2OPB?= =?utf-8?q?mIRwyb1dQ29ubmMvW6dQ+jjpaKXGuIT+oFlHGUoLac+ELLYb1LnNGNirQMut0yvoI?= =?utf-8?q?V0leZxrRTMtS4rvMXlZjJ4chIRUUmCZmF7k0/oinsEvrFUBq3oaHODGyrkO1tj2X6?= =?utf-8?q?44u6s20YqD6XOwSbotvY1vwivV7LofEEVdnrZMcvUQGY6f/gdW/WdKZQGGAPSuab4?= =?utf-8?q?aoG1vuHi40xoiNYuEvj7sPv2OVUEbUQycEoz1JLcrngBScgJvlmBvn7wTZU3s9PhX?= =?utf-8?q?WHtwObm1QWV+69UBAnG7QbwIoScFpfzWFY+UZkfXlzutj+jrNyh/Y6ESUCQ+RJr6R?= =?utf-8?q?aj2AMMd0pe4FeUXw8zl+/Xo8Y/jyJzwm73b5mKhRjLMV6YZtmFDlEz5PbIZ3Iqodr?= =?utf-8?q?eoqBVJYUR9dEzwfCHwxzdduSbHRqw91JHVFUUdBW1BL0k9H4WCdl0B+qyq1elDE8H?= =?utf-8?q?khPEXoLKccD1CE1XT0NHyyTrhFCfXa+XC79oSYxg/dsXhfCYiSZ79WHE=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:(13230031)(36860700004)(82310400017)(1800799015)(376005); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 May 2024 08:38:22.5606 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 93006c6e-65e8-4378-4bb2-08dc6da7e3ab 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: DB1PEPF000509F7.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR07MB6967 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add test suite to exercise the API. 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. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup --- app/test/meson.build | 1 + app/test/test_lcore_var.c | 432 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 433 insertions(+) create mode 100644 app/test/test_lcore_var.c diff --git a/app/test/meson.build b/app/test/meson.build index 7d909039ae..846affa98c 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -103,6 +103,7 @@ source_file_deps = { 'test_ipsec_sad.c': ['ipsec'], 'test_kvargs.c': ['kvargs'], 'test_latencystats.c': ['ethdev', 'latencystats', 'metrics'] + sample_packet_forward_deps, + 'test_lcore_var.c': [], 'test_lcores.c': [], 'test_link_bonding.c': ['ethdev', 'net_bond', 'net'] + packet_burst_generator_deps + virtual_pmd_deps, diff --git a/app/test/test_lcore_var.c b/app/test/test_lcore_var.c new file mode 100644 index 0000000000..e07d13460f --- /dev/null +++ b/app/test/test_lcore_var.c @@ -0,0 +1,432 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 Ericsson AB + */ + +#include +#include +#include + +#include +#include +#include + +#include "test.h" + +#define MIN_LCORES 2 + +RTE_LCORE_VAR_HANDLE(int, test_int); +RTE_LCORE_VAR_HANDLE(char, test_char); +RTE_LCORE_VAR_HANDLE(long, test_long_sized); +RTE_LCORE_VAR_HANDLE(short, test_short); +RTE_LCORE_VAR_HANDLE(long, test_long_sized_aligned); + +struct int_checker_state { + int old_value; + int new_value; + bool success; +}; + +static void +rand_blk(void *blk, size_t size) +{ + size_t i; + + for (i = 0; i < size; i++) + ((unsigned char *)blk)[i] = (unsigned char)rte_rand(); +} + +static bool +is_ptr_aligned(const void *ptr, size_t align) +{ + return ptr != NULL ? (uintptr_t)ptr % align == 0 : false; +} + +static int +check_int(void *arg) +{ + struct int_checker_state *state = arg; + + int *ptr = RTE_LCORE_VAR_VALUE(test_int); + + bool naturally_aligned = is_ptr_aligned(ptr, sizeof(int)); + + bool equal = *(RTE_LCORE_VAR_VALUE(test_int)) == state->old_value; + + state->success = equal && naturally_aligned; + + *ptr = state->new_value; + + return 0; +} + +RTE_LCORE_VAR_INIT(test_int); +RTE_LCORE_VAR_INIT(test_char); +RTE_LCORE_VAR_INIT_SIZE(test_long_sized, 32); +RTE_LCORE_VAR_INIT(test_short); +RTE_LCORE_VAR_INIT_SIZE_ALIGN(test_long_sized_aligned, sizeof(long), + RTE_CACHE_LINE_SIZE); + +static int +test_int_lvar(void) +{ + unsigned int lcore_id; + + struct int_checker_state states[RTE_MAX_LCORE] = {}; + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + struct int_checker_state *state = &states[lcore_id]; + + state->old_value = (int)rte_rand(); + state->new_value = (int)rte_rand(); + + *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, test_int) = + state->old_value; + } + + RTE_LCORE_FOREACH_WORKER(lcore_id) + rte_eal_remote_launch(check_int, &states[lcore_id], lcore_id); + + rte_eal_mp_wait_lcore(); + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + struct int_checker_state *state = &states[lcore_id]; + int value; + + TEST_ASSERT(state->success, "Unexpected value " + "encountered on lcore %d", lcore_id); + + value = *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, test_int); + TEST_ASSERT_EQUAL(state->new_value, value, + "Lcore %d failed to update int", lcore_id); + } + + /* take the opportunity to test the foreach macro */ + int *v; + lcore_id = 0; + RTE_LCORE_VAR_FOREACH_VALUE(v, test_int) { + TEST_ASSERT_EQUAL(states[lcore_id].new_value, *v, + "Unexpected value on lcore %d during " + "iteration", lcore_id); + lcore_id++; + } + + return TEST_SUCCESS; +} + +static int +test_sized_alignment(void) +{ + long *v; + + RTE_LCORE_VAR_FOREACH_VALUE(v, test_long_sized) { + TEST_ASSERT(is_ptr_aligned(v, alignof(long)), + "Type-derived alignment failed"); + } + + RTE_LCORE_VAR_FOREACH_VALUE(v, test_long_sized_aligned) { + TEST_ASSERT(is_ptr_aligned(v, RTE_CACHE_LINE_SIZE), + "Explicit alignment failed"); + } + + return TEST_SUCCESS; +} + +/* private, larger, struct */ +#define TEST_STRUCT_DATA_SIZE 1234 + +struct test_struct { + uint8_t data[TEST_STRUCT_DATA_SIZE]; +}; + +static RTE_LCORE_VAR_HANDLE(char, before_struct); +static RTE_LCORE_VAR_HANDLE(struct test_struct, test_struct); +static RTE_LCORE_VAR_HANDLE(char, after_struct); + +struct struct_checker_state { + struct test_struct old_value; + struct test_struct new_value; + bool success; +}; + +static int check_struct(void *arg) +{ + struct struct_checker_state *state = arg; + + struct test_struct *lcore_struct = RTE_LCORE_VAR_VALUE(test_struct); + + bool properly_aligned = + is_ptr_aligned(test_struct, alignof(struct test_struct)); + + bool equal = memcmp(lcore_struct->data, state->old_value.data, + TEST_STRUCT_DATA_SIZE) == 0; + + state->success = equal && properly_aligned; + + memcpy(lcore_struct->data, state->new_value.data, + TEST_STRUCT_DATA_SIZE); + + return 0; +} + +static int +test_struct_lvar(void) +{ + unsigned int lcore_id; + + RTE_LCORE_VAR_ALLOC(before_struct); + RTE_LCORE_VAR_ALLOC(test_struct); + RTE_LCORE_VAR_ALLOC(after_struct); + + struct struct_checker_state states[RTE_MAX_LCORE]; + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + struct struct_checker_state *state = &states[lcore_id]; + + rand_blk(state->old_value.data, TEST_STRUCT_DATA_SIZE); + rand_blk(state->new_value.data, TEST_STRUCT_DATA_SIZE); + + memcpy(RTE_LCORE_VAR_LCORE_VALUE(lcore_id, test_struct)->data, + state->old_value.data, TEST_STRUCT_DATA_SIZE); + } + + RTE_LCORE_FOREACH_WORKER(lcore_id) + rte_eal_remote_launch(check_struct, &states[lcore_id], + lcore_id); + + rte_eal_mp_wait_lcore(); + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + struct struct_checker_state *state = &states[lcore_id]; + struct test_struct *lstruct = + RTE_LCORE_VAR_LCORE_VALUE(lcore_id, test_struct); + + TEST_ASSERT(state->success, "Unexpected value encountered on " + "lcore %d", lcore_id); + + bool equal = memcmp(lstruct->data, state->new_value.data, + TEST_STRUCT_DATA_SIZE) == 0; + + TEST_ASSERT(equal, "Lcore %d failed to update struct", + lcore_id); + } + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + char before = + *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, before_struct); + char after = + *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, after_struct); + + TEST_ASSERT_EQUAL(before, 0, "Lcore variable before test " + "struct was modified on lcore %d", lcore_id); + TEST_ASSERT_EQUAL(after, 0, "Lcore variable after test " + "struct was modified on lcore %d", lcore_id); + } + + return TEST_SUCCESS; +} + +#define TEST_ARRAY_SIZE 99 + +typedef uint16_t test_array_t[TEST_ARRAY_SIZE]; + +static void test_array_init_rand(test_array_t a) +{ + size_t i; + for (i = 0; i < TEST_ARRAY_SIZE; i++) + a[i] = (uint16_t)rte_rand(); +} + +static bool test_array_equal(test_array_t a, test_array_t b) +{ + size_t i; + for (i = 0; i < TEST_ARRAY_SIZE; i++) { + if (a[i] != b[i]) + return false; + } + return true; +} + +static void test_array_copy(test_array_t dst, const test_array_t src) +{ + size_t i; + for (i = 0; i < TEST_ARRAY_SIZE; i++) + dst[i] = src[i]; +} + +static RTE_LCORE_VAR_HANDLE(char, before_array); +static RTE_LCORE_VAR_HANDLE(test_array_t, test_array); +static RTE_LCORE_VAR_HANDLE(char, after_array); + +struct array_checker_state { + test_array_t old_value; + test_array_t new_value; + bool success; +}; + +static int check_array(void *arg) +{ + struct array_checker_state *state = arg; + + test_array_t *lcore_array = RTE_LCORE_VAR_VALUE(test_array); + + bool properly_aligned = + is_ptr_aligned(lcore_array, alignof(test_array_t)); + + bool equal = test_array_equal(*lcore_array, state->old_value); + + state->success = equal && properly_aligned; + + test_array_copy(*lcore_array, state->new_value); + + return 0; +} + +static int +test_array_lvar(void) +{ + unsigned int lcore_id; + + RTE_LCORE_VAR_ALLOC(before_array); + RTE_LCORE_VAR_ALLOC(test_array); + RTE_LCORE_VAR_ALLOC(after_array); + + struct array_checker_state states[RTE_MAX_LCORE]; + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + struct array_checker_state *state = &states[lcore_id]; + + test_array_init_rand(state->new_value); + test_array_init_rand(state->old_value); + + test_array_copy(*RTE_LCORE_VAR_LCORE_VALUE(lcore_id, + test_array), + state->old_value); + } + + RTE_LCORE_FOREACH_WORKER(lcore_id) + rte_eal_remote_launch(check_array, &states[lcore_id], + lcore_id); + + rte_eal_mp_wait_lcore(); + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + struct array_checker_state *state = &states[lcore_id]; + test_array_t *larray = + RTE_LCORE_VAR_LCORE_VALUE(lcore_id, test_array); + + TEST_ASSERT(state->success, "Unexpected value encountered on " + "lcore %d", lcore_id); + + bool equal = test_array_equal(*larray, state->new_value); + + TEST_ASSERT(equal, "Lcore %d failed to update array", + lcore_id); + } + + RTE_LCORE_FOREACH_WORKER(lcore_id) { + char before = + *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, before_array); + char after = + *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, after_array); + + TEST_ASSERT_EQUAL(before, 0, "Lcore variable before test " + "array was modified on lcore %d", lcore_id); + TEST_ASSERT_EQUAL(after, 0, "Lcore variable after test " + "array was modified on lcore %d", lcore_id); + } + + return TEST_SUCCESS; +} + +#define MANY_LVARS (2 * RTE_MAX_LCORE_VAR / sizeof(uint32_t)) + +static int +test_many_lvars(void) +{ + uint32_t **handlers = malloc(sizeof(uint32_t *) * MANY_LVARS); + unsigned int i; + + TEST_ASSERT(handlers != NULL, "Unable to allocate memory"); + + for (i = 0; i < MANY_LVARS; i++) { + unsigned int lcore_id; + + RTE_LCORE_VAR_ALLOC(handlers[i]); + + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { + uint32_t *v = + RTE_LCORE_VAR_LCORE_VALUE(lcore_id, handlers[i]); + *v = (uint32_t)(i * lcore_id); + } + } + + for (i = 0; i < MANY_LVARS; i++) { + unsigned int lcore_id; + + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { + uint32_t v = *RTE_LCORE_VAR_LCORE_VALUE(lcore_id, + handlers[i]); + TEST_ASSERT_EQUAL((uint32_t)(i * lcore_id), v, + "Unexpected lcore variable value on " + "lcore %d", lcore_id); + } + } + + free(handlers); + + return TEST_SUCCESS; +} + +static int +test_large_lvar(void) +{ + RTE_LCORE_VAR_HANDLE(unsigned char, large); + unsigned int lcore_id; + + RTE_LCORE_VAR_ALLOC_SIZE(large, RTE_MAX_LCORE_VAR); + + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { + unsigned char *ptr = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, large); + + memset(ptr, (unsigned char)lcore_id, RTE_MAX_LCORE_VAR); + } + + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { + unsigned char *ptr = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, large); + size_t i; + + for (i = 0; i < RTE_MAX_LCORE_VAR; i++) + TEST_ASSERT_EQUAL(ptr[i], (unsigned char)lcore_id, + "Large lcore variable value is " + "corrupted on lcore %d.", + lcore_id); + } + + return TEST_SUCCESS; +} + +static struct unit_test_suite lcore_var_testsuite = { + .suite_name = "lcore variable autotest", + .unit_test_cases = { + TEST_CASE(test_int_lvar), + TEST_CASE(test_sized_alignment), + TEST_CASE(test_struct_lvar), + TEST_CASE(test_array_lvar), + TEST_CASE(test_many_lvars), + TEST_CASE(test_large_lvar), + TEST_CASES_END() + }, +}; + +static int test_lcore_var(void) +{ + if (rte_lcore_count() < MIN_LCORES) { + printf("Not enough cores for lcore_var_autotest; expecting at " + "least %d.\n", MIN_LCORES); + return TEST_SKIPPED; + } + + return unit_test_suite_runner(&lcore_var_testsuite); +} + +REGISTER_FAST_TEST(lcore_var_autotest, true, false, test_lcore_var); From patchwork Mon May 6 08:27:18 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: 139877 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 AD7A943FC4; Mon, 6 May 2024 10:38:58 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BF93440633; Mon, 6 May 2024 10:38:33 +0200 (CEST) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2079.outbound.protection.outlook.com [40.107.14.79]) by mails.dpdk.org (Postfix) with ESMTP id 4742A402E9 for ; Mon, 6 May 2024 10:38:26 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LL2vDDrKOi3xfeWnoGFbPe3fWdUL6a9HNCvWd1tyHjfpPE4zhe4mDTsmPwmPopZMBJRjwR6Tkgln9McDGYVmwIK8v2m/d7f8xNqbf4GOwV4QJSsL4DnXzxrM5taz697yQwriKP+5lxYic7LpPys9lunkMHw2E0C70P3aKOfIIWLaUg5ONeyVr5pWTgf/003sRCECsSLlCHaoe2Ok2yOYhPdTMA5tzB1mGXxtb7dzCmj0JpCnoHv0z6p9oJKnQvg1uER0wGAgiyzLwcX0M2Ebeh9JzKzZ4UUfx764t8wpuwrvuSVvUMm/XXlGM4fyrfhMlZFE/RvL3GglilupgyFNAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=A6J/3RAvMEZtYuQWbxJNql5QXwI0mQ2DklM3t8JmQcU=; b=cRQ/m+tnk4pouBm4AQTbNrvuhEvSCjRrEABCnsroHNUYJH1Ce/flEQw9GLrvCbWBYSPS1yBJvRvTeGRbo1cnxjSYDEuG6TrJnJHt1X5G6hwaEBWTZRLSAfB0idNqY7Sij6fjes7q4Y9xLRudR+kKXLuh4fOh8uf2C6rkB7hcIi3Gd0BU7o/Xn+llzV1VS/prf//528E2zsMv/9uQqhVnozsaoWSrKdrMi+nS0MRV8R62arJTXvYklt9NuRFZRYCv3VKu7ME2JybLV0kLUW+jguQ5fS6nBSa+sQKgo/YiU0qltyj5E0JKXi5T5SX0d2BvNrHS5zAHT6kQzoj6GbhErQ== 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=A6J/3RAvMEZtYuQWbxJNql5QXwI0mQ2DklM3t8JmQcU=; b=axGlWj6/MTIPDG6O1Fsx8GxTF5RqY2QuKln8FrOR4ujyD5DsaKMZ2ZLR6tLhfNytLGuYXhBOUZTFR5b7T+s0JxMUcqSVS0X+/Etsn8+lia83sQKS3n3MoXvqXwfOpFe6LjfxU2wLa9w/Yud9lYpjUFItDPDLu1xURjQgySz0YL74WIa1zFY0blnCnksqIraN1q6jLpLGIEuPLC6FPjlsgURODolD7yzZsY5nu4/QI85yBsmL925MI+atglYA0s/77b+oBuN6ZOYaSqQxYS+c7iYmRNIwU0OGjlS4ZRvb2NQG1lv+AbEVLaJpZg0bGu1DP4+woc4auNq3jyTUbbrDDg== Received: from DUZPR01CA0154.eurprd01.prod.exchangelabs.com (2603:10a6:10:4bd::24) by DU2PR07MB8142.eurprd07.prod.outlook.com (2603:10a6:10:270::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.42; Mon, 6 May 2024 08:38:23 +0000 Received: from DB5PEPF00014B91.eurprd02.prod.outlook.com (2603:10a6:10:4bd:cafe::a) by DUZPR01CA0154.outlook.office365.com (2603:10a6:10:4bd::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.28 via Frontend Transport; Mon, 6 May 2024 08:38:23 +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 DB5PEPF00014B91.mail.protection.outlook.com (10.167.8.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.18 via Frontend Transport; Mon, 6 May 2024 08:38:22 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.63) with Microsoft SMTP Server id 15.2.1544.9; Mon, 6 May 2024 10:38:22 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 8C42F1C006A; Mon, 6 May 2024 10:38:22 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , =?utf-8?q?Morten_Br=C3=B8rup?= , Stephen Hemminger , Konstantin Ananyev , =?utf-8?q?Mattias_R?= =?utf-8?q?=C3=B6nnblom?= Subject: [RFC v6 3/6] random: keep PRNG state in lcore variable Date: Mon, 6 May 2024 10:27:18 +0200 Message-ID: <20240506082721.120666-4-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240506082721.120666-1-mattias.ronnblom@ericsson.com> References: <20240228100928.524277-2-mattias.ronnblom@ericsson.com> <20240506082721.120666-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB5PEPF00014B91:EE_|DU2PR07MB8142:EE_ X-MS-Office365-Filtering-Correlation-Id: fdcde52b-8922-49a7-7a71-08dc6da7e3dc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|36860700004|82310400017|376005|1800799015; X-Microsoft-Antispam-Message-Info: =?utf-8?q?C/zzCrf1Cla+T1Bhao52GAVYcciOT/Q?= =?utf-8?q?QvqbNjDLbD8x5GZd3gMPSyiOAONsfvsxvZMHkoI5bSK6B355gsluGKHACWxBHn9fA?= =?utf-8?q?vwhf6MhdRO9J2LfZ5QNKm+znL/7W0Z5ggbJ9M+k25OZGoQuoMZDkTjcrmWrwJsrrc?= =?utf-8?q?VPhg51RyeiFFOIc/nl9QRQ8P3wnPM21x/bKCsWA1/eswQEr+v7/iaPRDYJ8gprCBe?= =?utf-8?q?RoAoQO5vf7kHaMqBTAZj4NJNfPcVDoOIb1H+J3OyYPGx4yZyYGzzAU9iZU7DSRJND?= =?utf-8?q?o8tDf4WQrlo6vzaLQURnJlD+1Myisk0aZEEDBId2LTw2fz/40xOdES++zbQlRfGPs?= =?utf-8?q?dIxR4X/tED0jLtFizbJ6dyuU04qPuyOMsijm8H1c0XtSHWiEIQbKU/clNA1i8PNlU?= =?utf-8?q?5SEOc627xiSEFXk+pQPEEhY/Fhh0T/QVydb8cnHRzqyv97fVHfirNvBu70iKrOEft?= =?utf-8?q?9HjqbgsqUJwVO/43Co5wdhHZCxltPjZbqS2n28zQ6/Mz2DO4r/vhYNB0R4dWizKtS?= =?utf-8?q?24DsdbnSHV7FdYWlRYW8aHWx3+TBv1Art4906wU4Ge5Dmn0gDAC+OGjY+VxgrGWyb?= =?utf-8?q?dx0dnTEokSz2Ej/bAMyCSNZ5TUGwWsmzUiRCwp96t9U6R9vZuDgeKvY8SRQOYTj1s?= =?utf-8?q?FIpkCOasgGG8h4UdWuJjqB6UUNig5y62Y2BYYcQ8vwTpLtxrJnsbyNZ3Qy9rQimS/?= =?utf-8?q?IdS5kszatq8lzuXzEB44vwzFpmqvSrnVqlmt9FSJQB5lSx1Wjon+XlcSwYI0OMjRx?= =?utf-8?q?lLPXZu0UTFBoVUwhJDNhNo+oi63X0HVfCL0Uhi+hCp44ZiPmotygP71lFMA7rh/BA?= =?utf-8?q?tiQlaXZGQXKATnF2gFBANVDqOpFsrh58WsiD4jj+8aDJijOoQIAuRIGlv312vSdzi?= =?utf-8?q?VKWHpVkje9VdFwtU+p7CymUQlL73tvVM3CW99+/Vt0G8AmdsWldQrb06zasera8WP?= =?utf-8?q?V9yv8c05t+BhmttPIE6u5PkVmyPNGXSM3jy2Bjwqf8DE1CR6yITCwKN0/N8kMEh3P?= =?utf-8?q?xTwWDXfdQAKq7quRabjkhvWIllPEUom9dt/Ivm8l37ztz9g8fK2N1qmY0rDf9gQHP?= =?utf-8?q?RmWANf7q4fSokvqKvpCJmVyzKB9/1eri5j/wDS9l64rgi5z+waKRXcW+AgBuAHkgY?= =?utf-8?q?MlM16nRn/5QMDlxWYTQl/rjnS/uaNc3MK94dwQ4i/S3WQyNEr5ikZD4SbDXxGPzod?= =?utf-8?q?udJyjmW9srYeJi6RthRL93sJFRqCUjWQvJP9ArkKMp03wCtuUBgVlTIMZhIlehZ5d?= =?utf-8?q?zmkj3GjHkxAle0bgsIpJcjUTf7e/67H0o73zyu0bwoSb4WhtkfeoH4qw=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:(13230031)(36860700004)(82310400017)(376005)(1800799015); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 May 2024 08:38:22.8829 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fdcde52b-8922-49a7-7a71-08dc6da7e3dc 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: DB5PEPF00014B91.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR07MB8142 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. RFC v3: * Remove cache alignment on unregistered threads' rte_rand_state. (Morten Brørup) Signed-off-by: Mattias Rönnblom Acked-by: 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 Mon May 6 08:27:19 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: 139878 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 E0B4943FC4; Mon, 6 May 2024 10:39:05 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4D7634068A; Mon, 6 May 2024 10:38:35 +0200 (CEST) Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2080.outbound.protection.outlook.com [40.107.13.80]) by mails.dpdk.org (Postfix) with ESMTP id DF67E402DE for ; Mon, 6 May 2024 10:38:26 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kTJKZiZfz46RD2yPKUMHcWCvu10VUQErMKridACMChFQVa4MY/QqGPAed/rrFGAlnlx2LzT5UD2E9YMRYIG8aCQx9z1lw6EFVWlPqW26xoFOxA5oOGKnCTpiYdhFmuYvv9dZGnSiATgyplQar5FRVRquL7lvrneVsTTbdQNDl2GN6OONUXrH+2FsUnwQPKnSYRS8/81eIKLeBxyC8Y0z5NUgcocYL7yTr4Vkgmb+Ee1yh2rxACxnlWCR++HVynoym3gipSn6CngNGM95o9NV5xSop1yQnsMfjp5Qf1po3jAiCtmzBgSxl3fScureZL4Fu0pREv0jSiV5jRrT8LPvrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UAPG5IrKv36TlW4hfjOUZ0AP0ETcFjlN5y7QwuYr6i8=; b=Bh8sqDo/gpMqc5kNvSzMEdecAhXpFYJ4ypepDnjO7bWUOsGlJbryNAfxPh6+OT57Sx8Nw5ySh1cwTS1BhbIioazv2SVIESky79GfJjMY1RzNgStAuixOxSGno0eif+9p1VWMCT4c9D/PTMSo3/mPkTPuusKSujuozCRx4NvAzTt5Mg21ITYRBXcQPxKuUY3hxy6i5MgtS3sJ56lj5BiExqzpIzXcMZf/CIilCo3pIGTXwIqXorYpsIceWMO+Hh0PzCDR/3ksoyBayjj1EWe7VWMQTbrQYk4MLoaPE0C/YfKEg3HXY43Bw1mFI1zxPxxb+OaMa6HfpCkEImlI5wXHuA== 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=UAPG5IrKv36TlW4hfjOUZ0AP0ETcFjlN5y7QwuYr6i8=; b=WNpYou7kzk4+XoWP20xAAuQL2alsjw5NI3K17lvn7uHcR0hl20AAWMlmmyBob1ohgnjD1WXJyUGlxWN/Re04dPUwZio88aySa2SKbLes+EqBW1JiYi81pk8XPbde8bisMKVtBKkxsUj9VouJfSb0SatAf7oLpOs6EFD07Ij+XjIgKX12r1Nm2bIPQJ/sm7SxTLGgDTuvsdHfYejZn4kEwCaPLRQ1JsvHYVM4+rwKtcq4DSB2JKUqqi5Trb0Uti5avZ3V0k2ScllYVjD25lr2q+mO8gtIckIIxiCkZnjdIYni/mk1f7SqCXG5dxWjubpEh8PUAxSq6fx6xOEqs9ERCw== Received: from DU6P191CA0028.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:53f::14) by AM9PR07MB7057.eurprd07.prod.outlook.com (2603:10a6:20b:2c1::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.41; Mon, 6 May 2024 08:38:25 +0000 Received: from DU2PEPF00028D04.eurprd03.prod.outlook.com (2603:10a6:10:53f:cafe::4) by DU6P191CA0028.outlook.office365.com (2603:10a6:10:53f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.41 via Frontend Transport; Mon, 6 May 2024 08:38:23 +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 DU2PEPF00028D04.mail.protection.outlook.com (10.167.242.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.19 via Frontend Transport; Mon, 6 May 2024 08:38:23 +0000 Received: from seliicinfr00050.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.9; Mon, 6 May 2024 10:38:23 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 234B71C006A; Mon, 6 May 2024 10:38:23 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , =?utf-8?q?Morten_Br=C3=B8rup?= , Stephen Hemminger , Konstantin Ananyev , =?utf-8?q?Mattias_R?= =?utf-8?q?=C3=B6nnblom?= Subject: [RFC v6 4/6] power: keep per-lcore state in lcore variable Date: Mon, 6 May 2024 10:27:19 +0200 Message-ID: <20240506082721.120666-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240506082721.120666-1-mattias.ronnblom@ericsson.com> References: <20240228100928.524277-2-mattias.ronnblom@ericsson.com> <20240506082721.120666-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PEPF00028D04:EE_|AM9PR07MB7057:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ae2840b-7287-4ce6-3694-08dc6da7e461 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|1800799015|82310400017|36860700004|376005; X-Microsoft-Antispam-Message-Info: =?utf-8?q?Fp1Nh8gM7X2EiWT22mYZbmiCc1und0E?= =?utf-8?q?R0taRyAt7hHhBJkDVy84+i61uaMV/XpIRrW4JK6txepp01sIvNQS8v89kkmnJ/YZL?= =?utf-8?q?m6UdkrVq4CbPmBqVehckND4j33fK4Cf0pElAd41rffHV+OcVO1ydNPlIkHHB8VtWt?= =?utf-8?q?00txKQXfiLqYplbUncf5dLgfeNr8EdVI1IoH3HuCHs9CFlzHD9uv6fTd2HQz33NPs?= =?utf-8?q?XoiCzecCpwZQ3ucEy+aRH3VNpfQq4oGi1GsaFTqOeNcozwWxAwt0MugTfKbRDmPif?= =?utf-8?q?S4NDg2PFGDKx73tKKxf+Mhd2ZXafMZT9YexPWPiixhj4Gqp9Ug9Hhsffwz4wiEVGm?= =?utf-8?q?pirhbNWiAIjL/eGhzQOSmYv6TOG3mMErYruCXbeuLB7c5nWLeqbVynP30MW72ub+y?= =?utf-8?q?GB6FrK39+9j9Q+YwCoLoPMJ1PxBf2CcU/2ZtT3wU0c+AsEnhWPQvFsWQS+I9z2/Ne?= =?utf-8?q?1D0W3Na1ua0r6zOJXfVBW9bRU6qf9OYejV0Yyio1jDbOXmlp88WJV1gT8GfOv+bpf?= =?utf-8?q?INnmQt5a3eogztzkM/nVRNwfOUfK20d13ipoThzs++LoNVsS4rDBUVdhDbbLv3k15?= =?utf-8?q?F1E3Gik+QvA65LUHarxOt6cMj46t5juwUdlhIQy8cTxRL94qCaW2sENg4Gwmgr2z7?= =?utf-8?q?HnbclRGgFis0ug30D2zb88HPTwXT+kCw7Fsi5uox8m1CXZPvtSijCFV+BnKWvv6zw?= =?utf-8?q?NlcFmfqxR7ctBGeDdjdZyV4xgvciqk+Udj3LulpvH/czEF2ZB+589++4Lq269zTXC?= =?utf-8?q?h2UV5ZODqJpMRMO+6BmzRLHTS/IVJnxR+uYiORFSkQV7ADOxu28AngBD7A5d/sNzy?= =?utf-8?q?PHJqX/Tta9yBtEy+d112NXBgfdwTqKzx8h1PzDTifjpyYULlMFJ3ICozKrKoOKKTW?= =?utf-8?q?fx0GRpwyCsByAjzTBT4ThWChdB5Ufa/gQY79uQA2DmGa3w2avcRxuFFuWv6ztl2LM?= =?utf-8?q?PgniIPLF/HGztXAm657zngU/8BqTl9xQgKBD/5egyqpXXraQ+tTNNMMaGnttMcXdO?= =?utf-8?q?8cz4lF4LDsSNo3MHEkc7BVsfkhVUoM4G0oHYGTkz7S5I1ebA1V4E2ZjZg/+TfmqCV?= =?utf-8?q?xAe5mLKWY7mhI3WJ6L+xThzG3TDOJOzjJEiv0gI1B+e+YEXFKCslCWKoLepw8WgNg?= =?utf-8?q?hZQN/twVNudz37fiopxO1m948c10B+F2bz8I/kgokuLDUiXimRS14wmus3eE7cEv4?= =?utf-8?q?SXVRcAjs9gsAZMNc7Fh0hSYj8DTEhuSsXiTA/X5jFxtFh+RhuChfQGMFDto8n+nus?= =?utf-8?q?tcjjODpqm/Y4yrDLhLU/O/wLz448dDLThFY3Nth/pztglg7iFaqxu93A=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:(13230031)(1800799015)(82310400017)(36860700004)(376005); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 May 2024 08:38:23.7060 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9ae2840b-7287-4ce6-3694-08dc6da7e461 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: DU2PEPF00028D04.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR07MB7057 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. RFC v3: * Replace for loop with FOREACH macro. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup --- lib/power/rte_power_pmd_mgmt.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/power/rte_power_pmd_mgmt.c b/lib/power/rte_power_pmd_mgmt.c index b1c18a5f56..a5139dd4f7 100644 --- a/lib/power/rte_power_pmd_mgmt.c +++ b/lib/power/rte_power_pmd_mgmt.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -69,7 +70,7 @@ struct __rte_cache_aligned pmd_core_cfg { uint64_t sleep_target; /**< Prevent a queue from triggering sleep multiple times */ }; -static struct pmd_core_cfg lcore_cfgs[RTE_MAX_LCORE]; +static RTE_LCORE_VAR_HANDLE(struct pmd_core_cfg, lcore_cfgs); static inline bool queue_equal(const union queue *l, const union queue *r) @@ -252,12 +253,11 @@ clb_multiwait(uint16_t port_id __rte_unused, uint16_t qidx __rte_unused, struct rte_mbuf **pkts __rte_unused, uint16_t nb_rx, uint16_t max_pkts __rte_unused, void *arg) { - const unsigned int lcore = rte_lcore_id(); struct queue_list_entry *queue_conf = arg; struct pmd_core_cfg *lcore_conf; const bool empty = nb_rx == 0; - lcore_conf = &lcore_cfgs[lcore]; + lcore_conf = RTE_LCORE_VAR_VALUE(lcore_cfgs); /* early exit */ if (likely(!empty)) @@ -317,13 +317,12 @@ clb_pause(uint16_t port_id __rte_unused, uint16_t qidx __rte_unused, struct rte_mbuf **pkts __rte_unused, uint16_t nb_rx, uint16_t max_pkts __rte_unused, void *arg) { - const unsigned int lcore = rte_lcore_id(); struct queue_list_entry *queue_conf = arg; struct pmd_core_cfg *lcore_conf; const bool empty = nb_rx == 0; uint32_t pause_duration = rte_power_pmd_mgmt_get_pause_duration(); - lcore_conf = &lcore_cfgs[lcore]; + lcore_conf = RTE_LCORE_VAR_VALUE(lcore_cfgs); if (likely(!empty)) /* early exit */ @@ -358,9 +357,8 @@ clb_scale_freq(uint16_t port_id __rte_unused, uint16_t qidx __rte_unused, struct rte_mbuf **pkts __rte_unused, uint16_t nb_rx, uint16_t max_pkts __rte_unused, void *arg) { - const unsigned int lcore = rte_lcore_id(); const bool empty = nb_rx == 0; - struct pmd_core_cfg *lcore_conf = &lcore_cfgs[lcore]; + struct pmd_core_cfg *lcore_conf = RTE_LCORE_VAR_VALUE(lcore_cfgs); struct queue_list_entry *queue_conf = arg; if (likely(!empty)) { @@ -518,7 +516,7 @@ rte_power_ethdev_pmgmt_queue_enable(unsigned int lcore_id, uint16_t port_id, goto end; } - lcore_cfg = &lcore_cfgs[lcore_id]; + lcore_cfg = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, lcore_cfgs); /* check if other queues are stopped as well */ ret = cfg_queues_stopped(lcore_cfg); @@ -619,7 +617,7 @@ rte_power_ethdev_pmgmt_queue_disable(unsigned int lcore_id, } /* no need to check queue id as wrong queue id would not be enabled */ - lcore_cfg = &lcore_cfgs[lcore_id]; + lcore_cfg = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, lcore_cfgs); /* check if other queues are stopped as well */ ret = cfg_queues_stopped(lcore_cfg); @@ -769,21 +767,21 @@ rte_power_pmd_mgmt_get_scaling_freq_max(unsigned int lcore) } RTE_INIT(rte_power_ethdev_pmgmt_init) { - size_t i; - int j; + struct pmd_core_cfg *lcore_cfg; + int i; + + RTE_LCORE_VAR_ALLOC(lcore_cfgs); /* initialize all tailqs */ - for (i = 0; i < RTE_DIM(lcore_cfgs); i++) { - struct pmd_core_cfg *cfg = &lcore_cfgs[i]; - TAILQ_INIT(&cfg->head); - } + RTE_LCORE_VAR_FOREACH_VALUE(lcore_cfg, lcore_cfgs) + TAILQ_INIT(&lcore_cfg->head); /* initialize config defaults */ emptypoll_max = 512; pause_duration = 1; /* scaling defaults out of range to ensure not used unless set by user or app */ - for (j = 0; j < RTE_MAX_LCORE; j++) { - scale_freq_min[j] = 0; - scale_freq_max[j] = UINT32_MAX; + for (i = 0; i < RTE_MAX_LCORE; i++) { + scale_freq_min[i] = 0; + scale_freq_max[i] = UINT32_MAX; } } From patchwork Mon May 6 08:27:20 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: 139876 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 46C7343FC4; Mon, 6 May 2024 10:38:50 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 16B484067A; Mon, 6 May 2024 10:38:32 +0200 (CEST) Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2089.outbound.protection.outlook.com [40.107.241.89]) by mails.dpdk.org (Postfix) with ESMTP id 151A5402E5 for ; Mon, 6 May 2024 10:38:26 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Se1v7b8o7LGIQgtIIXaSb58M3Q8A66FPCyaaFq/19+IAy4E2VJYjY87OxIPDlbzUdnp6q20APlcS2GNTqqmiCnvWsoocuH5SLybzJw1rZ/CUR6+mUJEAmv3zfwd0FYJCEYZGhSbE4l1vmzAVzGlcWijlJ0nPBoTPwvf++nd2UkFAw9iHg5FTYJ2+JDOcPuU480TVLEucRUpxHmsR0udA1jmQ6+yKp8VfyCp3yJB02QX7uxw9ydGq1vqRVJZEoiq2R9xvYfmSvJzEAQyznOSF7yPqhN7aeWeHnoqgALYMr/DLC85rEvHqML1+t6ETpGidCPNAVI73ovGaemuVYtWNNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Bz5Q71nFaQh1hIfld6+lVrURS6/xyko8jo9SsDlqzuM=; b=Ai8TBNcG2zZecPHP3xfblzFIgMaUk3sc9RBMBeBD7/fCq6jZIZFRPC7LjbCBy8Pmqek9ZIWQOTx02+FE5css5SS+OFklb4l5ssPfTNUbzphXpiTFOwfziZZdrozJeUGtEsEg03oLDp75BjL17MW96DCFXV00RnDLXl8yIvl0gnOxDbqYPr1kRWI021UwCHdU7koNuifSPiln12YK37Yu1P/LOqu7+jKOzOUl/p/mENIETwhEwc0cNXqXsw+jm6VX5Z+dVJV1H/uc91QAJUeBbq6JOOfChVVRGQAsUSJxatKiQ8mRSorEnkHq6RAYUHkA4+o5i8twi7xra5O/rrDKiQ== 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=Bz5Q71nFaQh1hIfld6+lVrURS6/xyko8jo9SsDlqzuM=; b=s8SfKKzOnlVjwmGwOodvD3B/ff4I4ehWzHmzCqT9cGJyQHaEJ3hoAhEZkqnUNo09RO7p1AVbEB5vqmMiJJfySKX8ylRZ7lpYJIJNWJsWA8D1NTH9pU+gsvOxdyBEZTi5am6AbAzPS0i6QV+JscDYDyoUD5kqA6ekEdGldPkD0KLH2rBC1+AFt0htj4pScFkx+qLKWfD7JfjLM2ooB0V5mTZSi689UxrTZnrrbtjNrxvrfgZph5Z2sHhO/9SsdKKsJFTmM0B0an/G99U2iF7MaDyxPUcpTSUg+y31lL5tsO0sAQQlhRZbGVlsVsSS/AUfxE011STWkHpYiSJwUhmOmA== Received: from DUZPR01CA0027.eurprd01.prod.exchangelabs.com (2603:10a6:10:46b::14) by AM7PR07MB6994.eurprd07.prod.outlook.com (2603:10a6:20b:1b2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.41; Mon, 6 May 2024 08:38:24 +0000 Received: from DU6PEPF00009526.eurprd02.prod.outlook.com (2603:10a6:10:46b:cafe::a9) by DUZPR01CA0027.outlook.office365.com (2603:10a6:10:46b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.39 via Frontend Transport; Mon, 6 May 2024 08:38:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 192.176.1.74) smtp.mailfrom=ericsson.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ericsson.com; Received-SPF: Pass (protection.outlook.com: domain of ericsson.com designates 192.176.1.74 as permitted sender) receiver=protection.outlook.com; client-ip=192.176.1.74; helo=oa.msg.ericsson.com; pr=C Received: from oa.msg.ericsson.com (192.176.1.74) by DU6PEPF00009526.mail.protection.outlook.com (10.167.8.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.18 via Frontend Transport; Mon, 6 May 2024 08:38:24 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.68) with Microsoft SMTP Server id 15.2.1544.9; Mon, 6 May 2024 10:38:23 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id ADB601C006A; Mon, 6 May 2024 10:38:23 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , =?utf-8?q?Morten_Br=C3=B8rup?= , Stephen Hemminger , Konstantin Ananyev , =?utf-8?q?Mattias_R?= =?utf-8?q?=C3=B6nnblom?= Subject: [RFC v6 5/6] service: keep per-lcore state in lcore variable Date: Mon, 6 May 2024 10:27:20 +0200 Message-ID: <20240506082721.120666-6-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240506082721.120666-1-mattias.ronnblom@ericsson.com> References: <20240228100928.524277-2-mattias.ronnblom@ericsson.com> <20240506082721.120666-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU6PEPF00009526:EE_|AM7PR07MB6994:EE_ X-MS-Office365-Filtering-Correlation-Id: d3b74d05-665a-4884-ff1c-08dc6da7e49c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|82310400017|376005|36860700004|1800799015; X-Microsoft-Antispam-Message-Info: =?utf-8?q?7PF1m6UroGHN1+tpWRsgz0iWTugBl4i?= =?utf-8?q?lXhWVc5Mtyu/qhro9PspfI2fcU3CzvGiOcp1HD+vnDdykjqkKwY3ThKRdib2kThvt?= =?utf-8?q?EwElmpVGZozXRoy/+oRghaerKe1d0KtzgKDBj5lN8u8WD/BegFEhC8KCQ8j8R9v5q?= =?utf-8?q?Hhaq+1Zs6eWsBrHsoIkeNxtTGHuOae5JyvO7zAmnAyAzDgzHvkT6aJHAw8g0yw173?= =?utf-8?q?KLv2w12mtlCLGyD4mCoj4q+a87gp7QkNYhlLd/hM3MmWsL1lmWXh8dGswZJqZUGlV?= =?utf-8?q?nVHD3txqg1hY9DixC3MLuXfew8UTAUr9kOspxXYd9LKEWlnEnnYuKt3ZGjN7UwhiK?= =?utf-8?q?4H96+jYVG4ZjVIqHnK41m0zn3J3PkwziPdDuPmQJOF6/ODTmDJqec5mRy1BKJPYWY?= =?utf-8?q?rBRY/1m8U6V7Jj3aithfFcDBrnNAmleOK/JHz4uAjgDgKqa3VTKiSKmUqtOm/i9XI?= =?utf-8?q?mUPO+10DcuwcTgfbALPfTYloZbt1eZl39Y43of9zZIJMgTjFmTNknJcg4VnsqxINR?= =?utf-8?q?u1pK2xwIkGsVDYMnyj0AYQznX2QLAVSkAJiYZFN91Kycx3u98sutX5NwMvUfkDhy+?= =?utf-8?q?LpjcPx5DEPQdGPAEoIDLgw6aEG6C63rNzOpy0nVoUwPTNkGaToYRFieSWa8nkOOm3?= =?utf-8?q?gRi3+IdU9dvPJel8JijohQ9+3VOhO6YedligXustOO4Ac5+op3/UNjx/O/7/aQWTB?= =?utf-8?q?Otp8A9/+qQ+9ICglrNlxIsJvXsHyxr/AZEOOcNdUrgoTg7Jhq8EYTae2wR5qbNlws?= =?utf-8?q?OOdFoh9pVYuUXf3GVU1VjVpG6NE1i7rj7EjXZvw0qH60cv2tuX4QWtA+0SxvFIcbJ?= =?utf-8?q?SrftUGXZGriMXAm+U8fhg6n65jGNtFHzynZUZ1VcCBux40FrcHaYhVO3U2nYf69an?= =?utf-8?q?0cQRgqnzgl7//9LUbkwd8fiQefBPJ89ivgxwaUb1SiTnBKs9HeyrxfSTMDD8O+DSd?= =?utf-8?q?lfLTNsE6kftbutQr7ceFQY1B5c1SSApP95TgD9PRhfPcA93jt1r4pftxiqLyiPFw/?= =?utf-8?q?g2X1/exi7T0xPSrKuVzaDv6R8p3vcfJkbpl/xvZqbwM9kjWrunhMXFEo9zBeBPerd?= =?utf-8?q?PzWo9F2J3Eh7IO2bcYoMf90r/oCvZEpMM7XOC3QUiMXDW0gM0PpwNDZ+GbSscxItF?= =?utf-8?q?6BRhb7yci7iROei4uIJrzQB5PdtEYlOOHSSKTf8L20bzCRjQPmy3Jx0PtBPE0G5P+?= =?utf-8?q?QM3el6U/w+sbCPdAcYiH16fJZ4z/jjvD/K9gPWBl1Z9pJVClh6DSvoAJeRw2JDdu8?= =?utf-8?q?fdm4TsgoTCRWRhlasQAm+WYe5h1pLdchnjmCiNnGs6w6E5kH1brH/XAfEL7eKa/tb?= =?utf-8?q?B74lmT74Ph7J?= X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230031)(82310400017)(376005)(36860700004)(1800799015); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 May 2024 08:38:24.0977 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d3b74d05-665a-4884-ff1c-08dc6da7e49c 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: DU6PEPF00009526.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR07MB6994 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. 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) Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup --- lib/eal/common/rte_service.c | 115 +++++++++++++++++++---------------- 1 file changed, 63 insertions(+), 52 deletions(-) diff --git a/lib/eal/common/rte_service.c b/lib/eal/common/rte_service.c index 56379930b6..03379f1588 100644 --- a/lib/eal/common/rte_service.c +++ b/lib/eal/common/rte_service.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -75,7 +76,7 @@ struct __rte_cache_aligned core_state { static uint32_t rte_service_count; static struct rte_service_spec_impl *rte_services; -static struct core_state *lcore_states; +static RTE_LCORE_VAR_HANDLE(struct core_state, lcore_states); static uint32_t rte_service_library_initialized; int32_t @@ -101,12 +102,8 @@ rte_service_init(void) goto fail_mem; } - lcore_states = rte_calloc("rte_service_core_states", RTE_MAX_LCORE, - sizeof(struct core_state), RTE_CACHE_LINE_SIZE); - if (!lcore_states) { - EAL_LOG(ERR, "error allocating core states array"); - goto fail_mem; - } + if (lcore_states == NULL) + RTE_LCORE_VAR_ALLOC(lcore_states); int i; struct rte_config *cfg = rte_eal_get_configuration(); @@ -122,7 +119,6 @@ rte_service_init(void) return 0; fail_mem: rte_free(rte_services); - rte_free(lcore_states); return -ENOMEM; } @@ -136,7 +132,6 @@ rte_service_finalize(void) rte_eal_mp_wait_lcore(); rte_free(rte_services); - rte_free(lcore_states); rte_service_library_initialized = 0; } @@ -286,7 +281,6 @@ rte_service_component_register(const struct rte_service_spec *spec, int32_t rte_service_component_unregister(uint32_t id) { - uint32_t i; struct rte_service_spec_impl *s; SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL); @@ -294,9 +288,10 @@ rte_service_component_unregister(uint32_t id) s->internal_flags &= ~(SERVICE_F_REGISTERED); + struct core_state *cs; /* clear the run-bit in all cores */ - for (i = 0; i < RTE_MAX_LCORE; i++) - lcore_states[i].service_mask &= ~(UINT64_C(1) << id); + RTE_LCORE_VAR_FOREACH_VALUE(cs, lcore_states) + cs->service_mask &= ~(UINT64_C(1) << id); memset(&rte_services[id], 0, sizeof(struct rte_service_spec_impl)); @@ -454,7 +449,10 @@ rte_service_may_be_active(uint32_t id) return -EINVAL; for (i = 0; i < lcore_count; i++) { - if (lcore_states[ids[i]].service_active_on_lcore[id]) + struct core_state *cs = + RTE_LCORE_VAR_LCORE_VALUE(ids[i], lcore_states); + + if (cs->service_active_on_lcore[id]) return 1; } @@ -464,7 +462,7 @@ rte_service_may_be_active(uint32_t id) int32_t rte_service_run_iter_on_app_lcore(uint32_t id, uint32_t serialize_mt_unsafe) { - struct core_state *cs = &lcore_states[rte_lcore_id()]; + struct core_state *cs = RTE_LCORE_VAR_VALUE(lcore_states); struct rte_service_spec_impl *s; SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL); @@ -486,8 +484,7 @@ service_runner_func(void *arg) { RTE_SET_USED(arg); uint8_t i; - const int lcore = rte_lcore_id(); - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_VALUE(lcore_states); rte_atomic_store_explicit(&cs->thread_active, 1, rte_memory_order_seq_cst); @@ -533,13 +530,15 @@ service_runner_func(void *arg) int32_t rte_service_lcore_may_be_active(uint32_t lcore) { - if (lcore >= RTE_MAX_LCORE || !lcore_states[lcore].is_service_core) + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); + + if (lcore >= RTE_MAX_LCORE || !cs->is_service_core) return -EINVAL; /* Load thread_active using ACQUIRE to avoid instructions dependent on * the result being re-ordered before this load completes. */ - return rte_atomic_load_explicit(&lcore_states[lcore].thread_active, + return rte_atomic_load_explicit(&cs->thread_active, rte_memory_order_acquire); } @@ -547,9 +546,11 @@ int32_t rte_service_lcore_count(void) { int32_t count = 0; - uint32_t i; - for (i = 0; i < RTE_MAX_LCORE; i++) - count += lcore_states[i].is_service_core; + + struct core_state *cs; + RTE_LCORE_VAR_FOREACH_VALUE(cs, lcore_states) + count += cs->is_service_core; + return count; } @@ -566,7 +567,8 @@ rte_service_lcore_list(uint32_t array[], uint32_t n) uint32_t i; uint32_t idx = 0; for (i = 0; i < RTE_MAX_LCORE; i++) { - struct core_state *cs = &lcore_states[i]; + struct core_state *cs = + RTE_LCORE_VAR_LCORE_VALUE(i, lcore_states); if (cs->is_service_core) { array[idx] = i; idx++; @@ -582,7 +584,7 @@ rte_service_lcore_count_services(uint32_t lcore) if (lcore >= RTE_MAX_LCORE) return -EINVAL; - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); if (!cs->is_service_core) return -ENOTSUP; @@ -634,30 +636,31 @@ rte_service_start_with_defaults(void) static int32_t service_update(uint32_t sid, uint32_t lcore, uint32_t *set, uint32_t *enabled) { + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); + /* validate ID, or return error value */ if (!service_valid(sid) || lcore >= RTE_MAX_LCORE || - !lcore_states[lcore].is_service_core) + !cs->is_service_core) return -EINVAL; uint64_t sid_mask = UINT64_C(1) << sid; if (set) { - uint64_t lcore_mapped = lcore_states[lcore].service_mask & - sid_mask; + uint64_t lcore_mapped = cs->service_mask & sid_mask; if (*set && !lcore_mapped) { - lcore_states[lcore].service_mask |= sid_mask; + cs->service_mask |= sid_mask; rte_atomic_fetch_add_explicit(&rte_services[sid].num_mapped_cores, 1, rte_memory_order_relaxed); } if (!*set && lcore_mapped) { - lcore_states[lcore].service_mask &= ~(sid_mask); + cs->service_mask &= ~(sid_mask); rte_atomic_fetch_sub_explicit(&rte_services[sid].num_mapped_cores, 1, rte_memory_order_relaxed); } } if (enabled) - *enabled = !!(lcore_states[lcore].service_mask & (sid_mask)); + *enabled = !!(cs->service_mask & (sid_mask)); return 0; } @@ -685,13 +688,14 @@ set_lcore_state(uint32_t lcore, int32_t state) { /* mark core state in hugepage backed config */ struct rte_config *cfg = rte_eal_get_configuration(); + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); cfg->lcore_role[lcore] = state; /* mark state in process local lcore_config */ lcore_config[lcore].core_role = state; /* update per-lcore optimized state tracking */ - lcore_states[lcore].is_service_core = (state == ROLE_SERVICE); + cs->is_service_core = (state == ROLE_SERVICE); rte_eal_trace_service_lcore_state_change(lcore, state); } @@ -702,14 +706,16 @@ rte_service_lcore_reset_all(void) /* loop over cores, reset all to mask 0 */ uint32_t i; for (i = 0; i < RTE_MAX_LCORE; i++) { - if (lcore_states[i].is_service_core) { - lcore_states[i].service_mask = 0; + struct core_state *cs = + RTE_LCORE_VAR_LCORE_VALUE(i, lcore_states); + if (cs->is_service_core) { + cs->service_mask = 0; set_lcore_state(i, ROLE_RTE); /* runstate act as guard variable Use * store-release memory order here to synchronize * with load-acquire in runstate read functions. */ - rte_atomic_store_explicit(&lcore_states[i].runstate, + rte_atomic_store_explicit(&cs->runstate, RUNSTATE_STOPPED, rte_memory_order_release); } } @@ -725,17 +731,19 @@ rte_service_lcore_add(uint32_t lcore) { if (lcore >= RTE_MAX_LCORE) return -EINVAL; - if (lcore_states[lcore].is_service_core) + + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); + if (cs->is_service_core) return -EALREADY; set_lcore_state(lcore, ROLE_SERVICE); /* ensure that after adding a core the mask and state are defaults */ - lcore_states[lcore].service_mask = 0; + cs->service_mask = 0; /* Use store-release memory order here to synchronize with * load-acquire in runstate read functions. */ - rte_atomic_store_explicit(&lcore_states[lcore].runstate, RUNSTATE_STOPPED, + rte_atomic_store_explicit(&cs->runstate, RUNSTATE_STOPPED, rte_memory_order_release); return rte_eal_wait_lcore(lcore); @@ -747,7 +755,7 @@ rte_service_lcore_del(uint32_t lcore) if (lcore >= RTE_MAX_LCORE) return -EINVAL; - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); if (!cs->is_service_core) return -EINVAL; @@ -771,7 +779,7 @@ rte_service_lcore_start(uint32_t lcore) if (lcore >= RTE_MAX_LCORE) return -EINVAL; - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); if (!cs->is_service_core) return -EINVAL; @@ -801,6 +809,8 @@ rte_service_lcore_start(uint32_t lcore) int32_t rte_service_lcore_stop(uint32_t lcore) { + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); + if (lcore >= RTE_MAX_LCORE) return -EINVAL; @@ -808,12 +818,11 @@ rte_service_lcore_stop(uint32_t lcore) * memory order here to synchronize with store-release * in runstate update functions. */ - if (rte_atomic_load_explicit(&lcore_states[lcore].runstate, rte_memory_order_acquire) == + if (rte_atomic_load_explicit(&cs->runstate, rte_memory_order_acquire) == RUNSTATE_STOPPED) return -EALREADY; uint32_t i; - struct core_state *cs = &lcore_states[lcore]; uint64_t service_mask = cs->service_mask; for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) { @@ -834,7 +843,7 @@ rte_service_lcore_stop(uint32_t lcore) /* Use store-release memory order here to synchronize with * load-acquire in runstate read functions. */ - rte_atomic_store_explicit(&lcore_states[lcore].runstate, RUNSTATE_STOPPED, + rte_atomic_store_explicit(&cs->runstate, RUNSTATE_STOPPED, rte_memory_order_release); rte_eal_trace_service_lcore_stop(lcore); @@ -845,7 +854,7 @@ rte_service_lcore_stop(uint32_t lcore) static uint64_t lcore_attr_get_loops(unsigned int lcore) { - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); return rte_atomic_load_explicit(&cs->loops, rte_memory_order_relaxed); } @@ -853,7 +862,7 @@ lcore_attr_get_loops(unsigned int lcore) static uint64_t lcore_attr_get_cycles(unsigned int lcore) { - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); return rte_atomic_load_explicit(&cs->cycles, rte_memory_order_relaxed); } @@ -861,7 +870,7 @@ lcore_attr_get_cycles(unsigned int lcore) static uint64_t lcore_attr_get_service_calls(uint32_t service_id, unsigned int lcore) { - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); return rte_atomic_load_explicit(&cs->service_stats[service_id].calls, rte_memory_order_relaxed); @@ -870,7 +879,7 @@ lcore_attr_get_service_calls(uint32_t service_id, unsigned int lcore) static uint64_t lcore_attr_get_service_cycles(uint32_t service_id, unsigned int lcore) { - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); return rte_atomic_load_explicit(&cs->service_stats[service_id].cycles, rte_memory_order_relaxed); @@ -886,7 +895,10 @@ attr_get(uint32_t id, lcore_attr_get_fun lcore_attr_get) uint64_t sum = 0; for (lcore = 0; lcore < RTE_MAX_LCORE; lcore++) { - if (lcore_states[lcore].is_service_core) + struct core_state *cs = + RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); + + if (cs->is_service_core) sum += lcore_attr_get(id, lcore); } @@ -930,12 +942,11 @@ int32_t rte_service_lcore_attr_get(uint32_t lcore, uint32_t attr_id, uint64_t *attr_value) { - struct core_state *cs; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); if (lcore >= RTE_MAX_LCORE || !attr_value) return -EINVAL; - cs = &lcore_states[lcore]; if (!cs->is_service_core) return -ENOTSUP; @@ -960,7 +971,8 @@ rte_service_attr_reset_all(uint32_t id) return -EINVAL; for (lcore = 0; lcore < RTE_MAX_LCORE; lcore++) { - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = + RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); cs->service_stats[id] = (struct service_stats) {}; } @@ -971,12 +983,11 @@ rte_service_attr_reset_all(uint32_t id) int32_t rte_service_lcore_attr_reset_all(uint32_t lcore) { - struct core_state *cs; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); if (lcore >= RTE_MAX_LCORE) return -EINVAL; - cs = &lcore_states[lcore]; if (!cs->is_service_core) return -ENOTSUP; @@ -1011,7 +1022,7 @@ static void service_dump_calls_per_lcore(FILE *f, uint32_t lcore) { uint32_t i; - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); fprintf(f, "%02d\t", lcore); for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) { From patchwork Mon May 6 08:27:21 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: 139879 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 4548C43FC4; Mon, 6 May 2024 10:39:15 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6B141406B7; Mon, 6 May 2024 10:38:37 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2058.outbound.protection.outlook.com [40.107.22.58]) by mails.dpdk.org (Postfix) with ESMTP id 17344402EE for ; Mon, 6 May 2024 10:38:28 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NwUiKaldlBWp8CbBOZYmustWPDvmbr6zshvBxcQGy7we6MyO5q3utOPKXW4nS1Tc8AvQ1P1e+GwduKq1ogq9htxpMMqlcNTXqWr1IjHN8//uVWUmU8IJOiRH3SO7zZtuanv0/daHs+HE5oy123RUz++mDMTuRKNnmHHiqKAcCQ/qTbFqwxr9+d+DGSfPFbMhfXuSf5RFban5jRrxAi8SRjPzmkFWmsFRxjOW/gsU8h2LcYMpsaAb3UCcGhcENqz0YhdH/7Szv6UdiJMJhgMGOpr+u6LlVMu00xD6lkCQJLF/7YcTp8NynU/v4i4EMrrYHhgMmSZm+CmHh2VTNjpDxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5KgLIeJsoXsbjQgRv+axyk0s7Khi0OpcLSDJyLLTnRM=; b=BG3yx/rU7U+2Yhso2ozreNYU7OuJSI2HpQtXhql52RDbTdOIuwPqNAGvBEhiNSyYNslAB8Df2b++2J3Cb4I3Q4ZwlqQevcfg54JbttXwIE+Vn3F7UwiuF2PsWhj2WE2guHjjR1r60ReBRf2RmncSB2LeXBnTPb2ljIjosrpUE1cpalk8L3YvC5hp5YJSszQhvBii84qzLp8cokEZzUtcIy7Br2Gu1BwBTiaynbIy4/OXzaAJsOOY2GQE7ylXwsNyK5xBPUuw4vZ07lGNEJW8ZB1Q7/OpYCDzh3QvLzzA4i2NmVSy7h6FXAN43RspVn2abHDTQOU/g47Eojw7sZNcaA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 192.176.1.74) smtp.rcpttodomain=dpdk.org smtp.mailfrom=ericsson.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ericsson.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5KgLIeJsoXsbjQgRv+axyk0s7Khi0OpcLSDJyLLTnRM=; b=wnsuZz/4UsRchq06jSTs70lRNBieGqE7O7KeOwP4ttR0SlYhmzkn6sQsX6ZT3+AI+yvyO5ZevUaPTQ9euJkSd8r3Q92sibghqlJ0aT+urSpkuV9gw3ZuZ+yE47PY3xE+OD4kxTe+Zta/GAoiDL/LSV98z/BmYBTSkxsTqU0AQn7vXDW62ER6T0MOsLl2Rxf4RqNqTSjpK1f0nCo3Y4V57B8EqsWhyQvbZtj6n8faGZCF+6jBEwkb1U7p0SPvN5/e4pQfW5OdXW4H5oUtSFOnn30XPCJw997FnqcY4KH7H7zEfs1+rgdh6FR09qB9mT+FN6sXr/EonLz9Furkzu6mGg== Received: from AM0PR02CA0162.eurprd02.prod.outlook.com (2603:10a6:20b:28d::29) by VI1PR07MB6496.eurprd07.prod.outlook.com (2603:10a6:800:183::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.41; Mon, 6 May 2024 08:38:26 +0000 Received: from AMS0EPF000001A8.eurprd05.prod.outlook.com (2603:10a6:20b:28d:cafe::d7) by AM0PR02CA0162.outlook.office365.com (2603:10a6:20b:28d::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.41 via Frontend Transport; Mon, 6 May 2024 08:38:25 +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 AMS0EPF000001A8.mail.protection.outlook.com (10.167.16.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.18 via Frontend Transport; Mon, 6 May 2024 08:38:25 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.64) with Microsoft SMTP Server id 15.2.1544.9; Mon, 6 May 2024 10:38:24 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 46CE51C006A; Mon, 6 May 2024 10:38:24 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , =?utf-8?q?Morten_Br=C3=B8rup?= , Stephen Hemminger , Konstantin Ananyev , =?utf-8?q?Mattias_R?= =?utf-8?q?=C3=B6nnblom?= Subject: [RFC v6 6/6] eal: keep per-lcore power intrinsics state in lcore variable Date: Mon, 6 May 2024 10:27:21 +0200 Message-ID: <20240506082721.120666-7-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240506082721.120666-1-mattias.ronnblom@ericsson.com> References: <20240228100928.524277-2-mattias.ronnblom@ericsson.com> <20240506082721.120666-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AMS0EPF000001A8:EE_|VI1PR07MB6496:EE_ X-MS-Office365-Filtering-Correlation-Id: 8dd2bb80-bd0f-4d52-c949-08dc6da7e57d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|82310400017|376005|36860700004|1800799015; X-Microsoft-Antispam-Message-Info: =?utf-8?q?MbYCNlPfI7wWklqSlnLwWlNSrrett8x?= =?utf-8?q?6Vb7Zp9CAYZeyWCSPAnl2z5XsGL8yT8lxWCh4DlivWHbAH1a4bL1Suz0dAweG4qSr?= =?utf-8?q?KuUiLAM8mpKELdq9fv0+g5hFXBY+qZ6nwrayIVZlrzjxBBFmPvNU0sF8nwEZz1UR7?= =?utf-8?q?xkH4xtha6B3v+iZmZAtVJ3mL2GeiJslFmX6lOOSp1ALQgdvWs37oNXF86BuspqGcS?= =?utf-8?q?H6QZTkXiEKY70MLDnG8wdVBx1H0gsdiqhVYnFrP0mh5jsdqWFAfDUGCWo9KpZbckd?= =?utf-8?q?wTET9qJ0b+PZbFOAaNhAwDxXN32W2o4Btjx12+FfTfxclV0sR5T1KoJldbih9YGvl?= =?utf-8?q?vznYN+UzzPtRQyKq0KW0CJfJpmZi7GUnIPOiXDDLRFqep/KH5xcpGHcpSEivMSBEr?= =?utf-8?q?DBkE04yM48+R/GbCw+XCYJ+8gpI5h7gTKlFv9xWdrRkbS8T5VIjc3b0GQFLWYb6cR?= =?utf-8?q?5mX2YcvPfa8OGyHrgH93/EVILM6tR32aInh2jT0lzVh9d2cbo++3TW2lnjNEMzs2R?= =?utf-8?q?7HFGEemJHy9M9QCGhm+ujWJ/0QDjmpAUYkAod4hIZu7VLw3fYj+UdQT9rynaRkFqD?= =?utf-8?q?MUg8TQunRVWz8MHFiei7RMA/14zW5oedNa9j96BK3Nt1qRmwVMBQEVDt9jdemB922?= =?utf-8?q?XhEEB0UVp8iC7emC/sd4xBjdGHnDNsMDxwrSLaItbmTaBMNj0OakoPhb3CL4H9Gx4?= =?utf-8?q?O9vcVgI2Eq+f6MbHZ0CRGHHS+JAbKNVxzUi8pWb+U2ZbiuIqbbkMzKKKJFfqGwmOe?= =?utf-8?q?pM6nbXEz0/URyzDAvfYJhGoIgi85EzBSnZcn8JYdoD4LLNH0bsUgYQirVznJwsTGf?= =?utf-8?q?1ofOWkMeOfkOUaONyLtZxHIwYMC+YRNtHXZ07RZvvzV59d/xqvi35aUDLBI3JbJ5/?= =?utf-8?q?yosnIgPNAK/3X2d0AA3dx511zO4NCr+6LHoe72VnvTvpnia3xNMa3gyroFOh7WmaA?= =?utf-8?q?D3rTBoQ+QgGkuYkf+REvnLCcykB0V4+D5qxxCw4izrb3nde86XL+B/hpk8u6wpdCq?= =?utf-8?q?yJnXk4XjIggEAPlNOr0Q3wiv3jPwWPqloIeMF6FToHe1dOqBiyhh6TVHU6G86gHmC?= =?utf-8?q?t8mnr926XiY+ZQaSgrqpK+NjRbCnyZfBvdTX8H3lSrgeyVOEzILCCOK8TCj3Kzskb?= =?utf-8?q?5cy96oj0FpK4ANQt7sXz+UxtvDxXT/n9JkhRL6a1GM0BfwAQb/76+eXnUNWh+uZkz?= =?utf-8?q?1jl+QpzJTo0VmRfiDiI8pZvmFmu/0TvEzJn+QdkoyilAapy3pQoVTWVnOqSulwlZh?= =?utf-8?q?JJL6pcqs9cfbzq4HB3Ll+EklVq+N9oueaXlFeNOZ6D2EALiGWeuqyXq0=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:(13230031)(82310400017)(376005)(36860700004)(1800799015); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 May 2024 08:38:25.6334 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8dd2bb80-bd0f-4d52-c949-08dc6da7e57d 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: AMS0EPF000001A8.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB6496 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Keep per-lcore power intrinsics state in a lcore variable to reduce cache working set size and avoid any CPU next-line-prefetching causing false sharing. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup --- lib/eal/x86/rte_power_intrinsics.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/eal/x86/rte_power_intrinsics.c b/lib/eal/x86/rte_power_intrinsics.c index 6d9b64240c..f4ba2c8ecb 100644 --- a/lib/eal/x86/rte_power_intrinsics.c +++ b/lib/eal/x86/rte_power_intrinsics.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -14,10 +15,14 @@ /* * Per-lcore structure holding current status of C0.2 sleeps. */ -static alignas(RTE_CACHE_LINE_SIZE) struct power_wait_status { +struct power_wait_status { rte_spinlock_t lock; volatile void *monitor_addr; /**< NULL if not currently sleeping */ -} wait_status[RTE_MAX_LCORE]; +}; + +RTE_LCORE_VAR_HANDLE(struct power_wait_status, wait_status); + +RTE_LCORE_VAR_INIT(wait_status); /* * This function uses UMONITOR/UMWAIT instructions and will enter C0.2 state. @@ -172,7 +177,7 @@ rte_power_monitor(const struct rte_power_monitor_cond *pmc, if (pmc->fn == NULL) return -EINVAL; - s = &wait_status[lcore_id]; + s = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, wait_status); /* update sleep address */ rte_spinlock_lock(&s->lock); @@ -264,7 +269,7 @@ rte_power_monitor_wakeup(const unsigned int lcore_id) if (lcore_id >= RTE_MAX_LCORE) return -EINVAL; - s = &wait_status[lcore_id]; + s = RTE_LCORE_VAR_LCORE_VALUE(lcore_id, wait_status); /* * There is a race condition between sleep, wakeup and locking, but we @@ -303,8 +308,8 @@ int rte_power_monitor_multi(const struct rte_power_monitor_cond pmc[], const uint32_t num, const uint64_t tsc_timestamp) { - const unsigned int lcore_id = rte_lcore_id(); - struct power_wait_status *s = &wait_status[lcore_id]; + struct power_wait_status *s = RTE_LCORE_VAR_VALUE(wait_status); + uint32_t i, rc; /* check if supported */