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 D70F843C1F; Wed, 28 Feb 2024 11:17:46 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0130341149; Wed, 28 Feb 2024 11:17:37 +0100 (CET) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2043.outbound.protection.outlook.com [40.107.7.43]) by mails.dpdk.org (Postfix) with ESMTP id 7FE9A4027D for ; Wed, 28 Feb 2024 11:17:24 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FzNmO1wYZr+L39ByLtnmWpoQWpnR76kgzHr6DD921j/ctkdqH+8miXJIrXeWFVVgBcWE3JtAJQdGqXJAoe2LgMtUBwlYJoOVXDi9ixJ3z/c9t8kvWAfOauEtt7esc2ZRGZKCkotf1hImloP2i+Ts1X2bh/gAUQ46r2wQLVdbg5v7QWZP4uWKGRUVVgev/oBRt3hpOrXwH2JTOQBnDYdoYqlHxgLXWxp4meg7B+SwzJT9b4lIYMkh6gW4QVYUGuCP6dyS/AYoCGloOO/kOH1/j5x+9IZFcge/6QHonQieBTrSTUVK5044YAOHyTR/H3BAQqXVlMf5eDadQuyey/IhyA== 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=xjwMbnBnEUMqtIj3sDNKGiBopp35z1bhhwJOhJUYdZ8=; b=ls7eiujqvMNfuvkU1OijtvoFz9EQ45l8wYSnAH73nJA1gPJ6MPNT4ep0IK7wqmyx/vqV7mxGACcWyX3rv6rtgCUgLtceJmeY6+vJvKvxFt7OIlMYC3xKPw3YY/HhPUVaArMemQP8lGl7MLwSWxSlylWBM9iy6rrCJGtQH7afcwhRshEa8G9q1k/MhCUiBLDouY64i39dCQUBEemjhHGqGytoCMEFJ8qFTOWHraDVrsVDRLt/J5z7VRgLL7Hb0+RiekumdTWabsGdMCSS84JINHdBipnpXQIVMCdiAif8NGzH3tt5jaYS9LKjryzrWyrAFHwPAbJCKUpLs3pxRY9bKw== 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=xjwMbnBnEUMqtIj3sDNKGiBopp35z1bhhwJOhJUYdZ8=; b=SgbfS8GuWOHcQUAv9pEDuq2AF0cpY8ZUHCACCVzR8VfV2xTD7aBRwacUqzW3dbtSalctNgBwe/COAIfZaSZm4yQiyRoUXK+9afOD5rj6XDPTqSY4AeY8VoVU4yoC0/qMiJoBjqtxDDBDD5RmUBw56jklIrdy5F3sicUh8vrBiIzbo/b/XleRcB/hU7TiyNd6kKcr6uV25AYRZihFMuZYusRkxAmFshhcNdcgWqoXvzAdVjgh3sSUjWL0aPdTAgh9EyU/plAt73cuNHOZSh4eWBjKCsgk65UW5GpDaxuhbAoyye4oT6EW0QQtfUu8ixNApDCuBOW+fxP/oirfwRUr0Q== Received: from AS8PR04CA0110.eurprd04.prod.outlook.com (2603:10a6:20b:31e::25) by DB9PR07MB7689.eurprd07.prod.outlook.com (2603:10a6:10:1f9::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.39; Wed, 28 Feb 2024 10:17:22 +0000 Received: from AMS1EPF0000004A.eurprd04.prod.outlook.com (2603:10a6:20b:31e:cafe::6b) by AS8PR04CA0110.outlook.office365.com (2603:10a6:20b:31e::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.50 via Frontend Transport; Wed, 28 Feb 2024 10:17:22 +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 AMS1EPF0000004A.mail.protection.outlook.com (10.167.16.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Wed, 28 Feb 2024 10:17:22 +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.1258.12; Wed, 28 Feb 2024 11:17:21 +0100 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 9742B380061; Wed, 28 Feb 2024 11:17:21 +0100 (CET) From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= To: CC: , =?UTF-8?q?Morten=20Br=C3=B8rup?= , Stephen Hemminger , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Subject: [RFC v5 3/6] random: keep PRNG state in lcore variable Date: Wed, 28 Feb 2024 11:09:25 +0100 Message-ID: <20240228100928.524277-4-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228100928.524277-1-mattias.ronnblom@ericsson.com> References: <20240225150330.517225-2-mattias.ronnblom@ericsson.com> <20240228100928.524277-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: AMS1EPF0000004A:EE_|DB9PR07MB7689:EE_ X-MS-Office365-Filtering-Correlation-Id: c0f388c5-7a1c-44d6-f8d3-08dc384673d0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zzG9JoeEdmiycAm51IfqaS8Mn0oW1fkILy+cE2v9k+gfiseSTuA7RVPL72dVAnP2W7wzoPj4qTDg9yYUDzGI9ane9ya7VejD1gMOkTgX9jPpaxcjO89v+pIs2zaIg8bVLzwEYkHS30+BW4aEvPfRPPDMeZBsW5uE+6yDXM8xrZEctvltNgY3cxja55OBQms5pbqic/ABYygdD5xpGkSuy8sa6G0DljH1DVYi2Uk7ay7f9CLH2YkCfUlQBsk9a9bZz6KcNv5PrDrBoKnKg7p/0Hp+6NVT9GwplHiyGKkcqKQfDi7tljfnlUyQsymYJ41Sy0IHD6gFIGpSdNL/Xz5bi99grzKcNUzqnHRlkT/EbC4mc4dval+m4g61etYfN3WMZmg2q6Q2ti1WaQecY01u3yjCNR3Ufak30qLW447a+R5B9rBFih/Q9N+LO88+Whac9iV9RSwNhnmeQ+hoVgLZDvmjAsIKRk9/SxEyUd4hrMvF3zFALiVFrae/6vwVJ+PJ3BSUj1oWD05YpicC67yi/4bFFrQC0+VDqxfmjJUgjb8rO7mIf67hpDFVlSFCTJW8W3AZHF7CWZEDaaq6/e3bb9IhnYakmNqZGoCErhuCTZ3P+91A5s0SDRxd4h8cYNCgkd38OEFbYGNzjtma0kZ0QcpkX/DsDNlqBTWE+kzTwAHVk2CPTYsZk/2vbdRFFGj3OQZ8YYo3ln66uUOiPk7ZYjIgQsiUPr7y8HVuZBA+Jg45sDovruP32Cw7k6F9ooZt 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)(82310400014)(36860700004); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 10:17:22.1084 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c0f388c5-7a1c-44d6-f8d3-08dc384673d0 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: AMS1EPF0000004A.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR07MB7689 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 | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/eal/common/rte_random.c b/lib/eal/common/rte_random.c index 7709b8f2c6..b265660283 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_rand_state { @@ -19,14 +20,12 @@ struct rte_rand_state { uint64_t z3; uint64_t z4; uint64_t z5; - RTE_CACHE_GUARD; -} __rte_cache_aligned; +}; -/* 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