From 4d4f85f2a6b1443008bfa5115dfa332fa5a536cf Mon Sep 17 00:00:00 2001 From: Matias Elo Date: Wed, 13 Sep 2023 16:41:21 +0300 Subject: [PATCH] test: performance: use common indefinite test runner function Use common indefinite test runner function bench_run_indef() for all odp_bench_* applications. Reduces the amount of duplicate code. Signed-off-by: Matias Elo Reviewed-by: Petri Savolainen --- test/performance/Makefile.am | 8 +++---- test/performance/bench_common.c | 34 +++++++++++++++++++++++++++++ test/performance/bench_common.h | 5 +++++ test/performance/odp_bench_buffer.c | 30 +------------------------ test/performance/odp_bench_misc.c | 26 +--------------------- test/performance/odp_bench_packet.c | 30 +------------------------ test/performance/odp_bench_timer.c | 23 +------------------ 7 files changed, 47 insertions(+), 109 deletions(-) create mode 100644 test/performance/bench_common.c diff --git a/test/performance/Makefile.am b/test/performance/Makefile.am index b5a1f9eb2b..ded16bce59 100644 --- a/test/performance/Makefile.am +++ b/test/performance/Makefile.am @@ -61,10 +61,10 @@ endif bin_PROGRAMS = $(EXECUTABLES) $(COMPILE_ONLY) odp_atomic_perf_SOURCES = odp_atomic_perf.c -odp_bench_buffer_SOURCES = odp_bench_buffer.c bench_common.h -odp_bench_misc_SOURCES = odp_bench_misc.c bench_common.h -odp_bench_packet_SOURCES = odp_bench_packet.c bench_common.h -odp_bench_timer_SOURCES = odp_bench_timer.c bench_common.h +odp_bench_buffer_SOURCES = odp_bench_buffer.c bench_common.c bench_common.h +odp_bench_misc_SOURCES = odp_bench_misc.c bench_common.c bench_common.h +odp_bench_packet_SOURCES = odp_bench_packet.c bench_common.c bench_common.h +odp_bench_timer_SOURCES = odp_bench_timer.c bench_common.c bench_common.h odp_cpu_bench_SOURCES = odp_cpu_bench.c odp_crc_SOURCES = odp_crc.c odp_crypto_SOURCES = odp_crypto.c diff --git a/test/performance/bench_common.c b/test/performance/bench_common.c new file mode 100644 index 0000000000..ae834f6129 --- /dev/null +++ b/test/performance/bench_common.c @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2023 Nokia + */ + +#include +#include + +#include "bench_common.h" + +#include + +void bench_run_indef(bench_info_t *info, odp_atomic_u32_t *exit_thread) +{ + const char *desc; + + desc = info->desc != NULL ? info->desc : info->name; + + printf("Running odp_%s test indefinitely\n", desc); + + while (!odp_atomic_load_u32(exit_thread)) { + int ret; + + if (info->init != NULL) + info->init(); + + ret = info->run(); + + if (info->term != NULL) + info->term(); + + if (!ret) + ODPH_ABORT("Benchmark %s failed\n", desc); + } +} diff --git a/test/performance/bench_common.h b/test/performance/bench_common.h index 40908771b9..08f9ab1951 100644 --- a/test/performance/bench_common.h +++ b/test/performance/bench_common.h @@ -63,6 +63,11 @@ typedef struct { } bench_info_t; +/** + * Run selected test indefinitely + */ +void bench_run_indef(bench_info_t *info, odp_atomic_u32_t *exit_thread); + #ifdef __cplusplus } #endif diff --git a/test/performance/odp_bench_buffer.c b/test/performance/odp_bench_buffer.c index 123e457a73..d65fa71a26 100644 --- a/test/performance/odp_bench_buffer.c +++ b/test/performance/odp_bench_buffer.c @@ -103,34 +103,6 @@ static void sig_handler(int signo ODP_UNUSED) odp_atomic_store_u32(&gbl_args->exit_thread, 1); } -/** - * Run given benchmark indefinitely - */ -static void run_indef(args_t *args, int idx) -{ - const char *desc; - - desc = args->bench[idx].desc != NULL ? - args->bench[idx].desc : args->bench[idx].name; - - printf("Running odp_%s test indefinitely\n", desc); - - while (!odp_atomic_load_u32(&gbl_args->exit_thread)) { - int ret; - - if (args->bench[idx].init != NULL) - args->bench[idx].init(); - - ret = args->bench[idx].run(); - - if (args->bench[idx].term != NULL) - args->bench[idx].term(); - - if (!ret) - ODPH_ABORT("Benchmark %s failed\n", desc); - } -} - static int run_benchmarks(void *arg) { int i, j, k; @@ -155,7 +127,7 @@ static int run_benchmarks(void *arg) continue; } else if (args->appl.bench_idx && (j + 1) == args->appl.bench_idx) { - run_indef(args, j); + bench_run_indef(&args->bench[j], &gbl_args->exit_thread); return 0; } diff --git a/test/performance/odp_bench_misc.c b/test/performance/odp_bench_misc.c index b4f55486dc..dac36dd129 100644 --- a/test/performance/odp_bench_misc.c +++ b/test/performance/odp_bench_misc.c @@ -102,29 +102,6 @@ static int setup_sig_handler(void) return 0; } -/* Run given benchmark indefinitely */ -static void run_indef(gbl_args_t *args, int idx) -{ - const char *desc; - const bench_info_t *bench = &args->bench[idx]; - - desc = bench->desc != NULL ? bench->desc : bench->name; - - printf("Running odp_%s test indefinitely\n", desc); - - while (!odp_atomic_load_u32(&gbl_args->exit_thread)) { - int ret; - - if (bench->init != NULL) - bench->init(); - - ret = bench->run(); - - if (!ret) - ODPH_ABORT("Benchmark %s failed\n", desc); - } -} - static int run_benchmarks(void *arg) { int i, j; @@ -156,8 +133,7 @@ static int run_benchmarks(void *arg) j++; continue; } - - run_indef(args, j); + bench_run_indef(&args->bench[j], &gbl_args->exit_thread); return 0; } diff --git a/test/performance/odp_bench_packet.c b/test/performance/odp_bench_packet.c index a8f4fb5673..7151e0a4d7 100644 --- a/test/performance/odp_bench_packet.c +++ b/test/performance/odp_bench_packet.c @@ -148,34 +148,6 @@ static void sig_handler(int signo ODP_UNUSED) odp_atomic_store_u32(&gbl_args->exit_thread, 1); } -/** - * Run given benchmark indefinitely - */ -static void run_indef(args_t *args, int idx) -{ - const char *desc; - - desc = args->bench[idx].desc != NULL ? - args->bench[idx].desc : args->bench[idx].name; - - printf("Running odp_%s test indefinitely\n", desc); - - while (!odp_atomic_load_u32(&gbl_args->exit_thread)) { - int ret; - - if (args->bench[idx].init != NULL) - args->bench[idx].init(); - - ret = args->bench[idx].run(); - - if (args->bench[idx].term != NULL) - args->bench[idx].term(); - - if (!ret) - ODPH_ABORT("Benchmark %s failed\n", desc); - } -} - /** * Master function for running the microbenchmarks */ @@ -210,7 +182,7 @@ static int run_benchmarks(void *arg) continue; } else if (args->appl.bench_idx && (j + 1) == args->appl.bench_idx) { - run_indef(args, j); + bench_run_indef(&args->bench[j], &gbl_args->exit_thread); return 0; } diff --git a/test/performance/odp_bench_timer.c b/test/performance/odp_bench_timer.c index 4bf0df3f86..822c31560d 100644 --- a/test/performance/odp_bench_timer.c +++ b/test/performance/odp_bench_timer.c @@ -116,26 +116,6 @@ static int setup_sig_handler(void) return 0; } -/* Run given benchmark indefinitely */ -static void run_indef(gbl_args_t *args, int idx) -{ - const char *desc; - const bench_info_t *bench = &args->bench[idx]; - - desc = bench->desc != NULL ? bench->desc : bench->name; - - printf("Running odp_%s test indefinitely\n", desc); - - while (!odp_atomic_load_u32(&gbl_args->exit_thread)) { - int ret; - - ret = bench->run(); - - if (!ret) - ODPH_ABORT("Benchmark %s failed\n", desc); - } -} - static int run_benchmarks(void *arg) { int i, j; @@ -167,8 +147,7 @@ static int run_benchmarks(void *arg) j++; continue; } - - run_indef(args, j); + bench_run_indef(&args->bench[j], &gbl_args->exit_thread); return 0; }