Skip to content

Commit

Permalink
test: performance: use common data types
Browse files Browse the repository at this point in the history
Utilize common data types among 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 59524e1 commit 65f383a
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 122 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
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
Expand Down
70 changes: 70 additions & 0 deletions test/performance/bench_common.h
Original file line number Diff line number Diff line change
@@ -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 <odp_api.h>
#include <odp/helper/odph_api.h>

#include <stdint.h>

/**
* 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
47 changes: 7 additions & 40 deletions test/performance/odp_bench_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <odp_api.h>
#include <odp/helper/odph_api.h>

#include "bench_common.h"

#include <getopt.h>
#include <inttypes.h>
#include <signal.h>
Expand Down Expand Up @@ -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
Expand All @@ -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
*/
Expand Down
31 changes: 4 additions & 27 deletions test/performance/odp_bench_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <odp_api.h>
#include <odp/helper/odph_api.h>

#include "bench_common.h"

#include <getopt.h>
#include <inttypes.h>
#include <signal.h>
Expand All @@ -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 */
Expand All @@ -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;
Expand Down
34 changes: 4 additions & 30 deletions test/performance/odp_bench_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <odp_api.h>
#include <odp/helper/odph_api.h>

#include "bench_common.h"

/** Minimum number of packet data bytes in the first segment */
#define PKT_POOL_SEG_LEN 128

Expand Down Expand Up @@ -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");
Expand All @@ -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
*/
Expand Down
25 changes: 4 additions & 21 deletions test/performance/odp_bench_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <odp_api.h>
#include <odp/helper/odph_api.h>

#include "bench_common.h"

#include <getopt.h>
#include <inttypes.h>
#include <signal.h>
Expand All @@ -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 */
Expand Down

0 comments on commit 65f383a

Please sign in to comment.