API Reference Manual  1.45.1
odp_bench_buffer.c

Microbenchmark application for buffer API functions

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (c) 2017-2018 Linaro Limited
* Copyright (c) 2022-2024 Nokia
*/
#include <odp_api.h>
#include <odp/helper/odph_api.h>
#include <bench_common.h>
#include <export_results.h>
#include <getopt.h>
#include <inttypes.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#define TEST_BUF_SIZE 1024
#define TEST_UAREA_SIZE 8
#define TEST_REPEAT_COUNT 1000
#define TEST_ROUNDS 100u
#define TEST_MAX_BURST 64
#define TEST_DEF_BURST 8
#define TEST_MAX_BENCH 40
#define NO_PATH(file_name) (strrchr((file_name), '/') ? \
strrchr((file_name), '/') + 1 : (file_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}
#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}
typedef struct {
int bench_idx;
int burst_size;
int cache_size;
int time;
uint32_t rounds;
} appl_args_t;
typedef struct {
appl_args_t appl;
bench_suite_t suite;
odp_pool_t pool;
uint32_t buf_size;
uint32_t uarea_size;
uint32_t max_flow_id;
odp_buffer_t buf_tbl[TEST_REPEAT_COUNT * TEST_MAX_BURST];
odp_event_t event_tbl[TEST_REPEAT_COUNT * TEST_MAX_BURST];
void *ptr_tbl[TEST_REPEAT_COUNT];
odp_pool_t pool_tbl[TEST_REPEAT_COUNT];
odp_event_type_t event_type_tbl[TEST_REPEAT_COUNT * TEST_MAX_BURST];
odp_event_subtype_t event_subtype_tbl[TEST_REPEAT_COUNT * TEST_MAX_BURST];
char cpumask_str[ODP_CPUMASK_STR_SIZE];
double result[TEST_MAX_BENCH];
} args_t;
static args_t *gbl_args;
static void sig_handler(int signo ODP_UNUSED)
{
if (gbl_args == NULL)
return;
odp_atomic_store_u32(&gbl_args->suite.exit_worker, 1);
}
static void allocate_test_buffers(odp_buffer_t buf[], int num)
{
int num_buf = 0;
while (num_buf < num) {
int ret;
ret = odp_buffer_alloc_multi(gbl_args->pool, &buf[num_buf], num - num_buf);
if (ret < 0)
ODPH_ABORT("Allocating test buffers failed\n");
num_buf += ret;
}
}
static void create_buffers(void)
{
allocate_test_buffers(gbl_args->buf_tbl, TEST_REPEAT_COUNT);
}
static void create_buffers_multi(void)
{
allocate_test_buffers(gbl_args->buf_tbl, TEST_REPEAT_COUNT * gbl_args->appl.burst_size);
}
static void create_events(void)
{
odp_buffer_t *buf_tbl = gbl_args->buf_tbl;
allocate_test_buffers(gbl_args->buf_tbl, TEST_REPEAT_COUNT);
for (int i = 0; i < TEST_REPEAT_COUNT; i++)
gbl_args->event_tbl[i] = odp_buffer_to_event(buf_tbl[i]);
}
static void create_events_multi(void)
{
odp_buffer_t *buf_tbl = gbl_args->buf_tbl;
allocate_test_buffers(gbl_args->buf_tbl,
TEST_REPEAT_COUNT * gbl_args->appl.burst_size);
for (int i = 0; i < TEST_REPEAT_COUNT * gbl_args->appl.burst_size; i++)
gbl_args->event_tbl[i] = odp_buffer_to_event(buf_tbl[i]);
}
static void free_buffers(void)
{
odp_buffer_free_multi(gbl_args->buf_tbl, TEST_REPEAT_COUNT);
}
static void free_buffers_multi(void)
{
odp_buffer_free_multi(gbl_args->buf_tbl, TEST_REPEAT_COUNT * gbl_args->appl.burst_size);
}
static int check_uarea(void)
{
return !!gbl_args->uarea_size;
}
static int check_flow_aware(void)
{
return !!gbl_args->max_flow_id;
}
static int buffer_from_event(void)
{
odp_buffer_t *buf_tbl = gbl_args->buf_tbl;
odp_event_t *event_tbl = gbl_args->event_tbl;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
buf_tbl[i] = odp_buffer_from_event(event_tbl[i]);
return i;
}
static int buffer_from_event_multi(void)
{
odp_buffer_t *buf_tbl = gbl_args->buf_tbl;
odp_event_t *event_tbl = gbl_args->event_tbl;
int burst_size = gbl_args->appl.burst_size;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
odp_buffer_from_event_multi(&buf_tbl[i * burst_size],
&event_tbl[i * burst_size], burst_size);
return i;
}
static int buffer_to_event(void)
{
odp_buffer_t *buf_tbl = gbl_args->buf_tbl;
odp_event_t *event_tbl = gbl_args->event_tbl;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
event_tbl[i] = odp_buffer_to_event(buf_tbl[i]);
return i;
}
static int buffer_to_event_multi(void)
{
odp_buffer_t *buf_tbl = gbl_args->buf_tbl;
odp_event_t *event_tbl = gbl_args->event_tbl;
int burst_size = gbl_args->appl.burst_size;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
odp_buffer_to_event_multi(&buf_tbl[i * burst_size],
&event_tbl[i * burst_size], burst_size);
return i;
}
static int buffer_addr(void)
{
odp_buffer_t *buf_tbl = gbl_args->buf_tbl;
void **ptr_tbl = gbl_args->ptr_tbl;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
ptr_tbl[i] = odp_buffer_addr(buf_tbl[i]);
return i;
}
static int buffer_size(void)
{
odp_buffer_t *buf_tbl = gbl_args->buf_tbl;
uint32_t ret = 0;
for (int i = 0; i < TEST_REPEAT_COUNT; i++)
ret += odp_buffer_size(buf_tbl[i]);
return ret;
}
static int buffer_user_area(void)
{
odp_buffer_t *buf_tbl = gbl_args->buf_tbl;
void **ptr_tbl = gbl_args->ptr_tbl;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
ptr_tbl[i] = odp_buffer_user_area(buf_tbl[i]);
return i;
}
static int buffer_pool(void)
{
odp_buffer_t *buf_tbl = gbl_args->buf_tbl;
odp_pool_t *pool_tbl = gbl_args->pool_tbl;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
pool_tbl[i] = odp_buffer_pool(buf_tbl[i]);
return i;
}
static int buffer_alloc(void)
{
odp_buffer_t *buf_tbl = gbl_args->buf_tbl;
odp_pool_t pool = gbl_args->pool;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
buf_tbl[i] = odp_buffer_alloc(pool);
return i;
}
static int buffer_alloc_multi(void)
{
odp_buffer_t *buf_tbl = gbl_args->buf_tbl;
odp_pool_t pool = gbl_args->pool;
int burst_size = gbl_args->appl.burst_size;
int num = 0;
for (int i = 0; i < TEST_REPEAT_COUNT; i++)
num += odp_buffer_alloc_multi(pool, &buf_tbl[num], burst_size);
return num;
}
static int buffer_free(void)
{
odp_buffer_t *buf_tbl = gbl_args->buf_tbl;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
odp_buffer_free(buf_tbl[i]);
return i;
}
static int buffer_free_multi(void)
{
odp_buffer_t *buf_tbl = gbl_args->buf_tbl;
int burst_size = gbl_args->appl.burst_size;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
odp_buffer_free_multi(&buf_tbl[i * burst_size], burst_size);
return i;
}
static int buffer_alloc_free(void)
{
odp_pool_t pool = gbl_args->pool;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++) {
return 0;
}
return i;
}
static int buffer_alloc_free_multi(void)
{
odp_buffer_t *buf_tbl = gbl_args->buf_tbl;
odp_pool_t pool = gbl_args->pool;
int burst_size = gbl_args->appl.burst_size;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++) {
int num = odp_buffer_alloc_multi(pool, buf_tbl, burst_size);
if (odp_unlikely(num < 1))
return 0;
odp_buffer_free_multi(buf_tbl, num);
}
return i;
}
static int buffer_is_valid(void)
{
odp_buffer_t *buf_tbl = gbl_args->buf_tbl;
uint32_t ret = 0;
for (int i = 0; i < TEST_REPEAT_COUNT; i++)
ret += odp_buffer_is_valid(buf_tbl[i]);
return ret;
}
static int event_type(void)
{
odp_event_t *event_tbl = gbl_args->event_tbl;
odp_event_type_t *event_type_tbl = gbl_args->event_type_tbl;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
event_type_tbl[i] = odp_event_type(event_tbl[i]);
return i;
}
static int event_subtype(void)
{
odp_event_t *event_tbl = gbl_args->event_tbl;
odp_event_subtype_t *event_subtype_tbl = gbl_args->event_subtype_tbl;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
event_subtype_tbl[i] = odp_event_subtype(event_tbl[i]);
return i;
}
static int event_types(void)
{
odp_event_t *event_tbl = gbl_args->event_tbl;
odp_event_type_t *event_type_tbl = gbl_args->event_type_tbl;
odp_event_subtype_t *event_subtype_tbl = gbl_args->event_subtype_tbl;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
event_type_tbl[i] = odp_event_types(event_tbl[i], &event_subtype_tbl[i]);
return i;
}
static int event_types_multi(void)
{
odp_event_t *event_tbl = gbl_args->event_tbl;
odp_event_type_t *event_type_tbl = gbl_args->event_type_tbl;
odp_event_subtype_t *event_subtype_tbl = gbl_args->event_subtype_tbl;
int burst_size = gbl_args->appl.burst_size;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
odp_event_types_multi(&event_tbl[i * burst_size],
&event_type_tbl[i * burst_size],
&event_subtype_tbl[i * burst_size], burst_size);
return i;
}
static int event_types_multi_no_sub(void)
{
odp_event_t *event_tbl = gbl_args->event_tbl;
odp_event_type_t *event_type_tbl = gbl_args->event_type_tbl;
int burst_size = gbl_args->appl.burst_size;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
odp_event_types_multi(&event_tbl[i * burst_size],
&event_type_tbl[i * burst_size], NULL, burst_size);
return i;
}
static int event_type_multi(void)
{
odp_event_t *event_tbl = gbl_args->event_tbl;
odp_event_type_t *event_type_tbl = gbl_args->event_type_tbl;
int burst_size = gbl_args->appl.burst_size;
uint32_t ret = 0;
for (int i = 0; i < TEST_REPEAT_COUNT; i++)
ret += odp_event_type_multi(&event_tbl[i * burst_size], burst_size,
&event_type_tbl[i]);
return ret;
}
static int event_pool(void)
{
odp_event_t *event_tbl = gbl_args->event_tbl;
odp_pool_t *pool_tbl = gbl_args->pool_tbl;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
pool_tbl[i] = odp_event_pool(event_tbl[i]);
return i;
}
static int event_user_area(void)
{
odp_event_t *event_tbl = gbl_args->event_tbl;
void **ptr_tbl = gbl_args->ptr_tbl;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
ptr_tbl[i] = odp_event_user_area(event_tbl[i]);
return i;
}
static int event_user_area_and_flag(void)
{
odp_event_t *event_tbl = gbl_args->event_tbl;
void **ptr_tbl = gbl_args->ptr_tbl;
int ret = 0;
int flag;
for (int i = 0; i < TEST_REPEAT_COUNT; i++) {
ptr_tbl[i] = odp_event_user_area_and_flag(event_tbl[i], &flag);
ret += flag;
}
return ret;
}
static int event_is_valid(void)
{
odp_event_t *event_tbl = gbl_args->event_tbl;
uint32_t ret = 0;
for (int i = 0; i < TEST_REPEAT_COUNT; i++)
ret += odp_event_is_valid(event_tbl[i]);
return ret;
}
static int event_free(void)
{
odp_event_t *event_tbl = gbl_args->event_tbl;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
odp_event_free(event_tbl[i]);
return i;
}
static int event_free_multi(void)
{
odp_event_t *event_tbl = gbl_args->event_tbl;
int burst_size = gbl_args->appl.burst_size;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
odp_event_free_multi(&event_tbl[i * burst_size], burst_size);
return i;
}
static int event_free_sp(void)
{
odp_event_t *event_tbl = gbl_args->event_tbl;
int burst_size = gbl_args->appl.burst_size;
int i;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
odp_event_free_sp(&event_tbl[i * burst_size], burst_size);
return i;
}
static int event_flow_id(void)
{
odp_event_t *event_tbl = gbl_args->event_tbl;
uint32_t ret = 0;
for (int i = 0; i < TEST_REPEAT_COUNT; i++)
ret += odp_event_flow_id(event_tbl[i]);
return !ret;
}
static int event_flow_id_set(void)
{
odp_event_t *event_tbl = gbl_args->event_tbl;
int i = 0;
for (i = 0; i < TEST_REPEAT_COUNT; i++)
odp_event_flow_id_set(event_tbl[i], 0);
return i;
}
static void usage(char *progname)
{
printf("\n"
"OpenDataPlane Buffer/Event API microbenchmarks.\n"
"\n"
"Usage: %s OPTIONS\n"
" E.g. %s\n"
"\n"
"Optional OPTIONS:\n"
" -b, --burst <num> Test burst size.\n"
" -c, --cache_size <num> Pool cache size.\n"
" -i, --index <idx> Benchmark index to run indefinitely.\n"
" -r, --rounds <num> Run each test case 'num' times (default %u).\n"
" -t, --time <opt> Time measurement. 0: measure CPU cycles (default), 1: measure time\n"
" -h, --help Display help and exit.\n\n"
"\n", NO_PATH(progname), NO_PATH(progname), TEST_ROUNDS);
}
static void parse_args(int argc, char *argv[], appl_args_t *appl_args)
{
int opt;
int long_index;
static const struct option longopts[] = {
{"burst", required_argument, NULL, 'b'},
{"cache_size", required_argument, NULL, 'c'},
{"index", required_argument, NULL, 'i'},
{"rounds", required_argument, NULL, 'r'},
{"time", required_argument, NULL, 't'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
};
static const char *shortopts = "c:b:i:r:t:h";
appl_args->bench_idx = 0; /* Run all benchmarks */
appl_args->burst_size = TEST_DEF_BURST;
appl_args->cache_size = -1;
appl_args->rounds = TEST_ROUNDS;
appl_args->time = 0;
while (1) {
opt = getopt_long(argc, argv, shortopts, longopts, &long_index);
if (opt == -1)
break; /* No more options */
switch (opt) {
case 'c':
appl_args->cache_size = atoi(optarg);
break;
case 'b':
appl_args->burst_size = atoi(optarg);
break;
case 'h':
usage(argv[0]);
exit(EXIT_SUCCESS);
break;
case 'i':
appl_args->bench_idx = atoi(optarg);
break;
case 'r':
appl_args->rounds = atoi(optarg);
break;
case 't':
appl_args->time = atoi(optarg);
break;
default:
break;
}
}
if (appl_args->burst_size < 1 ||
appl_args->burst_size > TEST_MAX_BURST) {
printf("Invalid burst size (max %d)\n", TEST_MAX_BURST);
exit(EXIT_FAILURE);
}
if (appl_args->rounds < 1) {
printf("Invalid number test rounds: %d\n", appl_args->rounds);
exit(EXIT_FAILURE);
}
optind = 1; /* Reset 'extern optind' from the getopt lib */
}
static void print_info(void)
{
printf("\n"
"odp_bench_buffer options\n"
"------------------------\n");
printf("Burst size: %d\n", gbl_args->appl.burst_size);
printf("Buffer size: %d\n", gbl_args->buf_size);
printf("CPU mask: %s\n", gbl_args->cpumask_str);
if (gbl_args->appl.cache_size < 0)
printf("Pool cache size: default\n");
else
printf("Pool cache size: %d\n", gbl_args->appl.cache_size);
printf("Measurement unit: %s\n", gbl_args->appl.time ? "nsec" : "CPU cycles");
printf("Test rounds: %u\n", gbl_args->appl.rounds);
printf("\n");
}
static int bench_buffer_export(void *data)
{
args_t *gbl_args = data;
int ret = 0;
if (test_common_write("%s", gbl_args->appl.time ?
"Function name,Average nsec per function call\n" :
"Function name,Average CPU cycles per function call\n")) {
ret = -1;
goto exit;
}
for (int i = 0; i < gbl_args->suite.num_bench; i++) {
if (test_common_write("odp_%s,%f\n",
gbl_args->suite.bench[i].name,
gbl_args->suite.result[i])) {
ret = -1;
goto exit;
}
}
exit:
test_common_write_term();
return ret;
}
bench_info_t test_suite[] = {
BENCH_INFO(buffer_from_event, create_events, free_buffers, NULL),
BENCH_INFO(buffer_from_event_multi, create_events_multi, free_buffers_multi, NULL),
BENCH_INFO(buffer_to_event, create_buffers, free_buffers, NULL),
BENCH_INFO(buffer_to_event_multi, create_buffers_multi, free_buffers_multi, NULL),
BENCH_INFO(buffer_addr, create_buffers, free_buffers, NULL),
BENCH_INFO(buffer_size, create_buffers, free_buffers, NULL),
BENCH_INFO_COND(buffer_user_area, create_buffers, free_buffers, NULL, check_uarea),
BENCH_INFO(buffer_pool, create_buffers, free_buffers, NULL),
BENCH_INFO(buffer_alloc, NULL, free_buffers, NULL),
BENCH_INFO(buffer_alloc_multi, NULL, free_buffers_multi, NULL),
BENCH_INFO(buffer_free, create_buffers, NULL, NULL),
BENCH_INFO(buffer_free_multi, create_buffers_multi, NULL, NULL),
BENCH_INFO(buffer_alloc_free, NULL, NULL, NULL),
BENCH_INFO(buffer_alloc_free_multi, NULL, NULL, NULL),
BENCH_INFO(buffer_is_valid, create_buffers, free_buffers, NULL),
BENCH_INFO(event_type, create_events, free_buffers, NULL),
BENCH_INFO(event_subtype, create_events, free_buffers, NULL),
BENCH_INFO(event_types, create_events, free_buffers, NULL),
BENCH_INFO(event_types_multi, create_events_multi, free_buffers_multi, NULL),
BENCH_INFO(event_types_multi_no_sub, create_events_multi, free_buffers_multi,
"event_types_multi (no sub)"),
BENCH_INFO(event_type_multi, create_events_multi, free_buffers_multi, NULL),
BENCH_INFO(event_pool, create_events, free_buffers, NULL),
BENCH_INFO_COND(event_user_area, create_events, free_buffers, NULL, check_uarea),
BENCH_INFO_COND(event_user_area_and_flag, create_events, free_buffers, NULL, check_uarea),
BENCH_INFO(event_is_valid, create_events, free_buffers, NULL),
BENCH_INFO(event_free, create_events, NULL, NULL),
BENCH_INFO(event_free_multi, create_events_multi, NULL, NULL),
BENCH_INFO(event_free_sp, create_events_multi, NULL, NULL),
BENCH_INFO_COND(event_flow_id, create_events, free_buffers, NULL, check_flow_aware),
BENCH_INFO_COND(event_flow_id_set, create_events, free_buffers, NULL, check_flow_aware),
};
ODP_STATIC_ASSERT(ODPH_ARRAY_SIZE(test_suite) < TEST_MAX_BENCH,
"Result array is too small to hold all the results");
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;
int cpu;
odp_shm_t shm;
odp_cpumask_t cpumask, default_mask;
odp_instance_t instance;
odp_init_t init_param;
uint32_t buf_num;
uint8_t ret;
/* Let helper collect its own arguments (e.g. --odph_proc) */
argc = odph_parse_options(argc, argv);
if (odph_options(&helper_options)) {
ODPH_ERR("Error: reading ODP helper options failed\n");
exit(EXIT_FAILURE);
}
argc = test_common_parse_options(argc, argv);
if (test_common_options(&common_options)) {
ODPH_ERR("Error: reading test options failed\n");
exit(EXIT_FAILURE);
}
odp_init_param_init(&init_param);
init_param.mem_model = helper_options.mem_model;
/* Init ODP before calling anything else */
if (odp_init_global(&instance, &init_param, NULL)) {
ODPH_ERR("Error: ODP global init failed\n");
exit(EXIT_FAILURE);
}
/* Init this thread */
ODPH_ERR("Error: ODP local init failed\n");
exit(EXIT_FAILURE);
}
/* Reserve memory for args from shared mem */
shm = odp_shm_reserve("shm_args", sizeof(args_t), ODP_CACHE_LINE_SIZE, 0);
if (shm == ODP_SHM_INVALID) {
ODPH_ERR("Error: shared mem reserve failed\n");
exit(EXIT_FAILURE);
}
gbl_args = odp_shm_addr(shm);
if (gbl_args == NULL) {
ODPH_ERR("Error: shared mem alloc failed\n");
exit(EXIT_FAILURE);
}
memset(gbl_args, 0, sizeof(args_t));
/* Parse and store the application arguments */
parse_args(argc, argv, &gbl_args->appl);
bench_suite_init(&gbl_args->suite);
gbl_args->suite.bench = test_suite;
gbl_args->suite.num_bench = ODPH_ARRAY_SIZE(test_suite);
gbl_args->suite.indef_idx = gbl_args->appl.bench_idx;
gbl_args->suite.rounds = gbl_args->appl.rounds;
gbl_args->suite.repeat_count = TEST_REPEAT_COUNT;
gbl_args->suite.measure_time = !!gbl_args->appl.time;
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("Error: unable to allocate worker thread\n");
exit(EXIT_FAILURE);
}
(void)odp_cpumask_to_str(&default_mask, gbl_args->cpumask_str,
sizeof(gbl_args->cpumask_str));
if (odp_schedule_capability(&sched_capa)) {
ODPH_ERR("Error: schedule capability failed\n");
exit(EXIT_FAILURE);
}
gbl_args->max_flow_id = 0;
if (sched_capa.max_flow_id) {
odp_schedule_config_t sched_config;
odp_schedule_config_init(&sched_config);
sched_config.max_flow_id = 1;
if (odp_schedule_config(&sched_config)) {
ODPH_ERR("Error: schedule config failed\n");
exit(EXIT_FAILURE);
}
gbl_args->max_flow_id = 1;
}
if (odp_pool_capability(&capa)) {
ODPH_ERR("Error: unable to query pool capability\n");
exit(EXIT_FAILURE);
}
buf_num = gbl_args->appl.burst_size * TEST_REPEAT_COUNT;
if (capa.buf.max_num && capa.buf.max_num < buf_num) {
ODPH_ERR("Error: pool size not supported (max %" PRIu32 ")\n", capa.buf.max_num);
exit(EXIT_FAILURE);
} else if (gbl_args->appl.cache_size > (int)capa.buf.max_cache_size) {
ODPH_ERR("Error: cache size not supported (max %" PRIu32 ")\n",
exit(EXIT_FAILURE);
}
gbl_args->buf_size = TEST_BUF_SIZE;
if (capa.buf.max_size && capa.buf.max_size < TEST_BUF_SIZE)
gbl_args->buf_size = capa.buf.max_size;
gbl_args->uarea_size = TEST_UAREA_SIZE < capa.buf.max_uarea_size ?
TEST_UAREA_SIZE : capa.buf.max_uarea_size;
print_info();
/* Create buffer pool */
params.buf.size = gbl_args->buf_size;
params.buf.num = buf_num;
params.buf.uarea_size = gbl_args->uarea_size;
if (gbl_args->appl.cache_size >= 0)
params.buf.cache_size = gbl_args->appl.cache_size;
gbl_args->pool = odp_pool_create("microbench", &params);
if (gbl_args->pool == ODP_POOL_INVALID) {
ODPH_ERR("Error: pool create failed\n");
exit(EXIT_FAILURE);
}
odp_pool_print(gbl_args->pool);
memset(&worker_thread, 0, sizeof(odph_thread_t));
signal(SIGINT, sig_handler);
/* Create worker thread */
cpu = odp_cpumask_first(&default_mask);
odp_cpumask_zero(&cpumask);
odp_cpumask_set(&cpumask, cpu);
odph_thread_common_param_init(&thr_common);
thr_common.instance = instance;
thr_common.cpumask = &cpumask;
thr_common.share_param = 1;
odph_thread_param_init(&thr_param);
thr_param.start = bench_run;
thr_param.arg = &gbl_args->suite;
thr_param.thr_type = ODP_THREAD_WORKER;
odph_thread_create(&worker_thread, &thr_common, &thr_param, 1);
odph_thread_join(&worker_thread, 1);
ret = gbl_args->suite.retval;
if (ret == 0 && common_options.is_export) {
if (bench_buffer_export(gbl_args)) {
ODPH_ERR("Error: Export failed\n");
ret = -1;
}
}
if (odp_pool_destroy(gbl_args->pool)) {
ODPH_ERR("Error: pool destroy\n");
exit(EXIT_FAILURE);
}
if (odp_shm_free(shm)) {
ODPH_ERR("Error: shm free\n");
exit(EXIT_FAILURE);
}
if (odp_term_local()) {
ODPH_ERR("Error: term local\n");
exit(EXIT_FAILURE);
}
if (odp_term_global(instance)) {
ODPH_ERR("Error: term global\n");
exit(EXIT_FAILURE);
}
return ret;
}
void odp_atomic_store_u32(odp_atomic_u32_t *atom, uint32_t val)
Store value to atomic uint32 variable.
void * odp_buffer_user_area(odp_buffer_t buf)
Buffer user area.
uint32_t odp_buffer_size(odp_buffer_t buf)
Buffer maximum data size.
odp_event_t odp_buffer_to_event(odp_buffer_t buf)
Convert buffer handle to event.
odp_buffer_t odp_buffer_alloc(odp_pool_t pool)
Buffer alloc.
void odp_buffer_free(odp_buffer_t buf)
Buffer free.
int odp_buffer_is_valid(odp_buffer_t buf)
Check that buffer is valid.
void * odp_buffer_addr(odp_buffer_t buf)
Buffer start address.
odp_buffer_t odp_buffer_from_event(odp_event_t ev)
Get buffer handle from event.
int odp_buffer_alloc_multi(odp_pool_t pool, odp_buffer_t buf[], int num)
Allocate multiple buffers.
#define ODP_BUFFER_INVALID
Invalid buffer.
void odp_buffer_free_multi(const odp_buffer_t buf[], int num)
Free multiple buffers.
void odp_buffer_from_event_multi(odp_buffer_t buf[], const odp_event_t ev[], int num)
Convert multiple buffer events to buffer handles.
void odp_buffer_to_event_multi(const odp_buffer_t buf[], odp_event_t ev[], int num)
Convert multiple buffer handles to events.
odp_pool_t odp_buffer_pool(odp_buffer_t buf)
Buffer pool of the buffer.
#define odp_unlikely(x)
Branch unlikely taken.
Definition: spec/hints.h:64
#define ODP_UNUSED
Intentionally unused variables of functions.
Definition: spec/hints.h:54
void odp_cpumask_set(odp_cpumask_t *mask, int cpu)
Add CPU to mask.
int odp_cpumask_default_worker(odp_cpumask_t *mask, int num)
Default CPU mask for worker threads.
int odp_cpumask_first(const odp_cpumask_t *mask)
Find first set CPU in mask.
void odp_cpumask_zero(odp_cpumask_t *mask)
Clear entire CPU mask.
int32_t odp_cpumask_to_str(const odp_cpumask_t *mask, char *str, int32_t size)
Format a string from CPU mask.
#define ODP_CPUMASK_STR_SIZE
The maximum number of characters needed to record any CPU mask as a string (output of odp_cpumask_to_...
void odp_event_free_sp(const odp_event_t event[], int num)
Free multiple events to the same pool.
void odp_event_free_multi(const odp_event_t event[], int num)
Free multiple events.
odp_event_subtype_t odp_event_subtype(odp_event_t event)
Event subtype of an event.
void odp_event_free(odp_event_t event)
Free event.
odp_pool_t odp_event_pool(odp_event_t event)
Event pool.
void odp_event_types_multi(const odp_event_t event[], odp_event_type_t type[], odp_event_subtype_t subtype[], int num)
Event types and subtypes of multiple events.
int odp_event_type_multi(const odp_event_t event[], int num, odp_event_type_t *type)
Event type of multiple events.
odp_event_type_t odp_event_type(odp_event_t event)
Event type of an event.
odp_event_subtype_t
Event subtype.
odp_event_type_t
Event type.
void odp_event_flow_id_set(odp_event_t event, uint32_t flow_id)
Set event flow id value.
uint32_t odp_event_flow_id(odp_event_t event)
Event flow id value.
void * odp_event_user_area(odp_event_t event)
Event user area.
odp_event_type_t odp_event_types(odp_event_t event, odp_event_subtype_t *subtype)
Event type and subtype of an event.
void * odp_event_user_area_and_flag(odp_event_t event, int *flag)
Event user area and flag.
int odp_event_is_valid(odp_event_t event)
Check that event is valid.
void odp_init_param_init(odp_init_t *param)
Initialize the odp_init_t to default values for all fields.
#define ODP_STATIC_ASSERT(cond, msg)
Compile time assertion macro.
int odp_init_local(odp_instance_t instance, odp_thread_type_t thr_type)
Thread local ODP initialization.
int odp_init_global(odp_instance_t *instance, const odp_init_t *params, const odp_platform_init_t *platform_params)
Global ODP initialization.
int odp_term_local(void)
Thread local ODP termination.
int odp_term_global(odp_instance_t instance)
Global ODP termination.
uint64_t odp_instance_t
ODP instance ID.
odp_pool_t odp_pool_create(const char *name, const odp_pool_param_t *param)
Create a pool.
int odp_pool_capability(odp_pool_capability_t *capa)
Query pool capabilities.
void odp_pool_param_init(odp_pool_param_t *param)
Initialize pool params.
int odp_pool_destroy(odp_pool_t pool)
Destroy a pool previously created by odp_pool_create()
void odp_pool_print(odp_pool_t pool)
Print pool info.
#define ODP_POOL_INVALID
Invalid pool.
@ ODP_POOL_BUFFER
Buffer pool.
void odp_schedule_config_init(odp_schedule_config_t *config)
Initialize schedule configuration options.
int odp_schedule_config(const odp_schedule_config_t *config)
Global schedule configuration.
int odp_schedule_capability(odp_schedule_capability_t *capa)
Query scheduler capabilities.
int odp_shm_free(odp_shm_t shm)
Free a contiguous block of shared memory.
#define ODP_SHM_INVALID
Invalid shared memory block.
void * odp_shm_addr(odp_shm_t shm)
Shared memory block address.
odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, uint32_t flags)
Reserve a contiguous block of shared memory.
void odp_sys_info_print(void)
Print system info.
@ ODP_THREAD_WORKER
Worker thread.
@ ODP_THREAD_CONTROL
Control thread.
The OpenDataPlane API.
Global initialization parameters.
odp_mem_model_t mem_model
Application memory model.
struct odp_pool_capability_t::@118 buf
Buffer pool capabilities
uint32_t max_num
Maximum number of buffers of any size.
uint32_t max_uarea_size
Maximum user area size in bytes.
uint32_t max_size
Maximum buffer data size in bytes.
uint32_t max_cache_size
Maximum size of thread local cache.
Pool parameters.
uint32_t uarea_size
Minimum user area size in bytes.
uint32_t num
Number of buffers in the pool.
struct odp_pool_param_t::@122 buf
Parameters for buffer pools.
uint32_t cache_size
Maximum number of buffers cached locally per thread.
uint32_t size
Minimum buffer size in bytes.
odp_pool_type_t type
Pool type.
uint32_t max_flow_id
Maximum flow ID per queue.
Schedule configuration.
uint32_t max_flow_id
Maximum flow ID per queue.