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 BE5C545952; Tue, 10 Sep 2024 09:13:49 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EF977427BB; Tue, 10 Sep 2024 09:13:16 +0200 (CEST) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2050.outbound.protection.outlook.com [40.107.21.50]) by mails.dpdk.org (Postfix) with ESMTP id 525D442793 for ; Tue, 10 Sep 2024 09:13:12 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KYClWTMPvU5D4wRUwJQCCMyEv+v0JiW88M3yXBHaAYm8qL1ZHGIePlFMPIfs2Q5XmvTbfrrFNJDN7SStwR4uzOAhVPC0Pmlh18IOBK+twmZKNRXLiPs5/909yVrqSHoxxZBpT/6AQImgI32pWie6k/xZJcMfI1XkQYEUrRZuPn+E1YzMWmGTmRHugU1ZC0eTi64ikwSBlPypPHLOVcUapbbAZxjdfJBIRWrWm7FoN5hMjXphLfmCJDVrcnt3cyBZ/F65al42ZVlvtcvTOo/wZt/nbuDQeB5omXelHGuagLqU1Az6SxfxNBNdZNc9O6qRFxZnA/0vRPTNV/RHY5sLEw== 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=c/MOS/+dRG0z0gX8jh99c5Nd4VS3n485K/iuO/clLFMzoQoBil+ZvqiArB8Jm/fRnbrB4FZc2QEA6mhaoZuaGLm4AawnVMIx4OpQgnApGd+BQBj4TqJ0iuxI1dglOU7h+7uhlPpCkDNHKyjPSj/bi4jhgpJ5MLnwe8z4KiiDcR0/GRS4LUpWMNFko8sLEfBUjzmzUC1k9sIgau3Rn7eGcmN0oYzBJYWIfrdu+q/WNMlPqmVEcI9Y6Cj0rqqZp1M1sKtFbWszA6IlULebGkE0ASZcYBvP3TYl3uJquc6EwzsIYbxijqpEHhk2alTqCJCjKxu2tZ1L4HfN4xvrOw78oQ== 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=X1NFwLd2Ikc1nfmn+fiwjFXa1ZHjIXfrEIaDw24ZWEl/n/EtmOFyZ4B46YMP3xvbfSs8Cjq40LzJ3zrCunn+7nbUtTgg0kBRVWq6QQnVsNAaVM2x/ZU2WsDn5yq14+nc4x+RqR283bwXbrVx6sh0aAzU4aAb8Wxa8aXBpaACAC8kqnteei/fEdbjxkocsmLH0n5fR1ERH37C0IZuQxh7GDjfnTBe/CnKxMxLZWfF2TP6ekbRjmzPNrPuAeF4FuIY54oDRA/JQ3T35c2fpz4cA50/HyUvs+VeOce3+gELlxv9l1XRIJ9c9MbD7Uzv5dvi0iDEFDg+rv/rGakZwdPrVg== Received: from AS8PR07CA0043.eurprd07.prod.outlook.com (2603:10a6:20b:459::12) by AM9PR07MB7841.eurprd07.prod.outlook.com (2603:10a6:20b:305::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24; Tue, 10 Sep 2024 07:13:07 +0000 Received: from AMS0EPF000001A0.eurprd05.prod.outlook.com (2603:10a6:20b:459:cafe::30) by AS8PR07CA0043.outlook.office365.com (2603:10a6:20b:459::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24 via Frontend Transport; Tue, 10 Sep 2024 07:13:07 +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 AMS0EPF000001A0.mail.protection.outlook.com (10.167.16.230) 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, 10 Sep 2024 07:13:07 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.65) with Microsoft SMTP Server id 15.2.1544.11; Tue, 10 Sep 2024 09:13:05 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 9482F380061; Tue, 10 Sep 2024 09:13:05 +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 3/6] random: keep PRNG state in lcore variable Date: Tue, 10 Sep 2024 09:03:41 +0200 Message-ID: <20240910070344.699183-4-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910070344.699183-1-mattias.ronnblom@ericsson.com> References: <20240506082721.120666-2-mattias.ronnblom@ericsson.com> <20240910070344.699183-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: AMS0EPF000001A0:EE_|AM9PR07MB7841:EE_ X-MS-Office365-Filtering-Correlation-Id: e2975098-811a-46d3-50b1-08dcd1680511 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?B?MW9xSkJseW1sRzJKUW8reStsbHVOTUtGdTdidHRiK2kxWDViekorQ0ZrUnBQ?= =?utf-8?B?dE4rK1dpdHRUZjA2bDNKOWN4M0kyNkV1cW1SU0pHSEVYY0R6NCt3Tm5KUmsw?= =?utf-8?B?RzJHRnpNK1RIci9JaXNPYjhCYTZWd1NkMncrQk16Qzk2eTQ5UUVPNFRMVW80?= =?utf-8?B?OGFtclNVaFBkSktqaGJlUnhpR0Fpa1hFRC9RSllNbTU1bHZuRnp3MHB4S21T?= =?utf-8?B?Z3Z1U09wWDYvYkY4QU1PUTdEZXJWRTZySU41d3F2NkpVWVhDdzBsa2ZyOW1x?= =?utf-8?B?bFROd0F6Q3Fya0ZiNTN3WDJxZWIzQStWTjQrbEQvaHNLbXFFdWU2Zm9TM2Fy?= =?utf-8?B?NkRwL3U0cTNCV3FRa1Q0N2dZbWEzMFplZHVNV09oMTltVDVXVzFlSTVwUTJK?= =?utf-8?B?d0VoVCtXRDdqVFJxTDFrK1FEZUE0R3ZkRjRLTkhTdDJ3aEUybWI1bTBpeVlx?= =?utf-8?B?WjZEMkNadVlSMThuaUpMNGpqYlpQVGNneHZHejl5d2x0bEdVbEVudUhzc2Rw?= =?utf-8?B?VDFHcEhLTVdjTW5ScDY3UW9wdjIyUkU1ajNuTVAzWU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U2Y2RUV6TjNmUmFmV2orbUZpRDN5TGp4ay9U?= =?utf-8?B?aVlMNG5uVjNSNW1HbjhSTUVXVnZKRThReXhxZGI0cmRWMEJNbGErMjZpY1dM?= =?utf-8?B?QUtSeVRJOU5UNWNzZ3JVWFB0ekNlYVIvU1JDOXFaaVN0NnkxMWxIMVFMUEZ1?= =?utf-8?B?VzF4SEIvYUYySVozcFFuM3dZc2FRakxSUkNVcUNJYmhBWlV3RTNLRG5WdVdB?= =?utf-8?B?N3h4VXVXVEU4OGx0M0tCRnBWeUNwSWEzTXVEb292YVBGQlQvaFMwaWxwVzFs?= =?utf-8?B?bkRIbVljVzFtRStzOEl1ZTRDL0hCQ00xd3d4Mm9VbG4xdXpGL2lRSVB3TTV1?= =?utf-8?B?Mk9WRUpqbGZOdXFQcFA2aW1oNlMyWlhUVVRpekFzWk8wa1ZLYkgyS0hXYmgx?= =?utf-8?B?ZWN6U0pZaWg0VzRIdW9OaFg5eHYrTWFsQkY3Q1F1R3dHMkR6ZGNGZmo4SjZu?= =?utf-8?Q?VQa4aTtkYQA7T2yVp1gsL9CnOP3etmeS?= 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)(1800799024)(376014)(36860700013)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 07:13:07.0342 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e2975098-811a-46d3-50b1-08dcd1680511 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: AMS0EPF000001A0.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR07MB7841 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