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 2AF0445B59; Thu, 17 Oct 2024 08:07:55 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 90C4A4066C; Thu, 17 Oct 2024 08:07:16 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2064.outbound.protection.outlook.com [40.107.22.64]) by mails.dpdk.org (Postfix) with ESMTP id BD556402F1 for ; Thu, 17 Oct 2024 08:07:03 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tanXtO85XcYA6sp/EJUAom1/hNCrb60Z0XyMLJYtq2Mz1OL/u27PB81koMABUpXAjlkIHUnAfLohUj3Pl7cU+nvGK0gafRHgSSnXZctfcaO5yTvxz+qyq/uo89aPo85ZwRIUgEAySOyh38Ouh132OMLuKRccc2TnQ3sLYhWacHjvzvBhC+HHL4B26MfwTR3JcNuLLRjPLto1TX6hFOW3lczhTSKzc50bx6M+Sku28x79FLKhhJ3YGjJqe4S0WDqJ/c/Q4EU/IW0SWi/cC6WZKeArpLzpP/qx6owmB53pQiQ0eh3I1IdnLx9xRTahXN9XxHD7mQYszmh3hUG/7GFLLQ== 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=DESL2qFVuTQWm/n9l4enH+FDESyNnVazkJ0Sbs+rOpQ=; b=KcTp9o7hXamkOk8fKL06TKz7IB2CVdru89UOS6QrQ99fhsGzmHarKLuU8ey5CS0ObDAhCDLzW0wxi55z/F82Wp7qYEzrsdSF0mfZ5PJWMCqGGCNwGF7Lqy14gkuGg+mXnbdauHMNoDOGemkBtK5RC5IxVOBJX5IuifQGVj4Ip9Kte0l9CFsvW/4m9Fm1XrbpBooL3UOoLsZf3R1pKiTg4EmV0sdX6nX5QGns3KJv2WtWyvqr/aALIMVOQxJkQ0vUnzpmQ3mPRVtQjmpNdLiAZhG2dhDVkRnKqtuRvkQaec3YYg8N2nRynlOToEr0yNMfPr//qKgXLJznVui4w/WbKw== 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=DESL2qFVuTQWm/n9l4enH+FDESyNnVazkJ0Sbs+rOpQ=; b=o1ZCAuXqIB5Tn9O0m3KsGcLxQo2ol/FA/Vp3gqDnI6YFIzIu3t0v8O5fY7fc5FYI+vUif9w5Lly8DWn0WlkQqgAMLTKm3TBLQ0cRyiUI1IHRNP/UnnUs40cSWGgc/rHFb39/xDckpgQ8BDuPmKDU559Vl+Uipin9yCZsGpl6FH1BqKR+zOjf8lDZzCF7qZU0SZ3QnjBOjry0OucXWO+J2YBA2QXL50zfxsMfBVzRBx9cNYYh+uCjjO9AfqPssyAbzUmOwuZnp37EK7tmQLhhOV4bkRmD2pEitoAlkLXIunNdnJa++r3MKfnW9GvoNVLShrVa+TAYigwMJjwtpCBftQ== Received: from AM6P193CA0037.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:8e::14) by DU0PR07MB8594.eurprd07.prod.outlook.com (2603:10a6:10:31e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.26; Thu, 17 Oct 2024 06:07:00 +0000 Received: from AMS0EPF000001A8.eurprd05.prod.outlook.com (2603:10a6:209:8e:cafe::a) by AM6P193CA0037.outlook.office365.com (2603:10a6:209:8e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.20 via Frontend Transport; Thu, 17 Oct 2024 06:07:00 +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 AMS0EPF000001A8.mail.protection.outlook.com (10.167.16.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Thu, 17 Oct 2024 06:06:59 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.65) with Microsoft SMTP Server id 15.2.1544.11; Thu, 17 Oct 2024 08:06:57 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 7140838007A; Thu, 17 Oct 2024 08:06:57 +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 v15 4/7] random: keep PRNG state in lcore variable Date: Thu, 17 Oct 2024 07:57:40 +0200 Message-ID: <20241017055743.848292-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241017055743.848292-1-mattias.ronnblom@ericsson.com> References: <20241016131916.827788-2-mattias.ronnblom@ericsson.com> <20241017055743.848292-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: AMS0EPF000001A8:EE_|DU0PR07MB8594:EE_ X-MS-Office365-Filtering-Correlation-Id: 7779dee1-f725-4edc-f959-08dcee71e98b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|82310400026|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?B?WWU2M25vWWlHRzArWVZjWm1hU0kvVFhyS05qNGNXQWI1SzRQSDZpTHZ4bzg4?= =?utf-8?B?ejVrb2x2UVd3RTNMNldmNHYrL1FkTE9neTFRd1ZnbldhZTdlcHJBcFJJYmw5?= =?utf-8?B?Q2xwTEtlRDRaakNJdDRQak5OV3RJWEtSRnRiTXpOdU5lQTNHcUNlNndCZE90?= =?utf-8?B?aEIxVUorclAydHlwTDFZakhRRHA3YXhoZUIyVnhhRkhkMjJNK092T2haeVBF?= =?utf-8?B?U2FOdGxndzUzRVZGUWdlaG1CZWtDY2s1MnE2OUxJSFJ4d1p1T05EU2tXVEJV?= =?utf-8?B?UnFWQVV2bmJ2aEYyR1RVdXA1RGoxY1FJTnczTHlINUYvU2VhMDc4ZWxEM3pY?= =?utf-8?B?K2g3amEwVHpCLzZFcGlWbjRiMmh6dmhsL0dqNjIybXowNXRCejZVc3l6SEtH?= =?utf-8?B?bDlSUHhTY3B0eEZPVGlZWlhnQ2N0dDdkMkcwR1NRQ3hFTTMvVkRNUFZNaXpz?= =?utf-8?B?QWlrUGRBblVmL0JBYVhsS2dYQTNwdFUwZU1JUmcwWXJ4Wm5oTGtjNnBMR3FJ?= =?utf-8?B?Z1ZabU1H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0NzWWM2aEczWWJw?= =?utf-8?B?L2c4NGVObUNwSzkvWXlFMlRXdi9tUXFoVmJaK3ZDb2kvdzVFdXAxYmgvSCtO?= =?utf-8?B?TmZOLzljRllKY3dNejVZZXV5TU90ZFdtN2lGenlJZlp6S1hjN1VzWlRPWVBl?= =?utf-8?B?V2M5emdkalU0VVNGbmhOYVh4VngyT3pYa1MxL3ZwaytLL0w1M0QycE5EeTdK?= =?utf-8?B?VXdlNEtWaHk5OHF0UUVqM2hZczFtNTBrNlEvMjNHUHNLbWlSTkJtWVN1Q0s2?= =?utf-8?B?aFk4UlMrckhzUEJXRDYxcFRpNTUwNTZRY2VteS92TSs5Y2ZZcVpublE2b1Ri?= =?utf-8?B?Mk4wZUFldGZwdHNzckVOWElrdWlsVHJ4RVZzM1duSGUvT0w1bDVvZW4xWTNt?= =?utf-8?B?VDlnMHlRN3ZXVGJjSTY0aGZ1SVFhSHhveHo0a1cwQXdCNWRjTkgvN2NHbW9E?= =?utf-8?B?YzBhRjV2Qy9XUGp6U0tyZENiTDZkcEdlZnJLOHJkYXExUWc9PQ==?= 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)(82310400026)(376014)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2024 06:06:59.6122 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7779dee1-f725-4edc-f959-08dcee71e98b 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: AMS0EPF000001A8.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR07MB8594 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..cf0756f26a 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(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(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