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?9HjqbgsqUJw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: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);