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 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=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 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit 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?B?QWYxeU45OE5XMFk0b3pwTVFWYW1YVUpFWkd6L0d3QmN4OXA3WGhnTGdhaGRv?= =?utf-8?B?ZDJKM2h3VVlvMzB5ckU2U2E5T2QzU0diekNxSUJxQ3N5K0pyMldMVCszakYz?= =?utf-8?B?ZXhUWW1TZ2NVTlVIbDVXUmlmRVU4WWF0b0tXYXF6UUliTHJoV2ZVSzVZMWsy?= =?utf-8?B?WkhkeGNOZUFOU0hZSHZVR2tMZjFpTkR6Z0R6TmFrc0lScklYZzJjV3RZNHor?= =?utf-8?B?SGtpTmVOUmxvRDNNbUhYL0lYbTRVWHpHWVQ0d09LRUxWNVIyOTJMcXpBU2gv?= =?utf-8?B?Y2s0U0JUay9kQlhnSTdtV2RaZEpVZ0tzSnAyWU5jZUw2aG82VnJybTQySlZV?= =?utf-8?B?YkdIekZTdm1nZWJTeXVUM1kvZ21WQitaWDJvUSs0WjJ4b3RObklpOGZXbzli?= =?utf-8?B?bGM5WjVWRWhMdDlwQ0JPN1RsdnFqdU5uNlJ5eXNDMmtGS29kRXY4MlR6dEJY?= =?utf-8?B?b09kdjF2S2JtNTMra2dvcDB1TldlNktIN2EwN3o4R3VjUkhWYWFHTzl1bDRN?= =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2VFVSajFoKzJq?= =?utf-8?B?SGN0ZEM4Z09EZnhhRVBtWkRuREsybGlCL3lXU2NPOUkwSjVFdUJkVldxcEFa?= =?utf-8?B?TmFFdWxON1dwdThBRGJFMmFNM2V0d1lkRjk3RE5wUzdyU3RRQTlGanVTa3pJ?= =?utf-8?B?bXA2ZEZockc5MzEvMWpmUDJQcjltaC9TaTE2REVEUDZmN1EzUVZYcTd2WC9G?= =?utf-8?B?VzJLVVdXcHdhOVl5SXlxd3VVdjBXWUJUTktGdGMrQTB5cVgrU2Z4dlNPQ05m?= =?utf-8?B?ZzlYRVhoMnBpOFl2eHEraEQzWEtHR1ZMTjFoRnFCaDF5ekRVZ3pBYXY5QkE2?= =?utf-8?B?MU5MSjNZOThYTXhWVlhqM2NVS0lCSUczRWIzMm5QOVk4Q01CMUFWR05vTVV5?= =?utf-8?Q?w9qbPbagrCi6UyYkUSWOP+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); -- 2.43.0