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 940E245962; Wed, 11 Sep 2024 19:13:57 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EEA2742F93; Wed, 11 Sep 2024 19:13:56 +0200 (CEST) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2081.outbound.protection.outlook.com [40.107.21.81]) by mails.dpdk.org (Postfix) with ESMTP id 4E7BC42EB0 for ; Wed, 11 Sep 2024 19:13:55 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mGAMxN0ojecrMp3Ppvvk+723cIdw5qTPsw9SgX7FfsX+xY9lY7Or9PpOOAUoOfckjQzrJLL7PyiHujrLu98hVCrMtJAJbecveEgkushEgT8muMiV8sALmho+eNzI6eIKLaS6Uqff1v97eT5FcR9kkkIoMFhV5Sc6tynZ9sFqzKM4SWOok60WchvJwTTfKiSM6Px6uqfAlgbaou3VXMhknMfh3qwiS47qaO+43OW68Wum2jHBfz7JACtTRbppOQZhFx+GhoaGxwvLasQgKt/a923m2xw5Zzah8gMfXszjAePp9kGYcbLCgdHqI+z2gEDiclLq/bEn4NWlTPGBT6BDAQ== 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=zISDW1GBkEsa6ggWGIfXJzOVRhTUGIhGxNJ8LygZRHo=; b=ZBKWmKk+4jaQPYLJ82k5t4X6pAPauxLErZsO0ZH8O/kzTJMhMNYy/XSxlPsPW5fv1PdBJ/UbnRcBHQ4n4+y5g/Vp1Z3NmQDpNxHfXK+Xr+KtQDjTgNxOTFGkLWU5FMC4dnABXJpIvQc0abq+hFQgekYWVII5dZSZnfhkEC17COccNcI2MQjZJem6YeF/2yJmsmc4w4lPJLbM8o8PXULaNX/vw59IAzkpnKXxU2RiS3pHSDcriXN10xv/xWzS+4xbsaHlNe97smRKuis0t+OAnHikbMSi9iImXFL0ddV9kCee1/i/jAqIC8cfdnDH62/ZjvVQnIET9xkUBvsFivZ0ag== 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=zISDW1GBkEsa6ggWGIfXJzOVRhTUGIhGxNJ8LygZRHo=; b=TtQD5nc8YGzZfstkEkI8QSXLdBrMOTPuqT4/0dOSuTH5RzERot/rsfSJI91Qw6V6uh4/pRNmuGUp9dzlUM+8hKOwgcDsGK00bRVE+7wmaOCdOLVbAQICqFhDo4RrjMP0cVcs+atAYywHaRFxHreLRxaBT/vjZ0N84xtz2ySNMw/R2mUpnQfSTgrpMquRuHQOUD5tXVRum1MKicCvKdq0ghGWE6gG+D1CVF0PvddDgao7RhAYHzfmEKs+LxQqzeb2E60sNdVmZbxWErviTbvZP84eWw6NSXkP00bSbUw4FDjxhKQoU1l0PzJyTIRqzz8yg7QEWkekFUdDmIUNam8W/g== Received: from DU2PR04CA0299.eurprd04.prod.outlook.com (2603:10a6:10:28c::34) by PR3PR07MB6730.eurprd07.prod.outlook.com (2603:10a6:102:77::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.23; Wed, 11 Sep 2024 17:13:52 +0000 Received: from DU6PEPF00009527.eurprd02.prod.outlook.com (2603:10a6:10:28c:cafe::74) by DU2PR04CA0299.outlook.office365.com (2603:10a6:10:28c::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.25 via Frontend Transport; Wed, 11 Sep 2024 17:13:52 +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 DU6PEPF00009527.mail.protection.outlook.com (10.167.8.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Wed, 11 Sep 2024 17:13:51 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.66) with Microsoft SMTP Server id 15.2.1544.11; Wed, 11 Sep 2024 19:13:50 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 91C01380061; Wed, 11 Sep 2024 19:13: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 , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Subject: [PATCH v2 3/6] random: keep PRNG state in lcore variable Date: Wed, 11 Sep 2024 19:04:27 +0200 Message-ID: <20240911170430.701685-4-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911170430.701685-1-mattias.ronnblom@ericsson.com> References: <20240910070344.699183-2-mattias.ronnblom@ericsson.com> <20240911170430.701685-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: DU6PEPF00009527:EE_|PR3PR07MB6730:EE_ X-MS-Office365-Filtering-Correlation-Id: 3fb41483-25d5-49ef-ccb0-08dcd2851bbc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|1800799024|36860700013|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?alc4RkZQZHVqVnRZTDZFWkZoNnVLbEFncmtuZnE1bTdadlMxSGVjSkhKRWVC?= =?utf-8?B?am1uZHJGd3AxQUZPT21vTHBrM1VHR3FMMWhrcVVvZ25nQU1jeDErUXo3bVFC?= =?utf-8?B?Zlg4azNJb2duaTZIRkRsS0xDUHlFSThxZEp5Qi93eE5YVkQzV2VPOEpFZEtK?= =?utf-8?B?cjNKVlQ2QWRTNjFoOTBxbnVIRERLK0tCVzlFWEVTdGExUllrS0lSWEcwUXB6?= =?utf-8?B?VlA0MFFRZmNuanErd1B0bnA4clBQMWFqd1lmb1F0c0E0Y3hCTms5V05IUWIv?= =?utf-8?B?SndpMWNndU9nWDNOZEpRdFlXTDZxdWdSbFVlV1V5TjkvYzcrc3J3aUlnL1lo?= =?utf-8?B?L2UxbitBYTFwTjdVMjQrTkxRVWJyZHlyb0JhVXZhc3VBcStwREtMMEVrVGd6?= =?utf-8?B?aHNtSXlCdE90RG1ZQVN4dCs4M1d1cHZITHZFZnZ2UnBVVjcvTzhTaWxVSzlR?= =?utf-8?B?NHltSnEveUI3ZTY4b2xxbjRQYnY5THN1bndydGdiYTJCTW0rU25KN0s5ZGs2?= =?utf-8?B?ZmhwWFFqK285YWNVVWFuREdtWXI3SjMxOXRuK0ltaW1wK0VOZWtvVjJBcTBa?= =?utf-8?B?ZVlkNk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8?B?VE5JUnc1ZVlzVkhoeFpsUzc1TTY5YWNwRmFLQ1hrOWJpVjZtR1p6dmVrNEpI?= =?utf-8?B?OXVVc2xQbUsvVzE4WEV3Y2pycXhoa1FGWVpvYTNJQjc3VEF3S2RyMzYvZjFh?= =?utf-8?B?eGZ3RnJBR3ZsRisrOE1zaUVXV0lLNlVNSlFJOExDT2I0cEs2NlJMa0JCQ2Rr?= =?utf-8?B?NldnNWphVUhNWWhvR2hRT1d4cTZQMmVLS3RYcTZ0NHpiMEU5STJwNU5EcVE5?= =?utf-8?B?eW5jQ01zVDF6RlBsR0ZPR0tzZEtobWJuOGl3UFg0T2FIamtFbUMyVE5HRjIx?= =?utf-8?B?R1RiQjVRWjlRRTF6T3Q1bi96QWpXcWJaK2RVQkI2M0kwaE1HTnkwclJqS09k?= =?utf-8?B?aFFiTnBsMmg4cGpzV0g5NkFsVWRwNTZKNEFZS2oyVnowbU9lNXdLK2YyNzll?= =?utf-8?Q?U9+kVOjBWqwzN+vROeYayAyBaxILBolp?= 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)(1800799024)(36860700013)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2024 17:13:51.6827 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3fb41483-25d5-49ef-ccb0-08dcd2851bbc 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: DU6PEPF00009527.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR07MB6730 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 -- 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