From patchwork Wed Mar 18 19:02:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerin Jacob Kollanukkaran X-Patchwork-Id: 66877 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id EF9A3A0579; Wed, 18 Mar 2020 20:07:13 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A8B711C1B8; Wed, 18 Mar 2020 20:03:47 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id 1AF361C1B7 for ; Wed, 18 Mar 2020 20:03:45 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 02IJ1UmP011083; Wed, 18 Mar 2020 12:03:45 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0818; bh=gwx/k+JaepHBVzWjWceNmRkymdoeu4Y+8LmjLQTpQt8=; b=cN35Od6aW97kZfps7XqxZAyBZvqeXw7FLX3lVyzmy3mhsJ2TQJuScsgEFE3gTbf2ap1c GLWoZwmc9JsXOMdpqOFgUntWBnpqtKEFMFRsWKDbPpItykdqXoWW9KEYpYPwxL/GGIby iJ0EFSXgZYUZDQo1z4LmGXuqH526ihGVAi3O7U4I5NMQkGj2Yn84oo2Fy4bMZWtXJkMc VWYTzeb+A00xmqmNKryzqlPveacJlJ/sAyWJiM+5hFm7tpVQNUZipVLe9EI2Nz1B6LnI PCfJMD0GWJYIlph8v5UtICLVgsO9I9BifkjqsS2dg9VvIu/5pThXyqP5py7yX6PfgQCI /w== Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0a-0016f401.pphosted.com with ESMTP id 2yu8pqm4ga-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 18 Mar 2020 12:03:45 -0700 Received: from SC-EXCH03.marvell.com (10.93.176.83) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 18 Mar 2020 12:03:43 -0700 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 18 Mar 2020 12:03:43 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id D01E13F703F; Wed, 18 Mar 2020 12:03:41 -0700 (PDT) From: To: CC: , , , , , , Jerin Jacob Date: Thu, 19 Mar 2020 00:32:36 +0530 Message-ID: <20200318190241.3150971-28-jerinj@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200318190241.3150971-1-jerinj@marvell.com> References: <20200318190241.3150971-1-jerinj@marvell.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.645 definitions=2020-03-18_07:2020-03-18, 2020-03-18 signatures=0 Subject: [dpdk-dev] [PATCH v1 27/32] eal/trace: add trace performance test cases X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Jerin Jacob This test case shall be used to measure the trace overhead. Example command to run the performance test case. echo "trace_perf" | ./build/app/test/dpdk-test -c 0x3 --trace-level=8 Signed-off-by: Jerin Jacob --- app/test/Makefile | 1 + app/test/meson.build | 1 + app/test/test_trace_perf.c | 179 +++++++++++++++++++++++++++++++++++++ 3 files changed, 181 insertions(+) create mode 100644 app/test/test_trace_perf.c diff --git a/app/test/Makefile b/app/test/Makefile index 8374c5399..1bd00ca9e 100644 --- a/app/test/Makefile +++ b/app/test/Makefile @@ -150,6 +150,7 @@ SRCS-y += test_version.c SRCS-y += test_func_reentrancy.c SRCS-y += test_trace.c SRCS-y += test_trace_register.c +SRCS-y += test_trace_perf.c SRCS-y += test_service_cores.c ifeq ($(CONFIG_RTE_LIBRTE_PMD_RING),y) diff --git a/app/test/meson.build b/app/test/meson.build index 68c1b56df..fef37d7e2 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -123,6 +123,7 @@ test_sources = files('commands.c', 'test_ticketlock.c', 'test_trace.c', 'test_trace_register.c', + 'test_trace_perf.c', 'test_version.c', 'virtual_pmd.c' ) diff --git a/app/test/test_trace_perf.c b/app/test/test_trace_perf.c new file mode 100644 index 000000000..d0f291771 --- /dev/null +++ b/app/test/test_trace_perf.c @@ -0,0 +1,179 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2020 Marvell International Ltd. + */ + +#include +#include +#include +#include +#include +#include + +#include "test.h" + +struct test_data; + +struct lcore_data { + volatile bool done; + volatile bool started; + uint64_t total_cycles; + uint64_t total_calls; +} __rte_cache_aligned; + +struct test_data { + unsigned int nb_workers; + struct lcore_data ldata[]; +} __rte_cache_aligned; + +#define STEP 100 +#define CENT_OPS(OP) do { \ +OP; OP; OP; OP; OP; OP; OP; OP; OP; OP;\ +OP; OP; OP; OP; OP; OP; OP; OP; OP; OP;\ +OP; OP; OP; OP; OP; OP; OP; OP; OP; OP;\ +OP; OP; OP; OP; OP; OP; OP; OP; OP; OP;\ +OP; OP; OP; OP; OP; OP; OP; OP; OP; OP;\ +OP; OP; OP; OP; OP; OP; OP; OP; OP; OP;\ +OP; OP; OP; OP; OP; OP; OP; OP; OP; OP;\ +OP; OP; OP; OP; OP; OP; OP; OP; OP; OP;\ +OP; OP; OP; OP; OP; OP; OP; OP; OP; OP;\ +OP; OP; OP; OP; OP; OP; OP; OP; OP; OP;\ +} while (0) + +static void +measure_perf(const char *str, struct test_data *data) +{ + uint64_t hz = rte_get_timer_hz(); + uint64_t total_cycles = 0; + uint64_t total_calls = 0; + double cycles, ns; + unsigned int workers; + + for (workers = 0; workers < data->nb_workers; workers++) { + total_cycles += data->ldata[workers].total_cycles; + total_calls += data->ldata[workers].total_calls; + } + + cycles = total_calls ? (double)total_cycles / (double)total_calls : 0; + cycles /= STEP; + cycles /= 100; /* CENT_OPS */ + + ns = (cycles / (double)hz) * 1E9; + printf("%16s: cycles=%f ns=%f\n", str, cycles, ns); +} + +static void +wait_till_workers_are_ready(struct test_data *data) +{ + unsigned int workers; + + for (workers = 0; workers < data->nb_workers; workers++) + while (!data->ldata[workers].started) + rte_pause(); +} + +static void +signal_workers_to_finish(struct test_data *data) +{ + unsigned int workers; + + for (workers = 0; workers < data->nb_workers; workers++) { + data->ldata[workers].done = 1; + rte_smp_wmb(); + } +} + +#define WORKER_DEFINE(func)\ +static void __rte_noinline \ +__worker_##func(struct lcore_data *ldata)\ +{\ + uint64_t start;\ + int i;\ + while (!ldata->done) {\ + start = rte_get_timer_cycles();\ + for (i = 0; i < STEP; i++)\ + CENT_OPS(func);\ + ldata->total_cycles += rte_get_timer_cycles() - start;\ + ldata->total_calls++;\ + } \ +} \ +static int \ +worker_fn_##func(void *arg)\ +{\ + struct lcore_data *ldata = arg;\ + ldata->started = 1;\ + rte_smp_wmb();\ + __worker_##func(ldata);\ + return 0;\ +} + + +/* Test to find trace overhead */ +#define GENERIC_VOID rte_trace_lib_eal_generic_void() +#define GENERIC_U64 rte_trace_lib_eal_generic_u64(0x120000) +#define GENERIC_INT rte_trace_lib_eal_generic_int(-34) +#define GENERIC_FLOAT rte_trace_lib_eal_generic_float(3.3f) +#define GENERIC_DOUBLE rte_trace_lib_eal_generic_double(3.66666) +#define GENERIC_STR rte_trace_lib_eal_generic_str("hello world") + +WORKER_DEFINE(GENERIC_VOID) +WORKER_DEFINE(GENERIC_U64) +WORKER_DEFINE(GENERIC_INT) +WORKER_DEFINE(GENERIC_FLOAT) +WORKER_DEFINE(GENERIC_DOUBLE) +WORKER_DEFINE(GENERIC_STR) + +static void +run_test(const char *str, lcore_function_t f, struct test_data *data, size_t sz) +{ + unsigned int id, worker = 0; + + memset(data, 0, sz); + data->nb_workers = rte_lcore_count() - 1; + RTE_LCORE_FOREACH_SLAVE(id) + rte_eal_remote_launch(f, &data->ldata[worker++], id); + + wait_till_workers_are_ready(data); + rte_delay_ms(100); /* Wait for some time to accumulate the stats */ + measure_perf(str, data); + signal_workers_to_finish(data); + + RTE_LCORE_FOREACH_SLAVE(id) + rte_eal_wait_lcore(id); +} + +static int +test_trace_perf(void) +{ + unsigned int nb_cores, nb_workers; + struct test_data *data; + size_t sz; + + nb_cores = rte_lcore_count(); + nb_workers = nb_cores - 1; + if (nb_cores < 2) { + printf("Need minimum two cores for testing\n"); + return TEST_SKIPPED; + } + + printf("Timer running at %5.2fMHz\n", rte_get_timer_hz()/1E6); + sz = sizeof(struct test_data); + sz += nb_workers * sizeof(struct lcore_data); + + data = rte_zmalloc(NULL, sz, RTE_CACHE_LINE_SIZE); + if (data == NULL) { + printf("Failed to allocate memory\n"); + return TEST_FAILED; + } + + run_test("void", worker_fn_GENERIC_VOID, data, sz); + run_test("u64", worker_fn_GENERIC_U64, data, sz); + run_test("int", worker_fn_GENERIC_INT, data, sz); + run_test("float", worker_fn_GENERIC_FLOAT, data, sz); + run_test("double", worker_fn_GENERIC_DOUBLE, data, sz); + run_test("string", worker_fn_GENERIC_STR, data, sz); + + rte_free(data); + return TEST_SUCCESS; +} + +REGISTER_TEST_COMMAND(trace_perf, test_trace_perf);