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 2838245BAE; Wed, 23 Oct 2024 10:02:57 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9991440ED3; Wed, 23 Oct 2024 10:02:22 +0200 (CEST) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2076.outbound.protection.outlook.com [40.107.21.76]) by mails.dpdk.org (Postfix) with ESMTP id A227E40E5A for ; Wed, 23 Oct 2024 10:02:10 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GxY1NKSMHxEKzbigqhxN4PWYn35awMaLACNzNkPNSdi2LDVtCM4WPU/oHmfcTXC1vMcivw4rZeqMe/eQ7NXqaaUct1Avpja16Y0TttGDdyFpV4nZFiIJLGryTqHP/ZbZkuBTUExmxfrWLDIpLP7A1LXj3miyfMERevwEazCgz8uPvfkNSCyL9TgjJHvDGjOl6pJOdiGA95IeMqoqBo8hbhLNufVicbik7JRoRkibgm+f6wulrXuv9DawD70fzhtBbKIwUjGHMTPo1bQ1s/I/8fuff9EtYxELe/Q+LJXtFMdkqHouuKbJbBIXBXKzHqphs5MWrJOcMbk/E0MOvz4M5w== 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=si1w3ocHJKxNuMLZgFmQDxIUvD6Ve0pMeHG4Z+pjvz/MZoZb8Mb6nAcJonrmafYUS8LvUSRlEtmMmi4mmQgUQOgyReZ7L6+GULHUkVJTeKdrCBEVhXkWrMHI6jp65omr77ocl4PrHsQqskYece8+6Uhy9ggeW8xl9Rqsxc0wgOPhQ8XoA+pUWCR0EbfyQUK0mScE3FmWBEphtnQkxjgLkQPa3BTfegLULOU0P/zL2NENzizENPjrJ0A32m+nFEdN3dLP5S0aaBKlLzX9IbTuo+Lw1RKLMnUes2VG5vxAObmvDO2horeQiUGGEhtnry970MQvawcpRWXEloxvrEHahg== 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=gYijSvEyyA+ywWt9wg4/TUG4mAvVKkBJAEo69hyrCB1LY7/MZtFeycM0n13g2AxCvDByEpHEuGaO/GK0bV0YH1juPoF9yormrwHv6f8X5qSa+w7NNmGh9J0wtVqbOhoCyA4n7EKMm3Q7i/WKMjKhvYGnoTyzdK4FlMGC8RHdZQv42k0j/YhbEsvo8bcItL3mCxBbngetq6/zyUMsr05QXkJgXfjokTdEvEd6RXAk4R5mKyYzHCDWgkQzfK93G8n5270ZX+3JId600GXOOAqlV8h9Pe1l+VP2rG1p4teHg1m8f4OikJTXOmtTsi82sMvVLP4UuUMuEstwJqkCE/1kcw== Received: from AS9PR06CA0356.eurprd06.prod.outlook.com (2603:10a6:20b:466::23) by AS4PR07MB8608.eurprd07.prod.outlook.com (2603:10a6:20b:4ff::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Wed, 23 Oct 2024 08:02:07 +0000 Received: from AMS0EPF000001B7.eurprd05.prod.outlook.com (2603:10a6:20b:466:cafe::6c) by AS9PR06CA0356.outlook.office365.com (2603:10a6:20b:466::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.29 via Frontend Transport; Wed, 23 Oct 2024 08:02: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 AMS0EPF000001B7.mail.protection.outlook.com (10.167.16.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.14 via Frontend Transport; Wed, 23 Oct 2024 08:02:07 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.67) with Microsoft SMTP Server id 15.2.1544.11; Wed, 23 Oct 2024 10:02:03 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 4BCD93800BC; Wed, 23 Oct 2024 10:02:03 +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 , Thomas Monjalon , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= , Konstantin Ananyev , Chengwen Feng Subject: [PATCH v16 5/8] random: keep PRNG state in lcore variable Date: Wed, 23 Oct 2024 09:52:59 +0200 Message-ID: <20241023075302.869008-6-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241023075302.869008-1-mattias.ronnblom@ericsson.com> References: <20241017055743.848292-1-mattias.ronnblom@ericsson.com> <20241023075302.869008-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: AMS0EPF000001B7:EE_|AS4PR07MB8608:EE_ X-MS-Office365-Filtering-Correlation-Id: 840e77b1-b7a9-4446-185f-08dcf338fd55 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|7416014|36860700013|1800799024|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?B?eUVDWEVkWVlqN1d2SjBlQ2RqVml0NWFNNWpobWtFKzRLTTg0UEFDT3dtcGZO?= =?utf-8?B?dDBZQm45QUFlNGNjbkV0QnZsTkRISzIveTBJMGpIVXl0N29DL0ZDQmhCaWZC?= =?utf-8?B?VExSSjFBUitESjdDQmFwMWQxL21lQit5VTJQR2pVWXVNOW12TlZNeklRai8v?= =?utf-8?B?N2xkUVJNM1dvM0R4YUNqU1BpQVB2VUEwSzlaN2ZOMSt3elhLc0prZmtzaXho?= =?utf-8?B?TCszalUybnZHaUJjbFZYQVRmMHZiM01Yb1hPMENMMWI1dXJ0ZDI1N3hTNjFF?= =?utf-8?B?bFVxOXl4MUxvVTdXU2pkR2dkYVNsd0IvNVR3elloRXJjT0U0clRIWXFhZTVp?= =?utf-8?B?WWpFRElSTWRtaUMwZjB5dnlYckZZQzJBa0ZBNWdkRlRDKzdMSE5QTU1ubzRR?= =?utf-8?B?Q0M5bDRSTmI0c2JTUkV0MkxMMFE3RmNKdFV4Mkk1YllJS2xwbnZCdWxnemNB?= =?utf-8?B?aWdubDJGVGFuZW81QkJGdmJ6R2hyLzZrWU1GVlNPVFBZVGRWQXI3YmdlQTFS?= =?utf-8?B?MmZORzFuOVlNMGNDazV4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HJwc25pZ25QY0tyTzZhV0g1bGdOdDVidkZHa2tra0lXYmxacnZydGVC?= =?utf-8?B?YmVkbDc3LzVSaE5TWkMwZmd0VC9NNElGblV1YW9sWWo0ckFVQUlib3lxRkd0?= =?utf-8?B?ejl5WjFWdDNvV2tKQzFyd3JqU2NyTVdQai9OdHcvN2tYV21BZkMvMUZyckxu?= =?utf-8?B?T0xBMlhPL1loZ3FyMHYwL2FMam04UjZaMWxZZ29ORUVnZXd5OUtORHo1blZI?= =?utf-8?B?N3dhZUFhQU10ckw2ZlpxL2UzNXBoRDhxQWVuMFErNmhvVlUzazFwc1FIQm9w?= =?utf-8?B?dzRQU21Oei8weFlVNEI2K1RSZnBXQlFBRDQ1ZklZWjIxS2JEWW0rMzRpVVdH?= =?utf-8?B?L3hHM280dnc1OWVPNURBOXRaWC80aWlmNzhnem5ZWnN4enVtSVN2bHRKbTg3?= =?utf-8?B?a2JTNXVWR1ZlNEpkcXBYZXF1OHpIY3VtYkhNOVZzMXQwT2c9PQ==?= 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)(7416014)(36860700013)(1800799024)(376014)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2024 08:02:07.3229 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 840e77b1-b7a9-4446-185f-08dcf338fd55 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: AMS0EPF000001B7.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4PR07MB8608 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