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 1330C4596C; Thu, 12 Sep 2024 10:54:16 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8282142788; Thu, 12 Sep 2024 10:54:05 +0200 (CEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2087.outbound.protection.outlook.com [40.107.20.87]) by mails.dpdk.org (Postfix) with ESMTP id 85CC7406BA for ; Thu, 12 Sep 2024 10:54:01 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MclhnIIlZ45DTn03ctFOM5YS/WlCzcDnaSz4FZSG7dBCMJl6DpF3rxe34ulTZCPoI4yPrSQtOwAjJHfyRLnzmPAWX6szOfCneC8Ar04fopAUeOPFdChc7ZLDIFfqn8T924KBMElTHgARKNCcI3JRWvujInthEIUM+cdcoj6U41+6Pz0Byd//pQFa8Gd2IQKCdRoiwm96VmCGr/gv4pNqXLq6HSsRjFe9MRVSEH8oxHODmqecOCRN15ywUAPivaZSsrW7qd98p7UZcZfrXR8orgnTHvMhF5Ho0IyCod9nCv5JqyBG+s4gD85aPKUKLku2x6vlVkFEqI3igZhTxvdZYg== 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=zISDW1GBkEsa6ggWGIfXJzOVRhTUGIhGxNJ8LygZRHo=; b=Jcuv0PPR/3wBdnY+wEHkPH3zlM86EWR9iC4WJRcFk0z8zQkfFv2CNTOFm15EoVWzz2wmPSxrPFT1IyB+qQ4GNVXVo1PFE8zHxiV3r4xDuT61KOjTZ+hg5C1w0mdiMkqnPGmBjNlf8ISgpw9N38KzZMVsmwH/uakDpU1pz7sOBvacWwmBTdd4xiAMplrtbQbTQt9lgn1gXpCGVeKWK4HtHFcg1C4QiwtbMJPHKcVtW7SrQG0S4P6UhK6f6x4G+aBLoGoVkNXEo75ixNnZcclo+NelpMYW+Wvimmmhgvzw8YsdVdWuLSzAW7XiPyJvDi2HT+mUsykZUYMUNWUKjwZ7FQ== 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=zISDW1GBkEsa6ggWGIfXJzOVRhTUGIhGxNJ8LygZRHo=; b=bU2Zj5ecLQawLsUdb/Y3FGBIpBcmeLxxxLl3hBaKLjTZZ/WK3iNiuhey8qtKapnjb6TvAT0vC6pFmLvV/hdzEuOuIK2QX43AjP4QdzUy+czJKfwrEl2thg8abTo2mD71Vx1jHh+XnxbE2mqFaeYn4ef4hftZG87cWRB7dYtxt3kd24k32miLvzEcsrl0oueeyMwlFmwFwLE78G71+AhUJCFKsgHgc1bmIUkAlWiF7PVUm/mwvkhJbBzufsFnxTR1/0l0Z6UE6e0tk71Sht4i6xjdRZbL7pGfkWmpn0yoOZ8c55qn80osZhmwz4Uvp4qw1uS5yrEUQ5n8IMUvdgeElw== Received: from DU7P194CA0020.EURP194.PROD.OUTLOOK.COM (2603:10a6:10:553::11) by GVXPR07MB9964.eurprd07.prod.outlook.com (2603:10a6:150:122::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24; Thu, 12 Sep 2024 08:53:58 +0000 Received: from DB3PEPF00008860.eurprd02.prod.outlook.com (2603:10a6:10:553:cafe::11) by DU7P194CA0020.outlook.office365.com (2603:10a6:10:553::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.25 via Frontend Transport; Thu, 12 Sep 2024 08:53:55 +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 DB3PEPF00008860.mail.protection.outlook.com (10.167.242.11) 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, 12 Sep 2024 08:53:55 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.66) with Microsoft SMTP Server id 15.2.1544.11; Thu, 12 Sep 2024 10:53:51 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 95F2338007D; Thu, 12 Sep 2024 10:53:51 +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?= Subject: [PATCH v3 4/7] random: keep PRNG state in lcore variable Date: Thu, 12 Sep 2024 10:44:26 +0200 Message-ID: <20240912084429.703405-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240912084429.703405-1-mattias.ronnblom@ericsson.com> References: <20240911170430.701685-2-mattias.ronnblom@ericsson.com> <20240912084429.703405-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: DB3PEPF00008860:EE_|GVXPR07MB9964:EE_ X-MS-Office365-Filtering-Correlation-Id: cc9165c3-6ece-4cbf-2c8a-08dcd3086ec9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|376014|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?B?ZkNua3ZPWEpGWVJEQ2w4dHVuSTY1bHhsb2lGNmhRMHgxb0UwWlpBNWdXcXJj?= =?utf-8?B?M2VrZXJZUW1nY3VlT0xpMDdKamhweGJJYVZtYlJpT2RkRGIxczZKRGljNnZz?= =?utf-8?B?dWxzWGJNa2g5UXJtVzRhcFI4UkFBdkZBWjR6aDh1SEM5anNnSDFOVU9tOWRX?= =?utf-8?B?WitrZi8yR3ptVTg4Q0VoK1dkY2MyeG9nVVFsVGN5RVFTMXMwWGk4M2pONDFH?= =?utf-8?B?ay9HV0JnSEhVL1R4MFhUaHBKcU9obHJRTWpLcXZXc1Fmd1cwOTFMNENDT2tR?= =?utf-8?B?ZW5MRSsrdDFseHZzcUhWVjNldU5QZnNqZEFNQi9EYkNXU1VydlF6V1Fod0l3?= =?utf-8?B?N0I5eXZYdlNTeVpSb0w4MnE5YWNuMGxSbDErWVdJWnBFWldNYWlxa3RMbklm?= =?utf-8?B?RzUzbXQrd1VEMWp0ME0xODg3VFo3UUJWUUx4OEdaeGlmc0ExdCtBQXRrMXh0?= =?utf-8?B?SUsveGM4b0RWcFQxdUdLNmI4L2hwcnBzQlZqMVBUKzMydHkzOHBHN2pHRVJ4?= =?utf-8?B?UHVGeTRwTnZTaXdRTG1MakZQR2NlZ3VmWWV5bWs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jhKQ1NiWjE1blg1MWpSa3dIWENNL2c5?= =?utf-8?B?ZjlWZGhPNEQrOFJNMXhaSnN6amh2UnJwRFVtbzBwcDRHbzgyM05Mc0RhTm1y?= =?utf-8?B?WiszNUFYRlhkTUl3TkpiaVlWSEd5bC9VY1Vab3U0dHFFMzNCd1loMERHMGFF?= =?utf-8?B?SkRMb2ZwTkhNbEVwZGdqNHQzZlljQmtVQU9yWURCdHovaTI0MEk1S0pFLzJG?= =?utf-8?B?VHdtcm0rcXVGTkZSZG1HdGN0Rk14VHl2eGx0QTh1aEtQd2R5bVY2Y0pBa0s2?= =?utf-8?B?bE5lVjlwTTJTQUNlZ3J1RWJGYSt2YjNydHkyK3NnUjBKZVBiQ2N6SVJxdHcz?= =?utf-8?B?b0VjYXlMVElUMXlMc3VRZnQrcFFOZHJ0OThFcThnajBQZHFmS055bWVyaWJ1?= =?utf-8?B?MzA3b2NjczhIWHdhMy9lUlN0Sm4vUi9PWUZORkQyUmJ2MnJ3bWp4Vk1Uc09r?= =?utf-8?Q?zUyt3NIp/3qQIyOnCgJWMM3RBAluLLfC?= 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)(1800799024)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2024 08:53:55.0863 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cc9165c3-6ece-4cbf-2c8a-08dcd3086ec9 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: DB3PEPF00008860.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR07MB9964 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 -- 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