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 D0E79459C6; Wed, 18 Sep 2024 10:11:03 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5E51742EEA; Wed, 18 Sep 2024 10:10:47 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2077.outbound.protection.outlook.com [40.107.22.77]) by mails.dpdk.org (Postfix) with ESMTP id 13FF742E7A for ; Wed, 18 Sep 2024 10:10:40 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mz9W/YDCbYz2n0UEUU3wKsnL3WdvuGri5+y8EVqgjTH/p3pKrR2rEPyvEr6AjVNUAdvtsHklLuKI4COddlq3ZP3vPitcxo5BRt0BvBeGmATFAajWVC5mpzGOVaSG6b5ArMfvxVy8TWQLUzko39OVXnKAqz7fOUVScYMDbUgnrUH5o8nbWqrL7lhh1RxaB+6c3PhaMukWqnxQi3ABMF/ea1RMAaKB02NOCGTB4qJKUP3gym5OQw8BTQbNa9aHyQ/BJR43SSRhjVGUvK/5EZzpEPjGJ6XvU6NRxdQzWipYwTYkML2O+qYYFSZjvv8t8IxaR1pmHaMrqhNrXxgjDpRxAg== 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=aI22BYRqdRgwLypa0hKf91jYil5TIYLYsHFd4rv8GZWcvD/E1h5VY2DpQemcwhIbKqQVoC8z7E+nrA+2UtSIpuNM5qvAV5D78XrGlmcZ32BF7Nyu5T9V8mOYswJJX4jyL1BSXrEJKVkqGpIo9oeUSrrkXsI+TZOklrzU2l26WFkg5PuDEeW7fwJDNgBPhBIzjimXiJQZu71uxc5ndR+LNkOosI6r/forMagSbSBeSOritx3pCWxdlRh8ZkVL4Qrf6h1ZG+we5UrWoY1atTeE0EYe106px7uP8G0JfodQVfa1Uk5iaK0FIhyMLuw4Lx0LaayLmrlSSSOW80TVDHGQFg== 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=cEOeB2XfxN+EzZm2ypVZuP011BLjrtcZJpuBhtpW9UtYQQzwAnLtsh8ms6Hviy9MbwskDHG9gZLokIBioY/tWUB6vy5La5ZbLueE5nxAVrGObZ73A/Wn7N18SHRHshzF+h3XeqO3huq2xHH0T2xPaskWF2XCDJQHjk2ItocTfBJfh5GinCOH/Ou3xx8exmSGSW1YzauRHfZr7RwwgLlXESDXrXmodsA5XBKeu0iF5wGO5Ewickg2/gf/2IXQTnmT6EGAw+Ji/vIcMGhAC+AYbFVeDlJQYYnRsfa4uQg7nw7VBRpIfnFYrBTLYmLlfSV0HPaZkv8CH+DeKA3YLJxgIQ== Received: from DBBPR09CA0022.eurprd09.prod.outlook.com (2603:10a6:10:c0::34) by PR3PR07MB8033.eurprd07.prod.outlook.com (2603:10a6:102:14c::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.16; Wed, 18 Sep 2024 08:10:36 +0000 Received: from DB1PEPF000509EB.eurprd03.prod.outlook.com (2603:10a6:10:c0:cafe::6) by DBBPR09CA0022.outlook.office365.com (2603:10a6:10:c0::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.30 via Frontend Transport; Wed, 18 Sep 2024 08:10:36 +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 DB1PEPF000509EB.mail.protection.outlook.com (10.167.242.69) 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, 18 Sep 2024 08:10:36 +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; Wed, 18 Sep 2024 10:10:36 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 38FBD1C0070; Wed, 18 Sep 2024 10:10:36 +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 v6 4/7] random: keep PRNG state in lcore variable Date: Wed, 18 Sep 2024 10:00:51 +0200 Message-ID: <20240918080054.725164-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240918080054.725164-1-mattias.ronnblom@ericsson.com> References: <20240917143239.724069-2-mattias.ronnblom@ericsson.com> <20240918080054.725164-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: DB1PEPF000509EB:EE_|PR3PR07MB8033:EE_ X-MS-Office365-Filtering-Correlation-Id: edd5c266-22c1-4245-5f50-08dcd7b96067 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?b3IyTGYvc1IyYUgwdm53NkZMMG1mTjNqTHQyTGNwSGVsLzFBZnl3RTRROWNj?= =?utf-8?B?cmt1a29VNnV5WXN4L3ArTEJQYmxFakNvZTY5R0pnOXYvdlJEM0srMXVIaEdW?= =?utf-8?B?U0hmQ2xGTHZmNE1hRENRREZCclpGaUwzZGxsT283dnAreDBCVUNSWWdmM3Ry?= =?utf-8?B?M2lDM0g4dkg0ZlZQZTlMVWxpQlBPbGVhc2tPaWpQbGJib2JCbnEyVUFPNFJY?= =?utf-8?B?YjJVRVdvRExxalMzV0YyU1pEQUhFQ0toUWtZY205Ui9FRWNQNkZJaUx5WjAv?= =?utf-8?B?cDlIT0hmUzdOd3YrbnIyNXkvakE4M1prOE9ITUhyT25SUjZuVEd3cUJYMjVP?= =?utf-8?B?WnltZUxGTytWcldEZmp4MGoxNTc3ZXcySlJCeDJEWlo3bW1GZVJDZDNlU2ZD?= =?utf-8?B?dnlZMnRScTQ5NW05dDlJZFI1Mzg1N2d2dHBMSWpSalVTWkFUaEx0ZmlsVnM2?= =?utf-8?B?aFZ2OFFDbVFjMlFvNEZKZkdLaGd6RFRDcXplV1ZIM3RUOEdGOW5BcTd4dWxC?= =?utf-8?B?NU9UNnVpalVWUG5mRzJVbGYwWGtnQkNuVzMx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Ub1dUanhzMWs5ZUlLR3VkRXBBL1ZuVkhZOFNGaE5k?= =?utf-8?B?SFB1YWZaVDkzaUdvWHlaZ3FBTGc5ZEE1RmltclpmeU1VSDVicW8rdVJMWndU?= =?utf-8?B?bFA2WUhUQ0h4cWRXREcxbHQ2ellIRjYyZzh6dnlKdVpkYzNYcmlnYjBlR01N?= =?utf-8?B?S1JQSThXaFN1KzVFd3B3Q25lUXVDZkNnUGV6ZWxCbHVSMnh2WTk3eUx6b2p4?= =?utf-8?B?RjNhdmVhWVgwTjhhaGY1bTlDckpsNGJnWjR4OFFxc3liYnlTUGVuZUUrdWRm?= =?utf-8?B?RDVEbU5Fakwrak9RYlVEdGR2VVMzL2FRVjM4VThkYmN6T2lSai9uaVhneWdT?= =?utf-8?Q?NOF12DF9OA/t2SM6Hs0S9Q6Zy+zkp1uVL/tjA=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)(1800799024)(82310400026)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2024 08:10:36.5295 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: edd5c266-22c1-4245-5f50-08dcd7b96067 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: DB1PEPF000509EB.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR07MB8033 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