Skip to content

Commit

Permalink
test: bench_pktio_sp: implement test result export
Browse files Browse the repository at this point in the history
Newly added test result export functionality is now utilized in
odp_bench_pktio_sp.

Signed-off-by: Ray Sointula <[email protected]>
Reviewed-by: Matias Elo <[email protected]>
Reviewed-by: Tuomas Taipale <[email protected]>
  • Loading branch information
Rayska authored and MatiasElo committed Jun 25, 2024
1 parent 83f1a8c commit 43fe4c0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
3 changes: 3 additions & 0 deletions test/common/bench_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ int bench_tm_run(void *arg)
}
printf("[%02d] %-26s\n", j + 1, bench->name);
print_results(&res);

if (suite->result)
suite->result[j] = res;
}
printf("\n");

Expand Down
3 changes: 3 additions & 0 deletions test/common/bench_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ typedef struct {
/* Break worker loop if set to 1 */
odp_atomic_u32_t exit_worker;

/* Optional test result output array */
bench_tm_result_t *result;

} bench_tm_suite_t;

/**
Expand Down
62 changes: 60 additions & 2 deletions test/performance/odp_bench_pktio_sp.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (c) 2023 Nokia
* Copyright (c) 2023-2024 Nokia
*/

/**
Expand All @@ -18,6 +18,7 @@
#include <odp/helper/odph_api.h>

#include <bench_common.h>
#include <export_results.h>

#include <getopt.h>
#include <inttypes.h>
Expand All @@ -31,6 +32,9 @@
/* Maximum interface name length */
#define MAX_NAME_LEN 128

/* Number of functions originally in test_suite */
#define TEST_MAX_BENCH_NUM 10

#define BENCH_INFO(run_fn, init_fn, term_fn, cond_fn, rounds) \
{.name = #run_fn, .run = run_fn, .init = init_fn, .term = term_fn, .cond = cond_fn,\
.max_rounds = rounds}
Expand Down Expand Up @@ -97,6 +101,9 @@ typedef struct {
/* CPU mask as string */
char cpumask_str[ODP_CPUMASK_STR_SIZE];

/* Array for storing results */
bench_tm_result_t result[TEST_MAX_BENCH_NUM];

} appl_args_t;

static appl_args_t *gbl_args;
Expand Down Expand Up @@ -781,6 +788,39 @@ static int cls_pmr_create(bench_tm_result_t *res, int repeat_count)
return ret;
}

static int bench_pktio_sp_export(void *data)
{
appl_args_t *gbl_args = data;
uint64_t num;
int ret = 0;

if (test_common_write("%s", "Function name,Latency (nsec) per function call (min),"
"Latency (nsec) per function call (avg),"
"Latency (nsec) per function call (max)\n")) {
ret = -1;
goto exit;
}

for (uint32_t i = 0; i < gbl_args->suite.num_bench; i++) {
for (int j = 0; j < gbl_args->result[i].num; j++) {
num = gbl_args->result[i].func[j].num ? gbl_args->result[i].func[j].num : 1;
if (test_common_write("%s,%i,%i,%i\n",
gbl_args->result[i].func[j].name,
odp_time_to_ns(gbl_args->result[i].func[j].min),
odp_time_to_ns(gbl_args->result[i].func[j].tot) / num,
odp_time_to_ns(gbl_args->result[i].func[j].max))) {
ret = -1;
goto exit;
}
}
}

exit:
test_common_write_term();

return ret;
}

bench_tm_info_t test_suite[] = {
BENCH_INFO(pktio_capability, pktio_setup, pktio_clean, NULL, 0),
BENCH_INFO(pktio_lookup, pktio_setup, pktio_clean, NULL, 0),
Expand All @@ -794,6 +834,9 @@ bench_tm_info_t test_suite[] = {
BENCH_INFO(cls_pmr_create, pktio_setup_cls, pktio_clean_sched_rx, check_cls_cond, 0)
};

ODP_STATIC_ASSERT(ODPH_ARRAY_SIZE(test_suite) <= TEST_MAX_BENCH_NUM,
"Result array is too small to hold all the results");

/* Print usage information */
static void usage(void)
{
Expand Down Expand Up @@ -1009,6 +1052,7 @@ static void print_info(appl_args_t *appl_args)
int main(int argc, char *argv[])
{
odph_helper_options_t helper_options;
test_common_options_t common_options;
odph_thread_t worker_thread;
odph_thread_common_param_t thr_common;
odph_thread_param_t thr_param;
Expand All @@ -1026,6 +1070,12 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}

argc = test_common_parse_options(argc, argv);
if (test_common_options(&common_options)) {
ODPH_ERR("Error: reading test helper options failed\n");
exit(EXIT_FAILURE);
}

odp_init_param_init(&init_param);
init_param.mem_model = helper_options.mem_model;

Expand Down Expand Up @@ -1080,7 +1130,8 @@ int main(int argc, char *argv[])
gbl_args->suite.num_bench = ODPH_ARRAY_SIZE(test_suite);
gbl_args->suite.rounds = gbl_args->opt.rounds;
gbl_args->suite.bench_idx = gbl_args->opt.case_idx;

if (common_options.is_export)
gbl_args->suite.result = gbl_args->result;
/* Get default worker cpumask */
if (odp_cpumask_default_worker(&default_mask, 1) != 1) {
ODPH_ERR("Unable to allocate worker thread\n");
Expand Down Expand Up @@ -1117,6 +1168,13 @@ int main(int argc, char *argv[])

ret = gbl_args->suite.retval;

if (ret == 0 && common_options.is_export) {
if (bench_pktio_sp_export(gbl_args)) {
ODPH_ERR("Error: Export failed\n");
ret = -1;
}
}

exit:
if (odp_shm_free(shm)) {
ODPH_ERR("Shared mem free failed\n");
Expand Down

0 comments on commit 43fe4c0

Please sign in to comment.