From patchwork Thu Sep 12 08:44:26 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: 143997 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 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_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?= 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 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?q?fCnkvOXJFYRDCl8tunI65lxloiF6hQ0?= =?utf-8?q?x1oE0ZZA5gWqrc3ekerYQmgcueOLi07JjhpxbIaVmbRiOddDb1s6JDic6vsulsXbM?= =?utf-8?q?kh9QrmW4apR8RAAvFAZ4zh8uHC9jsgH1NUOm9dWZ+kf/2GzmU88CEh+Wdcc2xogUQ?= =?utf-8?q?lTcyEQS1s0Xi83jN41Gk/GWBgHHU/Tx0XThpJqOhlrQMjKqvWsQfwW091L4CCOkQe?= =?utf-8?q?nLE++t1lxvsqHVV3euNPfsjdAMB/DbCWSUrvQzWQhwIw7B9yvXvSSyZRoL82q9acn?= =?utf-8?q?0lRl1+YWIZpEZWMaiqktLnIfG53mt+wUD1jt0M1887TZ7QBVQLx8GZxifsA1t+AAt?= =?utf-8?q?k1xtIK/xc8oDVpT1uGK6b8/hprpsBVj1PT+32ty38pG7jGERxPuFy4pNvSiwQLmLj?= =?utf-8?q?FPGcegufYeymk6EUBUIFMIkyXBdB1jjTncJICkE8I0cVq2IP69ubcZVhofke1Y+ov?= =?utf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RStJn/R/OYFNFD2Rbv2rwmjxVMTsOkzUyt3NIp/3qQIyOnCgJWM?= =?utf-8?q?M3RBAluLLfC?= 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);