From 65f383acaca4135f16314d065319b27ebf6fc38e Mon Sep 17 00:00:00 2001 From: Matias Elo Date: Wed, 13 Sep 2023 16:11:14 +0300 Subject: [PATCH] test: performance: use common data types Utilize common data types among 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.h | 70 +++++++++++++++++++++++++++++ test/performance/odp_bench_buffer.c | 47 +++---------------- test/performance/odp_bench_misc.c | 31 ++----------- test/performance/odp_bench_packet.c | 34 ++------------ test/performance/odp_bench_timer.c | 25 ++--------- 6 files changed, 93 insertions(+), 122 deletions(-) create mode 100644 test/performance/bench_common.h diff --git a/test/performance/Makefile.am b/test/performance/Makefile.am index 24c1767fe6..b5a1f9eb2b 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 -odp_bench_misc_SOURCES = odp_bench_misc.c -odp_bench_packet_SOURCES = odp_bench_packet.c -odp_bench_timer_SOURCES = odp_bench_timer.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_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.h b/test/performance/bench_common.h new file mode 100644 index 0000000000..40908771b9 --- /dev/null +++ b/test/performance/bench_common.h @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2023 Nokia + */ + +#ifndef BENCH_COMMON_H +#define BENCH_COMMON_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#include + +/** + * Check benchmark preconditions + * + * @retval !0 test enabled + */ +typedef int (*bench_cond_fn_t)(void); + +/** + * Initialize benchmark resources + */ +typedef void (*bench_init_fn_t)(void); + +/** + * Run benchmark + * + * @retval >0 on success + */ +typedef int (*bench_run_fn_t)(void); + +/** + * Release benchmark resources + */ +typedef void (*bench_term_fn_t)(void); + +/* Benchmark test data */ +typedef struct { + /* Default test name */ + const char *name; + + /* Optional alternate test description */ + const char *desc; + + /* Optional precondition to run test */ + bench_cond_fn_t cond; + + /* Optional test initializer function */ + bench_init_fn_t init; + + /* Test function to run */ + bench_run_fn_t run; + + /* Optional test terminate function */ + bench_term_fn_t term; + + /* Optional test specific limit for rounds (tuning for slow implementations) */ + uint32_t max_rounds; + +} bench_info_t; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/test/performance/odp_bench_buffer.c b/test/performance/odp_bench_buffer.c index e0e7c85cdc..123e457a73 100644 --- a/test/performance/odp_bench_buffer.c +++ b/test/performance/odp_bench_buffer.c @@ -8,6 +8,8 @@ #include #include +#include "bench_common.h" + #include #include #include @@ -36,11 +38,12 @@ #define NO_PATH(file_name) (strrchr((file_name), '/') ? \ strrchr((file_name), '/') + 1 : (file_name)) -#define BENCH_INFO(run, init, term, name) \ - {#run, run, init, term, name, NULL} +#define BENCH_INFO(run_fn, init_fn, term_fn, alt_name) \ + {.name = #run_fn, .run = run_fn, .init = init_fn, .term = term_fn, .desc = alt_name} -#define BENCH_INFO_COND(run, init, term, name, cond) \ - {#run, run, init, term, name, cond} +#define BENCH_INFO_COND(run_fn, init_fn, term_fn, alt_name, cond_fn) \ + {.name = #run_fn, .run = run_fn, .init = init_fn, .term = term_fn, .desc = alt_name, \ + .cond = cond_fn} /** * Parsed command line arguments @@ -52,42 +55,6 @@ typedef struct { int test_cycles; /** Test cycles per tested function */ } appl_args_t; -/** - * Initialize benchmark resources - */ -typedef void (*bench_init_fn_t)(void); - -/** - * Run benchmark - * - * @retval >0 on success - * */ -typedef int (*bench_run_fn_t)(void); - -/** - * Release benchmark resources - */ -typedef void (*bench_term_fn_t)(void); - -/** - * Check benchmark preconditions - * - * @retval !0 test enabled - * */ -typedef int (*bench_cond_fn_t)(void); - -/** - * Benchmark data - */ -typedef struct { - const char *name; - bench_run_fn_t run; - bench_init_fn_t init; - bench_term_fn_t term; - const char *desc; - bench_cond_fn_t cond; -} bench_info_t; - /** * Grouping of all global data */ diff --git a/test/performance/odp_bench_misc.c b/test/performance/odp_bench_misc.c index 3da4a66161..b4f55486dc 100644 --- a/test/performance/odp_bench_misc.c +++ b/test/performance/odp_bench_misc.c @@ -11,6 +11,8 @@ #include #include +#include "bench_common.h" + #include #include #include @@ -23,8 +25,8 @@ /* Default number of rounds per test case */ #define ROUNDS 1000u -#define BENCH_INFO(run, init, max, name) \ - {#run, run, init, max, name} +#define BENCH_INFO(run_fn, init_fn, max, alt_name) \ + {.name = #run_fn, .run = run_fn, .init = init_fn, .max_rounds = max, .desc = alt_name} typedef struct { /* Measure time vs CPU cycles */ @@ -38,31 +40,6 @@ typedef struct { } appl_args_t; -/* Initialize benchmark resources */ -typedef void (*bench_init_fn_t)(void); - -/* Run benchmark, returns >0 on success */ -typedef int (*bench_run_fn_t)(void); - -/* Benchmark data */ -typedef struct { - /* Default test name */ - const char *name; - - /* Test function to run */ - bench_run_fn_t run; - - /* Test init function */ - bench_init_fn_t init; - - /* Test specific limit for rounds (tuning for slow implementation) */ - uint32_t max_rounds; - - /* Override default test name */ - const char *desc; - -} bench_info_t; - /* Global data */ typedef struct { appl_args_t appl; diff --git a/test/performance/odp_bench_packet.c b/test/performance/odp_bench_packet.c index 8da2d736a0..a8f4fb5673 100644 --- a/test/performance/odp_bench_packet.c +++ b/test/performance/odp_bench_packet.c @@ -24,6 +24,8 @@ #include #include +#include "bench_common.h" + /** Minimum number of packet data bytes in the first segment */ #define PKT_POOL_SEG_LEN 128 @@ -66,8 +68,8 @@ #define NO_PATH(file_name) (strrchr((file_name), '/') ? \ strrchr((file_name), '/') + 1 : (file_name)) -#define BENCH_INFO(run, init, term, name) \ - {#run, run, init, term, name} +#define BENCH_INFO(run_fn, init_fn, term_fn, alt_name) \ + {.name = #run_fn, .run = run_fn, .init = init_fn, .term = term_fn, .desc = alt_name} ODP_STATIC_ASSERT((TEST_ALIGN_OFFSET + TEST_ALIGN_LEN) <= TEST_MIN_PKT_SIZE, "Invalid_alignment"); @@ -88,34 +90,6 @@ typedef struct { int cache_size; /** Pool cache size */ } appl_args_t; -/** - * Initialize benchmark resources - */ -typedef void (*bench_init_fn_t)(void); - -/** - * Run benchmark - * - * @retval >0 on success - * */ -typedef int (*bench_run_fn_t)(void); - -/** - * Release benchmark resources - */ -typedef void (*bench_term_fn_t)(void); - -/** - * Benchmark data - */ -typedef struct { - const char *name; - bench_run_fn_t run; - bench_init_fn_t init; - bench_term_fn_t term; - const char *desc; -} bench_info_t; - /** * Grouping of all global data */ diff --git a/test/performance/odp_bench_timer.c b/test/performance/odp_bench_timer.c index 918d19e5d7..4bf0df3f86 100644 --- a/test/performance/odp_bench_timer.c +++ b/test/performance/odp_bench_timer.c @@ -11,6 +11,8 @@ #include #include +#include "bench_common.h" + #include #include #include @@ -29,27 +31,8 @@ /** Timer duration in nsec */ #define TIMER_NSEC 50000000 -#define BENCH_INFO(run, max, name) \ - {#run, run, max, name} - -/* Run benchmark, returns >0 on success */ -typedef int (*bench_run_fn_t)(void); - -/* Benchmark data */ -typedef struct { - /* Default test name */ - const char *name; - - /* Test function to run */ - bench_run_fn_t run; - - /* Test specific limit for rounds (tuning for slow implementation) */ - uint32_t max_rounds; - - /* Override default test name */ - const char *desc; - -} bench_info_t; +#define BENCH_INFO(run_fn, max, alt_name) \ + {.name = #run_fn, .run = run_fn, .max_rounds = max, .desc = alt_name} typedef struct { /* Command line options */