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 BDA6845B04; Thu, 10 Oct 2024 16:31:37 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CBF7440A71; Thu, 10 Oct 2024 16:31:20 +0200 (CEST) Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2050.outbound.protection.outlook.com [40.107.105.50]) by mails.dpdk.org (Postfix) with ESMTP id EBF124065D for ; Thu, 10 Oct 2024 16:31:17 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bg+/Rplf3P18JWmgto1ipmkZZCmgtpZ5vmsAPWZ1yY5+MkFPk5bWcafyLy1h5dHQ+GOP5aicU57BX+TgCczESBFJDgVeazEyG1Wtkn+oPHkDT9VW9RGIhex5JOu57NIQyKXbY5sUccTpydpXCb9/K6juttyaX8x4RaKGUaOmju5BoeA8SN5NbroMkH9NwobUOaYBSTRy2gMOVaq27PdmfHva3wdJeKIEkof0nBGKn5aBxaPPohPTXuxOzVV9C3zMmG0PBiA3ALKU4/F7xSQZsQ42y5cj7Im9IpF3H20oah85BzV1ra5M5dE9ZBe6f8RrN3D+T8cSW6nTFvKNYCci3A== 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=ZcrIxsUczn3eEQ4B3j0n5Yi5yrD0dIPqXBBskKRbBbI=; b=j+uh3bX12KFjpwBsZLfWhlktaJzy3muH+CpY1fEqOfilMk9KwVF6dn+qErMaJTDRmMcGRHMlBCT5fS2H6CLrGxo0aZkvodFd8qRUAoadImr+/L9JhYpFmbK5fe36qY9pGNWer8AuqgfwU6gyKMgpro3o2lmQ0r36KhLZIKMPMeaqrVgkz1/twnqpd/Qtbqz9J+L7rftmkaT5W8VWhwgH3xMKKEUdp6AiCAqs96OUj5dEiR5/uvrHazEiUX9iVe42BgQuRkI9zBdhdHXi2Fy3qg+pUbDM7hq0pYobFghR43XuHtn/oq2NiOhi4eZXLdqCHztGXLpwVgV9RbKNaE1J5A== 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=ZcrIxsUczn3eEQ4B3j0n5Yi5yrD0dIPqXBBskKRbBbI=; b=dncb6qJ4XMASUocS9PcGrmSAJi7NEwDC0jOjMrCBJuXxkbbK1e5/a9khBIUPr+kxQcek8GqrN0R3josCc8FVvgi/NdoKXnC9EdzFcyLGTJJLgCNSdgKU7HB1YoYstvqrVELf85MME/vJBFWu23Edt/uIAWFjIdypmyRdWDr49J09CX3ClsJp19A2sOtWSBH+WcbSuuB5fkvVyQ/A52gZORLEEVdacaD/P2DW1UJN1WYXOhjHU/BeD52TyVkqj3AUW9/AgCVt3fvHK0uRMfS3gwrhrxwy0hgnhgrkiqqRZGsCodEBCJ4C+//FDKTkYjR/guSNN38SICqczklCyS4+6A== Received: from DUZPR01CA0054.eurprd01.prod.exchangelabs.com (2603:10a6:10:469::10) by PR3PR07MB6972.eurprd07.prod.outlook.com (2603:10a6:102:79::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Thu, 10 Oct 2024 14:31:14 +0000 Received: from DB5PEPF00014B92.eurprd02.prod.outlook.com (2603:10a6:10:469:cafe::5) by DUZPR01CA0054.outlook.office365.com (2603:10a6:10:469::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18 via Frontend Transport; Thu, 10 Oct 2024 14:31:14 +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 DB5PEPF00014B92.mail.protection.outlook.com (10.167.8.230) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.13 via Frontend Transport; Thu, 10 Oct 2024 14:31:14 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.60) with Microsoft SMTP Server id 15.2.1544.11; Thu, 10 Oct 2024 16:31:12 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 2BA3E38007A; Thu, 10 Oct 2024 16:31:12 +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 v9 4/7] random: keep PRNG state in lcore variable Date: Thu, 10 Oct 2024 16:22:02 +0200 Message-ID: <20241010142205.813134-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241010142205.813134-1-mattias.ronnblom@ericsson.com> References: <20241010141349.813088-2-mattias.ronnblom@ericsson.com> <20241010142205.813134-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: DB5PEPF00014B92:EE_|PR3PR07MB6972:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ad104a0-49b5-42cf-3b60-08dce9383219 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|36860700013|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?B?ZWd1bk8yMFVIeEw0dUJCYS84SXJwdGhPY0tWNU4yQjRmamFyNEJJeXVpRm90?= =?utf-8?B?VDdmZDFhdThTdnFQUzJPcUpNaXhrVDlmVmFjMzF2QkppUXJ6MjA5TGhHOVJZ?= =?utf-8?B?ZUFwUnMwV25FSFdEMVZkUGtjSW0zTy9OZ3dpN2FxUmZzTXQ4TTdiQXRBTXd2?= =?utf-8?B?MDk1MWFnWTZjQzRJUjUrT2pYUXJFWE1KVlJRUFRWZW5iMGVqdG9QTFFDN1BD?= =?utf-8?B?K0JGUXpuM2I1cXVxZmEzVHpOUlhReVduNGczaHJ3akZTK09ZOXNTN3RzZWdV?= =?utf-8?B?eDNiakpteTVOcUQzeWJWaEZHUGRSRDJHSTBPNnc3ZFN5VUV5WGVHY1dLREZ2?= =?utf-8?B?NHQ0K3FEbWpjUUZWN2w5eFowa0pZK0pGVXgrdjk3NFVzcXRndTduYytzeXlO?= =?utf-8?B?Mjd5aUZEY2RENE1keFJuc1hjN09jWC9CVEUzR0pZbnJqMmx6aVd1Y2RtNU53?= =?utf-8?B?T0RodkxFMmdkdUkvclFVR3ZMRUpELzJBUE1sTkpLNTcwQnZKSUhadEQwcDBM?= =?utf-8?B?a2hDaGdBY0tiU1AwSG9RVG5J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B?akxPSTdXaXVBVXV5aDZYcjZiLyt4SERtSEExK0xScEt6SFFwY1pxejZ0dTJB?= =?utf-8?B?Q1R0RHdBRjlUbTFBRGtZR0Z1b3hwSWZOdFNOZ1JQSlFrckQxSkNzYmM5S09v?= =?utf-8?B?UWQwMHdIYTJFZC9hOFY1dDR4Qm95K3VkdEkwSWlXeEZPRXZJUm1FcHpXa1ps?= =?utf-8?B?clZyclg0WnlFR1pYM2FRNXlLdGxYQWowcGJLSHhVbHVaU0RBWmc0dkhHZnZD?= =?utf-8?B?NmlwVWQxTkhUL0RNTTVGZUo3TlhYMkpEa1RUdHY5dVlUeU1KZlJneXFKM3Aw?= =?utf-8?B?cVE0VlJrcWVsdE9hVXloSTE1NFdFK2hFV3h1L1htMis2cVR5czJVNHBXMTVm?= =?utf-8?Q?LoYsH6SNNnbyIx67/EQyk+4C5YH36srhf2WHU=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)(376014)(36860700013)(82310400026)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2024 14:31:14.6785 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9ad104a0-49b5-42cf-3b60-08dce9383219 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: DB5PEPF00014B92.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR07MB6972 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..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.43.0