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 75B32459AD; Mon, 16 Sep 2024 13:01:51 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 89A5240E37; Mon, 16 Sep 2024 13:01:37 +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 42FDA40E13 for ; Mon, 16 Sep 2024 13:01:34 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=T0D0DEj8jq9+GRh+Hu4PWzYe+iNINZnV1jIGmtnLW9JHD11yw4+6DQ69ZedvF6vgJAxmQJSrlD9zjcy0//ZhV2zi7d7KtLYmned1b4X9H2syQa3aaVcdqHHzRl5q677KOwFQHq4eosBXIp3PbO130dIVqbKfj6EmLmbfaBcIfyBiFEcHKR6MUoCoDM3gZ8cZ2nrtWTO43v1nWcNEdR+CjIAyKMwr4tQaTeutb7AFSjYBS9aVm7+Nc3pWJHstWS8yOZIxJXXYgzswL2urKisLc1FfVSojDq5IfWhHM5XiTvE2zbRDkhgKyI+2uMeh0gLA7a0UCqlzQsfXpfIIIcuWBg== 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=wWSyxXfPEZNMfJVqgOt9mnJgNmuZa4ccRIJvmbZNpOxlijmiEJY9Rv5n8NxX/P2sTaOZdGvEdKWHuPVD51cfTTBz2MmhXzYgGnlGD7sLI7eH4nQlTBccu8fYbOIkcV2tdgV8+gCPhZCcU5l4lSgbGHK8+oHz0WL8BFANgMO1FD7W1G0q6XTzMXyM+hWKKbajeE1ljynL/CPumIRXhYoOBI5ll7lQ0FgCnuyJC1bBlDkXnpzgG92BNFVBmyb8ahfpauRuKhaL+E190kgUzNUT7jYpS2wLrVhimNE6iZZOCCVLW2LF6Hsd568GY9sJRmcmwRR0ifbF7V+AS3LMXZRgNw== 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=eyX5RZ8ZnlW7gclTJHRY0PZvCts72NBrMkZAQHtUJZoqkuiI3QYrBXrSwv8Un8dIAyWw0mTKqIFFVZT2w6brPjXHgyA8V1Dn+XhlimtL/W6xCpKxR8EoHvKGs0sNT+vIwWISlIg68zQ56urifEw2hG2lc8x92Mpgj/YqLuJ706GR38XFusUpdyFDWCXZ4ShuWHRlaFY4BenFofVSWK3vIFRBgAsGC+WLHJgzXHQ2cM+wn1v/pCU/qXltnZEhtJWu6K6s2IWh8TyIoFOMXDfDee6mzn2pqphDYL9uJKjNZJz3RLE9gzlR6CWBjcBtV+jP57Vp/JhipbdfIh5W/s8eEA== Received: from AS9PR05CA0039.eurprd05.prod.outlook.com (2603:10a6:20b:489::15) by AM7PR07MB6978.eurprd07.prod.outlook.com (2603:10a6:20b:1bf::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.23; Mon, 16 Sep 2024 11:01:31 +0000 Received: from AMS1EPF0000004E.eurprd04.prod.outlook.com (2603:10a6:20b:489:cafe::f6) by AS9PR05CA0039.outlook.office365.com (2603:10a6:20b:489::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.30 via Frontend Transport; Mon, 16 Sep 2024 11:01:31 +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 AMS1EPF0000004E.mail.protection.outlook.com (10.167.16.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Mon, 16 Sep 2024 11:01:31 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.62) with Microsoft SMTP Server id 15.2.1544.11; Mon, 16 Sep 2024 13:01:28 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 7F5DC38007D; Mon, 16 Sep 2024 13:01:28 +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?= Subject: [PATCH v4 4/7] random: keep PRNG state in lcore variable Date: Mon, 16 Sep 2024 12:52:07 +0200 Message-ID: <20240916105210.721315-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240916105210.721315-1-mattias.ronnblom@ericsson.com> References: <20240912084429.703405-2-mattias.ronnblom@ericsson.com> <20240916105210.721315-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: AMS1EPF0000004E:EE_|AM7PR07MB6978:EE_ X-MS-Office365-Filtering-Correlation-Id: d6b633f8-c819-4238-3be3-08dcd63eebb6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|36860700013|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?aldPVDg0RVFLL0ZjcDZrOWVhWkdlY1VnVUd2Mnl5b2xLeU9xUnVCbmhFRWxN?= =?utf-8?B?K0NuNGwvRzNnemg0SnkxNUdNWTFIK0pWT3cvM0VPZXIrSDZERTgxYkEwTWZ5?= =?utf-8?B?UnNISWdCYjJSR0RHNDVZcEdCallqYXp3dUhQYjNYODlCOE9pdGpGK2N0M0hC?= =?utf-8?B?WnJjRTN4R3ptU2NJMmk2dnhCTHI0RGNkL0hZZFpOV3Q1RmZHNVFLV3lZaHFu?= =?utf-8?B?QWFJZGRER3RFVWhwNXVWU3krVkd2Yk1UNEYvWnA1R203bnBFZWJQZldQOGl0?= =?utf-8?B?Q3BHQjhCajJENTl6Z29tR0dZUU53WXE3QnoxcFM4OXNWOEUxcnpKdVRUS1BC?= =?utf-8?B?SXI5R1YwRXZCZDVnaHhNOXYyeUE4S2RRc1JZTXROVkY4RGtEM3RGU1M0enEw?= =?utf-8?B?K2d6bnppcmtiMHZFM2hJQmc3WlE1MEw0d0V6bWZLZU9idUFUbXF5UjV2S1py?= =?utf-8?B?ZnhtUGNzcnVnNzZjNUUrWG5ldVNNQ0lvb2ZaUGpUSEx3VUhZQkcyeFhNK2gx?= =?utf-8?B?UWJEYitIejJwRGJqOXJ2Z2Uz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8?B?K3dHOE9NUjE4WHBjdnZLTE1YYTl3c1VpVHNER2F2bUVzcUJzMGxKZXlhTVY1?= =?utf-8?B?QzZ6TlNTWjdmbEpXT1hVNFRxVDRqbzEzVHhPeTg0ajNZcFltYW1HZE9kL0xr?= =?utf-8?B?enUyc0dyK25JNDIva3A2WHhqM1lxZU53My9ONUtuam14LzN3d3JXMEZmYjIz?= =?utf-8?B?V2FNK3VGVmZGQ0ozTktLM2RUU25SWSsrSDNUb09VSmJTUktsbHBmSkJSSUsz?= =?utf-8?B?SlQ3d0lmZFNrSlFIOTh6a3NPUit1ZVJ3aldKdk5VaHJjL215RjBRcTE5ZS9y?= =?utf-8?B?bHVWVk9yUkdUUGRjTDJGcFlzM0l6WkdYVGxaS3JpVFBFSmRPd3V3QVg5Sk5Y?= =?utf-8?Q?wdBf36JL+wq4d9+8qxhytBYWC8sJok6S2ecz8=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)(82310400026)(36860700013)(1800799024)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2024 11:01:31.0204 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d6b633f8-c819-4238-3be3-08dcd63eebb6 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: AMS1EPF0000004E.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR07MB6978 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