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 70D4545B12; Fri, 11 Oct 2024 10:28:43 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B39A140648; Fri, 11 Oct 2024 10:28:27 +0200 (CEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2085.outbound.protection.outlook.com [40.107.20.85]) by mails.dpdk.org (Postfix) with ESMTP id EBFC7402EE for ; Fri, 11 Oct 2024 10:28:21 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TaHLPmkLc0x/zFiw+ph6v5l8dpzvH9RYzpt78aOOxrwyLnNpUCC4wk+L3C69FSIsPdamePIvUDKPbks6VewrQAsEr5WquI3TPVocdVY45zojtJl7/U0coCVa13VOJJwL8OaK+yMu3cXspD3Lmymbbmg3okqvRXRkVr9ahLXCv21HsD3fDZT0/2jmcJVAxACB2u1omuFJYPhsebCtenWPEhZjXmNme2it6vB+jTW2U7jkkAoUY8iX7ZnhA5g6w5Okk8ZXV0lHWTuLDnOcsSIU+bgqNc84R/fw4jxE7i5UMi6f5Di1GMHCEnLzS9hLAK8mmgjm+e6jLC8EkqNx9w+C9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZcrIxsUczn3eEQ4B3j0n5Yi5yrD0dIPqXBBskKRbBbI=; b=sVB2vNvuNxq9ELObqMr2z+lAkGS8lmItmnAF5Z7aBtv8Rpxe+ULQ93yK09aJIIq+9N4W38qqJfT/30HaGr6gYqMs+AIFnHf0BGh4Up513GbtKY4Eq0INiIDFg5oXXMcsl353e2A5ZZ0z2iY2OBrSkehARmOhelaMFQNsn74DnjBGdY0Adur9iLLAalDgI+8IOw+FCjTYl75/I2U2trKp0YWGokXlyJl39te5xinnpo2Qga8KIOedT6kTbk9vOdHvO0fYj/PAaXFOrbLg7MQsM3R4YExYvA3HQlucKpmS1xluHG3PMzwc32jjZWP/7BJqEc0LZvisCJ1R5r6eQ4Sk1Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 192.176.1.74) smtp.rcpttodomain=dpdk.org smtp.mailfrom=ericsson.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ericsson.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZcrIxsUczn3eEQ4B3j0n5Yi5yrD0dIPqXBBskKRbBbI=; b=BfT/pSBSpA53LCAbk+CY94XgDxUaQeHFvYkgNSkfTmYp9/eeeVj6gRicBI4q7iqZkY7suqVMALXZVFM6OlmbD2HeQBqyzMvlXcF+icrdvHDygd+YqmaXED66Rd5lon7qrw1WicMgNOvjnaw8LJT/K/VBcpiIhcbtJoc7MK9sG3l2AvK8FUIcIbRHymtIAcWUjxxvIyBPPOYrsKHxyi8WOIvDTPq9jJ8iY2EaOzljY4zrAjHBkh892Tk1OnP5pKF3W2mj140QLP2br9Xy5QhNqraiYrgaVrjfBdTL50eqpv/5XmXiTKe5n36xXzhLeyTyd6c4qrrI5VNn6aQZVXJCNA== Received: from DU7P189CA0016.EURP189.PROD.OUTLOOK.COM (2603:10a6:10:552::28) by AS1PR07MB8568.eurprd07.prod.outlook.com (2603:10a6:20b:470::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18; Fri, 11 Oct 2024 08:28:18 +0000 Received: from DB5PEPF00014B88.eurprd02.prod.outlook.com (2603:10a6:10:552:cafe::f5) by DU7P189CA0016.outlook.office365.com (2603:10a6:10:552::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.17 via Frontend Transport; Fri, 11 Oct 2024 08:28:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 192.176.1.74) smtp.mailfrom=ericsson.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ericsson.com; Received-SPF: Pass (protection.outlook.com: domain of ericsson.com designates 192.176.1.74 as permitted sender) receiver=protection.outlook.com; client-ip=192.176.1.74; helo=oa.msg.ericsson.com; pr=C Received: from oa.msg.ericsson.com (192.176.1.74) by DB5PEPF00014B88.mail.protection.outlook.com (10.167.8.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.13 via Frontend Transport; Fri, 11 Oct 2024 08:28:18 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.62) with Microsoft SMTP Server id 15.2.1544.11; Fri, 11 Oct 2024 10:28:16 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id F2EEA38007A; Fri, 11 Oct 2024 10:28:15 +0200 (CEST) From: =?UTF-8?q?Mattias=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 v10 4/7] random: keep PRNG state in lcore variable Date: Fri, 11 Oct 2024 10:18:58 +0200 Message-ID: <20241011081901.816211-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241011081901.816211-1-mattias.ronnblom@ericsson.com> References: <20241010142205.813134-2-mattias.ronnblom@ericsson.com> <20241011081901.816211-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB5PEPF00014B88:EE_|AS1PR07MB8568:EE_ X-MS-Office365-Filtering-Correlation-Id: 72231348-b182-464e-bb70-08dce9cea8d9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: =?utf-8?B?Y0VGRVhqYWVXdFVwWXFZcHZSWXhSV0lGNmlnRDVFWVkxWDFxYXZjM2l2RFpP?= =?utf-8?B?Y0ZaVWw1R2RMVDZydmo2ZzRyZk1Dc080MXlVbmNuNVgwTW5uUHBjL2VUT3Ix?= =?utf-8?B?V3dJRC9ibEwyLy81ejkyZXgxWVNCbE9zVnU0TXp6cVdCTk1CSzNwTkl4Sjh6?= =?utf-8?B?b1JweXFtWFVnaHZlb2Z6ejVUOWFrOEJ1OWh1N05vaGZENS9DU1JDOHBlRHI4?= =?utf-8?B?eXFNeURvcHE4dFZybWFRNkxqWFdJb0VRdUIyVkNaL2JuNlhzaCtXZ1VwU2Q5?= =?utf-8?B?WmF0ak5VY2w5MklWRWZZZHZaYnFtTHRyKzYrQUtscVg3RUpob1IvWnFRNjRF?= =?utf-8?B?ZDBzZC9OVGJWM0txUlYwMWUxOU00UjR0M1UzMnNGaDVRMlZ1NE9WZVR3cjl4?= =?utf-8?B?dkxTQzkzbmhzZkhZVG9oVnQwRzFOSlk3WnpONjdyVm55TW1YakxwbXhUMVZC?= =?utf-8?B?WUt4L244OUV4OHpsbUhRdlNVcDI4YmI0Zy9YczVQNUNUVG54Ly91Vm1QdFJ1?= =?utf-8?B?VHFuczN3S043VmF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?B?SlBqTUFQL1pEdGxaVnZMdC9LREZsZzlJNDFray9BSXQwSlpBOXBSdlluZitN?= =?utf-8?B?bXZlVzV1VWpyTEp5bTA0WXIvd2c5YkFlN3lneUtkZ0tuQ0pqZ1pwYzFmVFkw?= =?utf-8?B?UE1NdVZPQmZ2NElVdzBPTGE2ZHlVaXY0ZC9vMzBLUWp0QXgvaFZjZGRtUXZG?= =?utf-8?B?dG5oQ3MyUlFRdXhKaGZYZzVUaEdIa3FvNzY3SDV1MVY2NThWdms1STU5TkNY?= =?utf-8?B?ZFhQMjJhSk5mbTdQczhJOFFEb1M0b0JnYklMbllaNU92aGc0ODhmMEV5YjZv?= =?utf-8?B?WlhBVFFPMFZwazJGQVdJL1hweWFyckxVZkhpZlhMUTJPOUpDcW9vUlhkcjVB?= =?utf-8?Q?PQWt1xqW3pPE3Vrmfl9ZAc4gsZ0kL3N6iXrtg=3D?= X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230040)(376014)(1800799024)(82310400026)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2024 08:28:18.3737 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 72231348-b182-464e-bb70-08dce9cea8d9 X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=92e84ceb-fbfd-47ab-be52-080c6b87953f; Ip=[192.176.1.74]; Helo=[oa.msg.ericsson.com] X-MS-Exchange-CrossTenant-AuthSource: DB5PEPF00014B88.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR07MB8568 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Replace keeping PRNG state in a RTE_MAX_LCORE-sized static array of cache-aligned and RTE_CACHE_GUARDed struct instances with keeping the same state in a more cache-friendly lcore variable. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup Acked-by: Konstantin Ananyev Acked-by: Chengwen Feng Acked-by: Stephen Hemminger -- RFC v3: * Remove cache alignment on unregistered threads' rte_rand_state. (Morten Brørup) --- lib/eal/common/rte_random.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/eal/common/rte_random.c b/lib/eal/common/rte_random.c index 90e91b3c4f..a8d00308dd 100644 --- a/lib/eal/common/rte_random.c +++ b/lib/eal/common/rte_random.c @@ -11,6 +11,7 @@ #include #include #include +#include #include struct __rte_cache_aligned rte_rand_state { @@ -19,14 +20,12 @@ struct __rte_cache_aligned rte_rand_state { uint64_t z3; uint64_t z4; uint64_t z5; - RTE_CACHE_GUARD; }; -/* One instance each for every lcore id-equipped thread, and one - * additional instance to be shared by all others threads (i.e., all - * unregistered non-EAL threads). - */ -static struct rte_rand_state rand_states[RTE_MAX_LCORE + 1]; +RTE_LCORE_VAR_HANDLE(struct rte_rand_state, rand_state); + +/* instance to be shared by all unregistered non-EAL threads */ +static struct rte_rand_state unregistered_rand_state; static uint32_t __rte_rand_lcg32(uint32_t *seed) @@ -85,8 +84,14 @@ rte_srand(uint64_t seed) unsigned int lcore_id; /* add lcore_id to seed to avoid having the same sequence */ - for (lcore_id = 0; lcore_id < RTE_DIM(rand_states); lcore_id++) - __rte_srand_lfsr258(seed + lcore_id, &rand_states[lcore_id]); + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { + struct rte_rand_state *lcore_state = + RTE_LCORE_VAR_LCORE_VALUE(lcore_id, rand_state); + + __rte_srand_lfsr258(seed + lcore_id, lcore_state); + } + + __rte_srand_lfsr258(seed + lcore_id, &unregistered_rand_state); } static __rte_always_inline uint64_t @@ -124,11 +129,10 @@ struct rte_rand_state *__rte_rand_get_state(void) idx = rte_lcore_id(); - /* last instance reserved for unregistered non-EAL threads */ if (unlikely(idx == LCORE_ID_ANY)) - idx = RTE_MAX_LCORE; + return &unregistered_rand_state; - return &rand_states[idx]; + return RTE_LCORE_VAR_VALUE(rand_state); } uint64_t @@ -228,6 +232,8 @@ RTE_INIT(rte_rand_init) { uint64_t seed; + RTE_LCORE_VAR_ALLOC(rand_state); + seed = __rte_random_initial_seed(); rte_srand(seed); -- 2.43.0