From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C2568A00C2; Wed, 22 Apr 2020 21:08:40 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 05F3E1D6CC; Wed, 22 Apr 2020 21:05:53 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id 180A11D655 for ; Wed, 22 Apr 2020 21:05:36 +0200 (CEST) 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 03MJ5apY020038; Wed, 22 Apr 2020 12:05:36 -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=3LIebgj9HOOiNycJYLOotA0+B3n8FGYIk4qeZ5FWAYQ=; b=pfA/qvI+FdXBKvZWWpKj6Nh3b+AUwnSUo+sfQRk3S5cfK/ZsQ/nyLBnRDVS0Ljp77EeH 5gQeDTar5naUY/V5HlxL5bJdo5ez8q5hhxh8gzGQyzm/UOC+Z0/S9mc17Y5WmL+Bvpll RbhK1fLcAZbTmyDA00VDCLpT8L77zzw3v7vRfQhfy/shIRaTtWUY4O9oKFzJvKWXY9xv SiucJpKeI2LII6H5RtyOChYj/sBPsy7/2ixY7PyTENI6OEJgTsTlv7dTtnMXkNWfrTRN S7+I3d81b0Iti2TLO9MOlnrxY8y7ev4rL9i4FdJ6eCEWkp0flvDY6f04zE+wdtncuZUK MQ== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0a-0016f401.pphosted.com with ESMTP id 30fxwpk040-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 22 Apr 2020 12:05:36 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 22 Apr 2020 12:05:34 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 22 Apr 2020 12:05:34 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id 6459D3F703F; Wed, 22 Apr 2020 12:05:32 -0700 (PDT) From: To: CC: , , , , , , Jerin Jacob Date: Thu, 23 Apr 2020 00:33:44 +0530 Message-ID: <20200422190349.3768487-28-jerinj@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200422190349.3768487-1-jerinj@marvell.com> References: <20200419100133.3232316-1-jerinj@marvell.com> <20200422190349.3768487-1-jerinj@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.676 definitions=2020-04-22_06:2020-04-22, 2020-04-22 signatures=0 Subject: [dpdk-dev] [PATCH v7 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_autotest" | ./build/app/test/dpdk-test -c 0x3 --trace=.* Signed-off-by: Jerin Jacob --- app/test/Makefile | 1 + app/test/meson.build | 2 + app/test/test_trace_perf.c | 183 +++++++++++++++++++++++++++++++++++++ 3 files changed, 186 insertions(+) create mode 100644 app/test/test_trace_perf.c diff --git a/app/test/Makefile b/app/test/Makefile index 0b5807d7e..4582eca6c 100644 --- a/app/test/Makefile +++ b/app/test/Makefile @@ -155,6 +155,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 a0b2c1fa8..a9a8eabcd 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -129,6 +129,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' ) @@ -283,6 +284,7 @@ perf_test_names = [ 'rand_perf_autotest', 'hash_readwrite_perf_autotest', 'hash_readwrite_lf_perf_autotest', + 'trace_perf_autotest', ] driver_test_names = [ diff --git a/app/test/test_trace_perf.c b/app/test/test_trace_perf.c new file mode 100644 index 000000000..df1c8eb76 --- /dev/null +++ b/app/test/test_trace_perf.c @@ -0,0 +1,183 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2020 Marvell International Ltd. + */ + +#include +#include +#include +#include +#include +#include + +#include "test.h" +#include "test_trace.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_eal_trace_generic_void() +#define GENERIC_U64 rte_eal_trace_generic_u64(0x120000) +#define GENERIC_INT rte_eal_trace_generic_int(-34) +#define GENERIC_FLOAT rte_eal_trace_generic_float(3.3f) +#define GENERIC_DOUBLE rte_eal_trace_generic_double(3.66666) +#define GENERIC_STR rte_eal_trace_generic_str("hello world") +#define VOID_FP app_dpdk_test_fp() + +WORKER_DEFINE(GENERIC_VOID) +WORKER_DEFINE(GENERIC_U64) +WORKER_DEFINE(GENERIC_INT) +WORKER_DEFINE(GENERIC_FLOAT) +WORKER_DEFINE(GENERIC_DOUBLE) +WORKER_DEFINE(GENERIC_STR) +WORKER_DEFINE(VOID_FP) + +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); + run_test("void_fp", worker_fn_VOID_FP, data, sz); + + rte_free(data); + return TEST_SUCCESS; +} + +REGISTER_TEST_COMMAND(trace_perf_autotest, test_trace_perf); -- 2.25.1