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 BC6034596C; Thu, 12 Sep 2024 10:54:25 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AA883427A9; Thu, 12 Sep 2024 10:54:25 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2082.outbound.protection.outlook.com [40.107.22.82]) by mails.dpdk.org (Postfix) with ESMTP id 98856427A6 for ; Thu, 12 Sep 2024 10:54:24 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xptz6IKmdxpdBpjjMwH8RIUlSRnpwTeu/CAueIdRvRKoLG0hkD+qdzW8Mw0Owlc8hJFgwwYZ8C21+9tqIiCVO3LxhFOQK3nfbknfr2hnj9qwrEJM7N8i9m8q2WyjDKZaAO2BbBdihNstcP9Oci0ubGiovNV8HXhsqA7bENJ9mGV1zAlLbTzPiRsmVlPKIvpjA37VWzSVmxaWTu8aWK1+0La+v0eukG/DY5mvkdgsnc+5VSSWOehd6RTQxcAOmkV2gW4s3ieEjUATBXIt8PUsUbhCba73TJ/l5ahH4F+7vqYFB9kgJwr1KDndvTPtpQpk8oX73DGS2ITlqOZjhkNm0g== 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=MxM7ysnjy+w1H2kDtPMldDz2pz3hqnUIkyx9cJbf8iQ=; b=FQFm37g5nTYJhO7CIrvD+9DZN44CkGCe1a3yUq/0UpN5UEs/nCMVZz7jxf15cNpBtWeLO2z4lAYVzzezX47vNirCNW1BqXiNogwwZWmTko57wW3/9jVHdU8uU4HstL3f6/bUKq2A/BN8ROCUSN07UuY94WSChgLrczntYmHh90M5b1FbSZeYXiXAVlodMGwVfooHb/mCn6O7mS5u5E1cmPQqqdtImCEGwce1g1HAfL9EnnIN9NTeK3XL16ebTXypSUhJRtKWwA5Z/6BUoPcbBZfrF3fJMXWaj+gA3yDbryERe90DsbANVbOjPMkr0h6FDOlqMrGYZQedVgrTNguguQ== 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=MxM7ysnjy+w1H2kDtPMldDz2pz3hqnUIkyx9cJbf8iQ=; b=QSdaAMAcZWwexe3IXOFkd9XBLJ7xX1ImviFAaKZZhZojfG8LDi+KqBetqBZIIbY2RaAwEjRsR78OnAB+tCXLSpQClta4YToVFwhr9bnP7PugLNowoRvAXoihcTS4m62VCuTN9s2s89UN0XKPXu8BxxaEjT5f9qf9JBj5nABgu0TwxHUk2RJwskhLG/gNmPuws7t5chZlIMa6iEYG+5RXJUp8n8O8U5pgm/Ck/3GYX7U/C9z7FKINgKUNaqVFdIhSAYELVvEKVmg83U0T2UBdUaYANLYgsw7r0AIMo/r3l/ioQIwHy0yUId+Sp0X942VJNyHmGOcDQXxBtIEjtlmL2Q== Received: from AS4P189CA0021.EURP189.PROD.OUTLOOK.COM (2603:10a6:20b:5db::12) by PA4PR07MB8413.eurprd07.prod.outlook.com (2603:10a6:102:2a1::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.17; Thu, 12 Sep 2024 08:54:22 +0000 Received: from AM3PEPF0000A797.eurprd04.prod.outlook.com (2603:10a6:20b:5db:cafe::cd) by AS4P189CA0021.outlook.office365.com (2603:10a6:20b:5db::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.25 via Frontend Transport; Thu, 12 Sep 2024 08:54:22 +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 AM3PEPF0000A797.mail.protection.outlook.com (10.167.16.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Thu, 12 Sep 2024 08:54:22 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.60) with Microsoft SMTP Server id 15.2.1544.11; Thu, 12 Sep 2024 10:53:51 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 8555A380061; Thu, 12 Sep 2024 10:53:51 +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 v3 3/7] eal: add lcore variable performance test Date: Thu, 12 Sep 2024 10:44:25 +0200 Message-ID: <20240912084429.703405-4-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240912084429.703405-1-mattias.ronnblom@ericsson.com> References: <20240911170430.701685-2-mattias.ronnblom@ericsson.com> <20240912084429.703405-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: AM3PEPF0000A797:EE_|PA4PR07MB8413:EE_ X-MS-Office365-Filtering-Correlation-Id: ed09301f-b271-43f1-592b-08dcd3087f43 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?B?UFdXanZVOFJybEJrZ2lxSFVqMURGUjVaZVJkMmEzbDVPN0Rib2VmdzBWSmFE?= =?utf-8?B?YXJJdC9kSkFvazNQMjcrWkZGTEl2OEZ6UzlSN21IaXY4QncweVU1NVUwVWZY?= =?utf-8?B?dG1ZVmhTenA3cno5MjIvYTFWc0NkZkVFS1cwYjZsWTIrYVpjaUVGUVJIazlW?= =?utf-8?B?YXpWY3JiRFpHb1psUmhrTmx0ZG1qRFRxOVUwUnpwVHpzL0tCSXJ0ZEh2Mksv?= =?utf-8?B?UTlPcTFwY0xLSC9HZEU3OHBIdXgrV0dKb1Z0ZDg2MGpWQ2tIVXJoYU92bUwr?= =?utf-8?B?THhwRXJ0eTdEd21UTzFtZlUvSy9COVdlZ3gxcUVwOEUxWVR3L1ExeVdLT0pN?= =?utf-8?B?NVAzd0tOZCtuRU1oSXd0a3RIOUdDOElCbytKbWhudTVIYjlyd1hsMVc4NGw4?= =?utf-8?B?WSs1ODZ4M0IwY0J0cm9TcWF0Wk5PNnF5NE1ZRkJNK1lsalVxUnRWZG1XSnBy?= =?utf-8?B?YlA5VUhrSlplVnRKZkxPb0R0TjVJVVJJWTMvUi9Fdk1oeWpDbFJrbzBFc0hJ?= =?utf-8?B?L01objNhMEptMTdIcDcyMTltK1d6aTM1RXFDbnRWa2EzR2ZEM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0NnBkd09GckdMRmFQeUpFbEVHc05tYVRZWk16YWxP?= =?utf-8?B?RFNZSzhSei9wajg4c29VTUtHNzE4OU9zaU9rZFhzRmkrSkk2TUVLdERxc0RF?= =?utf-8?B?dmpRU2NBTCt6M2JjblBFYitMWTZYcUVWM2NFTXJlaFc1eDkvdW95bDNWaGI1?= =?utf-8?B?cTBvR3FCMkpOUDF5aWN3VHlzd2dMcTRsSzFCNUdWTXpIbExXbGhvTEQ1NGt6?= =?utf-8?B?cmp0ekNuNnUzSXJsMllvVHFEUnR6cXdJS3lVSEFNNDFFcklNbkZOYXM4bWdE?= =?utf-8?B?YWhwTVY5SCtpdHY5aWRiMUtydlhoeThqckNGdnNGa3c1d3doZ0xKbUxsQ0Fv?= =?utf-8?B?TWt1QjdZcW55bEgrQ0M3MHNiYk5NSFN5RWVuWjIyYnJvRzNSSzhPaHZLb0JZ?= =?utf-8?B?ZjhhdlVSUkZjZHpRS29lek85WG9XRGF2eVpiZm5ialljKzZVR2dqT2tMWnpL?= =?utf-8?Q?Sn8VN1YR1KOEibfiifK31UOTqjHV2W8U?= 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)(376014)(1800799024)(36860700013)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2024 08:54:22.7618 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ed09301f-b271-43f1-592b-08dcd3087f43 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: AM3PEPF0000A797.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR07MB8413 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 Add basic micro benchmark for lcore variables, in an attempt to assure that the overhead isn't significantly greater than alternative approaches, in scenarios where the benefits aren't expected to show up (i.e., when plenty of cache is available compared to the working set size of the per-lcore data). Signed-off-by: Mattias Rönnblom --- app/test/meson.build | 1 + app/test/test_lcore_var_perf.c | 160 +++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 app/test/test_lcore_var_perf.c diff --git a/app/test/meson.build b/app/test/meson.build index 48279522f0..d4e0c59900 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -104,6 +104,7 @@ source_file_deps = { 'test_kvargs.c': ['kvargs'], 'test_latencystats.c': ['ethdev', 'latencystats', 'metrics'] + sample_packet_forward_deps, 'test_lcore_var.c': [], + 'test_lcore_var_perf.c': [], 'test_lcores.c': [], 'test_link_bonding.c': ['ethdev', 'net_bond', 'net'] + packet_burst_generator_deps + virtual_pmd_deps, diff --git a/app/test/test_lcore_var_perf.c b/app/test/test_lcore_var_perf.c new file mode 100644 index 0000000000..ea1d7ba90b --- /dev/null +++ b/app/test/test_lcore_var_perf.c @@ -0,0 +1,160 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 Ericsson AB + */ + +#include + +#include +#include +#include +#include + +#include "test.h" + +struct lcore_state { + uint64_t a; + uint64_t b; + uint64_t sum; +}; + +static void +init(struct lcore_state *state) +{ + state->a = rte_rand(); + state->b = rte_rand(); + state->sum = 0; +} + +static __rte_always_inline void +update(struct lcore_state *state) +{ + state->sum += state->a * state->b; +} + +static RTE_DEFINE_PER_LCORE(struct lcore_state, tls_lcore_state); + +static void +tls_init(void) +{ + init(&RTE_PER_LCORE(tls_lcore_state)); +} + +static __rte_noinline void +tls_update(void) +{ + update(&RTE_PER_LCORE(tls_lcore_state)); +} + +struct __rte_cache_aligned lcore_state_aligned { + uint64_t a; + uint64_t b; + uint64_t sum; +}; + +static struct lcore_state_aligned sarray_lcore_state[RTE_MAX_LCORE]; + +static void +sarray_init(void) +{ + struct lcore_state *state = + (struct lcore_state *)&sarray_lcore_state[rte_lcore_id()]; + + init(state); +} + +static __rte_noinline void +sarray_update(void) +{ + struct lcore_state *state = + (struct lcore_state *)&sarray_lcore_state[rte_lcore_id()]; + + update(state); +} + +RTE_LCORE_VAR_HANDLE(struct lcore_state, lvar_lcore_state); + +static void +lvar_init(void) +{ + RTE_LCORE_VAR_ALLOC(lvar_lcore_state); + + struct lcore_state *state = RTE_LCORE_VAR_VALUE(lvar_lcore_state); + + init(state); +} + +static __rte_noinline void +lvar_update(void) +{ + struct lcore_state *state = RTE_LCORE_VAR_VALUE(lvar_lcore_state); + + update(state); +} + +#define ITERATIONS UINT64_C(10000000) + +static double +benchmark_access_method(void (*init_fun)(void), void (*update_fun)(void)) +{ + uint64_t i; + uint64_t start; + uint64_t end; + double latency; + + init_fun(); + + start = rte_get_timer_cycles(); + + for (i = 0; i < ITERATIONS; i++) + update_fun(); + + end = rte_get_timer_cycles(); + + latency = ((end - start) / (double)rte_get_timer_hz()) / ITERATIONS; + + return latency; +} + +static int +test_lcore_var_access(void) +{ + /* Note: the potential performance benefit of lcore variables + * compared thread-local storage or the use of statically + * sized, lcore id-indexed arrays are not shorter latencies in + * a scenario with low cache pressure, but rather fewer cache + * misses in a real-world scenario, with extensive cache + * usage. These tests just tries to assure that the lcore + * variable overhead is not significantly greater other + * alternatives, when the per-lcore data is in L1. + */ + double tls_latency; + double sarray_latency; + double lvar_latency; + + tls_latency = benchmark_access_method(tls_init, tls_update); + sarray_latency = benchmark_access_method(sarray_init, sarray_update); + lvar_latency = benchmark_access_method(lvar_init, lvar_update); + + printf("Latencies [ns/update]\n"); + printf("Thread-local storage Static array Lcore variables\n"); + printf("%20.1f %13.1f %16.1f\n", tls_latency * 1e9, + sarray_latency * 1e9, lvar_latency * 1e9); + + return TEST_SUCCESS; +} + +static struct unit_test_suite lcore_var_testsuite = { + .suite_name = "lcore variable perf autotest", + .unit_test_cases = { + TEST_CASE(test_lcore_var_access), + TEST_CASES_END() + }, +}; + +static int +test_lcore_var_perf(void) +{ + return unit_test_suite_runner(&lcore_var_testsuite); +} + +REGISTER_PERF_TEST(lcore_var_perf_autotest, test_lcore_var_perf); -- 2.34.1