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 05F3A45B40; Tue, 15 Oct 2024 09:04:33 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D09FB4065E; Tue, 15 Oct 2024 09:04:21 +0200 (CEST) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2040.outbound.protection.outlook.com [40.107.21.40]) by mails.dpdk.org (Postfix) with ESMTP id 16D6A4060B for ; Tue, 15 Oct 2024 09:04:17 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XSDkY89K3ptzZDd1x/kiWER/4wvZeiHsh0ZL7+kL6r8YZChVdeLYPXjYF5PdmZIE0ZPlyKC8raSCeSKnc8OjxrhGikerYvPut1yazPO9aQpxJ6nmp3TxyCYfAHvdzMGDWqLZIQoGpGEzDKRcGAgzt5DPpmJt2voWKOa27DHTKgh7UbX6nhp+ZOVJLXBDEw2Q//NqUOSrl3utgjerOA+my0cNzGXQrtDT9DsHMTLzU7mg4SQ3LkvZUdmCzYK4Yp0Gcrt2TGqvZ3y8WKNwwQ0LAMcTL+dqBtp7qN+dRyw3cpdQlT8mSP3kFN+K3gE0JAAkm5a1T3Jhv+4t/EfRbPvfEw== 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=Tj8GTqcFfslh++e+WQO1ae9lVVSt2msMBM5h+j5sbbyCix40qvjwtW9rGcfCp4HuXxVColzf3IdfDlZaF+rxPYd76Ved6bYeN9pEOibH4PXuiSk3UsukkvQtq+opIomEMis93hOzqgN0I0oXrT3zTL94/DjX4Q592vVNGg9kG1p0eDp0SBFJCcS7vtk3FUzHYrPHpNgEJhHFtRs0s8UETN4FLeiXD4eRVF41sZpPDRmf1/HC6EvDCIBgmQafy/ANORQS7ShuRnyE8JcperE/JngIaqEo9SZrHD3FFapoICcASSUCNAXVzoACvP2eJuEdl7AJx2VPwTZx21nQattTvQ== 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=I/cy+mI7yOMvH5Ad0qpygXwtVDfeNHpNAI5IwpD7C1aPFVfLLeEYFIHu3Qpkqx7PWvpBe/hixhlk5UWCqxALR3dLPlB67ZiEvACZFfXhDHFwfdGr/8QfIn8krdDeD1wFqno/ceHnYL6Iws80GKkQ4iKyd+00A4Fct3EaeIGZBJ9vfcIRyUHs6wiFaBSjwEoFL7m83IUCPbhXTL2UL8lmu6nnsU8JZG2QD8G7EQXMZ++yEBxNgIcJ2g9TRfwZjpUypPFDrWgIfcWbAHSO0gCbxgVc40Nmqq/goSvZdZfD1c2qppsQbXnIsJ2VYZxpw6Enbo9c/KqSyaxs0KnsFcI/Sg== Received: from DUZPR01CA0192.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b6::15) by PA4PR07MB7533.eurprd07.prod.outlook.com (2603:10a6:102:b9::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.25; Tue, 15 Oct 2024 07:04:13 +0000 Received: from DB1PEPF000509EC.eurprd03.prod.outlook.com (2603:10a6:10:4b6:cafe::e) by DUZPR01CA0192.outlook.office365.com (2603:10a6:10:4b6::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.27 via Frontend Transport; Tue, 15 Oct 2024 07:04:13 +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 DB1PEPF000509EC.mail.protection.outlook.com (10.167.242.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.17 via Frontend Transport; Tue, 15 Oct 2024 07:04:13 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.60) with Microsoft SMTP Server id 15.2.1544.11; Tue, 15 Oct 2024 09:04:11 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 79B261C006D; Tue, 15 Oct 2024 09:04:11 +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 v12 4/7] random: keep PRNG state in lcore variable Date: Tue, 15 Oct 2024 08:55:02 +0200 Message-ID: <20241015065505.823840-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241015065505.823840-1-mattias.ronnblom@ericsson.com> References: <20241014074348.821962-2-mattias.ronnblom@ericsson.com> <20241015065505.823840-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: DB1PEPF000509EC:EE_|PA4PR07MB7533:EE_ X-MS-Office365-Filtering-Correlation-Id: 2a4b53f0-65d0-4bd9-c18f-08dcece79349 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|376014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?B?TUZPRHU0TFZsTW4za1JTVmZsRWROL1o4Rk1YRDZueXhjdm1mNk9xWnFucnlW?= =?utf-8?B?bjlFTkp2bmtpNGVnNk5hNnhXVHhNczJlRXZodm9TTTlYenRzU1JtOG1wd281?= =?utf-8?B?VHlNdXdYbXlVQ0V6SHlqOC9LTU0rMFJLTnc2VDM0b0I2MVZqMEgraE1hUzJL?= =?utf-8?B?NlRsVktHcWx3dm41M29pTXhnaVZDYWx4enJkdVFaL2xkVjl5L2pzSWQ3MGEz?= =?utf-8?B?bmtMbEFzT1BRcWRlUGdjd1ExN201NW9UUjVsQjNXSDR5R1VTNHUzYXZzNmpF?= =?utf-8?B?YUNnVHFEQVF0YnZObkl0RGFVN01MOVRvVkxPUVFrOEk2YWpQK2wyNWo5b2o5?= =?utf-8?B?TFo4a1RONmdnT21uZGNMVk4zSGpMdlEzK2JCeWE1SVBGRDc1ZVhoVndwRXdk?= =?utf-8?B?WVVSdzE2OHVGNGtHSXphSWd5UTh1SC9VdEJRS3JoQUU0YXNkMVFZVmpTWUVz?= =?utf-8?B?UEZrNEJzRXA0RENZdEw5QUxtNVJ0RWEvK2p2cmYrUUxGelpQQm4zQVo3SjRh?= =?ut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VdHNmFKS3FNdmVNYlJ3?= =?utf-8?B?czkyMVlMT0FXRW9JT3pCS2ErazFRK2hsYzdHNm1pYjdwdk1LdmxWbDVPZ1NB?= =?utf-8?B?bjlnTmx4M0NVamtwUExMR0tDNGg2YU9OV2xXelQzeHdJK245SStwWThabnFT?= =?utf-8?B?QVlXQlBtQ1NBM2lWa0lIbDZwa3YxWnYzWnlDYXpMajN1d1BCT3B1dFBPY08y?= =?utf-8?B?THRLeEtDaWttdm9IaVU0eDhYMjArQU40eU4vSy9MMWdaNUpWWEdRSjJUUzRq?= =?utf-8?B?QS9sZUVZdkM1SUgzdEcrYXNvb2xQek5qOFplcXI4cVhLSWNsUUQ3ZEwwS1pq?= =?utf-8?B?Q2pBNU9kZ05BK1FCbXR0V0o1Nll4TjAvOG9wSWRwYmpTMHdudjVaRUJsck9P?= =?utf-8?Q?o9c9jwdDWWRt6DpLBw/6HJKwkTkINR4h7G+LU=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)(36860700013)(376014)(82310400026)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2024 07:04:13.1671 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2a4b53f0-65d0-4bd9-c18f-08dcece79349 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: DB1PEPF000509EC.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR07MB7533 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