From patchwork Fri Oct 11 08:18:58 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: 145740 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 70D4545B12; Fri, 11 Oct 2024 10:28:43 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B39A140648; Fri, 11 Oct 2024 10:28:27 +0200 (CEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2085.outbound.protection.outlook.com [40.107.20.85]) by mails.dpdk.org (Postfix) with ESMTP id EBFC7402EE for ; Fri, 11 Oct 2024 10:28:21 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TaHLPmkLc0x/zFiw+ph6v5l8dpzvH9RYzpt78aOOxrwyLnNpUCC4wk+L3C69FSIsPdamePIvUDKPbks6VewrQAsEr5WquI3TPVocdVY45zojtJl7/U0coCVa13VOJJwL8OaK+yMu3cXspD3Lmymbbmg3okqvRXRkVr9ahLXCv21HsD3fDZT0/2jmcJVAxACB2u1omuFJYPhsebCtenWPEhZjXmNme2it6vB+jTW2U7jkkAoUY8iX7ZnhA5g6w5Okk8ZXV0lHWTuLDnOcsSIU+bgqNc84R/fw4jxE7i5UMi6f5Di1GMHCEnLzS9hLAK8mmgjm+e6jLC8EkqNx9w+C9g== 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=sVB2vNvuNxq9ELObqMr2z+lAkGS8lmItmnAF5Z7aBtv8Rpxe+ULQ93yK09aJIIq+9N4W38qqJfT/30HaGr6gYqMs+AIFnHf0BGh4Up513GbtKY4Eq0INiIDFg5oXXMcsl353e2A5ZZ0z2iY2OBrSkehARmOhelaMFQNsn74DnjBGdY0Adur9iLLAalDgI+8IOw+FCjTYl75/I2U2trKp0YWGokXlyJl39te5xinnpo2Qga8KIOedT6kTbk9vOdHvO0fYj/PAaXFOrbLg7MQsM3R4YExYvA3HQlucKpmS1xluHG3PMzwc32jjZWP/7BJqEc0LZvisCJ1R5r6eQ4Sk1Q== 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=BfT/pSBSpA53LCAbk+CY94XgDxUaQeHFvYkgNSkfTmYp9/eeeVj6gRicBI4q7iqZkY7suqVMALXZVFM6OlmbD2HeQBqyzMvlXcF+icrdvHDygd+YqmaXED66Rd5lon7qrw1WicMgNOvjnaw8LJT/K/VBcpiIhcbtJoc7MK9sG3l2AvK8FUIcIbRHymtIAcWUjxxvIyBPPOYrsKHxyi8WOIvDTPq9jJ8iY2EaOzljY4zrAjHBkh892Tk1OnP5pKF3W2mj140QLP2br9Xy5QhNqraiYrgaVrjfBdTL50eqpv/5XmXiTKe5n36xXzhLeyTyd6c4qrrI5VNn6aQZVXJCNA== Received: from DU7P189CA0016.EURP189.PROD.OUTLOOK.COM (2603:10a6:10:552::28) by AS1PR07MB8568.eurprd07.prod.outlook.com (2603:10a6:20b:470::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18; Fri, 11 Oct 2024 08:28:18 +0000 Received: from DB5PEPF00014B88.eurprd02.prod.outlook.com (2603:10a6:10:552:cafe::f5) by DU7P189CA0016.outlook.office365.com (2603:10a6:10:552::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.17 via Frontend Transport; Fri, 11 Oct 2024 08:28:18 +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 DB5PEPF00014B88.mail.protection.outlook.com (10.167.8.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.13 via Frontend Transport; Fri, 11 Oct 2024 08:28:18 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.62) with Microsoft SMTP Server id 15.2.1544.11; Fri, 11 Oct 2024 10:28:16 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id F2EEA38007A; Fri, 11 Oct 2024 10:28:15 +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 , Luka Jankovic , =?utf-8?q?Mattias_R=C3=B6nnblom?= , Konstantin Ananyev , Chengwen Feng Subject: [PATCH v10 4/7] random: keep PRNG state in lcore variable Date: Fri, 11 Oct 2024 10:18:58 +0200 Message-ID: <20241011081901.816211-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241011081901.816211-1-mattias.ronnblom@ericsson.com> References: <20241010142205.813134-2-mattias.ronnblom@ericsson.com> <20241011081901.816211-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB5PEPF00014B88:EE_|AS1PR07MB8568:EE_ X-MS-Office365-Filtering-Correlation-Id: 72231348-b182-464e-bb70-08dce9cea8d9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: =?utf-8?q?cEFEXjaeWtUpYqYpvRYxRWIF6igD5EY?= =?utf-8?q?Y1X1qavc3ivDZOcFZUl5GdLT6rvj6g4rfMCsO41yUncn5X0MnnPpc/eTOr1WwID/b?= =?utf-8?q?lL2//5z92ex1YSBlOsVu4MzzqWBNMBK3pNIxJ8zoRpyqmXUghveofzz5T9ak8Bu9h?= =?utf-8?q?u7NohfD5/CSRC8peDr8yqMyDopq8tVrmaQ6LjXWIoEQuB2VCZ/bn6Xsh+WgUpSd9Z?= =?utf-8?q?atjNUcl92IVEfYdvZbqmLtr+6+AKlqX7EJhoR/ZqQ64Ed0sd/NTbV3KqRV01e19M4?= =?utf-8?q?R4t3U32sFh5Q2Vu4OVeTwr9xvLSC93nhsfHYTohVt0G1NJY7ZzN67rVnyMmXjLpmx?= =?utf-8?q?T1VBYKx/n89Ex8zlmHQvSUp28bb4g/Xs5P5CTTnx//uVmPtRuTqns3wKN7VaSlp6W?= =?utf-8?q?rZLE+Q5yXtJX4kExBKqk1Z85vFgo26oKXn75i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xqW3pPE3Vrmfl9ZAc4gsZ0kL3N6iXrtg=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)(376014)(1800799024)(82310400026)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2024 08:28:18.3737 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 72231348-b182-464e-bb70-08dce9cea8d9 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: DB5PEPF00014B88.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR07MB8568 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);