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 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=20R=C3=B6nnblom?= To: CC: , =?UTF-8?q?Morten=20Br=C3=B8rup?= , Stephen Hemminger , Konstantin Ananyev , =?UTF-8?q?Mattias=20R=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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit 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?B?Qy96ekNyZjFDbGErVDFCaGFvNTJHQVZZY2NpT1QvUVF2cWJOakRMYkQ4eDVH?= =?utf-8?B?WmQzZ01QU3lpT0FPTnNmdnN4dlpNSGtvSTViU0s2QjM1NWdzbHVHS0hBQ1d4?= =?utf-8?B?QkhuOWZBdndoZjZNaGRSTzlKMkxmWjVRTkttK3puTC83VzBaNWdnYko5TStr?= =?utf-8?B?MjVPWkdvUXVvTVpEa1RqY3JtV3J3SnNycmNWUGhnNTFSeWVpRkZPSWMvbmw5?= =?utf-8?B?UVJROFAzd25QTTIxeC9iS0NzV0ExL2Vzd1FFcit2Ny9pYVBSRFlKOGdwckNC?= =?utf-8?B?ZVJvQW9RTzV2ZjdrSGFNcUJUQVpqNE5KTmZQY1ZEb09JYjFIK0ozT3lZUEd4?= =?utf-8?B?NHlaeVlHenpBVTlpWlU3RFNSSk5Ebzh0RGY0V1FybG82dnphTFFVUm5KbEQr?= =?utf-8?B?MU15aXNrMGFaRUVEQklkMkxUdzJmei80MHhPZEVTKyt6YlFsUmZHUHNkSXhS?= =?utf-8?B?NFgvdEVEMGpMdEZpemJKNmR5dVUwNHFQdXlPTXNpam04SDFjMFh0U0hXaUVJ?= =?utf-8?B?UWJLVS9jbE5BMWk4UE5sVTVTRU9jNjI3eGlTRUZYaytwUVBFRWhZL0ZoaDBU?= =?utf-8?B?L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ksyTjFx?= =?utf-8?B?bVkwckRmOWdRSFBSbVdBTmY3cTRmU29rdnFLdnBDSm1WeXpLQjkvMWVyaTVq?= =?utf-8?B?L3dEUzlsNjRyZ2k1eit3YUtSWGNXK0FnQnVBSGtnWU1sTTE2blJuLzVRTURs?= =?utf-8?B?eFdZVFFsL3JqblMvdWFOYzNNSzk0ZHdRNGkvUzNXUXlORXI1aWtaRDRTYkRY?= =?utf-8?B?eEdQem9kdWRKeWptVzlzclllSmk2UnRoUkw5M3NKRlJxQ1VqV1F2SlA5QXJr?= =?utf-8?B?S01wMDN3Q3R1VUJnVmxUSU1aaElsZWhaNWR6bWtqM0dqSGt4QWxlMGJnc0lw?= =?utf-8?Q?JcjUTf7e/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); -- 2.34.1