From patchwork Wed Sep 18 08:26:11 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: 144236 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 56949459C6; Wed, 18 Sep 2024 10:35:51 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E433942ED8; Wed, 18 Sep 2024 10:35:46 +0200 (CEST) Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2064.outbound.protection.outlook.com [40.107.247.64]) by mails.dpdk.org (Postfix) with ESMTP id 75F5740264 for ; Wed, 18 Sep 2024 10:35:44 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LefV8Da7/cXj53RKnl0jMHXVe2riG91QMmhxJU0Dp1fo0T00CcMZ8I8Dc1ItqAnxoXB1AGEd42zURNISwp8p7QIHlsv4yIeXDs85lY/yYrtaLFdteVKDJxRZcaWwrXjfdmnsgZyXnNnBB8HFJaA608A8cLX4HHg3vp6rdR7XaxsR1N1+X6vHGnqQ7aMMZntFLqqUuSrXuKFWln2uMgTY74aXq5d7n9UQLRfX0a0jPYORaLNg4oLzndrQv6IWjk652wDvd4YOZl4oASMXa5VD+6bEZc2JKda4LqJn1IwL7YGkICn8unUgtl71ibR8qosdS6aHEDvbWkSn85o+OgosHw== 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=RbedT1DRhpG4D0rH9NvaS3EAQph1B0l32q5FK4gkWIs=; b=QLPkEOTZVP84fhuBfJdLZQt2FYOD12S1kyDPbTWvceAOf2/FGScnEBiZCZAQnEnw+LJzDWezNWaQke7gDALLN1pQPr3YSl8U5+LojvBXAlOdaJ/ZvPa9JHC8CGSmLM9kcrTioFseubJ2QQo/SDFoXY5OAutqeDiTZtYcXX4zp1cci6gX4N91QaFgRyhUK7tz0eYxRVjkrY8uhYq6U4+j5+GoD3OxpS+Pw/NdRunLm6EX+DvYAq8Ahwx/cN5f+XRK2TZa7jyjrY8PI5r1df7AiBEn6MTygV7rQdXsMrQ08EIAD7uXVnwQMs4Sl5gDum0Kfnmhmcp0ebrK9QL5ZR0FCg== 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=RbedT1DRhpG4D0rH9NvaS3EAQph1B0l32q5FK4gkWIs=; b=mErYpZhIh9Ct+1hzT+x41tTXbhegeCHke+KpVjR7TxX9eoI66cxbpNnltD7MAI1/TM9adDxorv1gVQ/CgXQ9cJ5Z3oEBcRLc49sylBKQG3HQgWlJXvmm2AjRSwJXQl0cRr/n227JS+eXTh9g8eHabFVS6yNu0qP6huH1l7ZfjG9hs+D6tUhh1hYrXK+1KRnnfxuAChVQFesMelB715170sfAsR4MLD7EuqxoLcXuYpwLJ4hdexU6cSQ1gJeDBEbhwuAe/RpPYMed1DkDYsSpxj4Bp/RBbNb1t2BVlmQRj3zxIiY2IDTIiLHgG4iuzBBW5Z3Ln9QhEZmo6LPZ5dBEZw== Received: from AS9PR06CA0324.eurprd06.prod.outlook.com (2603:10a6:20b:45b::13) by GVXPR07MB10035.eurprd07.prod.outlook.com (2603:10a6:150:120::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.23; Wed, 18 Sep 2024 08:35:41 +0000 Received: from AM4PEPF00027A6A.eurprd04.prod.outlook.com (2603:10a6:20b:45b:cafe::c9) by AS9PR06CA0324.outlook.office365.com (2603:10a6:20b:45b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.30 via Frontend Transport; Wed, 18 Sep 2024 08:35:41 +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 AM4PEPF00027A6A.mail.protection.outlook.com (10.167.16.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Wed, 18 Sep 2024 08:35:41 +0000 Received: from seliicinfr00049.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; Wed, 18 Sep 2024 10:35:40 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 842CC38007D; Wed, 18 Sep 2024 10:35:40 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , =?utf-8?q?Morten_Br=C3=B8rup?= , Stephen Hemminger , Konstantin Ananyev , David Marchand , Jerin Jacob , =?utf-8?q?Mattias_R=C3=B6nnblom?= , Konstantin Ananyev Subject: [PATCH v7 4/7] random: keep PRNG state in lcore variable Date: Wed, 18 Sep 2024 10:26:11 +0200 Message-ID: <20240918082614.725220-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240918082614.725220-1-mattias.ronnblom@ericsson.com> References: <20240918080054.725164-2-mattias.ronnblom@ericsson.com> <20240918082614.725220-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM4PEPF00027A6A:EE_|GVXPR07MB10035:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ea31233-2869-4097-358c-08dcd7bce12a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|82310400026|376014|36860700013; X-Microsoft-Antispam-Message-Info: =?utf-8?q?Bi24H2ejS/X0BNzyTFxYGmgWGkm2gOl?= =?utf-8?q?vH7kTb4J85O9jhC9fg7TAlSX7bCIku4XbCU4quwCyPGbfgTgThehDlf1Wrqwc18oP?= =?utf-8?q?QdCKLyrSHROM2lvtr5ETzKxj0whQWuf/Oj5eDOqMyvBcWJ/Jx0KuqHjzncG2eY/sz?= =?utf-8?q?dhjFFFsv7Zn88SlAnYTp1Fmcz++Yylm/jwb47/4ELeSQQVbj4bJfTg7+u8gLoON11?= =?utf-8?q?689XeNI/6YDWEPPy9u5JsSofQ1oU+wux7ECaaf3Ina7q/nwZotltBruu9whCIZTzI?= =?utf-8?q?G5Td6dHBKZ1ScydPsjSiP9Vv849Ytqq2m5vHbdFMHHdNqPbtTxInyNDoSb/8y1naw?= =?utf-8?q?fvKpR3hkS+bUlAI0viBlTpT09LnWgj8AP/o+wF7kRg/KS7jyKLC5bqwe8/FHUU+fU?= =?utf-8?q?CTRNGy9pLqOWXw3uhwQ16ISoYzjoY7uNhVv+BKuoovwi1PgfEeP+ps/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Ldu9TE=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)(1800799024)(82310400026)(376014)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2024 08:35:41.0606 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9ea31233-2869-4097-358c-08dcd7bce12a 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: AM4PEPF00027A6A.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR07MB10035 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 --- 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);