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 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=20R=C3=B6nnblom?= To: CC: , =?UTF-8?q?Morten=20Br=C3=B8rup?= , Stephen Hemminger , Konstantin Ananyev , David Marchand , Jerin Jacob , =?UTF-8?q?Mattias=20R=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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit 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?B?QmkyNEgyZWpTL1gwQk56eVRGeFlHbWdXR2ttMmdPbHZIN2tUYjRKODVPOWpo?= =?utf-8?B?QzlmZzdUQWxTWDdiQ0lrdTRYYkNVNHF1d0N5UEdiZmdUZ1RoZWhEbGYxV3Jx?= =?utf-8?B?d2MxOG9QUWRDS0x5clNIUk9NMmx2dHI1RVR6S3hqMHdoUVd1Zi9PajVlRE9x?= =?utf-8?B?TXl2QmNXSi9KeDBLdXFIanpuY0cyZVkvc3pkaGpGRkZzdjdabjg4U2xBbllU?= =?utf-8?B?cDFGbWN6KytZeWxtL2p3YjQ3LzRFTGVTUVFWYmo0YkpmVGc3K3U4Z0xvT04x?= =?utf-8?B?MTY4OVhlTkkvNllEV0VQUHk5dTVKc1NvZlExb1Urd3V4N0VDYWFmM0luYTdx?= =?utf-8?B?L253Wm90bHRCcnV1OXdoQ0laVHpJRzVUZDZkSEJLWjFTY3lkUHNqU2lQOVZ2?= =?utf-8?B?ODQ5WXRxcTJtNXZIYmRGTUhIZE5xUGJ0VHhJbnlORG9TYi84eTFuYXdmdktw?= =?utf-8?B?UjNoa1MrYlVsQUkwdmlCbFRwVDA5TG5XZ2o4QVAvbyt3RjdrUmcvS1M3anlL?= =?utf-8?B?TEM1YnF3ZTgvRkhVVStmVUNUUk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?B?d0doZGdJSUJVTXE3Wmoyazd2ZkhwNGxvVnB2bzBTTkIzRDYvYlVhaUQ3UFFp?= =?utf-8?B?L0pnalRKL1Zidm1rQ29RZ2ZQVDI1MTBNUFdiZzdialRMNVZnQWV0NGdwYnpt?= =?utf-8?B?aWhTMlBmUSt6aGZOSjdCUXR0MDFxNURVc1prMlFWS3pERVExV1l0b1Y4Nll1?= =?utf-8?B?STg5bGpNWm41b3RUWlJXT2YzZFFCMyt2dWlKUzFtTk9lVExWSEpCVHZiVzFy?= =?utf-8?B?Z3NuVFVVOG84SlR3ei9NTjFJZXhNUW8xdVVkSmhVMHE3RUhRdDlJaWpaRStR?= =?utf-8?B?dHI0Yk5iOTlIblgybVVoaWdTMFlqT3ZxZEtNSGZhNlNuS0l4Y3FxaXNKYytN?= =?utf-8?Q?ZykNCWaD26ilX8cYv4hRjMVyRGyXwe9Ldu9TE=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); -- 2.34.1