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 F0A89459BF; Tue, 17 Sep 2024 16:42:31 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1BB94410F6; Tue, 17 Sep 2024 16:42:08 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2063.outbound.protection.outlook.com [40.107.22.63]) by mails.dpdk.org (Postfix) with ESMTP id 4B7D940261 for ; Tue, 17 Sep 2024 16:42:02 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=t0G79TKpNiyKYU8SGRP7z4gtLBzsuwl8LWXkwllIlNxBO1p7+aem4ZOlRbagMAJ6nRwdPvOZaUhC3bf5iNLOg7xXlAZxLtsZdJGxks6Cv7N9mgjGYADEbIZCGtoxu/z7hAaEtlyfOs/ixWR5YFmknkdH6p0eLFja/zbVvrU2CXbheHPZFzFNiJn/Bsq6CXxaFhuKcXRNbujXK4+9RAkvAawhkbPCvra13yGe3H/pihno+XfMDiO0szsOZ7s6VkB02B8oFIdmN8wlhRCz+GrqbPkgTKVVXfYJhfv330GXjwYPdlXPaNwS4ZBjtgMkMER7QLTfvNzCz7Azqg6Eo1ZFTw== 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=RbedT1DRhpG4D0rH9NvaS3EAQph1B0l32q5FK4gkWIs=; b=k62CWhibv302r8Ex9568WmEc9jGVtzLno7AZ9a0x8iDxMkRfypYP/jsQH2R7ecoVt2AKW2k18NaFENPcqRqvv6KyB/MeOcGzJkOHV55dsRrZlYfqyHqagyLtLkcvvrFQrxKVu3vd5tbpuxux6w+fV7BCBCbZRHwBuzcuzjgLntn8y2CXRFx/OE3NauXNQ8sYcUZoDs1rqXrJDNCmu3GLdoPwqT7S3P0aWoRS1Li75N+GkM8LV7o3utK8JcFpdQYYbM3BeU1iF4WM0LzEk0OhtBtV3Q0saeKB4jMhBMVNYcx4SfaqicCieEWwmwiBJG3Od/IeFNyiSL1sZDJnKkpPGg== 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=RbedT1DRhpG4D0rH9NvaS3EAQph1B0l32q5FK4gkWIs=; b=jpNz/8VAxJQPUVsEmwYVnlsM1yeQb7phYI1xHNY50dsHGA9+OBu+QY7S9u51MvUI7YUEolWdDFw49WaMXTWo2fdFSdlpY0VSXQzZDsw5+y3R8X3GgsmOm3swlhh9Tv43phg2BqIU4+FxwxAwvT/pvrHqlBxKr3yRYmQtznTfnthFIt4ZgnAzF1MZ2qzFAsTpBphObZLG3WcU0uK5vqJPgl8VxDCDIXnrgb7V86Q3lpLK7F+f7p/XzeCO5ebmn+fZhLVhuIbiuI7zrkfSN7v6Q7JL/jS9Be73QW5TiKoGFk3jmhFlcvzAHlFad8KyjfbAWy2cAg2SqDzy8pg8QgSQIQ== Received: from DUZPR01CA0246.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b5::12) by DB9PR07MB8611.eurprd07.prod.outlook.com (2603:10a6:10:307::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.24; Tue, 17 Sep 2024 14:41:57 +0000 Received: from DB5PEPF00014B95.eurprd02.prod.outlook.com (2603:10a6:10:4b5:cafe::80) by DUZPR01CA0246.outlook.office365.com (2603:10a6:10:4b5::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.30 via Frontend Transport; Tue, 17 Sep 2024 14:41:57 +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 DB5PEPF00014B95.mail.protection.outlook.com (10.167.8.233) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Tue, 17 Sep 2024 14:41:57 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.69) with Microsoft SMTP Server id 15.2.1544.11; Tue, 17 Sep 2024 16:41:57 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id E003738007D; Tue, 17 Sep 2024 16:41:56 +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 , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= , Konstantin Ananyev Subject: [PATCH v5 4/7] random: keep PRNG state in lcore variable Date: Tue, 17 Sep 2024 16:32:36 +0200 Message-ID: <20240917143239.724069-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240917143239.724069-1-mattias.ronnblom@ericsson.com> References: <20240916105210.721315-2-mattias.ronnblom@ericsson.com> <20240917143239.724069-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: DB5PEPF00014B95:EE_|DB9PR07MB8611:EE_ X-MS-Office365-Filtering-Correlation-Id: 07125a64-58d8-4060-cb06-08dcd726e1aa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|82310400026|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?R1BxNXRlSVE0ZitsYStQelhQdExpbEVmTkJIaVE4emxUeVNMb0tYcXdDWXk2?= =?utf-8?B?aG5LYnJYNmVycHNSY3VSWk95Z0hxUXBsdmo5OEhmK21QdFFqZUpDUDlZQ0xM?= =?utf-8?B?U3pnbVI4eWdIWGVwQ3dNUURabGNYQW0xT3pXeXhuR3FLc2hONzBaREhpUWdo?= =?utf-8?B?bWRWN2lLM3dDdW1WNlZQakozdk1HUThyWnZ1UUJUWE1TRjRQUmd6ZDdnd0VZ?= =?utf-8?B?cUtBV3YxeVJCcndET21KL0p6TEM4djJmVm9kakhQdTFudFJZZzBHMFB5Z0p4?= =?utf-8?B?VHhjVUJqUzRpTVA2SmlYK3RDbWVPc29kY1RzS1J5SXlSNEpWdmxiUGg3cFdk?= =?utf-8?B?RmRrVFcwSEJpVk84ZUYyWUY1N085Z29uaGtqUUoyVlUxcGdMMzNyclN2Qm9u?= =?utf-8?B?Ry9oMHZ4cU9lbjlaSkREVXlrUWJqdmRXZWQ5ckFRYnpIVjhnc2VNVWJrbTNp?= =?utf-8?B?MmNGd1Q3ZFJ4dWtWVXlZZkdWMWcwcUVWZ2M0Q0VYSWJHZUVUcUl2YWxmMURu?= =?utf-8?B?UHF1WjhIR2NHd3JiQkh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ME9zNk5RZ2NRK2xIbW9HSnlQMFNlc1M1d0hSR0FYdEdFcXhU?= =?utf-8?B?VTQxQXdGN0hpMitzWC9RZEFnUnprWjk3T0VyelhGdTYvNzJkNUpEQ3pTajJ3?= =?utf-8?B?aDFITTJoQWFncFBrNGRKek1FY1FsSXR6YUUwV0l0S2s0L3dKKytTenJUSHFJ?= =?utf-8?B?d1RNaEVhbGFmMkt3R2k0V1BDVkJDNHU5b3R3NE00SW9IQms2SUhQQ2llVldm?= =?utf-8?B?T3Z2ek1Gdkw0RHZtbkt6QkFRa2JLUFBIVVU2WFc1QUsrOVY1ZnFpK2pMSjRK?= =?utf-8?B?YWZibFJHWUx6ODJZOER6dEhpaS9Cc0NoUHhMK2xLVE1BN0JVbjRhamVLUTVu?= =?utf-8?Q?N4Ndcx/SeuNDAyMPNqtxCbmmsv6YGfPjfaOhE=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)(36860700013)(82310400026)(1800799024)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2024 14:41:57.3782 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 07125a64-58d8-4060-cb06-08dcd726e1aa 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: DB5PEPF00014B95.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR07MB8611 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 -- 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.34.1