From patchwork Wed Oct 16 13:19:13 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: 146087 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 8EFA945B50; Wed, 16 Oct 2024 15:29:26 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 12F4840663; Wed, 16 Oct 2024 15:28:43 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2060.outbound.protection.outlook.com [40.107.22.60]) by mails.dpdk.org (Postfix) with ESMTP id 3A0F840430 for ; Wed, 16 Oct 2024 15:28:27 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uPANcrArx4vzJJNfiYzAsbADZAYHJ9VBV++Pdpe8psVigAKBTe9NIB7xBZw3px9Dp3YHKDnszC8rxBOTiXt/Zd2Q4rbNGrQcL/g5irbpKrqsAS7NpWvvfmL4YLxdECiDmDq8Wcj109Z0anq4l3Fd2hV5Pfp9aTF0pWvKaOchbZ4BT/r5onQ4zQurn5qlG5sHekeASsPDZaSGg+ORR9ZJsFcQUFApAYGTr1BDHyiaIibQr1lsWBs1R+ZpIqwm/aBljwZLoqd9Yz+mH56vEHb/lH72kAQyjlYOEEYO0TlOgwrZDvy/urllXD8eGuMa4R52HxJVCdgMTPzw+M/m7n24ZQ== 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=lMh7IE+iRAodUfwrvzJDWi6LzpekxJR6R7y6dmqa5jWGrZ8t7K9nsEfjry8jECTlVqk7zQ7re9Y2gN0wysPT8Sjdu/BXL2/W9xAnGFRRAaQ+W8a1HdTuzBRDi5OD1o71d+Ac7K+NonaAPhKFo5s1q9zT69gbpHm6cO1q1rcAWH7FMSGah7zGoxvqVRxQbwZAeGLP+LcKqM1jg+UX0OCAg1sBvxAtjfTWWtwQZyH3+lRsZLQqlKyhkG6e9OEaU9jOtezxrOxi7FyTmwTlN5MzavuaFCgD9s8u2fCFlqnXf39owyscSPRIqQwUB768D5FrgHNTEGhqSR0Qpm0OMGnjww== 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=RsDjvYDIlIbb6UbK3rfBqIo7+Dii3p2SrQ9+Df80Gw7yUpM4vgVv4X0SSDZpAWro7Sf7pnUe3DEBknZH/pMhjMcw1LwgZzx4I1O5tWKMeOL2fJWg7RcP6CPtTAiz3UQnHZK+Sv2qDcm4ZDPSNozx/+T9Jl9YjLo6tt+sBRBMlexN1PMiq71YzPa5TuzCF1tba2fzgznxS0c/EzvvE1KACmOYFACzs/RtBSG0gAmvF2wlgSsxvbmbRsYchP4nkSHfm8O3vRwcKAaKFjDwHPXDeL2RqBDUs4nCpclnKBei7RW8QxJJ2pRddFdAg+HKQWdH4bCxlryzd3kXVCUY22b5Mw== Received: from AM0PR01CA0090.eurprd01.prod.exchangelabs.com (2603:10a6:208:10e::31) by GVXPR07MB9677.eurprd07.prod.outlook.com (2603:10a6:150:111::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.17; Wed, 16 Oct 2024 13:28:22 +0000 Received: from AM3PEPF0000A795.eurprd04.prod.outlook.com (2603:10a6:208:10e:cafe::d7) by AM0PR01CA0090.outlook.office365.com (2603:10a6:208:10e::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.18 via Frontend Transport; Wed, 16 Oct 2024 13:28:21 +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 AM3PEPF0000A795.mail.protection.outlook.com (10.167.16.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.17 via Frontend Transport; Wed, 16 Oct 2024 13:28:21 +0000 Received: from seliicinfr00050.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; Wed, 16 Oct 2024 15:28:21 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id DF8E61C006D; Wed, 16 Oct 2024 15:28:20 +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 v14 4/7] random: keep PRNG state in lcore variable Date: Wed, 16 Oct 2024 15:19:13 +0200 Message-ID: <20241016131916.827788-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241016131916.827788-1-mattias.ronnblom@ericsson.com> References: <20241015093344.824073-2-mattias.ronnblom@ericsson.com> <20241016131916.827788-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM3PEPF0000A795:EE_|GVXPR07MB9677:EE_ X-MS-Office365-Filtering-Correlation-Id: 8a684f69-e24f-4ee5-cc21-08dcede6676d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?q?Af1yN98NW0Y4ozpMQVamXUJEZGz/GwB?= =?utf-8?q?cx9p7XhgLgahdod2J3hwUYo30yrE6Sa9Od3SGbzCqIBqCsy+Jr2WLT+3jF3exTYmS?= =?utf-8?q?gcUNUHl5WRifEU8YatoKWaqzQIbLrhWfUK5Y1k2ZHdxcNeANSHYHvUGkLf1iNDzgD?= =?utf-8?q?zNaksIRrIXg2cWtY4z+HkiNeNRloD3MmHX/IXm4UXzGYT4wOKELV5R292LqzASh/c?= =?utf-8?q?k4SBTk/dBXgI7mWdZdJUgKsJp2YNceL6ho6Vrrm42JVUbGHzFSvmgebSyuT3Y/gmV?= =?utf-8?q?B+ZX2oQ+4Z2xotNnIi8fWo9blc9Z5VEhLt9pCBO7TlvqjuNn6RyysC2kFKodEv82T?= =?utf-8?q?ztBXoOdv1vKbm53+kgop0uNWe6KH7a07z8GucRHVaaGO9ul4M6J1WJ9JX3m2Y6Eqs?= =?utf-8?q?xzdzPDUrP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oMUyw9qbPbagrCi6UyYkUSWOP+loxqpzCZ4JqYV+Q=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)(376014)(36860700013)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2024 13:28:21.2808 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8a684f69-e24f-4ee5-cc21-08dcede6676d 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: AM3PEPF0000A795.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR07MB9677 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);