From patchwork Wed Sep 11 17:04:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Mattias_R=C3=B6nnblom?= X-Patchwork-Id: 143960 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org 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_R=C3=B6nnblom?= To: CC: , =?utf-8?q?Morten_Br=C3=B8rup?= , Stephen Hemminger , Konstantin Ananyev , David Marchand , =?utf-8?q?Mattias_R=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 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?q?jW8FFPdujVtYL6EZFh6uKlAgrknfq5m?= =?utf-8?q?7ZvS1HecJHJEeBjmndrFwp1AFOOmoLpk3UGGqL1hkqUogngAMcx1+Qz7mQBfX8k3I?= =?utf-8?q?ogni6HFDlKLCPyEI8qdJyB/wxNXVD3WeO8JEdKJr3JVT6AdS61h90qnuHDDK+KBW9?= =?utf-8?q?EXESta1RYkKIRXG0QpzVP40QQfcnjq+wPtnp8rPP1ajwYfoQtsA4cxBNk9WNHQb/J?= =?utf-8?q?wi1cguOgX3NdJQtYWL6qugRlUeWUyN9/c7+srwiIg/Yh/e1n+Aa1pN7U24+NLQUbr?= =?utf-8?q?dyroBaUvasuAq+pDKL0EkTgzhsmIyBtOtDmYASxt+83WupvHLvEfvvRpUV7/O8Sil?= =?utf-8?q?UK9Q4ymJq/yB7e68olqn4Pbv9Lsunwrtgba2BMm+SnJ7K9dk6fhpXQj+o9acUUanD?= =?utf-8?q?GmYr7J319tn+Imimp+ENekoV2Aq0ZeYd6HP3dwDzTGAhcJy7K/pGOul0ptZDURMgq?= =?utf-8?q?7v2TNJccDsECPr9dtSp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96AlUdp56J4AYKj2Vz0mOe5wK+f279eU9+kVOjBWqwzN+vROeYay?= =?utf-8?q?AyBaxILBolp?= 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);