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 5F8F2A0561; Sun, 19 Apr 2020 12:10:50 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D67011D69A; Sun, 19 Apr 2020 12:03:55 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id 5ACE21D63F for ; Sun, 19 Apr 2020 12:03:25 +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 03J9vQl5031337; Sun, 19 Apr 2020 03:03:22 -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=GilAl6dTMGT1dOShqh/q2qPpEUtvFYgJOBdqMz57UVo=; b=uOVZPsWP1OH6fp3NwI5RAmOi1+Vx8usAd3/XnwwIhjb1DU6bMI34CDO0ehTGI7H3RMNp xjrXwSkiAS4uuRfhZ+5lB8Le7ElyrKNtQ24eAXcDDbwXqr2mz3S5FCe2NvlVfW97/4jR 0G5dqxSHu8jVI3nSaXzIL0qGQjuCUHMlQQzedQDY2RZUXFgAJ+3gXHfefiBFHtJ43/Tt 4gbeHhQCeYBuVuQwrHg6ri90+ep21OLF3HniY4gBo0LNUE0bCNojZvOLiGYtY2lNGrWN FV/NX2wHSy1djIdd8SeBH6F5bOsYy3SffFa2zyOroAePtQCUamqwIfYqAAbgyEdFXU92 qQ== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0a-0016f401.pphosted.com with ESMTP id 30fxwp3d8a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 19 Apr 2020 03:03:22 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 19 Apr 2020 03:03:21 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 19 Apr 2020 03:03:20 -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; Sun, 19 Apr 2020 03:03:20 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id 1105E3F703F; Sun, 19 Apr 2020 03:03:17 -0700 (PDT) From: To: CC: , , , , , , Jerin Jacob Date: Sun, 19 Apr 2020 15:31:28 +0530 Message-ID: <20200419100133.3232316-29-jerinj@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200419100133.3232316-1-jerinj@marvell.com> References: <20200413150116.734047-1-jerinj@marvell.com> <20200419100133.3232316-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-19_02:2020-04-17, 2020-04-19 signatures=0 Subject: [dpdk-dev] [PATCH v6 28/33] 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=.* Signed-off-by: Jerin Jacob --- app/test/Makefile | 1 + app/test/meson.build | 1 + app/test/test_trace_perf.c | 183 +++++++++++++++++++++++++++++++++++++ 3 files changed, 185 insertions(+) create mode 100644 app/test/test_trace_perf.c diff --git a/app/test/Makefile b/app/test/Makefile index 9fb7b843f..0f990a0ae 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 78023ee71..00dc6f540 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..0f2fc22bd --- /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_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") +#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, test_trace_perf); -- 2.25.1