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 94EA045BD4; Fri, 25 Oct 2024 10:51:38 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 17EB440667; Fri, 25 Oct 2024 10:51:12 +0200 (CEST) Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2045.outbound.protection.outlook.com [40.107.241.45]) by mails.dpdk.org (Postfix) with ESMTP id 9EB454003C for ; Fri, 25 Oct 2024 10:50:56 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CGZK65mKhQhlZpNhqEcmk4SxBWzfMPKd5C2gLwFi6AtpoDMEgJFvbiHzOl5gLUAna0zzlmjVx+1EUxCCOPs+tQPD0FFHVLXy8IYPc+p2yDbY9BDcZTozlO+9Pp9NzW2NFiYRW4q1hFN2r1HaPhPv6SWee2N2QUPQXkqRaa9DUuRO7lI+3Sla6c2SoRpn6P51mVx1dGmmAz8Zw5XB+zqefdV9Pz0JQ2i1m8+73VBILBGnlQZvjkqQ2jO083HYHMaZUpzhEhg5CUKeFH02nurvOUhYwJZ+79CL6tKKG3aTa2BUTrgr6NtqTNZ6Hk/+wQQHPhlEJdjjSZL1C+8lhbDMQA== 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=KOUrkQUglZ02vid9BkXsLh1usrVRPik6awjmBtjUX1i5QKBn0caPmXjGoifI+9Rhxc/AtAcCpWWbHAF6sLByp6rWLsu4+HaVvuYbiIMWE+u6RCFxzPDdw6L5xHItbmjuo8EE2AkocJhxw5n2t4cIdJX/+GfCAo3VJi+OBIqcyNBGV6ya+YeTERv1dsaRtmMZxmYcm/8Cc9tFtBFiP8SaE1hrafHT5N5eC+0sbTmTqCio/VGSbhdJr1M+AiFMAAtqbG7mkjJsYUWcEs6Z3dva0ikaELb9qZLN7pTGktwUE2rEtvAaZ76a2zp6EREjt+GzBu8YRVwBjXIPkpQPhidZxg== 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=nKqI5sCQGhOd/2tJh1G0N9aZpoaaaWKmXLVjA6zm3yWTfvA/qZBxtvYOFkCcSpc68xfSzkGTMSPB37M9Lzf+AQR8JHPGqsUiiJKaaJD8bgDzv8yDLoacHx1rwAf/J3/Ro9/TvlnNoeglNJuYA1G0lHJDeWnZjRVfVgJFrqxDDG6+TaVafW25LdV/vzseTIc5xYEFI2W9NZCypCFPHOvh01KaiqAcTrcSNRPsvG6KBQqUn/FPKNio2rrtiPMyHsjUPrZmTbWc8YDzXymzWGMiyUn5RfL1HuabLncGJqH6Bw4f/rsDoiyPQeIUkhgCED/WWQnUEcqt1uY98JQEoY2fSw== Received: from DU7P195CA0011.EURP195.PROD.OUTLOOK.COM (2603:10a6:10:54d::14) by PAWPR07MB10094.eurprd07.prod.outlook.com (2603:10a6:102:38f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.20; Fri, 25 Oct 2024 08:50:51 +0000 Received: from DB3PEPF00008859.eurprd02.prod.outlook.com (2603:10a6:10:54d:cafe::5) by DU7P195CA0011.outlook.office365.com (2603:10a6:10:54d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.20 via Frontend Transport; Fri, 25 Oct 2024 08:50:51 +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 DB3PEPF00008859.mail.protection.outlook.com (10.167.242.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.14 via Frontend Transport; Fri, 25 Oct 2024 08:50:51 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.61) with Microsoft SMTP Server id 15.2.1544.11; Fri, 25 Oct 2024 10:50:50 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 0A9C91C00A5; Fri, 25 Oct 2024 10:50:50 +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 , Thomas Monjalon , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= , Konstantin Ananyev , Chengwen Feng Subject: [PATCH v17 5/8] random: keep PRNG state in lcore variable Date: Fri, 25 Oct 2024 10:41:46 +0200 Message-ID: <20241025084149.873037-6-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241025084149.873037-1-mattias.ronnblom@ericsson.com> References: <20241023075302.869008-1-mattias.ronnblom@ericsson.com> <20241025084149.873037-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: DB3PEPF00008859:EE_|PAWPR07MB10094:EE_ X-MS-Office365-Filtering-Correlation-Id: a3a51026-9f29-4798-dbcf-08dcf4d220da X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|36860700013|1800799024|376014|7416014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?eUpZc29uaWF2eExMZ3UxSFVIdlZuVE10WmI2Nmk3dlZuSXZXZmcvNEsrNHAz?= =?utf-8?B?bnZUSmtzV3A2VlBKeWhiWFRoWEV3TkZLRmhwYmZ6K3RWZEZudVZWM21xWWVX?= =?utf-8?B?KzR5ZVoraUFqR1BUYlo5NENXZSs5b256YWFZQUxnbHpGWDhNYWRLZ2tGWEVo?= =?utf-8?B?SG82ZkFaUk5lcEdIT2VheDd1djEvVTVmbnljdm15NSt2aDU4a3M5TUVtQ0Ju?= =?utf-8?B?Sm9LbEwyTmIrd2tjb3ZCYmFpcFpSby9LRTNNZm1ZZ3VVVHd3N2wzaFNoZUxL?= =?utf-8?B?UU9FMDVUc0NGZUttWE1nTjU2eGIyWllWMXJVRjMwTE9HQkZqY0wrYXpma0wv?= =?utf-8?B?UHFocU5RODJnWmlScnQ5aHZJT240R1JBMFd3SFBkSWNhaVlEajhhajdPZHJl?= =?utf-8?B?RUNuTy9leUZIUXJrTGhvUUc2WWZFSVJFNDRZMnl1TWp5UldyZEx1a0Z0UnB0?= =?utf-8?B?cVZnSFlxOEh6bXRXcXkzeFFNZkRQajE4NGVrMytkRnptRHVzK1J0WDRR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BV3hseVBU?= =?utf-8?B?T0YrcFk1STI3WEIwMG9nRmE0ZXp6cHR1eXF1Z1lIY0t6ekFlN0tXTWN2OTR4?= =?utf-8?B?Y1Fwcm9UMUJRSjlGWStzMlBVRUxHUTZjd2NiRnp6T1V2NHcreXBKTndKWXo0?= =?utf-8?B?cmdWT1p0VWNBbFFlWVRJc3poc1VycDg0emNwM3RwcElBRmhHR3hkSmdQQnlr?= =?utf-8?B?bytaRmJGVVAzUzlzSGhJMGh6U0w3ZHFzOHpCWnc2Y0xuNWFzbWlEVDk3NWM2?= =?utf-8?B?NC82WjRuRWp3ZXp1dUVkTHdnb0dhZ1kxQmlSSm9uZzMwNmVZeXI3N0xOUnkw?= =?utf-8?B?cUZ1VG53eVIyREg1Nyt0VWk5bWRUakllRjl0MFBjc0pVTGRuNU5OYlZYVDJM?= =?utf-8?B?dStnMzN6Slg0TDVVblR5UEhoalNZWUN6aFVmbDNvei9LeGNVUmpQUmJoN3Bk?= =?utf-8?B?cWVYZEtGdlBNU2FVeUJ4WEJGSnhGd0xkakRRK2VLR3pQYlE9PQ==?= 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)(82310400026)(36860700013)(1800799024)(376014)(7416014); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2024 08:50:51.0510 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a3a51026-9f29-4798-dbcf-08dcf4d220da 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: DB3PEPF00008859.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR07MB10094 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