From patchwork Mon Feb 19 09:40:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Mattias_R=C3=B6nnblom?= X-Patchwork-Id: 136873 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E0F8D43B4B; Mon, 19 Feb 2024 10:48:42 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 45BB6406BA; Mon, 19 Feb 2024 10:48:38 +0100 (CET) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2081.outbound.protection.outlook.com [40.107.6.81]) by mails.dpdk.org (Postfix) with ESMTP id A05A240608 for ; Mon, 19 Feb 2024 10:48:36 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kny53+a/O+abDWy+zTwEKwXDoau5hGWgiqStukYInJ/0hIMsp9Cjm5Kl4Sor1g5MiYijLU4H11ctjy6DzyV3JXn/JFyTRIS6tjcCWQ18LjcV8o6Rd8aKZQfQL91QW/xldTuMb2CZqqnFtoUwqqu7wIaI81kYI81Bis9we2SD37R+ew090DvBd99TZw1uoyTfwe+OJbpmPQk/7IYR9lrPlw5jZy0/nJvv4dvAZbyl3ZV2vNL5w1AY98Odj+XDXbvDuEyeby6zSYXusSdH3GF53Oy3kK3gJQ56NNfBBdAEHAfoxaP1WXgM9kcBzjjlmfkUtuE6dKwYHcClJGAMA9pDiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=0CKWr1/GFeKeMFOcxFssC7hi55ZMoZfDCfll81xNT3k=; b=CF+zPz/6bdjLPHD+Iqza+whY+3SxTQTzmy5sa8BpmR9GTJbvv2qu7zBiqdZhliYd7Lk/TUO6xinlymYsbiVjuqFNpKYZml4e86PLQ4ytfkRreTxLRKsQnwcZ/MjUM83y+++SDa6Pz+kecT8ipnaYbGbmdCWXhbCL/JVqb7MqavPPNRhLd7qvwrtOjiEPp61Zr5eWg+DP2qdj3Y3xn6jOf7lgXttiGvhdWppotNOuGwrnAt1gdbki8GiQEXFJaAIDJTUcuxqNo1NOGmEKzNjmyjt+rnS/2IJuSgz3rDd+v9j0pEckZB1eRB6uYHYVQ9pfFT3RNZ42AovHa51B9EuulQ== 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=0CKWr1/GFeKeMFOcxFssC7hi55ZMoZfDCfll81xNT3k=; b=rEVRbyEhB1/L6uEWXE4lsHklC/qw5st8S+ZatPVsBzIIVDLOkLsKnlfYAvMhUhTS5AXVtSOtEuo36P1sevq9r2gPxufE1Ie8zbqv5+65XbgUbrFIlQcKFtxq2nvCcxXnGXvwHYRJ3AsbeS0/lcBDIP7zMz5aHazLS+dM2HxcMk9nTPryZtJE/U8vmQwaSWROAb3eOmdDVRTUQnePw/dUfcDhbGgT31HlGyFBpL2AneUD0clrQsRNm6tp6FY99voN7adpcYaI4G0vEfrAVXla4IEb9PcE+Ez6r6zqT4EcgzlU+730DpJuILucM341ueNZTZUT7lQLdlyR69jvtqKQEw== Received: from DUZPR01CA0040.eurprd01.prod.exchangelabs.com (2603:10a6:10:468::18) by AS8PR07MB7941.eurprd07.prod.outlook.com (2603:10a6:20b:38f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.38; Mon, 19 Feb 2024 09:48:34 +0000 Received: from DU6PEPF0000B620.eurprd02.prod.outlook.com (2603:10a6:10:468:cafe::e) by DUZPR01CA0040.outlook.office365.com (2603:10a6:10:468::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.38 via Frontend Transport; Mon, 19 Feb 2024 09:48:34 +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 DU6PEPF0000B620.mail.protection.outlook.com (10.167.8.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Mon, 19 Feb 2024 09:48:34 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.66) with Microsoft SMTP Server id 15.2.1258.12; Mon, 19 Feb 2024 10:48:33 +0100 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 730C91C006A; Mon, 19 Feb 2024 10:48:33 +0100 (CET) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , =?utf-8?q?Morten_Br=C3=B8rup?= , Stephen Hemminger , =?utf-8?q?Mattias_R=C3=B6nn?= =?utf-8?q?blom?= Subject: [RFC v2 3/5] random: keep PRNG state in lcore variable Date: Mon, 19 Feb 2024 10:40:34 +0100 Message-ID: <20240219094036.485727-4-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240219094036.485727-1-mattias.ronnblom@ericsson.com> References: <20240208181644.455233-2-mattias.ronnblom@ericsson.com> <20240219094036.485727-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU6PEPF0000B620:EE_|AS8PR07MB7941:EE_ X-MS-Office365-Filtering-Correlation-Id: ce028218-9a45-4b81-b9c7-08dc312ff02a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UNyZKRgjuiFR4K0LyeaULeI2JOtOMWjMkibKgB/9buGiwogP1KvDzETBUEyDSO0tcCFdQu/SscnAXtE6Brt4jhpAT6wbYfX34slfTdTWLJxCvVlaG7C26jigNgC1fiODoiK3Ondf7/XxW0yMQc1KwcFv12NOnC3RB/TsvZ3hB7l4CmffRP9Iqq8dvYVQ1psWZmzIHsEBmcPWstQL6bJJNADvdykJVu9LT18mLoBVGlYH9Q5u0cxy5RWagekpWKU1pss/y5Pozbs3/rhZmhzqu8ub7bI2mEtAvtoiqZn/AgijDa1yDz8t8gZjigQaXmKvA6K6TWcNoUIVlc9xa4jN2icNetfNGDFI9OtJurCkl8E67MH+j6zKJ9KimbR8fCRB5dy5pGd5/cpPCriMgTKs15BXy0FJOGDw1/Psssf+fzpvfWDxElCyBpl77D0VUUSm2kX3lhwP5VVl2t8SPj/kZQm/tNZZrgUPpkZiw1fCFn/NtocTE5VTQHr58HcMhd2lDDLzSxu1UT6NWUX62iCIlXByQRr+59K+pqxfMagoAQZrhMgIewt0KkOYSl21BK1/XM589SzjZyCRYoSmociaNsuTWJPRZaEmaU/jgONWug0jH+5WmDZwmFV1lBulL6fDT4w23aDtkcW68SopJQ5kTelAzU7LXC37jHZweTX34Sc= 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:(13230031)(4636009)(39860400002)(346002)(396003)(136003)(376002)(230922051799003)(82310400011)(186009)(451199024)(64100799003)(1800799012)(36860700004)(46966006)(40470700004)(83380400001)(82960400001)(356005)(86362001)(7636003)(82740400003)(478600001)(6916009)(54906003)(70206006)(70586007)(26005)(1076003)(2616005)(107886003)(316002)(336012)(6266002)(36756003)(4326008)(8676002)(8936002)(2906002)(5660300002)(41300700001); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2024 09:48:34.1386 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ce028218-9a45-4b81-b9c7-08dc312ff02a 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: DU6PEPF0000B620.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR07MB7941 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 --- lib/eal/common/rte_random.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/eal/common/rte_random.c b/lib/eal/common/rte_random.c index 7709b8f2c6..af9fffd81b 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_rand_state { @@ -19,14 +20,12 @@ struct rte_rand_state { uint64_t z3; uint64_t z4; uint64_t z5; - RTE_CACHE_GUARD; -} __rte_cache_aligned; +}; -/* 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 __rte_cache_aligned; 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_PTR(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_PTR(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);