aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorPetri Savolainen <petri.savolainen@nokia.com>2016-03-17 09:58:41 +0200
committerMaxim Uvarov <maxim.uvarov@linaro.org>2016-04-21 18:54:41 +0300
commitdba05a282cf38f11075338323ce698b184085c24 (patch)
tree6ba6a35330c8578c801809a0a4c89610fffaa785 /example
parentbe6a409a665b914b96bad40bb2b8db8c1f9ff0fa (diff)
api: init: add instance handle
Added opaque odp_instance_t handle for storing ODP instance ID. Global init generates instance ID which is used to identify an ODP instance in the system. Instance ID allows to launch multiple separate ODP applications (without name space clash). Application threads define in odp_init_local() call which instance they join. Simultaneously, a thread may belong to only single instance and thus odp_term_local() call does not need instance handle parameter. Currently, linux-generic implementation supports only single instance. Linux helper pthread and process create APIs were updated with instance handle through a new type (odph_linux_thr_param_t). Process API calls were missing thread type selection. A params type decreases number of parameters needed (from 6 to 3 for pthreads) and reduces need for future function prototype changes (if e.g. new parameters need to be added). Signed-off-by: Petri Savolainen <petri.savolainen@nokia.com> Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'example')
-rw-r--r--example/classifier/odp_classifier.c17
-rw-r--r--example/generator/odp_generator.c39
-rw-r--r--example/ipsec/odp_ipsec.c15
-rw-r--r--example/l2fwd_simple/odp_l2fwd_simple.c16
-rw-r--r--example/packet/odp_pktio.c18
-rw-r--r--example/switch/odp_switch.c18
-rw-r--r--example/time/time_global_test.c17
-rw-r--r--example/timer/odp_timer_test.c17
-rw-r--r--example/traffic_mgmt/odp_traffic_mgmt.c5
9 files changed, 116 insertions, 46 deletions
diff --git a/example/classifier/odp_classifier.c b/example/classifier/odp_classifier.c
index abf3d2666..a477e2324 100644
--- a/example/classifier/odp_classifier.c
+++ b/example/classifier/odp_classifier.c
@@ -482,15 +482,17 @@ int main(int argc, char *argv[])
odp_cos_t default_cos;
odp_shm_t shm;
int ret;
+ odp_instance_t instance;
+ odph_linux_thr_params_t thr_params;
/* Init ODP before calling anything else */
- if (odp_init_global(NULL, NULL)) {
+ if (odp_init_global(&instance, NULL, NULL)) {
EXAMPLE_ERR("Error: ODP global init failed.\n");
exit(EXIT_FAILURE);
}
/* Init this thread */
- if (odp_init_local(ODP_THREAD_CONTROL)) {
+ if (odp_init_local(instance, ODP_THREAD_CONTROL)) {
EXAMPLE_ERR("Error: ODP local init failed.\n");
exit(EXIT_FAILURE);
}
@@ -564,6 +566,12 @@ int main(int argc, char *argv[])
/* Create and init worker threads */
memset(thread_tbl, 0, sizeof(thread_tbl));
+ memset(&thr_params, 0, sizeof(thr_params));
+ thr_params.start = pktio_receive_thread;
+ thr_params.arg = args;
+ thr_params.thr_type = ODP_THREAD_WORKER;
+ thr_params.instance = instance;
+
cpu = odp_cpumask_first(&cpumask);
for (i = 0; i < num_workers; ++i) {
odp_cpumask_t thd_mask;
@@ -573,8 +581,7 @@ int main(int argc, char *argv[])
odp_cpumask_zero(&thd_mask);
odp_cpumask_set(&thd_mask, cpu);
odph_linux_pthread_create(&thread_tbl[i], &thd_mask,
- pktio_receive_thread,
- args, ODP_THREAD_WORKER);
+ &thr_params);
cpu = odp_cpumask_next(&cpumask, cpu);
}
@@ -606,7 +613,7 @@ int main(int argc, char *argv[])
ret = odp_term_local();
if (ret)
EXAMPLE_ERR("odp_term_local error %d\n", ret);
- ret = odp_term_global();
+ ret = odp_term_global(instance);
if (ret)
EXAMPLE_ERR("odp_term_global error %d\n", ret);
printf("Exit\n\n");
diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c
index aceee0b55..fd1141a90 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -635,14 +635,16 @@ int main(int argc, char *argv[])
odp_queue_t tq;
odp_event_t ev;
odp_pktio_t *pktio;
+ odp_instance_t instance;
+ odph_linux_thr_params_t thr_params;
/* Init ODP before calling anything else */
- if (odp_init_global(NULL, NULL)) {
+ if (odp_init_global(&instance, NULL, NULL)) {
EXAMPLE_ERR("Error: ODP global init failed.\n");
exit(EXIT_FAILURE);
}
- if (odp_init_local(ODP_THREAD_CONTROL)) {
+ if (odp_init_local(instance, ODP_THREAD_CONTROL)) {
EXAMPLE_ERR("Error: ODP local init failed.\n");
exit(EXIT_FAILURE);
}
@@ -747,6 +749,11 @@ int main(int argc, char *argv[])
/* Create and init worker threads */
memset(thread_tbl, 0, sizeof(thread_tbl));
+ /* Init threads params */
+ memset(&thr_params, 0, sizeof(thr_params));
+ thr_params.thr_type = ODP_THREAD_WORKER;
+ thr_params.instance = instance;
+
/* num workers + print thread */
odp_barrier_init(&barrier, num_workers + 1);
@@ -772,9 +779,15 @@ int main(int argc, char *argv[])
if (args->thread[1].tmo_ev == ODP_TIMEOUT_INVALID)
abort();
args->thread[1].mode = args->appl.mode;
+
+ memset(&thr_params, 0, sizeof(thr_params));
+ thr_params.start = gen_recv_thread;
+ thr_params.arg = &args->thread[1];
+ thr_params.thr_type = ODP_THREAD_WORKER;
+ thr_params.instance = instance;
+
odph_linux_pthread_create(&thread_tbl[1], &cpu_mask,
- gen_recv_thread, &args->thread[1],
- ODP_THREAD_WORKER);
+ &thr_params);
tq = odp_queue_create("", NULL);
if (tq == ODP_QUEUE_INVALID)
@@ -793,9 +806,12 @@ int main(int argc, char *argv[])
cpu_next = odp_cpumask_next(&cpumask, cpu_first);
odp_cpumask_zero(&cpu_mask);
odp_cpumask_set(&cpu_mask, cpu_next);
+
+ thr_params.start = gen_send_thread;
+ thr_params.arg = &args->thread[0];
+
odph_linux_pthread_create(&thread_tbl[0], &cpu_mask,
- gen_send_thread, &args->thread[0],
- ODP_THREAD_WORKER);
+ &thr_params);
} else {
int cpu = odp_cpumask_first(&cpumask);
@@ -836,11 +852,12 @@ int main(int argc, char *argv[])
*/
odp_cpumask_zero(&thd_mask);
odp_cpumask_set(&thd_mask, cpu);
+
+ thr_params.start = thr_run_func;
+ thr_params.arg = &args->thread[i];
+
odph_linux_pthread_create(&thread_tbl[i],
- &thd_mask,
- thr_run_func,
- &args->thread[i],
- ODP_THREAD_WORKER);
+ &thd_mask, &thr_params);
cpu = odp_cpumask_next(&cpumask, cpu);
}
@@ -881,7 +898,7 @@ int main(int argc, char *argv[])
if (0 != odp_pool_destroy(tmop))
fprintf(stderr, "unable to destroy pool \"tmop\"\n");
odp_term_local();
- odp_term_global();
+ odp_term_global(instance);
printf("Exit\n\n");
return 0;
diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
index 2e93fcdbf..05563071d 100644
--- a/example/ipsec/odp_ipsec.c
+++ b/example/ipsec/odp_ipsec.c
@@ -1220,6 +1220,8 @@ main(int argc, char *argv[])
odp_cpumask_t cpumask;
char cpumaskstr[ODP_CPUMASK_STR_SIZE];
odp_pool_param_t params;
+ odp_instance_t instance;
+ odph_linux_thr_params_t thr_params;
/* create by default scheduled queues */
queue_create = odp_queue_create;
@@ -1232,13 +1234,13 @@ main(int argc, char *argv[])
}
/* Init ODP before calling anything else */
- if (odp_init_global(NULL, NULL)) {
+ if (odp_init_global(&instance, NULL, NULL)) {
EXAMPLE_ERR("Error: ODP global init failed.\n");
exit(EXIT_FAILURE);
}
/* Init this thread */
- if (odp_init_local(ODP_THREAD_CONTROL)) {
+ if (odp_init_local(instance, ODP_THREAD_CONTROL)) {
EXAMPLE_ERR("Error: ODP local init failed.\n");
exit(EXIT_FAILURE);
}
@@ -1334,8 +1336,13 @@ main(int argc, char *argv[])
/*
* Create and init worker threads
*/
- odph_linux_pthread_create(thread_tbl, &cpumask,
- pktio_thread, NULL, ODP_THREAD_WORKER);
+ memset(&thr_params, 0, sizeof(thr_params));
+ thr_params.start = pktio_thread;
+ thr_params.arg = NULL;
+ thr_params.thr_type = ODP_THREAD_WORKER;
+ thr_params.instance = instance;
+
+ odph_linux_pthread_create(thread_tbl, &cpumask, &thr_params);
/*
* If there are streams attempt to verify them else
diff --git a/example/l2fwd_simple/odp_l2fwd_simple.c b/example/l2fwd_simple/odp_l2fwd_simple.c
index 11d342f3c..45bb9b198 100644
--- a/example/l2fwd_simple/odp_l2fwd_simple.c
+++ b/example/l2fwd_simple/odp_l2fwd_simple.c
@@ -117,6 +117,8 @@ int main(int argc, char **argv)
odp_pool_param_t params;
odp_cpumask_t cpumask;
odph_linux_pthread_t thd;
+ odp_instance_t instance;
+ odph_linux_thr_params_t thr_params;
if (argc != 5 ||
odph_eth_addr_parse(&global.dst, argv[3]) != 0 ||
@@ -130,12 +132,12 @@ int main(int argc, char **argv)
exit(1);
}
- if (odp_init_global(NULL, NULL)) {
+ if (odp_init_global(&instance, NULL, NULL)) {
printf("Error: ODP global init failed.\n");
exit(1);
}
- if (odp_init_local(ODP_THREAD_CONTROL)) {
+ if (odp_init_local(instance, ODP_THREAD_CONTROL)) {
printf("Error: ODP local init failed.\n");
exit(1);
}
@@ -158,8 +160,14 @@ int main(int argc, char **argv)
global.if1 = create_pktio(argv[2], pool, &global.if1in, &global.if1out);
odp_cpumask_default_worker(&cpumask, 1);
- odph_linux_pthread_create(&thd, &cpumask, run_worker, NULL,
- ODP_THREAD_WORKER);
+
+ memset(&thr_params, 0, sizeof(thr_params));
+ thr_params.start = run_worker;
+ thr_params.arg = NULL;
+ thr_params.thr_type = ODP_THREAD_WORKER;
+ thr_params.instance = instance;
+
+ odph_linux_pthread_create(&thd, &cpumask, &thr_params);
odph_linux_pthread_join(&thd, 1);
return 0;
}
diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c
index dd3e8e3df..f82f01f50 100644
--- a/example/packet/odp_pktio.c
+++ b/example/packet/odp_pktio.c
@@ -346,6 +346,8 @@ int main(int argc, char *argv[])
odp_cpumask_t cpumask;
char cpumaskstr[ODP_CPUMASK_STR_SIZE];
odp_pool_param_t params;
+ odp_instance_t instance;
+ odph_linux_thr_params_t thr_params;
args = calloc(1, sizeof(args_t));
if (args == NULL) {
@@ -357,13 +359,13 @@ int main(int argc, char *argv[])
parse_args(argc, argv, &args->appl);
/* Init ODP before calling anything else */
- if (odp_init_global(NULL, NULL)) {
+ if (odp_init_global(&instance, NULL, NULL)) {
EXAMPLE_ERR("Error: ODP global init failed.\n");
exit(EXIT_FAILURE);
}
/* Init this thread */
- if (odp_init_local(ODP_THREAD_CONTROL)) {
+ if (odp_init_local(instance, ODP_THREAD_CONTROL)) {
EXAMPLE_ERR("Error: ODP local init failed.\n");
exit(EXIT_FAILURE);
}
@@ -406,6 +408,10 @@ int main(int argc, char *argv[])
/* Create and init worker threads */
memset(thread_tbl, 0, sizeof(thread_tbl));
+ memset(&thr_params, 0, sizeof(thr_params));
+ thr_params.thr_type = ODP_THREAD_WORKER;
+ thr_params.instance = instance;
+
cpu = odp_cpumask_first(&cpumask);
for (i = 0; i < num_workers; ++i) {
odp_cpumask_t thd_mask;
@@ -428,10 +434,12 @@ int main(int argc, char *argv[])
*/
odp_cpumask_zero(&thd_mask);
odp_cpumask_set(&thd_mask, cpu);
+
+ thr_params.start = thr_run_func;
+ thr_params.arg = &args->thread[i];
+
odph_linux_pthread_create(&thread_tbl[i], &thd_mask,
- thr_run_func,
- &args->thread[i],
- ODP_THREAD_WORKER);
+ &thr_params);
cpu = odp_cpumask_next(&cpumask, cpu);
}
diff --git a/example/switch/odp_switch.c b/example/switch/odp_switch.c
index 5418bc13f..b0e5b9145 100644
--- a/example/switch/odp_switch.c
+++ b/example/switch/odp_switch.c
@@ -889,15 +889,18 @@ int main(int argc, char **argv)
int ret;
stats_t (*stats)[MAX_PKTIOS];
int if_count;
+ odp_instance_t instance;
+ odph_linux_thr_params_t thr_params;
+
/* Init ODP before calling anything else */
- if (odp_init_global(NULL, NULL)) {
+ if (odp_init_global(&instance, NULL, NULL)) {
printf("Error: ODP global init failed.\n");
exit(EXIT_FAILURE);
}
/* Init this thread */
- if (odp_init_local(ODP_THREAD_CONTROL)) {
+ if (odp_init_local(instance, ODP_THREAD_CONTROL)) {
printf("Error: ODP local init failed.\n");
exit(EXIT_FAILURE);
}
@@ -984,6 +987,11 @@ int main(int argc, char **argv)
stats = gbl_args->stats;
+ memset(&thr_params, 0, sizeof(thr_params));
+ thr_params.thr_type = ODP_THREAD_WORKER;
+ thr_params.instance = instance;
+ thr_params.start = run_worker;
+
/* Create worker threads */
cpu = odp_cpumask_first(&cpumask);
for (i = 0; i < num_workers; ++i) {
@@ -992,12 +1000,12 @@ int main(int argc, char **argv)
for (j = 0; j < MAX_PKTIOS; j++)
gbl_args->thread[i].stats[j] = &stats[i][j];
+ thr_params.arg = &gbl_args->thread[i];
+
odp_cpumask_zero(&thd_mask);
odp_cpumask_set(&thd_mask, cpu);
odph_linux_pthread_create(&thread_tbl[i], &thd_mask,
- run_worker,
- &gbl_args->thread[i],
- ODP_THREAD_WORKER);
+ &thr_params);
cpu = odp_cpumask_next(&cpumask, cpu);
}
diff --git a/example/time/time_global_test.c b/example/time/time_global_test.c
index 16dda4c32..8e3de5ce0 100644
--- a/example/time/time_global_test.c
+++ b/example/time/time_global_test.c
@@ -253,17 +253,19 @@ int main(void)
odp_shm_t shm_log = ODP_SHM_INVALID;
int log_size, log_enries_num;
odph_linux_pthread_t thread_tbl[MAX_WORKERS];
+ odp_instance_t instance;
+ odph_linux_thr_params_t thr_params;
printf("\nODP global time test starts\n");
- if (odp_init_global(NULL, NULL)) {
+ if (odp_init_global(&instance, NULL, NULL)) {
err = 1;
EXAMPLE_ERR("ODP global init failed.\n");
goto end;
}
/* Init this thread. */
- if (odp_init_local(ODP_THREAD_CONTROL)) {
+ if (odp_init_local(instance, ODP_THREAD_CONTROL)) {
err = 1;
EXAMPLE_ERR("ODP local init failed.\n");
goto err_global;
@@ -314,9 +316,14 @@ int main(void)
goto err;
}
+ memset(&thr_params, 0, sizeof(thr_params));
+ thr_params.start = run_thread;
+ thr_params.arg = gbls;
+ thr_params.thr_type = ODP_THREAD_WORKER;
+ thr_params.instance = instance;
+
/* Create and launch worker threads */
- odph_linux_pthread_create(thread_tbl, &cpumask,
- run_thread, gbls, ODP_THREAD_WORKER);
+ odph_linux_pthread_create(thread_tbl, &cpumask, &thr_params);
/* Wait for worker threads to exit */
odph_linux_pthread_join(thread_tbl, num_workers);
@@ -339,7 +346,7 @@ err:
if (odp_term_local())
err = 1;
err_global:
- if (odp_term_global())
+ if (odp_term_global(instance))
err = 1;
end:
if (err) {
diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c
index 4294376e0..f1d3be4bf 100644
--- a/example/timer/odp_timer_test.c
+++ b/example/timer/odp_timer_test.c
@@ -332,20 +332,22 @@ int main(int argc, char *argv[])
odp_timer_pool_info_t tpinfo;
odp_cpumask_t cpumask;
char cpumaskstr[ODP_CPUMASK_STR_SIZE];
+ odp_instance_t instance;
+ odph_linux_thr_params_t thr_params;
odp_shm_t shm = ODP_SHM_INVALID;
test_globals_t *gbls = NULL;
int err = 0;
printf("\nODP timer example starts\n");
- if (odp_init_global(NULL, NULL)) {
+ if (odp_init_global(&instance, NULL, NULL)) {
err = 1;
printf("ODP global init failed.\n");
goto err_global;
}
/* Init this thread. */
- if (odp_init_local(ODP_THREAD_CONTROL)) {
+ if (odp_init_local(instance, ODP_THREAD_CONTROL)) {
err = 1;
printf("ODP local init failed.\n");
goto err_local;
@@ -489,8 +491,13 @@ int main(int argc, char *argv[])
odp_barrier_init(&gbls->test_barrier, num_workers);
/* Create and launch worker threads */
- odph_linux_pthread_create(thread_tbl, &cpumask,
- run_thread, gbls, ODP_THREAD_WORKER);
+ memset(&thr_params, 0, sizeof(thr_params));
+ thr_params.start = run_thread;
+ thr_params.arg = gbls;
+ thr_params.thr_type = ODP_THREAD_WORKER;
+ thr_params.instance = instance;
+
+ odph_linux_pthread_create(thread_tbl, &cpumask, &thr_params);
/* Wait for worker threads to exit */
odph_linux_pthread_join(thread_tbl, num_workers);
@@ -515,7 +522,7 @@ err:
if (odp_term_local())
err = 1;
err_local:
- if (odp_term_global())
+ if (odp_term_global(instance))
err = 1;
err_global:
if (err) {
diff --git a/example/traffic_mgmt/odp_traffic_mgmt.c b/example/traffic_mgmt/odp_traffic_mgmt.c
index 406c396c9..15f585d77 100644
--- a/example/traffic_mgmt/odp_traffic_mgmt.c
+++ b/example/traffic_mgmt/odp_traffic_mgmt.c
@@ -738,6 +738,7 @@ int main(int argc, char *argv[])
struct sigaction signal_action;
struct rlimit rlimit;
uint32_t pkts_into_tm, pkts_from_tm;
+ odp_instance_t instance;
memset(&signal_action, 0, sizeof(signal_action));
signal_action.sa_handler = signal_handler;
@@ -752,8 +753,8 @@ int main(int argc, char *argv[])
rlimit.rlim_cur = rlimit.rlim_max;
setrlimit(RLIMIT_CORE, &rlimit);
- odp_init_global(&ODP_INIT_PARAMS, &PLATFORM_PARAMS);
- odp_init_local(ODP_THREAD_CONTROL);
+ odp_init_global(&instance, &ODP_INIT_PARAMS, &PLATFORM_PARAMS);
+ odp_init_local(instance, ODP_THREAD_CONTROL);
if (process_cmd_line_options(argc, argv) < 0)
return -1;