From patchwork Thu Sep 12 08:44:25 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: 143998 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 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_R=C3=B6nnblom?= To: CC: , =?utf-8?q?Morten_Br=C3=B8rup?= , Stephen Hemminger , Konstantin Ananyev , David Marchand , Jerin Jacob , =?utf-8?q?Mattias_R=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 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?q?PWWjvU8RrlBkgiqHUj1DFR5ZeRd2a3l?= =?utf-8?q?5O7Dboefw0VJaDarIt/dJAok3P27+ZFFLIv8FzS9R7mHiv8Bw0yU55U0UfXtmYVhS?= =?utf-8?q?zp7rz922/a1VsCdfEEKW0b6lY2+aZciEFQRHk9VazVcrbDZGoZlRhkNltdmjDTq9U?= =?utf-8?q?0RzpTzs/KBIrtdHv2K/Q9Oq1pcLKH/GdE78pHux+WGJoVtd860jVCkHUrhaOvmL+L?= =?utf-8?q?xpErty7DwmTO1mfU/K/B9Wegx1qEp8E1YTw/Q1yWKOJM5P3wKNd+nEMhIwtktH9GC?= =?utf-8?q?8IBo+Jmhnu5Hb9rwXl1W84l8Y+586x3B0cBtroSqatZNO6qy4MYFBM+YljUqRtVdm?= =?utf-8?q?WJprbP9UHkJZeVtJfLOoDtN5IURIY3/R/EvMhyjClRko0EsHI/Mhn3a0Jm17Hp721?= =?utf-8?q?9m+Wzi35EqCntVka3GfD0zBa9+xKtUKKCEXnuW1AKZ55aiKb+zUVxsUuZn3vXeBN+?= =?utf-8?q?VI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KoezO9XoWDavyZbfnbjYc+6UGgjOkLZzKSn8VN1YR1KOEibfiifK31?= =?utf-8?q?UOTqjHV2W8U?= 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 Acked-by: Morten Brørup --- 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);