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 58AF045B34; Mon, 14 Oct 2024 09:53:12 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5183640151; Mon, 14 Oct 2024 09:53:02 +0200 (CEST) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2081.outbound.protection.outlook.com [40.107.21.81]) by mails.dpdk.org (Postfix) with ESMTP id 8F0BD40273 for ; Mon, 14 Oct 2024 09:52:58 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tn8osSEgL3lc352n+FHOW7O+u+Jqt03gwztXh/ruI6iDa6FSGTkPgg2Gg5dwMBTXksN3MpHwK/zPqusZNQmuJn96o8W8nCIvf7G+aT8uMgGuCfBQjKp+ULA8N6E0xmZ+NX9lIj0++O87jUgTTqPA7RvmVz/QQ9Z+N94u27OdGrRai5qv/VkmmK4buvcV7srR2bZs1UvQ3/Xx0Z11sxNt94m36uMCvBuFduNpDlfDGFkuQAgQxq9AaKS9wrj/UZtvRe+AIf1ObVYDfMR9oIboSvUFIB5qJSriSkiho/fGIPUDCY1+n7XCoZYFW0xWrtXs9DdQlcqwpNtgDf45EG9Afw== 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=VupZFg3OujdkDrQQD871zMleyYE4uBdZfJu09GU/TYLPEgdM2kjQXrrRUYNkve4PCNfn0+aeMMER4cpWTDjdpXLuGQeeghY3eqWZGI53I/qr09ayDaxQ8gBT6z5C7IA6kjUrjFJwBTpjEHM/4I0VdC7tdYC/rbExcWIXp0TBuk+DZg0JmJ/F+j/4M2FKOdjXung/ih5yVq0dqq75P3vKs4bIXzleqfJWcZNs4b7Itpa3VzwoYol/JuMjw6UIzd4gAt+LnR/Wg2le4VT8YiwYaKMODLrO8RTIMa9UbV/myGuv3veV1bHPynkRaleU2bs9VFidpoNI+tiLxDviuoX98Q== 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=DezdpxHulvS7xpaZOw9j3gFeGh6h3s3GS2tZIUAcSSIXaIcYVvGe7QxSizuTokVx8W+83wWs81dt8AolFQ4G0cKORuMo7W5kpjdGOQbmzO3PbhPGvI+EHNGZTkdv8+Dm5oSi0hl9MHqz7+8K4O0Qr4k1lRT8kdmYy0tDx3CjquUuPBP+0p2V60YBJy6y1Onw2Cggc1lvo7yli1fuvLlnx3cjiEce5LfKIuiWnJ2UIYaE+AAaTa1HIRqsvnbU6KwpH5VidOliZYnGXmQ1JwzgthIF6LIAw1QS757OGM5RkRcFxKUrNISdfAA3kL9xrG5nvUu9PkmXSJRXcN4JnFzqCw== Received: from DUZPR01CA0219.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b4::16) by AS8PR07MB7367.eurprd07.prod.outlook.com (2603:10a6:20b:2a2::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.25; Mon, 14 Oct 2024 07:52:55 +0000 Received: from DU2PEPF00028CFD.eurprd03.prod.outlook.com (2603:10a6:10:4b4:cafe::9b) by DUZPR01CA0219.outlook.office365.com (2603:10a6:10:4b4::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.26 via Frontend Transport; Mon, 14 Oct 2024 07:52:55 +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 DU2PEPF00028CFD.mail.protection.outlook.com (10.167.242.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.13 via Frontend Transport; Mon, 14 Oct 2024 07:52:55 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.68) with Microsoft SMTP Server id 15.2.1544.11; Mon, 14 Oct 2024 09:52:54 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 7415B1C0073; Mon, 14 Oct 2024 09:52:54 +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 v11 4/7] random: keep PRNG state in lcore variable Date: Mon, 14 Oct 2024 09:43:45 +0200 Message-ID: <20241014074348.821962-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241014074348.821962-1-mattias.ronnblom@ericsson.com> References: <20241011081901.816211-2-mattias.ronnblom@ericsson.com> <20241014074348.821962-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: DU2PEPF00028CFD:EE_|AS8PR07MB7367:EE_ X-MS-Office365-Filtering-Correlation-Id: ca319ba3-2fa2-49b3-10f5-08dcec253675 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?B?dzZlNG1DM29DZWI0RWhRVDhuK2dadFRBRERNTjIrb0ZRN2NaTC9NMlVDem9n?= =?utf-8?B?d0tmZXlRUWpSeDBXTys5aDVudERvMXhsWHZnUVFLbWYxa1BBdGJYSkUrU1p4?= =?utf-8?B?Y1dnc1FTUWhURTd1Wi85K3czUWg4d25BWUpQWEZBYStneGRHc1p5VkNMcU90?= =?utf-8?B?QTNJZkcxNEV5YU9aL3VoQlh1SEk3NjVuSzZhRGtRcG14TUxQcHlZeXo0bFN1?= =?utf-8?B?VmxqZDJneVNvZVVQQ0puMk1saFUxTkkzQ1cvY2FsZ3VCUUNXcjVUN3ExRENj?= =?utf-8?B?a3lNRE5zelhSYmlJRFRKWEp0eGJISG5QMWhZeFkyTkhCamZlRC91WlNabC9R?= =?utf-8?B?dmt4WTlqbkQzVUtaYUI5RlhOMEEvQkVXQzFZUXV6WnlJQTJhSkZYL0lyTVln?= =?utf-8?B?T0FQeThjVXM4OEduZ3BqZVJVRURMVFVaZHlhLzZsc2pUNUtQdUE2OGFDeUpG?= =?utf-8?B?M3QweWlWMFhpcHRHM2F0VEMyQmwrYW85c3lNOFJQREltZW94U1JNVjlPNlRw?= =?utf-8?B?dElEV2llRmFNVH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P?= =?utf-8?B?c2NFWWNTL254SzBBME5HamJjaS9KRE5xUHdNMXRUZGE4b0dld1grRnVSdFVu?= =?utf-8?B?VzRxZ3gyVmNSdVFYTDlIMHliN3dhNVBVbTErYVNhUFJ0S1hiak5sVGlKdHhk?= =?utf-8?B?ZCs0UXFETENaVEZTbEFpN1d4dVBjQ0NOSEprN1A0ZW1WcnU2N0VaWDBnd3Ex?= =?utf-8?B?QjJ6dVpGckw0OXlyYmpUNXBqNEovVkdVWXZ6Q1lTM09YcUduUE5GaVB5MFRL?= =?utf-8?B?YlBuVEpkNG1FcWlZYlk4cGFoaW9sQmh5UVd3Rk45TzNZZWZGWC9IbjA1ai9E?= =?utf-8?B?aUF1clRKVnMrd3ZYcGxWSGVUdGkrNWxpVjZ5eFYrbkg3MlhWUktkSEJBL3Yz?= =?utf-8?Q?b/v89nViyEHCRpxPzXiAVM3SOqO184875dayw=3D?= X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230040)(1800799024)(376014)(36860700013)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Oct 2024 07:52:55.0729 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ca319ba3-2fa2-49b3-10f5-08dcec253675 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: DU2PEPF00028CFD.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR07MB7367 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