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 AE9E645B42; Tue, 15 Oct 2024 11:43:05 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 97C79402E3; Tue, 15 Oct 2024 11:43:05 +0200 (CEST) Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2076.outbound.protection.outlook.com [40.107.247.76]) by mails.dpdk.org (Postfix) with ESMTP id 360F2400D7 for ; Tue, 15 Oct 2024 11:43:04 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nKJ/aCbMEoOuUa1HEA4jH75W3/y7psybb0qVje0sTtFRhsG0v5fWlt+5lwNt5SMX+gqmKzJkZl2IvP+8NwwVhr5jwTNUSzssDLOEQDJLgcj/Te/d53OUqEnyxeVMuY4JGADxE+Nh6ML63iparmPmjnNGHhoMlYEuzwZrbeZMKqZ85kVH4RoBDluXDL+Isa8bvqVGoHMWEzPIZKPJwny/6GBizP2N5eOGqAP+g5HWrXnM68hKdFPrEmVeyBr5Z5YvUM0lwGyDUT+EJE7dD/d5UL2xnr/thPVWRxXM9V5i4c7x02jMitPep6sTjqUH7NciREdlSejy4CsdPjfivmo7eA== 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=DESL2qFVuTQWm/n9l4enH+FDESyNnVazkJ0Sbs+rOpQ=; b=HhOogRYsMCWWkpmguENZQa9tdK/p/sUbLJ66XriS5gzSjLPFesq5yDmEZVVGPWYbpU+zKnzQmN2MRwP3pCIdbK+94c8P3fwVoLTrDxBxW1WyXyhSyDNx0PH/iUz7ZTcrVfADQ7f8BNE3WDfx2vJJDYev8ps7wVOEKezXuAckHAIa/RNF9i1sZZPOj655NRPUyr7g2E2kA0EJrcVKQfQx8i+OTkDWICqKo3V42H4sq+xygmkFBRrdsBKRe0CENz3DVcjPo5n28JZTjanq4vKbR7u6vCPMjXaUlZOlygQJOalfpXM3Q36GWrihK/V5g5M1nvsjqO7gJCyBHixQBzP2QA== 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=DESL2qFVuTQWm/n9l4enH+FDESyNnVazkJ0Sbs+rOpQ=; b=y7TmqpwYsZ8UlNE5QNHKXOR9xdATgXyQaSv2ioa/lh6pnJ2d6uk9UQO8U1Uk17p22sreKQ7Us+sX0ZgAvzechihbdvGv5qyLPt5zI//PwfL9B/NPkvFXM2aVxmsQEuXQTwaLpfnq2+CocGsQtm/7vA62sw0KTZzHcficbvYkVvOzoKAcvshQAOT/kNkVbYpMZxHpAHqtLZxh43YYQQ/npUKJ8eLHRojr1XYUXJTSTWHuI+dNFa2/PEaHt8zO3gIpc1oPK3gzEqT5N+JCqVK9APVAUH1odFVK5jPYAFNJwVvWDnD/YPdZ328GLxIj4zjnUnFruxMkkx5GKWYjtdmrAg== Received: from DUZPR01CA0092.eurprd01.prod.exchangelabs.com (2603:10a6:10:4bb::27) by VI1PR07MB9755.eurprd07.prod.outlook.com (2603:10a6:800:1da::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.26; Tue, 15 Oct 2024 09:43:00 +0000 Received: from DU6PEPF0000B61F.eurprd02.prod.outlook.com (2603:10a6:10:4bb:cafe::c3) by DUZPR01CA0092.outlook.office365.com (2603:10a6:10:4bb::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.27 via Frontend Transport; Tue, 15 Oct 2024 09:43:00 +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 DU6PEPF0000B61F.mail.protection.outlook.com (10.167.8.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.17 via Frontend Transport; Tue, 15 Oct 2024 09:43:00 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.63) with Microsoft SMTP Server id 15.2.1544.11; Tue, 15 Oct 2024 11:42:59 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 4C85138007F; Tue, 15 Oct 2024 11:42:59 +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 , Luka Jankovic , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= , Konstantin Ananyev , Chengwen Feng Subject: [PATCH v13 4/7] random: keep PRNG state in lcore variable Date: Tue, 15 Oct 2024 11:33:41 +0200 Message-ID: <20241015093344.824073-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241015093344.824073-1-mattias.ronnblom@ericsson.com> References: <20241015065505.823840-2-mattias.ronnblom@ericsson.com> <20241015093344.824073-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: DU6PEPF0000B61F:EE_|VI1PR07MB9755:EE_ X-MS-Office365-Filtering-Correlation-Id: a30cdba7-e4f4-4f94-57fc-08dcecfdc1e7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|376014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?B?bmhmWEYxVU5Pa3JKOWRHbE4wK2MzMXJ1ck5lc2NOaXNMN3cxZTJHMkw1bE9o?= =?utf-8?B?NHdXTXBockk4R2ROdWxzUGZiVDRhNlIyN09oNTZZdk8zbG5xMS8veTVhSTM2?= =?utf-8?B?cGxIeXRvV2QyV0Q4end2em9DZDhQU1dtdUZTOWJ2R3RPTTJPTmljcjBpTXVh?= =?utf-8?B?S2ZvbVRrRUI5MGlpUk1VTG8rQXk0anJsOE44TGRUNTNtSW5YZm13SGtiNGJk?= =?utf-8?B?Mlk1V2h6ZElvQ3ZFZXBMdFloakc2ZEpMSCtCNWtJZE1XVnY2bVowNmw5SHBn?= =?utf-8?B?TUs0TjJZc0c4Sk1TZnJ3UlBSQVl0OGwrd1BZd1MwK243SHVPVkw4RWFHL1p0?= =?utf-8?B?bE52UllQOThlcW8zUTdKMTNzOUNnZDBUUkJKY29iK1Jqdjh6Wi9yN3U0TTUw?= =?utf-8?B?WDRiaGduQjZ3cUx2K1o5WXZWRWordCsrY2hQb0FSc2tzTlBOam1mYlFTbXhj?= =?utf-8?B?eHhHd3NDcjlNQVFPWUkzZkIvRTQxbHFPVnRWYlIzRnY1NDllV0I2WDBLbGd4?= =?utf-8?B?aj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jVqUzlT?= =?utf-8?B?UUdPZUxzb2dYWHV5QkdaMXMzL0xnNTRnM29lSHM1Q0pieDBOY1ZSWTdxaGxO?= =?utf-8?B?SzA5Q2l1ZU1LMXdsbTZnTnBpemt4WjNLdGl4RFBVWnU3Y0JEM3JpbGtlTFky?= =?utf-8?B?WklJYUpqdjFFSjRXVk1Oaytha1VQUUg2YXUrYWpZOWVTYUg1YjVKMWNobkdQ?= =?utf-8?B?WmYwOWxlWmh0T2xNRGFZYzFXUUJTblFHdGkrT1F6cGlTUW5nL3VDUzBnMHFB?= =?utf-8?B?WXNHVTl5Tnc4TklCV1JLUVBYTys3US94QmFWSUJRbzFGdU5KRys1dmhWWFJS?= =?utf-8?B?dU5EQ01WYUtkSDJsSnJvcVRhV3hYR2ovWDllRzBpOGtBZDNiSC9oc3dMeXli?= =?utf-8?Q?z9NocMY84sXVdnZnl0Ut4eAok6wQLpsh3aXcQ=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)(376014)(82310400026)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2024 09:43:00.3031 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a30cdba7-e4f4-4f94-57fc-08dcecfdc1e7 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: DU6PEPF0000B61F.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB9755 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 Acked-by: Chengwen Feng Acked-by: Stephen Hemminger -- 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..cf0756f26a 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(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(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.43.0