From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 264BE45B04; Thu, 10 Oct 2024 16:23:03 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 132EE40655; Thu, 10 Oct 2024 16:23:03 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2042.outbound.protection.outlook.com [40.107.22.42]) by mails.dpdk.org (Postfix) with ESMTP id 008114026B for ; Thu, 10 Oct 2024 16:23:01 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=k09946+42MDhSqM/AumQh+9c21HfUHNPs88vygLkFo2UaFDeV9/8BP9h2ttP5sZLHs0NyWP4EK0AB2gb0WWexNQu1WzOIjb1SS0DJaY5Zt4cccVZ7InjHo5aV+MzRIV7DMIqIUZaoWBRhY/9daku5vN/YjZ6oAY4JtT5Oe85l9m6qPKQET5IL16rX/MjrRC2Ch3Q0iWRW9SybW4qHf/DRHVNh87JEmrKAINOxdm1Fy3DnITnyvJ9XekiQ0Rr4aT4ZnkLTg1eL7qcHDKG/8wkR87qKSwHCqa/W8t1S4Sv5jm0zfGbWs/x/clirr+RfVp05KBjRdb/LcnXlEFZv9zrxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZcrIxsUczn3eEQ4B3j0n5Yi5yrD0dIPqXBBskKRbBbI=; b=OKKbIu2FinzZoQhPGSxDWqige+BeoZPR8XJAC/oLIYpkgN0CGxcP20hGFKI6V4JYo7lJ6avg+ZTuQ6Z8xLbQj8BEuci/1AfT4ZG9dlkJOl1AuMzUg6Auot3q01yspZg1wC/lW9iSn8ktUEqVeTAhIaxLz66ImkHFOWI64EkwAPUieqM3sX64WhsyUqh41w2GKHGGYgpexblcteIxWlwtX9pXQz7G5Udm4YTBlDqoWZihOqIJVJIIa+IeD8ZN+B2ZXhomz9KdTxTZQEwinwcGkhx8NmGDoUHaHV6aEMmtMkeQB5V7ZNx0q24HX/ew6mcexog4ZyWhqazxy9jKIEgg3w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 192.176.1.74) smtp.rcpttodomain=dpdk.org smtp.mailfrom=ericsson.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ericsson.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZcrIxsUczn3eEQ4B3j0n5Yi5yrD0dIPqXBBskKRbBbI=; b=Yc871SVvrWN3eXkEF7XmpE8QKaFuOUIvhOOlM2YiI1SRA82mNaCorsUpazyuGgvZmL1j85J6A3Cgl+LHB/AJgaLJdXwNCBUFqOoVP0lvD6HJQlBKlw6VU7IkKBI3E4QrGbY1fcpyORexR2UUFeqL2os3piTvY+4GEp124Md3/vGBbX+FqBmoi/oLuQFV+FU/Yr9S22jvyHwxz/JEMPNsa+FhseAmP14sYad1dQt5OCKZf1DmzxD2IMJ31ajqq7Ux57D5hq4byHylDbsuX4OKed6/E5p4BZn9pA4GIMFmLOxZE5fQGr61wlQUcl0Bh0F/DYXbm36qbnUEa+32q1vstg== Received: from AM5PR1001CA0038.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:206:15::15) by AS8PR07MB9307.eurprd07.prod.outlook.com (2603:10a6:20b:61c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18; Thu, 10 Oct 2024 14:22:59 +0000 Received: from AMS0EPF000001A7.eurprd05.prod.outlook.com (2603:10a6:206:15:cafe::cf) by AM5PR1001CA0038.outlook.office365.com (2603:10a6:206:15::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.17 via Frontend Transport; Thu, 10 Oct 2024 14:22:59 +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 AMS0EPF000001A7.mail.protection.outlook.com (10.167.16.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Thu, 10 Oct 2024 14:22:59 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.63) with Microsoft SMTP Server id 15.2.1544.11; Thu, 10 Oct 2024 16:22:58 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id D3B5F380070; Thu, 10 Oct 2024 16:22:58 +0200 (CEST) From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= To: CC: , =?UTF-8?q?Morten=20Br=C3=B8rup?= , Stephen Hemminger , Konstantin Ananyev , David Marchand , Jerin Jacob , Luka Jankovic , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= , Konstantin Ananyev , Chengwen Feng Subject: [PATCH v8 4/7] random: keep PRNG state in lcore variable Date: Thu, 10 Oct 2024 16:13:46 +0200 Message-ID: <20241010141349.813088-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241010141349.813088-1-mattias.ronnblom@ericsson.com> References: <20240918082614.725220-2-mattias.ronnblom@ericsson.com> <20241010141349.813088-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AMS0EPF000001A7:EE_|AS8PR07MB9307:EE_ X-MS-Office365-Filtering-Correlation-Id: 22b29755-c649-46d7-a991-08dce9370ad7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?B?VEk5V3ZqT2FxK1ZDK0hBc1hnemR6NlZ3TUpPQnpYd1VlLzY2MVQyclBIbXJV?= =?utf-8?B?M3hlMzR0V01sckk5MVpUWnZLRjdKNHZjNVpzVmNVek9NTktBaVo0NWpJd0I0?= =?utf-8?B?dmFDMERSalVPQWNSRGpDWHhFVE9IRnExcGllUjkycDlxWXgrRmJPd3hrS2Jx?= =?utf-8?B?SlRubldmdnBEVjBZNGdSdWJURmNBZGRtRkpoTlV6SFhlSUVMb29tLzhScDQ3?= =?utf-8?B?cGxJUG53bi80c0xNUmJZbVBDTDN4UjJUSTQwaStLTG5SaTQvNVllSVZzSWEw?= =?utf-8?B?NUdZY011R3N6MjBkYUtmemMyOFZOS3JZL1VZUnJsRzZHaEhlZHNtNlEzVHBi?= =?utf-8?B?bHlpc2g5SytzY0R0R0dUcVhxSzlsMFpvRWEyZWZaanoxVVRYbFRxWjlHRUpi?= =?utf-8?B?QXNKUFJQeUpPMTZOUVZHbXNmSVZmalYzSFdXbVJib1VQNHJhYlRJM0xaNSt4?= =?utf-8?B?YjA2eFg4NkFTQ3VobEMyMGdVY0J6d2dOQ2VzclQwREZGQjdUWlFQOU5OL29Y?= =?utf-8?B?M2hrKzFwWTRTdHlOU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ZDQ0NUN1RWFNMURHWGYzZ0l5K011OTNxMW9FVW9sYU01UGw2?= =?utf-8?B?dllKREhMamhoNUxGQmYwVnhITTRhMVdkMERwRUlvSzlEdVA3bEhWdFJqaHRh?= =?utf-8?B?REpvWnRWaHBFKzFkY1NqVk54R0Q2NVNtNDR2alhOS3FadzlwUHo0ZUtHcnlE?= =?utf-8?B?bVQ0clhEdTQrZFAra2IxWmZRN3duOGc3KytqU2RwV3d4MU1aK3l4MWYwaGxk?= =?utf-8?B?VUlvQUw2alpCcmhPdDloZXlCQ3Y1K3A4NWZ5NVV5UkZscDZoME5oSld0aHVi?= =?utf-8?B?emtyMHhpS2haSXZHWThHaGtjK0d4SlBQLzhrSFBKNno0MlloaTRiVTdtamZk?= =?utf-8?Q?scPG3r5pJ04B1vKrl8xg4DteF/2QAbf/Qd1pQ=3D?= X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230040)(376014)(1800799024)(36860700013)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2024 14:22:59.3677 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 22b29755-c649-46d7-a991-08dce9370ad7 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: AMS0EPF000001A7.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR07MB9307 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Replace keeping PRNG state in a RTE_MAX_LCORE-sized static array of cache-aligned and RTE_CACHE_GUARDed struct instances with keeping the same state in a more cache-friendly lcore variable. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup Acked-by: Konstantin Ananyev Acked-by: Chengwen Feng Acked-by: Stephen Hemminger -- RFC v3: * Remove cache alignment on unregistered threads' rte_rand_state. (Morten Brørup) --- lib/eal/common/rte_random.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/eal/common/rte_random.c b/lib/eal/common/rte_random.c index 90e91b3c4f..a8d00308dd 100644 --- a/lib/eal/common/rte_random.c +++ b/lib/eal/common/rte_random.c @@ -11,6 +11,7 @@ #include #include #include +#include #include struct __rte_cache_aligned rte_rand_state { @@ -19,14 +20,12 @@ struct __rte_cache_aligned rte_rand_state { uint64_t z3; uint64_t z4; uint64_t z5; - RTE_CACHE_GUARD; }; -/* One instance each for every lcore id-equipped thread, and one - * additional instance to be shared by all others threads (i.e., all - * unregistered non-EAL threads). - */ -static struct rte_rand_state rand_states[RTE_MAX_LCORE + 1]; +RTE_LCORE_VAR_HANDLE(struct rte_rand_state, rand_state); + +/* instance to be shared by all unregistered non-EAL threads */ +static struct rte_rand_state unregistered_rand_state; static uint32_t __rte_rand_lcg32(uint32_t *seed) @@ -85,8 +84,14 @@ rte_srand(uint64_t seed) unsigned int lcore_id; /* add lcore_id to seed to avoid having the same sequence */ - for (lcore_id = 0; lcore_id < RTE_DIM(rand_states); lcore_id++) - __rte_srand_lfsr258(seed + lcore_id, &rand_states[lcore_id]); + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { + struct rte_rand_state *lcore_state = + RTE_LCORE_VAR_LCORE_VALUE(lcore_id, rand_state); + + __rte_srand_lfsr258(seed + lcore_id, lcore_state); + } + + __rte_srand_lfsr258(seed + lcore_id, &unregistered_rand_state); } static __rte_always_inline uint64_t @@ -124,11 +129,10 @@ struct rte_rand_state *__rte_rand_get_state(void) idx = rte_lcore_id(); - /* last instance reserved for unregistered non-EAL threads */ if (unlikely(idx == LCORE_ID_ANY)) - idx = RTE_MAX_LCORE; + return &unregistered_rand_state; - return &rand_states[idx]; + return RTE_LCORE_VAR_VALUE(rand_state); } uint64_t @@ -228,6 +232,8 @@ RTE_INIT(rte_rand_init) { uint64_t seed; + RTE_LCORE_VAR_ALLOC(rand_state); + seed = __rte_random_initial_seed(); rte_srand(seed); -- 2.43.0