Skip to content

Commit

Permalink
test: performance: use common indefinite test runner function
Browse files Browse the repository at this point in the history
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 <matias.elo@nokia.com>
Reviewed-by: Petri Savolainen <petri.savolainen@nokia.com>
  • Loading branch information
MatiasElo committed Sep 20, 2023
1 parent 65f383a commit 4d4f85f
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 109 deletions.
8 changes: 4 additions & 4 deletions test/performance/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions test/performance/bench_common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (c) 2023 Nokia
*/

#include <odp_api.h>
#include <odp/helper/odph_api.h>

#include "bench_common.h"

#include <stdint.h>

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);
}
}
5 changes: 5 additions & 0 deletions test/performance/bench_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 1 addition & 29 deletions test/performance/odp_bench_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
26 changes: 1 addition & 25 deletions test/performance/odp_bench_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
30 changes: 1 addition & 29 deletions test/performance/odp_bench_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
}

Expand Down
23 changes: 1 addition & 22 deletions test/performance/odp_bench_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 4d4f85f

Please sign in to comment.