This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "".
The branch, master has been updated via 66d4b2811d1742dde1a8b84afdf6ab5914bfd1c6 (commit) via 5a9f779843e0140dce38f0d24640f995a6fcc25a (commit) via 6e3954910345b19f596fa35a3427c432ffaa0ecf (commit) via e86f2adb4c33cf047f6521149d67a340288dc8ca (commit) via 32eba5cfc30b0708ffe6819b87fcff50d8c8102b (commit) via 8343da812a20c3e1431e75656d97ff74c82bff41 (commit) via 9cbb27956fffac255bde543e6d52ebb3cc6d589d (commit) via 6b4331e9e3251d54db409a45cac7e5848d30029c (commit) via da173cd050d227730307850830b1d02a76db6d2a (commit) via d2ae9854243a72b7f7bc8c86a7226035c53c37be (commit) via 84507e04c0d1e1cedaa0b83737c0baa8cdf8d265 (commit) via c12678f1712dd291c7ce951243b52287f3028883 (commit) via 07fb2ebf0a16f9ef54b2bdd15c99e2c46eda3afc (commit) via 8002e2b5ce58a532615f9c630e14c793037f8ef7 (commit) via 984ffe3caae07b8d5cd9dab14b7b93ca7d87a87d (commit) via 194f82dac1ff10500ea10d2f25f9c010d67c6e5a (commit) via bfc46064595db98814a70a048ad9d4de70d12e56 (commit) via bb3a47d7eb62cfe50b111b357435f8bd554f374f (commit) via 22dcddaa3dcc82f88b4e9b97a6aa6deb632269f6 (commit) via 9a4f8305e9c90f0ca0e7e4c240eb88d81b864ae0 (commit) from a08beb4afc6b7da7786cd7c827643689c1ee86d0 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- commit 66d4b2811d1742dde1a8b84afdf6ab5914bfd1c6 Author: Matias Elo matias.elo@nokia.com Date: Wed Sep 26 13:31:21 2018 +0300
travis: add process mode test
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/.travis.yml b/.travis.yml index f2b97e4f..16e3a310 100644 --- a/.travis.yml +++ b/.travis.yml @@ -98,6 +98,21 @@ script: fi jobs: include: + - stage: test + env: TEST=process_mode + install: + - true + compiler: gcc + script: + - if [ -z "${DOCKER_NAMESPACE}" ] ; then export DOCKER_NAMESPACE="opendataplane"; fi + - docker run --privileged -i -t + -v `pwd`:/odp --shm-size 8g + -e CODECOV_TOKEN="${CODECOV_TOKEN}" + -e CC="${CC}" + -e CONF="${CONF}" + -e ODP_CONFIG_FILE=/odp/platform/linux-generic/test/process-mode.conf + -e ODPH_PROC_MODE=1 + ${DOCKER_NAMESPACE}/travis-odp-lng-ubuntu_${UBUNTU_VERS} /odp/scripts/ci/check.sh ; - stage: test env: TEST=coverage compiler: gcc
commit 5a9f779843e0140dce38f0d24640f995a6fcc25a Author: Matias Elo matias.elo@nokia.com Date: Wed Sep 26 11:01:51 2018 +0300
linux-gen: test: configuration file for running process mode tests
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/test/process-mode.conf b/platform/linux-generic/test/process-mode.conf new file mode 100644 index 00000000..8618f2fd --- /dev/null +++ b/platform/linux-generic/test/process-mode.conf @@ -0,0 +1,10 @@ +# Mandatory fields +odp_implementation = "linux-generic" +config_file_version = "0.1.0" + +# Shared memory options +shm: { + # Override default option and allocate internal shms using single + # virtual address space. + single_va = 1 +}
commit 6e3954910345b19f596fa35a3427c432ffaa0ecf Author: Matias Elo matias.elo@nokia.com Date: Wed Sep 26 13:25:06 2018 +0300
helper: threads: add ODPH_PROC_MODE environment variable
ODPH_PROC_MODE environment variable can be used to enable process mode. Setting environment variable is simpler in CI compared to using command line arguments.
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/helper/threads.c b/helper/threads.c index 86d6bf7b..f1f63875 100644 --- a/helper/threads.c +++ b/helper/threads.c @@ -10,6 +10,7 @@ #define _GNU_SOURCE #endif #include <sched.h> +#include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/wait.h> @@ -332,10 +333,18 @@ int odph_odpthread_getaffinity(void)
int odph_parse_options(int argc, char *argv[]) { + char *env; int i, j;
helper_options.proc = 0;
+ /* Enable process mode using environment variable. Setting environment + * variable is easier for CI testing compared to command line + * argument. */ + env = getenv("ODPH_PROC_MODE"); + if (env && atoi(env)) + helper_options.proc = 1; + /* Find and remove option */ for (i = 0; i < argc;) { if (strcmp(argv[i], "--odph_proc") == 0) {
commit e86f2adb4c33cf047f6521149d67a340288dc8ca Author: Matias Elo matias.elo@nokia.com Date: Fri Sep 28 13:32:11 2018 +0300
test: mmap_vlan_ins: allocate global data from shm
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/test/mmap_vlan_ins/mmap_vlan_ins.c b/platform/linux-generic/test/mmap_vlan_ins/mmap_vlan_ins.c index cf3d6d93..5066eede 100644 --- a/platform/linux-generic/test/mmap_vlan_ins/mmap_vlan_ins.c +++ b/platform/linux-generic/test/mmap_vlan_ins/mmap_vlan_ins.c @@ -19,14 +19,15 @@ #define MAX_PKT_BURST 32 #define MAX_WORKERS 1
-static int g_ret; - -struct { +typedef struct { odp_pktio_t if0, if1; odp_pktin_queue_t if0in, if1in; odp_pktout_queue_t if0out, if1out; odph_ethaddr_t src, dst; -} global; + int g_ret; +} global_data_t; + +static global_data_t *global;
static odp_pktio_t create_pktio(const char *name, odp_pool_t pool, odp_pktin_queue_t *pktin, @@ -80,12 +81,12 @@ static int run_worker(void *arg ODP_UNUSED) int total_pkts = 0; uint64_t wait_time = odp_pktin_wait_time(2 * ODP_TIME_SEC_IN_NS);
- if (odp_pktio_start(global.if0)) { + if (odp_pktio_start(global->if0)) { printf("unable to start input interface\n"); exit(1); } printf("started input interface\n"); - if (odp_pktio_start(global.if1)) { + if (odp_pktio_start(global->if1)) { printf("unable to start output interface\n"); exit(1); } @@ -93,7 +94,7 @@ static int run_worker(void *arg ODP_UNUSED) printf("started all\n");
while (1) { - pkts = odp_pktin_recv_tmo(global.if0in, pkt_tbl, MAX_PKT_BURST, + pkts = odp_pktin_recv_tmo(global->if0in, pkt_tbl, MAX_PKT_BURST, wait_time); if (odp_unlikely(pkts <= 0)) { printf("recv tmo!\n"); @@ -109,10 +110,10 @@ static int run_worker(void *arg ODP_UNUSED) return 0; } eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, NULL); - eth->src = global.src; - eth->dst = global.dst; + eth->src = global->src; + eth->dst = global->dst; } - sent = odp_pktout_send(global.if1out, pkt_tbl, pkts); + sent = odp_pktout_send(global->if1out, pkt_tbl, pkts); if (sent < 0) sent = 0; total_pkts += sent; @@ -124,7 +125,7 @@ static int run_worker(void *arg ODP_UNUSED) printf("Total send packets: %d\n", total_pkts);
if (total_pkts < 10) - g_ret = -1; + global->g_ret = -1;
return 0; } @@ -137,6 +138,8 @@ int main(int argc, char **argv) odph_odpthread_t thd[MAX_WORKERS]; odp_instance_t instance; odph_odpthread_params_t thr_params; + odp_shm_t shm; + int ret;
/* let helper collect its own arguments (e.g. --odph_proc) */ argc = odph_parse_options(argc, argv); @@ -157,6 +160,17 @@ int main(int argc, char **argv) exit(1); }
+ /* Reserve memory for args from shared mem */ + shm = odp_shm_reserve("_appl_global_data", sizeof(global_data_t), + ODP_CACHE_LINE_SIZE, 0); + global = odp_shm_addr(shm); + if (global == NULL) { + printf("Error: shared mem alloc failed.\n"); + exit(EXIT_FAILURE); + } + + memset(global, 0, sizeof(global_data_t)); + /* Create packet pool */ odp_pool_param_init(¶ms); params.pkt.seg_len = POOL_SEG_LEN; @@ -171,8 +185,10 @@ int main(int argc, char **argv) exit(1); }
- global.if0 = create_pktio(argv[1], pool, &global.if0in, &global.if0out); - global.if1 = create_pktio(argv[2], pool, &global.if1in, &global.if1out); + global->if0 = create_pktio(argv[1], pool, &global->if0in, + &global->if0out); + global->if1 = create_pktio(argv[2], pool, &global->if1in, + &global->if1out);
odp_cpumask_default_worker(&cpumask, MAX_WORKERS);
@@ -185,11 +201,18 @@ int main(int argc, char **argv) odph_odpthreads_create(thd, &cpumask, &thr_params); odph_odpthreads_join(thd);
+ ret = global->g_ret; + if (odp_pool_destroy(pool)) { printf("Error: pool destroy\n"); exit(EXIT_FAILURE); }
+ if (odp_shm_free(shm)) { + printf("Error: shm free global data\n"); + exit(EXIT_FAILURE); + } + if (odp_term_local()) { printf("Error: term local\n"); exit(EXIT_FAILURE); @@ -200,5 +223,5 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); }
- return g_ret; + return ret; }
commit 32eba5cfc30b0708ffe6819b87fcff50d8c8102b Author: Matias Elo matias.elo@nokia.com Date: Thu Sep 27 16:52:06 2018 +0300
test: ring: allocate global data from shm
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/test/ring/ring_stress.c b/platform/linux-generic/test/ring/ring_stress.c index c9bd5308..ddabffad 100644 --- a/platform/linux-generic/test/ring/ring_stress.c +++ b/platform/linux-generic/test/ring/ring_stress.c @@ -33,12 +33,6 @@ * this many successful enq or deq operations */ #define NUM_BULK_OP ((RING_SIZE / PIECE_BULK) * 100)
-/* - * Since cunit framework cannot work with multi-threading, ask workers - * to save their results for delayed assertion after thread collection. - */ -static int worker_results[MAX_WORKERS]; - /* * Note : make sure that both enqueue and dequeue * operation starts at same time so to avoid data corruption @@ -54,18 +48,42 @@ typedef enum { STRESS_N_M_PRODUCER_CONSUMER } stress_case_t;
+#define GLOBAL_SHM_NAME "RingGlobalShm" + /* worker function declarations */ static int stress_worker(void *_data);
/* global name for later look up in workers' context */ static const char *ring_name = "stress_ring";
-/* barrier to run threads at the same time */ -static odp_barrier_t barrier; +typedef struct { + odp_shm_t shm; + /* Barrier to run threads at the same time */ + odp_barrier_t barrier; + /* + * Since cunit framework cannot work with multi-threading, ask workers + * to save their results for delayed assertion after thread collection. + */ + int worker_results[MAX_WORKERS]; +} global_shared_mem_t; + +static global_shared_mem_t *global_mem;
int ring_test_stress_start(void) { _ring_t *r_stress = NULL; + odp_shm_t shm; + + shm = odp_shm_reserve(GLOBAL_SHM_NAME, sizeof(global_shared_mem_t), 64, + ODP_SHM_SW_ONLY); + if (shm == ODP_SHM_INVALID) { + fprintf(stderr, "Unable reserve memory for global_shm\n"); + return -1; + } + + global_mem = odp_shm_addr(shm); + memset(global_mem, 0, sizeof(global_shared_mem_t)); + global_mem->shm = shm;
/* multiple thread usage scenario, thread or process sharable */ r_stress = _ring_create(ring_name, RING_SIZE, _RING_SHM_PROC); @@ -79,7 +97,11 @@ int ring_test_stress_start(void)
int ring_test_stress_end(void) { - _ring_destroy(ring_name); + if (odp_shm_free(global_mem->shm)) { + fprintf(stderr, "error: odp_shm_free() failed.\n"); + return -1; + } + return 0; }
@@ -90,7 +112,8 @@ void ring_test_stress_1_1_producer_consumer(void) pthrd_arg worker_param;
/* reset results for delayed assertion */ - memset(worker_results, 0, sizeof(worker_results)); + memset(global_mem->worker_results, 0, + sizeof(global_mem->worker_results));
/* request 2 threads to run 1:1 stress */ worker_param.numthrds = odp_cpumask_default_worker(&cpus, 2); @@ -103,7 +126,7 @@ void ring_test_stress_1_1_producer_consumer(void) return; }
- odp_barrier_init(&barrier, 2); + odp_barrier_init(&global_mem->barrier, 2);
/* kick the workers */ odp_cunit_thread_create(stress_worker, &worker_param); @@ -113,7 +136,7 @@ void ring_test_stress_1_1_producer_consumer(void)
/* delayed assertion due to cunit limitation */ for (i = 0; i < worker_param.numthrds; i++) - CU_ASSERT(0 == worker_results[i]); + CU_ASSERT(0 == global_mem->worker_results[i]); }
void ring_test_stress_N_M_producer_consumer(void) @@ -123,7 +146,8 @@ void ring_test_stress_N_M_producer_consumer(void) pthrd_arg worker_param;
/* reset results for delayed assertion */ - memset(worker_results, 0, sizeof(worker_results)); + memset(global_mem->worker_results, 0, + sizeof(global_mem->worker_results));
/* request MAX_WORKERS threads to run N:M stress */ worker_param.numthrds = @@ -141,7 +165,7 @@ void ring_test_stress_N_M_producer_consumer(void) if (worker_param.numthrds & 0x1) worker_param.numthrds -= 1;
- odp_barrier_init(&barrier, worker_param.numthrds); + odp_barrier_init(&global_mem->barrier, worker_param.numthrds);
/* kick the workers */ odp_cunit_thread_create(stress_worker, &worker_param); @@ -151,7 +175,7 @@ void ring_test_stress_N_M_producer_consumer(void)
/* delayed assertion due to cunit limitation */ for (i = 0; i < worker_param.numthrds; i++) - CU_ASSERT(0 == worker_results[i]); + CU_ASSERT(0 == global_mem->worker_results[i]); }
void ring_test_stress_1_N_producer_consumer(void) @@ -214,7 +238,8 @@ static int stress_worker(void *_data) int worker_id = odp_thread_id();
/* save the worker result for delayed assertion */ - result = &worker_results[(worker_id % worker_param->numthrds)]; + result = &global_mem->worker_results[(worker_id % + worker_param->numthrds)];
/* verify ring lookup in worker context */ r_stress = _ring_lookup(ring_name); @@ -223,7 +248,7 @@ static int stress_worker(void *_data) return (*result = -1); }
- odp_barrier_wait(&barrier); + odp_barrier_wait(&global_mem->barrier);
switch (worker_param->testcase) { case STRESS_1_1_PRODUCER_CONSUMER: @@ -242,7 +267,7 @@ static int stress_worker(void *_data) break; }
- odp_barrier_wait(&barrier); + odp_barrier_wait(&global_mem->barrier);
return 0; }
commit 8343da812a20c3e1431e75656d97ff74c82bff41 Author: Matias Elo matias.elo@nokia.com Date: Thu Sep 27 10:28:45 2018 +0300
test: example: allocate global data from shm
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/example/classifier/odp_classifier.c b/example/classifier/odp_classifier.c index 3403647b..26ad67ee 100644 --- a/example/classifier/odp_classifier.c +++ b/example/classifier/odp_classifier.c @@ -73,6 +73,7 @@ typedef struct { unsigned int cpu_count; /**< Number of CPUs to use */ uint32_t time; /**< Number of seconds to run */ char *if_name; /**< pointer to interface names */ + int shutdown; /**< Shutdown threads if !0 */ } appl_args_t;
enum packet_mode { @@ -80,8 +81,6 @@ enum packet_mode { APPL_MODE_REPLY /**< Packet is sent back */ };
-static int shutdown; /**< Shutdown threads if !0 */ - /* helper funcs */ static int drop_err_pkts(odp_packet_t pkt_tbl[], unsigned len); static void swap_pkt_addrs(odp_packet_t pkt_tbl[], unsigned len); @@ -272,7 +271,7 @@ static int pktio_receive_thread(void *arg) for (;;) { odp_pktio_t pktio_tmp;
- if (shutdown) + if (appl->shutdown) break;
/* Use schedule to get buf from any input queue */ @@ -574,7 +573,7 @@ int main(int argc, char *argv[]) print_cls_statistics(args);
odp_pktio_stop(pktio); - shutdown = 1; + args->shutdown = 1; odph_odpthreads_join(thread_tbl);
for (i = 0; i < args->policy_count; i++) { diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index 0785e3ec..4e06115c 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -151,14 +151,13 @@ typedef struct { int thread_cnt; int tx_burst_size; int rx_burst_size; + /** Barrier to sync threads execution */ + odp_barrier_t barrier; } args_t;
/** Global pointer to args */ static args_t *args;
-/** Barrier to sync threads execution */ -static odp_barrier_t barrier; - /** Packet processing function types */ typedef odp_packet_t (*setup_pkt_ref_fn_t)(odp_pool_t, odp_pktout_config_opt_t *); @@ -758,7 +757,7 @@ static int gen_send_thread(void *arg)
printf(" [%02i] created mode: SEND\n", thr);
- odp_barrier_wait(&barrier); + odp_barrier_wait(&args->barrier);
for (;;) { if (thr_args->stop) @@ -929,7 +928,7 @@ static int gen_recv_thread(void *arg) burst_size = args->rx_burst_size;
printf(" [%02i] created mode: RECEIVE SCHEDULER\n", thr); - odp_barrier_wait(&barrier); + odp_barrier_wait(&args->barrier);
for (;;) { if (thr_args->stop) @@ -980,7 +979,7 @@ static int gen_recv_direct_thread(void *arg) burst_size = args->rx_burst_size;
printf(" [%02i] created mode: RECEIVE\n", thr); - odp_barrier_wait(&barrier); + odp_barrier_wait(&args->barrier);
for (;;) { if (thr_args->stop) @@ -1046,7 +1045,7 @@ static void print_global_stats(int num_workers) int verbose_interval = 20, i; odp_thrmask_t thrd_mask;
- odp_barrier_wait(&barrier); + odp_barrier_wait(&args->barrier);
wait = odp_time_local_from_ns(verbose_interval * ODP_TIME_SEC_IN_NS); next = odp_time_sum(odp_time_local(), wait); @@ -1293,7 +1292,7 @@ int main(int argc, char *argv[]) thr_params.instance = instance;
/* num workers + print thread */ - odp_barrier_init(&barrier, num_workers + 1); + odp_barrier_init(&args->barrier, num_workers + 1);
if (args->appl.mode == APPL_MODE_PING) { odp_cpumask_t cpu_mask; diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c index 2624af5d..ee63451c 100644 --- a/example/ipsec/odp_ipsec.c +++ b/example/ipsec/odp_ipsec.c @@ -66,6 +66,8 @@ static int create_stream_db_entry(char *input ODP_UNUSED) /* maximum number of worker threads */ #define MAX_WORKERS (ODP_THREAD_COUNT_MAX - 1)
+#define MAX_POLL_QUEUES 256 + /** * Parsed command line application arguments */ @@ -79,21 +81,30 @@ typedef struct { } appl_args_t;
/** - * Grouping of both parsed CL args and thread specific args - alloc together + * Grouping of both parsed CL args and global application data */ typedef struct { /** Application (parsed) arguments */ appl_args_t appl; -} args_t; + odp_shm_t shm; + odp_pool_t ctx_pool; + odp_pool_t out_pool; + odp_pool_t pkt_pool; + /** ATOMIC queue for IPsec sequence number assignment */ + odp_queue_t seqnumq; + /** ORDERED queue for per packet crypto API completion events */ + odp_queue_t completionq; + /** Synchronize threads before packet processing begins */ + odp_barrier_t sync_barrier; + odp_queue_t poll_queues[MAX_POLL_QUEUES]; + int num_polled_queues; +} global_data_t;
/* helper funcs */ static void parse_args(int argc, char *argv[], appl_args_t *appl_args); static void print_info(char *progname, appl_args_t *appl_args); static void usage(char *progname);
-/** Global pointer to args */ -static args_t *args; - /** * Buffer pool for packet IO */ @@ -101,8 +112,6 @@ static args_t *args; #define SHM_PKT_POOL_BUF_SIZE 4096 #define SHM_PKT_POOL_SIZE (SHM_PKT_POOL_BUF_COUNT * SHM_PKT_POOL_BUF_SIZE)
-static odp_pool_t pkt_pool = ODP_POOL_INVALID; - /** * Buffer pool for crypto session output packets */ @@ -110,17 +119,6 @@ static odp_pool_t pkt_pool = ODP_POOL_INVALID; #define SHM_OUT_POOL_BUF_SIZE 4096 #define SHM_OUT_POOL_SIZE (SHM_OUT_POOL_BUF_COUNT * SHM_OUT_POOL_BUF_SIZE)
-static odp_pool_t out_pool = ODP_POOL_INVALID; - -/** ATOMIC queue for IPsec sequence number assignment */ -static odp_queue_t seqnumq; - -/** ORDERED queue (eventually) for per packet crypto API completion events */ -static odp_queue_t completionq; - -/** Synchronize threads before packet processing begins */ -static odp_barrier_t sync_barrier; - /** * Packet processing states/steps */ @@ -184,7 +182,7 @@ typedef struct { #define SHM_CTX_POOL_BUF_COUNT (SHM_PKT_POOL_BUF_COUNT + SHM_OUT_POOL_BUF_COUNT) #define SHM_CTX_POOL_SIZE (SHM_CTX_POOL_BUF_COUNT * SHM_CTX_POOL_BUF_SIZE)
-static odp_pool_t ctx_pool = ODP_POOL_INVALID; +static global_data_t *global;
/** * Get per packet processing context from packet buffer @@ -210,7 +208,7 @@ pkt_ctx_t *get_pkt_ctx_from_pkt(odp_packet_t pkt) static pkt_ctx_t *alloc_pkt_ctx(odp_packet_t pkt) { - odp_buffer_t ctx_buf = odp_buffer_alloc(ctx_pool); + odp_buffer_t ctx_buf = odp_buffer_alloc(global->ctx_pool); pkt_ctx_t *ctx;
if (odp_unlikely(ODP_BUFFER_INVALID == ctx_buf)) @@ -245,11 +243,6 @@ typedef odp_event_t (*schedule_func_t) (odp_queue_t *); static queue_create_func_t queue_create; static schedule_func_t schedule;
-#define MAX_POLL_QUEUES 256 - -static odp_queue_t poll_queues[MAX_POLL_QUEUES]; -static int num_polled_queues; - /** * odp_queue_create wrapper to enable polling versus scheduling */ @@ -275,7 +268,7 @@ odp_queue_t polled_odp_queue_create(const char *name, my_queue = odp_queue_create(name, &qp);
if (ODP_QUEUE_TYPE_SCHED == type) { - poll_queues[num_polled_queues++] = my_queue; + global->poll_queues[global->num_polled_queues++] = my_queue; printf("%s: adding %"PRIu64"\n", __func__, odp_queue_to_u64(my_queue)); } @@ -298,10 +291,10 @@ odp_event_t polled_odp_schedule_cb(odp_queue_t *from) int idx = 0;
while (1) { - if (idx >= num_polled_queues) + if (idx >= global->num_polled_queues) idx = 0;
- odp_queue_t queue = poll_queues[idx++]; + odp_queue_t queue = global->poll_queues[idx++]; odp_event_t buf;
buf = odp_queue_deq(queue); @@ -337,8 +330,8 @@ void ipsec_init_pre(void) qparam.sched.sync = ODP_SCHED_SYNC_ATOMIC; qparam.sched.group = ODP_SCHED_GROUP_ALL;
- completionq = queue_create("completion", &qparam); - if (ODP_QUEUE_INVALID == completionq) { + global->completionq = queue_create("completion", &qparam); + if (ODP_QUEUE_INVALID == global->completionq) { EXAMPLE_ERR("Error: completion queue creation failed\n"); exit(EXIT_FAILURE); } @@ -348,8 +341,8 @@ void ipsec_init_pre(void) qparam.sched.sync = ODP_SCHED_SYNC_ATOMIC; qparam.sched.group = ODP_SCHED_GROUP_ALL;
- seqnumq = queue_create("seqnum", &qparam); - if (ODP_QUEUE_INVALID == seqnumq) { + global->seqnumq = queue_create("seqnum", &qparam); + if (ODP_QUEUE_INVALID == global->seqnumq) { EXAMPLE_ERR("Error: sequence number queue creation failed\n"); exit(EXIT_FAILURE); } @@ -361,9 +354,9 @@ void ipsec_init_pre(void) params.pkt.num = SHM_PKT_POOL_BUF_COUNT; params.type = ODP_POOL_PACKET;
- out_pool = odp_pool_create("out_pool", ¶ms); + global->out_pool = odp_pool_create("out_pool", ¶ms);
- if (ODP_POOL_INVALID == out_pool) { + if (ODP_POOL_INVALID == global->out_pool) { EXAMPLE_ERR("Error: message pool create failed.\n"); exit(EXIT_FAILURE); } @@ -414,8 +407,8 @@ void ipsec_init_post(crypto_api_mode_e api_mode) tun, api_mode, entry->input, - completionq, - out_pool)) { + global->completionq, + global->out_pool)) { EXAMPLE_ERR("Error: IPSec cache entry failed.\n" ); exit(EXIT_FAILURE); @@ -480,7 +473,7 @@ void initialize_intf(char *intf) /* * Open a packet IO instance for thread and get default output queue */ - pktio = odp_pktio_open(intf, pkt_pool, &pktio_param); + pktio = odp_pktio_open(intf, global->pkt_pool, &pktio_param); if (ODP_PKTIO_INVALID == pktio) { EXAMPLE_ERR("Error: pktio create failed for %s\n", intf); exit(EXIT_FAILURE); @@ -1052,7 +1045,7 @@ int pktio_thread(void *arg EXAMPLE_UNUSED)
printf("Pktio thread [%02i] starts\n", thr);
- odp_barrier_wait(&sync_barrier); + odp_barrier_wait(&global->sync_barrier);
/* Loop packets */ for (;;) { @@ -1067,7 +1060,8 @@ int pktio_thread(void *arg EXAMPLE_UNUSED) /* Determine new work versus completion or sequence number */ if (ODP_EVENT_PACKET == odp_event_types(ev, &subtype)) { pkt = odp_packet_from_event(ev); - if (seqnumq == dispatchq || completionq == dispatchq) { + if (global->seqnumq == dispatchq || + global->completionq == dispatchq) { ctx = get_pkt_ctx_from_pkt(pkt); } else { ctx = alloc_pkt_ctx(pkt); @@ -1132,7 +1126,7 @@ int pktio_thread(void *arg EXAMPLE_UNUSED) ctx->state = PKT_STATE_TRANSMIT; } else { ctx->state = PKT_STATE_IPSEC_OUT_SEQ; - if (odp_queue_enq(seqnumq, ev)) + if (odp_queue_enq(global->seqnumq, ev)) rc = PKT_DROP; } break; @@ -1226,16 +1220,17 @@ main(int argc, char *argv[]) }
/* Reserve memory for args from shared mem */ - shm = odp_shm_reserve("shm_args", sizeof(args_t), ODP_CACHE_LINE_SIZE, - 0); + shm = odp_shm_reserve("shm_args", sizeof(global_data_t), + ODP_CACHE_LINE_SIZE, 0);
- args = odp_shm_addr(shm); + global = odp_shm_addr(shm);
- if (NULL == args) { + if (NULL == global) { EXAMPLE_ERR("Error: shared mem alloc failed.\n"); exit(EXIT_FAILURE); } - memset(args, 0, sizeof(*args)); + memset(global, 0, sizeof(global_data_t)); + global->shm = shm;
/* Must init our databases before parsing args */ ipsec_init_pre(); @@ -1243,14 +1238,14 @@ main(int argc, char *argv[]) init_stream_db();
/* Parse and store the application arguments */ - parse_args(argc, argv, &args->appl); + parse_args(argc, argv, &global->appl);
/* Print both system and application information */ - print_info(NO_PATH(argv[0]), &args->appl); + print_info(NO_PATH(argv[0]), &global->appl);
num_workers = MAX_WORKERS; - if (args->appl.cpu_count && args->appl.cpu_count < MAX_WORKERS) - num_workers = args->appl.cpu_count; + if (global->appl.cpu_count && global->appl.cpu_count < MAX_WORKERS) + num_workers = global->appl.cpu_count;
/* Get default worker cpumask */ num_workers = odp_cpumask_default_worker(&cpumask, num_workers); @@ -1261,7 +1256,7 @@ main(int argc, char *argv[]) printf("cpu mask: %s\n", cpumaskstr);
/* Create a barrier to synchronize thread startup */ - odp_barrier_init(&sync_barrier, num_workers); + odp_barrier_init(&global->sync_barrier, num_workers);
/* Create packet buffer pool */ odp_pool_param_init(¶ms); @@ -1270,9 +1265,9 @@ main(int argc, char *argv[]) params.pkt.num = SHM_PKT_POOL_BUF_COUNT; params.type = ODP_POOL_PACKET;
- pkt_pool = odp_pool_create("packet_pool", ¶ms); + global->pkt_pool = odp_pool_create("packet_pool", ¶ms);
- if (ODP_POOL_INVALID == pkt_pool) { + if (ODP_POOL_INVALID == global->pkt_pool) { EXAMPLE_ERR("Error: packet pool create failed.\n"); exit(EXIT_FAILURE); } @@ -1283,24 +1278,23 @@ main(int argc, char *argv[]) params.buf.num = SHM_CTX_POOL_BUF_COUNT; params.type = ODP_POOL_BUFFER;
- ctx_pool = odp_pool_create("ctx_pool", ¶ms); + global->ctx_pool = odp_pool_create("ctx_pool", ¶ms);
- if (ODP_POOL_INVALID == ctx_pool) { + if (ODP_POOL_INVALID == global->ctx_pool) { EXAMPLE_ERR("Error: context pool create failed.\n"); exit(EXIT_FAILURE); }
/* Populate our IPsec cache */ printf("Using %s mode for crypto API\n\n", - (CRYPTO_API_SYNC == args->appl.mode) ? "SYNC" : - (CRYPTO_API_ASYNC_IN_PLACE == args->appl.mode) ? + (CRYPTO_API_SYNC == global->appl.mode) ? "SYNC" : + (CRYPTO_API_ASYNC_IN_PLACE == global->appl.mode) ? "ASYNC_IN_PLACE" : "ASYNC_NEW_BUFFER"); - ipsec_init_post(args->appl.mode); + ipsec_init_post(global->appl.mode);
/* Initialize interfaces (which resolves FWD DB entries */ - for (i = 0; i < args->appl.if_count; i++) { - initialize_intf(args->appl.if_names[i]); - } + for (i = 0; i < global->appl.if_count; i++) + initialize_intf(global->appl.if_names[i]);
/* If we have test streams build them before starting workers */ resolve_stream_db(); @@ -1331,12 +1325,9 @@ main(int argc, char *argv[]) odph_odpthreads_join(thread_tbl); }
- free(args->appl.if_names); - free(args->appl.if_str); + free(global->appl.if_names); + free(global->appl.if_str);
- shm = odp_shm_lookup("shm_args"); - if (odp_shm_free(shm) != 0) - EXAMPLE_ERR("Error: shm free shm_args failed\n"); shm = odp_shm_lookup("shm_ipsec_cache"); if (odp_shm_free(shm) != 0) EXAMPLE_ERR("Error: shm free shm_ipsec_cache failed\n"); @@ -1355,6 +1346,10 @@ main(int argc, char *argv[]) shm = odp_shm_lookup("stream_db"); if (odp_shm_free(shm) != 0) EXAMPLE_ERR("Error: shm free stream_db failed\n"); + if (odp_shm_free(global->shm)) { + EXAMPLE_ERR("Error: shm free global data failed\n"); + exit(EXIT_FAILURE); + }
printf("Exit\n\n");
diff --git a/example/ipsec_api/odp_ipsec.c b/example/ipsec_api/odp_ipsec.c index f827eeeb..b402002c 100644 --- a/example/ipsec_api/odp_ipsec.c +++ b/example/ipsec_api/odp_ipsec.c @@ -66,6 +66,8 @@ static int create_stream_db_entry(char *input ODP_UNUSED) /* maximum number of worker threads */ #define MAX_WORKERS (ODP_THREAD_COUNT_MAX - 1)
+#define MAX_POLL_QUEUES 256 + /** * Parsed command line application arguments */ @@ -80,21 +82,27 @@ typedef struct { } appl_args_t;
/** - * Grouping of both parsed CL args and thread specific args - alloc together + * Grouping of both parsed CL args and global application data */ typedef struct { /** Application (parsed) arguments */ appl_args_t appl; -} args_t; + odp_shm_t shm; + odp_pool_t ctx_pool; + odp_pool_t pkt_pool; + /** ORDERED queue for per packet crypto API completion events */ + odp_queue_t completionq; + /** Synchronize threads before packet processing begins */ + odp_barrier_t sync_barrier; + odp_queue_t poll_queues[MAX_POLL_QUEUES]; + int num_polled_queues; +} global_data_t;
/* helper funcs */ static void parse_args(int argc, char *argv[], appl_args_t *appl_args); static void print_info(char *progname, appl_args_t *appl_args); static void usage(char *progname);
-/** Global pointer to args */ -static args_t *args; - /** * Buffer pool for packet IO */ @@ -102,14 +110,6 @@ static args_t *args; #define SHM_PKT_POOL_BUF_SIZE 4096 #define SHM_PKT_POOL_SIZE (SHM_PKT_POOL_BUF_COUNT * SHM_PKT_POOL_BUF_SIZE)
-static odp_pool_t pkt_pool = ODP_POOL_INVALID; - -/** ORDERED queue (eventually) for per packet crypto API completion events */ -static odp_queue_t completionq = ODP_QUEUE_INVALID; - -/** Synchronize threads before packet processing begins */ -static odp_barrier_t sync_barrier; - /** * Packet processing states/steps */ @@ -146,7 +146,7 @@ typedef struct { #define SHM_CTX_POOL_BUF_COUNT (SHM_PKT_POOL_BUF_COUNT) #define SHM_CTX_POOL_SIZE (SHM_CTX_POOL_BUF_COUNT * SHM_CTX_POOL_BUF_SIZE)
-static odp_pool_t ctx_pool = ODP_POOL_INVALID; +static global_data_t *global;
/** * Allocate per packet processing context and associate it with @@ -159,7 +159,7 @@ static odp_pool_t ctx_pool = ODP_POOL_INVALID; static pkt_ctx_t *alloc_pkt_ctx(odp_packet_t pkt) { - odp_buffer_t ctx_buf = odp_buffer_alloc(ctx_pool); + odp_buffer_t ctx_buf = odp_buffer_alloc(global->ctx_pool); pkt_ctx_t *ctx;
if (odp_unlikely(ODP_BUFFER_INVALID == ctx_buf)) @@ -194,11 +194,6 @@ typedef odp_event_t (*schedule_func_t) (odp_queue_t *); static queue_create_func_t queue_create; static schedule_func_t schedule;
-#define MAX_POLL_QUEUES 256 - -static odp_queue_t poll_queues[MAX_POLL_QUEUES]; -static int num_polled_queues; - /** * odp_queue_create wrapper to enable polling versus scheduling */ @@ -224,7 +219,7 @@ odp_queue_t polled_odp_queue_create(const char *name, my_queue = odp_queue_create(name, &qp);
if (ODP_QUEUE_TYPE_SCHED == type) { - poll_queues[num_polled_queues++] = my_queue; + global->poll_queues[global->num_polled_queues++] = my_queue; printf("%s: adding %" PRIu64 "\n", __func__, odp_queue_to_u64(my_queue)); } @@ -247,10 +242,10 @@ odp_event_t polled_odp_schedule_cb(odp_queue_t *from) int idx = 0;
while (1) { - if (idx >= num_polled_queues) + if (idx >= global->num_polled_queues) idx = 0;
- odp_queue_t queue = poll_queues[idx++]; + odp_queue_t queue = global->poll_queues[idx++]; odp_event_t buf;
buf = odp_queue_deq(queue); @@ -285,8 +280,8 @@ void ipsec_init_pre(void) qparam.sched.sync = ODP_SCHED_SYNC_ATOMIC; qparam.sched.group = ODP_SCHED_GROUP_ALL;
- completionq = queue_create("completion", &qparam); - if (ODP_QUEUE_INVALID == completionq) { + global->completionq = queue_create("completion", &qparam); + if (ODP_QUEUE_INVALID == global->completionq) { EXAMPLE_ERR("Error: completion queue creation failed\n"); exit(EXIT_FAILURE); } @@ -326,7 +321,7 @@ void ipsec_init_post(odp_ipsec_op_mode_t api_mode) ipsec_config.inbound.parse_level = ODP_PROTO_LAYER_ALL; ipsec_config.inbound_mode = api_mode; ipsec_config.outbound_mode = api_mode; - ipsec_config.inbound.default_queue = completionq; + ipsec_config.inbound.default_queue = global->completionq; if (odp_ipsec_config(&ipsec_config) != ODP_IPSEC_OK) { EXAMPLE_ERR("Error: failure setting IPSec config\n"); exit(EXIT_FAILURE); @@ -358,7 +353,7 @@ void ipsec_init_post(odp_ipsec_op_mode_t api_mode) auth_sa, tun, entry->input, - completionq)) { + global->completionq)) { EXAMPLE_ERR("Error: IPSec cache entry failed.\n" ); exit(EXIT_FAILURE); @@ -445,7 +440,7 @@ void initialize_intf(char *intf) /* * Open a packet IO instance for thread and get default output queue */ - pktio = odp_pktio_open(intf, pkt_pool, &pktio_param); + pktio = odp_pktio_open(intf, global->pkt_pool, &pktio_param); if (ODP_PKTIO_INVALID == pktio) { EXAMPLE_ERR("Error: pktio create failed for %s\n", intf); exit(EXIT_FAILURE); @@ -481,10 +476,10 @@ void initialize_intf(char *intf)
odp_pktio_config_init(&config); if (check_stream_db_in(intf) && - args->appl.mode == ODP_IPSEC_OP_MODE_INLINE) + global->appl.mode == ODP_IPSEC_OP_MODE_INLINE) config.inbound_ipsec = capa.config.inbound_ipsec; if (check_stream_db_out(intf) && - args->appl.mode == ODP_IPSEC_OP_MODE_INLINE) + global->appl.mode == ODP_IPSEC_OP_MODE_INLINE) config.outbound_ipsec = capa.config.outbound_ipsec;
if (odp_pktio_config(pktio, &config) != 0) { @@ -571,7 +566,7 @@ pkt_disposition_e do_route_fwd_db(odp_packet_t pkt, pkt_ctx_t *ctx) memcpy(&ctx->eth.src, entry->src_mac, ODPH_ETHADDR_LEN); ctx->eth.type = odp_cpu_to_be_16(ODPH_ETHTYPE_IPV4);
- if (args->appl.mode != ODP_IPSEC_OP_MODE_INLINE) { + if (global->appl.mode != ODP_IPSEC_OP_MODE_INLINE) { odp_packet_l2_offset_set(pkt, 0); odp_packet_copy_from_mem(pkt, 0, ODPH_ETHHDR_LEN, &ctx->eth); @@ -620,7 +615,7 @@ pkt_disposition_e do_ipsec_in_classify(odp_packet_t *ppkt) return PKT_CONTINUE;
memset(&in_param, 0, sizeof(in_param)); - if (args->appl.lookup) { + if (global->appl.lookup) { in_param.num_sa = 0; in_param.sa = NULL; } else { @@ -629,7 +624,7 @@ pkt_disposition_e do_ipsec_in_classify(odp_packet_t *ppkt) }
/* Issue crypto request */ - if (args->appl.mode != ODP_IPSEC_OP_MODE_SYNC) { + if (global->appl.mode != ODP_IPSEC_OP_MODE_SYNC) { rc = odp_ipsec_in_enq(ppkt, 1, &in_param); if (rc <= 0) return PKT_DROP; @@ -682,7 +677,7 @@ pkt_disposition_e do_ipsec_out_classify(odp_packet_t *ppkt, pkt_ctx_t *ctx) out_param.opt = NULL;
/* Issue crypto request */ - if (args->appl.mode == ODP_IPSEC_OP_MODE_INLINE) { + if (global->appl.mode == ODP_IPSEC_OP_MODE_INLINE) { odp_ipsec_out_inline_param_t inline_param;
inline_param.pktio = ctx->pktio; @@ -693,7 +688,7 @@ pkt_disposition_e do_ipsec_out_classify(odp_packet_t *ppkt, pkt_ctx_t *ctx) return PKT_DROP;
return PKT_DONE; - } else if (args->appl.mode != ODP_IPSEC_OP_MODE_SYNC) { + } else if (global->appl.mode != ODP_IPSEC_OP_MODE_SYNC) { rc = odp_ipsec_out_enq(ppkt, 1, &out_param); if (rc <= 0) return PKT_DROP; @@ -737,7 +732,7 @@ int pktio_thread(void *arg EXAMPLE_UNUSED)
printf("Pktio thread [%02i] starts\n", thr);
- odp_barrier_wait(&sync_barrier); + odp_barrier_wait(&global->sync_barrier);
/* Loop packets */ for (;;) { @@ -924,16 +919,17 @@ main(int argc, char *argv[]) }
/* Reserve memory for args from shared mem */ - shm = odp_shm_reserve("shm_args", sizeof(args_t), ODP_CACHE_LINE_SIZE, - 0); + shm = odp_shm_reserve("shm_args", sizeof(global_data_t), + ODP_CACHE_LINE_SIZE, 0);
- args = odp_shm_addr(shm); + global = odp_shm_addr(shm);
- if (NULL == args) { + if (NULL == global) { EXAMPLE_ERR("Error: shared mem alloc failed.\n"); exit(EXIT_FAILURE); } - memset(args, 0, sizeof(*args)); + memset(global, 0, sizeof(global_data_t)); + global->shm = shm;
/* Must init our databases before parsing args */ ipsec_init_pre(); @@ -941,14 +937,14 @@ main(int argc, char *argv[]) init_stream_db();
/* Parse and store the application arguments */ - parse_args(argc, argv, &args->appl); + parse_args(argc, argv, &global->appl);
/* Print both system and application information */ - print_info(NO_PATH(argv[0]), &args->appl); + print_info(NO_PATH(argv[0]), &global->appl);
num_workers = MAX_WORKERS; - if (args->appl.cpu_count && args->appl.cpu_count < MAX_WORKERS) - num_workers = args->appl.cpu_count; + if (global->appl.cpu_count && global->appl.cpu_count < MAX_WORKERS) + num_workers = global->appl.cpu_count;
/* Get default worker cpumask */ num_workers = odp_cpumask_default_worker(&cpumask, num_workers); @@ -959,7 +955,7 @@ main(int argc, char *argv[]) printf("cpu mask: %s\n", cpumaskstr);
/* Create a barrier to synchronize thread startup */ - odp_barrier_init(&sync_barrier, num_workers); + odp_barrier_init(&global->sync_barrier, num_workers);
/* Create packet buffer pool */ odp_pool_param_init(¶ms); @@ -968,9 +964,9 @@ main(int argc, char *argv[]) params.pkt.num = SHM_PKT_POOL_BUF_COUNT; params.type = ODP_POOL_PACKET;
- pkt_pool = odp_pool_create("packet_pool", ¶ms); + global->pkt_pool = odp_pool_create("packet_pool", ¶ms);
- if (ODP_POOL_INVALID == pkt_pool) { + if (ODP_POOL_INVALID == global->pkt_pool) { EXAMPLE_ERR("Error: packet pool create failed.\n"); exit(EXIT_FAILURE); } @@ -981,23 +977,23 @@ main(int argc, char *argv[]) params.buf.num = SHM_CTX_POOL_BUF_COUNT; params.type = ODP_POOL_BUFFER;
- ctx_pool = odp_pool_create("ctx_pool", ¶ms); + global->ctx_pool = odp_pool_create("ctx_pool", ¶ms);
- if (ODP_POOL_INVALID == ctx_pool) { + if (ODP_POOL_INVALID == global->ctx_pool) { EXAMPLE_ERR("Error: context pool create failed.\n"); exit(EXIT_FAILURE); }
/* Populate our IPsec cache */ printf("Using %s mode for IPsec API\n\n", - (ODP_IPSEC_OP_MODE_SYNC == args->appl.mode) ? "SYNC" : - (ODP_IPSEC_OP_MODE_ASYNC == args->appl.mode) ? "ASYNC" : + (ODP_IPSEC_OP_MODE_SYNC == global->appl.mode) ? "SYNC" : + (ODP_IPSEC_OP_MODE_ASYNC == global->appl.mode) ? "ASYNC" : "INLINE"); - ipsec_init_post(args->appl.mode); + ipsec_init_post(global->appl.mode);
/* Initialize interfaces (which resolves FWD DB entries */ - for (i = 0; i < args->appl.if_count; i++) - initialize_intf(args->appl.if_names[i]); + for (i = 0; i < global->appl.if_count; i++) + initialize_intf(global->appl.if_names[i]);
/* If we have test streams build them before starting workers */ resolve_stream_db(); @@ -1029,12 +1025,9 @@ main(int argc, char *argv[]) odph_odpthreads_join(thread_tbl); }
- free(args->appl.if_names); - free(args->appl.if_str); + free(global->appl.if_names); + free(global->appl.if_str);
- shm = odp_shm_lookup("shm_args"); - if (odp_shm_free(shm) != 0) - EXAMPLE_ERR("Error: shm free shm_args failed\n"); shm = odp_shm_lookup("shm_ipsec_cache"); if (odp_shm_free(shm) != 0) EXAMPLE_ERR("Error: shm free shm_ipsec_cache failed\n"); @@ -1053,6 +1046,10 @@ main(int argc, char *argv[]) shm = odp_shm_lookup("stream_db"); if (odp_shm_free(shm) != 0) EXAMPLE_ERR("Error: shm free stream_db failed\n"); + if (odp_shm_free(global->shm)) { + EXAMPLE_ERR("Error: shm free global data failed\n"); + exit(EXIT_FAILURE); + }
printf("Exit\n\n");
diff --git a/example/ipsec_offload/odp_ipsec_offload.c b/example/ipsec_offload/odp_ipsec_offload.c index 63c8f126..89b9dddf 100644 --- a/example/ipsec_offload/odp_ipsec_offload.c +++ b/example/ipsec_offload/odp_ipsec_offload.c @@ -48,6 +48,8 @@ /* maximum number of worker threads */ #define MAX_WORKERS (ODP_THREAD_COUNT_MAX - 1)
+#define MAX_COMPL_QUEUES 32 + /** * Parsed command line application arguments */ @@ -61,12 +63,19 @@ typedef struct { } appl_args_t;
/** - * Grouping of both parsed CL args and thread specific args - alloc together + * Grouping of both parsed CL args and global application data */ typedef struct { /** Application (parsed) arguments */ appl_args_t appl; -} args_t; + odp_pool_t pkt_pool; + /** Atomic queue IPSEC completion events */ + odp_queue_t completionq[MAX_COMPL_QUEUES]; + /** Synchronize threads before packet processing begins */ + odp_barrier_t sync_barrier; + int num_compl_queues; + int num_workers; +} global_data_t;
/* helper funcs */ static void parse_args(int argc, char *argv[], appl_args_t *appl_args); @@ -74,7 +83,7 @@ static void print_info(char *progname, appl_args_t *appl_args); static void usage(char *progname);
/** Global pointer to args */ -static args_t *args; +static global_data_t *global;
/** * Buffer pool for packet IO @@ -83,11 +92,6 @@ static args_t *args; #define SHM_PKT_POOL_BUF_SIZE 4096 #define SHM_PKT_POOL_SIZE (SHM_PKT_POOL_BUF_COUNT * SHM_PKT_POOL_BUF_SIZE)
-static odp_pool_t pkt_pool = ODP_POOL_INVALID; - -/** Synchronize threads before packet processing begins */ -static odp_barrier_t sync_barrier; - /** * Packet processing result codes */ @@ -98,15 +102,8 @@ typedef enum { PKT_DONE /**< Finished with packet, stop processing */ } pkt_disposition_e;
-#define MAX_COMPL_QUEUES 32 #define GET_THR_QUEUE_ID(x) ((odp_thread_id() - 1) % (x))
-/** Atomic queue IPSEC completion events */ -static odp_queue_t completionq[MAX_COMPL_QUEUES]; - -static int num_compl_queues; -static int num_workers; - /** * Calculate hash value on given 2-tuple i.e. sip, dip * @@ -154,9 +151,9 @@ void ipsec_init_post(void) sa_db_entry_t *auth_sa = NULL; tun_db_entry_t *tun = NULL;
- queue_id %= num_workers; - if (num_compl_queues < num_workers) - num_compl_queues++; + queue_id %= global->num_workers; + if (global->num_compl_queues < global->num_workers) + global->num_compl_queues++; queue_id++; if (entry->esp) { cipher_sa = find_sa_db_entry(&entry->src_subnet, @@ -172,11 +169,13 @@ void ipsec_init_post(void) }
if (cipher_sa && auth_sa) { + odp_queue_t queue = global->completionq[queue_id - 1]; + if (create_ipsec_cache_entry(cipher_sa, auth_sa, tun, entry->input, - completionq[queue_id - 1]) + queue) ) { EXAMPLE_ABORT("Error: IPSec cache entry failed.\n"); } @@ -213,7 +212,7 @@ static void initialize_intf(char *intf, int queue_type) /* * Open a packet IO instance for thread and get default output queue */ - pktio = odp_pktio_open(intf, pkt_pool, &pktio_param); + pktio = odp_pktio_open(intf, global->pkt_pool, &pktio_param); if (ODP_PKTIO_INVALID == pktio) EXAMPLE_ABORT("Error: pktio create failed for %s\n", intf);
@@ -431,7 +430,7 @@ int pktio_thread(void *arg EXAMPLE_UNUSED) odp_event_t ev = ODP_EVENT_INVALID;
printf("Pktio thread [%02i] starts\n", thr); - odp_barrier_wait(&sync_barrier); + odp_barrier_wait(&global->sync_barrier);
/* Loop packets */ for (;;) { @@ -523,26 +522,26 @@ main(int argc, char *argv[]) if (odp_init_local(instance, ODP_THREAD_CONTROL)) EXAMPLE_ABORT("Error: ODP local init failed.\n"); /* Reserve memory for arguments from shared memory */ - shm = odp_shm_reserve("shm_args", sizeof(args_t), + shm = odp_shm_reserve("shm_args", sizeof(global_data_t), ODP_CACHE_LINE_SIZE, 0); - args = odp_shm_addr(shm); + global = odp_shm_addr(shm);
- if (NULL == args) + if (NULL == global) EXAMPLE_ABORT("Error: shared mem alloc failed.\n"); - memset(args, 0, sizeof(*args)); + memset(global, 0, sizeof(global_data_t));
/* Must init our databases before parsing args */ ipsec_init_pre(); init_fwd_db();
/* Parse and store the application arguments */ - parse_args(argc, argv, &args->appl); + parse_args(argc, argv, &global->appl);
/*Initialize route table for user given parameter*/ init_routing_table();
/* Print both system and application information */ - print_info(NO_PATH(argv[0]), &args->appl); + print_info(NO_PATH(argv[0]), &global->appl);
if (odp_ipsec_capability(&capa)) EXAMPLE_ABORT("Error: Capability not configured.\n"); @@ -559,15 +558,16 @@ main(int argc, char *argv[]) if (odp_ipsec_config(&config)) EXAMPLE_ABORT("Error: IPSec not configured.\n");
- num_workers = MAX_WORKERS; - if (args->appl.cpu_count && args->appl.cpu_count < MAX_WORKERS) - num_workers = args->appl.cpu_count; + global->num_workers = MAX_WORKERS; + if (global->appl.cpu_count && global->appl.cpu_count < MAX_WORKERS) + global->num_workers = global->appl.cpu_count;
/* * By default CPU #0 runs Linux kernel background tasks. * Start mapping thread from CPU #1 */ - num_workers = odp_cpumask_default_worker(&cpumask, num_workers); + global->num_workers = odp_cpumask_default_worker(&cpumask, + global->num_workers); (void)odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr));
/* @@ -576,20 +576,21 @@ main(int argc, char *argv[]) odp_queue_param_init(&qparam); qparam.type = ODP_QUEUE_TYPE_SCHED; qparam.sched.prio = ODP_SCHED_PRIO_HIGHEST; - qparam.sched.sync = args->appl.queue_type; + qparam.sched.sync = global->appl.queue_type; qparam.sched.group = ODP_SCHED_GROUP_ALL;
- for (i = 0; i < num_workers; i++) { - completionq[i] = odp_queue_create("completion", &qparam); - if (ODP_QUEUE_INVALID == completionq[i]) + for (i = 0; i < global->num_workers; i++) { + global->completionq[i] = odp_queue_create("completion", + &qparam); + if (ODP_QUEUE_INVALID == global->completionq[i]) EXAMPLE_ABORT("Error: completion queue creation failed\n"); } - printf("num worker threads: %i\n", num_workers); + printf("num worker threads: %i\n", global->num_workers); printf("first CPU: %i\n", odp_cpumask_first(&cpumask)); printf("cpu mask: %s\n", cpumaskstr);
/* Create a barrier to synchronize thread startup */ - odp_barrier_init(&sync_barrier, num_workers); + odp_barrier_init(&global->sync_barrier, global->num_workers);
/* Create packet buffer pool */ odp_pool_param_init(¶ms); @@ -598,21 +599,22 @@ main(int argc, char *argv[]) params.pkt.num = SHM_PKT_POOL_BUF_COUNT; params.type = ODP_POOL_PACKET;
- pkt_pool = odp_pool_create("packet_pool", ¶ms); + global->pkt_pool = odp_pool_create("packet_pool", ¶ms);
- if (ODP_POOL_INVALID == pkt_pool) + if (ODP_POOL_INVALID == global->pkt_pool) EXAMPLE_ABORT("Error: packet pool create failed.\n");
ipsec_init_post();
/* Initialize interfaces (which resolves FWD DB entries */ - for (i = 0; i < args->appl.if_count; i++) - initialize_intf(args->appl.if_names[i], args->appl.queue_type); + for (i = 0; i < global->appl.if_count; i++) + initialize_intf(global->appl.if_names[i], + global->appl.queue_type);
printf(" Configured queues SYNC type: [%s]\n", - (args->appl.queue_type == 0) ? + (global->appl.queue_type == 0) ? "PARALLEL" : - (args->appl.queue_type == 1) ? + (global->appl.queue_type == 1) ? "ATOMIC" : "ORDERED"); memset(&thr_params, 0, sizeof(thr_params)); thr_params.start = pktio_thread; @@ -625,8 +627,14 @@ main(int argc, char *argv[]) &thr_params); odph_odpthreads_join(thread_tbl);
- free(args->appl.if_names); - free(args->appl.if_str); + free(global->appl.if_names); + free(global->appl.if_str); + + if (odp_shm_free(shm)) { + EXAMPLE_ERR("Error: shm free global data\n"); + exit(EXIT_FAILURE); + } + printf("Exit\n\n"); return 0; } diff --git a/example/l2fwd_simple/odp_l2fwd_simple.c b/example/l2fwd_simple/odp_l2fwd_simple.c index fcdd8183..6835e5bb 100644 --- a/example/l2fwd_simple/odp_l2fwd_simple.c +++ b/example/l2fwd_simple/odp_l2fwd_simple.c @@ -17,20 +17,22 @@ #define MAX_PKT_BURST 32 #define MAX_WORKERS 1
-static int exit_thr; -static int wait_sec; - -struct { +typedef struct { odp_pktio_t if0, if1; odp_pktin_queue_t if0in, if1in; odp_pktout_queue_t if0out, if1out; odph_ethaddr_t src, dst; -} global; + odp_shm_t shm; + int exit_thr; + int wait_sec; +} global_data_t; + +static global_data_t *global;
static void sig_handler(int signo ODP_UNUSED) { printf("sig_handler!\n"); - exit_thr = 1; + global->exit_thr = 1; }
static odp_pktio_t create_pktio(const char *name, odp_pool_t pool, @@ -89,25 +91,25 @@ static int run_worker(void *arg ODP_UNUSED) int pkts, sent, tx_drops, i; uint64_t wait_time = odp_pktin_wait_time(ODP_TIME_SEC_IN_NS);
- if (odp_pktio_start(global.if0)) { + if (odp_pktio_start(global->if0)) { printf("unable to start input interface\n"); exit(1); } printf("started input interface\n"); - if (odp_pktio_start(global.if1)) { + if (odp_pktio_start(global->if1)) { printf("unable to start output interface\n"); exit(1); } printf("started output interface\n"); printf("started all\n");
- while (!exit_thr) { - pkts = odp_pktin_recv_tmo(global.if0in, pkt_tbl, MAX_PKT_BURST, + while (!global->exit_thr) { + pkts = odp_pktin_recv_tmo(global->if0in, pkt_tbl, MAX_PKT_BURST, wait_time);
if (odp_unlikely(pkts <= 0)) { - if (wait_sec > 0) - if (!(--wait_sec)) + if (global->wait_sec > 0) + if (!(--global->wait_sec)) break; continue; } @@ -121,10 +123,10 @@ static int run_worker(void *arg ODP_UNUSED) return 0; } eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, NULL); - eth->src = global.src; - eth->dst = global.dst; + eth->src = global->src; + eth->dst = global->dst; } - sent = odp_pktout_send(global.if1out, pkt_tbl, pkts); + sent = odp_pktout_send(global->if1out, pkt_tbl, pkts); if (sent < 0) sent = 0; tx_drops = pkts - sent; @@ -145,13 +147,36 @@ int main(int argc, char **argv) odph_odpthread_params_t thr_params; odph_ethaddr_t correct_src; uint32_t mtu1, mtu2; + odp_shm_t shm; + + if (odp_init_global(&instance, NULL, NULL)) { + printf("Error: ODP global init failed.\n"); + exit(1); + } + + if (odp_init_local(instance, ODP_THREAD_CONTROL)) { + printf("Error: ODP local init failed.\n"); + exit(1); + } + + /* Reserve memory for args from shared mem */ + shm = odp_shm_reserve("_appl_global_data", sizeof(global_data_t), + ODP_CACHE_LINE_SIZE, 0); + global = odp_shm_addr(shm); + if (global == NULL) { + printf("Error: shared mem alloc failed.\n"); + exit(EXIT_FAILURE); + } + + memset(global, 0, sizeof(global_data_t)); + global->shm = shm;
/* let helper collect its own arguments (e.g. --odph_proc) */ argc = odph_parse_options(argc, argv);
if (argc > 7 || - odph_eth_addr_parse(&global.dst, argv[3]) != 0 || - odph_eth_addr_parse(&global.src, argv[4]) != 0) { + odph_eth_addr_parse(&global->dst, argv[3]) != 0 || + odph_eth_addr_parse(&global->src, argv[4]) != 0) { printf("Usage: odp_l2fwd_simple eth0 eth1 01:02:03:04:05:06" " 07:08:09:0a:0b:0c [-t sec]\n"); printf("Where eth0 and eth1 are the used interfaces" @@ -161,20 +186,10 @@ int main(int argc, char **argv) exit(1); } if (argc == 7 && !strncmp(argv[5], "-t", 2)) - wait_sec = atoi(argv[6]); - - if (wait_sec) - printf("running test for %d sec\n", wait_sec); - - if (odp_init_global(&instance, NULL, NULL)) { - printf("Error: ODP global init failed.\n"); - exit(1); - } + global->wait_sec = atoi(argv[6]);
- if (odp_init_local(instance, ODP_THREAD_CONTROL)) { - printf("Error: ODP local init failed.\n"); - exit(1); - } + if (global->wait_sec) + printf("running test for %d sec\n", global->wait_sec);
/* Create packet pool */ odp_pool_param_init(¶ms); @@ -190,23 +205,25 @@ int main(int argc, char **argv) exit(1); }
- global.if0 = create_pktio(argv[1], pool, &global.if0in, &global.if0out); - global.if1 = create_pktio(argv[2], pool, &global.if1in, &global.if1out); + global->if0 = create_pktio(argv[1], pool, &global->if0in, + &global->if0out); + global->if1 = create_pktio(argv[2], pool, &global->if1in, + &global->if1out);
/* Do some operations to increase code coverage in tests */ - if (odp_pktio_mac_addr(global.if0, &correct_src, sizeof(correct_src)) + if (odp_pktio_mac_addr(global->if0, &correct_src, sizeof(correct_src)) != sizeof(correct_src)) printf("Warning: can't get MAC address\n"); - else if (memcmp(&correct_src, &global.src, sizeof(correct_src)) != 0) + else if (memcmp(&correct_src, &global->src, sizeof(correct_src)) != 0) printf("Warning: src MAC invalid\n");
- odp_pktio_promisc_mode_set(global.if0, true); - odp_pktio_promisc_mode_set(global.if1, true); - (void)odp_pktio_promisc_mode(global.if0); - (void)odp_pktio_promisc_mode(global.if1); + odp_pktio_promisc_mode_set(global->if0, true); + odp_pktio_promisc_mode_set(global->if1, true); + (void)odp_pktio_promisc_mode(global->if0); + (void)odp_pktio_promisc_mode(global->if1);
- mtu1 = odp_pktin_maxlen(global.if0); - mtu2 = odp_pktout_maxlen(global.if1); + mtu1 = odp_pktin_maxlen(global->if0); + mtu2 = odp_pktout_maxlen(global->if1); if (mtu1 && mtu2 && mtu1 > mtu2) printf("Warning: input MTU bigger than output MTU\n");
@@ -228,6 +245,11 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); }
+ if (odp_shm_free(global->shm)) { + printf("Error: shm free global data\n"); + exit(EXIT_FAILURE); + } + if (odp_term_local()) { printf("Error: term local\n"); exit(EXIT_FAILURE); diff --git a/example/l3fwd/odp_l3fwd.c b/example/l3fwd/odp_l3fwd.c index 34e2bfce..f72cf373 100644 --- a/example/l3fwd/odp_l3fwd.c +++ b/example/l3fwd/odp_l3fwd.c @@ -80,20 +80,24 @@ typedef struct { int error_check; /* Check packets for errors */ } app_args_t;
-struct { +typedef struct { app_args_t cmd_args; struct l3fwd_pktio_s l3fwd_pktios[MAX_NB_PKTIO]; odph_odpthread_t l3fwd_workers[MAX_NB_WORKER]; struct thread_arg_s worker_args[MAX_NB_WORKER]; odph_ethaddr_t eth_dest_mac[MAX_NB_PKTIO]; + /** Global barrier to synchronize main and workers */ + odp_barrier_t barrier; + /** Shm for storing global data */ + odp_shm_t shm; + /** Break workers loop if set to 1 */ + int exit_threads;
/* forward func, hash or lpm */ int (*fwd_func)(odp_packet_t pkt, int sif); -} global; +} global_data_t;
-/** Global barrier to synchronize main and workers */ -static odp_barrier_t barrier; -static int exit_threads; /**< Break workers loop if set to 1 */ +static global_data_t *global;
static int create_pktio(const char *name, odp_pool_t pool, struct l3fwd_pktio_s *fwd_pktio) @@ -122,7 +126,7 @@ static int create_pktio(const char *name, odp_pool_t pool, }
odp_pktio_config_init(&config); - config.parser.layer = global.cmd_args.error_check ? + config.parser.layer = global->cmd_args.error_check ? ODP_PROTO_LAYER_ALL : ODP_PROTO_LAYER_L4; odp_pktio_config(pktio, &config); @@ -145,7 +149,7 @@ static void setup_fwd_db(void) int if_idx; app_args_t *args;
- args = &global.cmd_args; + args = &global->cmd_args; if (args->hash_mode) init_fwd_hash_cache(); else @@ -157,9 +161,9 @@ static void setup_fwd_db(void) fib_tbl_insert(entry->subnet.addr, if_idx, entry->subnet.depth); if (args->dest_mac_changed[if_idx]) - global.eth_dest_mac[if_idx] = entry->dst_mac; + global->eth_dest_mac[if_idx] = entry->dst_mac; else - entry->dst_mac = global.eth_dest_mac[if_idx]; + entry->dst_mac = global->eth_dest_mac[if_idx]; } }
@@ -237,8 +241,8 @@ static inline int l3fwd_pkt_lpm(odp_packet_t pkt, int sif) if (ret) dif = sif;
- eth->dst = global.eth_dest_mac[dif]; - eth->src = global.l3fwd_pktios[dif].mac_addr; + eth->dst = global->eth_dest_mac[dif]; + eth->src = global->l3fwd_pktios[dif].mac_addr;
return dif; } @@ -265,7 +269,7 @@ static inline int drop_err_pkts(odp_packet_t pkt_tbl[], unsigned num) pkt = pkt_tbl[i]; err = 0;
- if (global.cmd_args.error_check) + if (global->cmd_args.error_check) err = odp_packet_has_error(pkt);
if (odp_unlikely(err || !odp_packet_has_ipv4(pkt))) { @@ -286,7 +290,7 @@ static int run_worker(void *arg) odp_pktin_queue_t inq; int input_ifs[thr_arg->nb_pktio]; odp_pktin_queue_t input_queues[thr_arg->nb_pktio]; - odp_pktout_queue_t output_queues[global.cmd_args.if_count]; + odp_pktout_queue_t output_queues[global->cmd_args.if_count]; odp_packet_t pkt_tbl[MAX_PKT_BURST]; odp_packet_t *tbl; int pkts, drop, sent; @@ -296,16 +300,16 @@ static int run_worker(void *arg) int num_pktio = 0;
/* Copy all required handles to local memory */ - for (i = 0; i < global.cmd_args.if_count; i++) { + for (i = 0; i < global->cmd_args.if_count; i++) { int txq_idx = thr_arg->pktio[i].txq_idx;
- output_queues[i] = global.l3fwd_pktios[i].ifout[txq_idx]; + output_queues[i] = global->l3fwd_pktios[i].ifout[txq_idx];
if_idx = thr_arg->pktio[i].if_idx; for (j = 0; j < thr_arg->pktio[i].nb_rxq; j++) { int rxq_idx = thr_arg->pktio[i].rxq[j];
- inq = global.l3fwd_pktios[if_idx].ifin[rxq_idx]; + inq = global->l3fwd_pktios[if_idx].ifin[rxq_idx]; input_ifs[num_pktio] = if_idx; input_queues[num_pktio] = inq; num_pktio++; @@ -318,9 +322,9 @@ static int run_worker(void *arg) if_idx = input_ifs[pktio]; inq = input_queues[pktio];
- odp_barrier_wait(&barrier); + odp_barrier_wait(&global->barrier);
- while (!exit_threads) { + while (!global->exit_threads) { if (num_pktio > 1) { if_idx = input_ifs[pktio]; inq = input_queues[pktio]; @@ -340,12 +344,12 @@ static int run_worker(void *arg) if (odp_unlikely(pkts < 1)) continue;
- dif = global.fwd_func(pkt_tbl[0], if_idx); + dif = global->fwd_func(pkt_tbl[0], if_idx); tbl = &pkt_tbl[0]; while (pkts) { dst_port = dif; for (i = 1; i < pkts; i++) { - dif = global.fwd_func(tbl[i], if_idx); + dif = global->fwd_func(tbl[i], if_idx); if (dif != dst_port) break; } @@ -695,10 +699,10 @@ static void setup_worker_qconf(app_args_t *args) if (!args->qconf_count) { if (nb_worker > if_count) { for (i = 0; i < nb_worker; i++) { - arg = &global.worker_args[i]; + arg = &global->worker_args[i]; arg->thr_idx = i; j = i % if_count; - port = &global.l3fwd_pktios[j]; + port = &global->l3fwd_pktios[j]; arg->pktio[0].rxq[0] = port->rxq_idx % port->nb_rxq; arg->pktio[0].nb_rxq = 1; @@ -709,9 +713,9 @@ static void setup_worker_qconf(app_args_t *args) } else { for (i = 0; i < if_count; i++) { j = i % nb_worker; - arg = &global.worker_args[j]; + arg = &global->worker_args[j]; arg->thr_idx = j; - port = &global.l3fwd_pktios[i]; + port = &global->l3fwd_pktios[i]; rxq_idx = arg->pktio[i].nb_rxq; pktio = arg->nb_pktio; arg->pktio[pktio].rxq[rxq_idx] = @@ -744,7 +748,7 @@ static void setup_worker_qconf(app_args_t *args) q->if_idx, q->rxq_idx, q->core_idx); queue_mask[q->if_idx][q->rxq_idx] = 1;
- port = &global.l3fwd_pktios[q->if_idx]; + port = &global->l3fwd_pktios[q->if_idx]; if (port->rxq_idx < q->rxq_idx) EXAMPLE_ABORT("Error queue (%d, %d, %d), queue should" " be in sequence and start from 0, queue" @@ -760,7 +764,7 @@ static void setup_worker_qconf(app_args_t *args) port->rxq_idx = q->rxq_idx + 1;
/* put the queue into worker_args */ - arg = &global.worker_args[q->core_idx]; + arg = &global->worker_args[q->core_idx];
/* Check if interface already has queues configured */ for (j = 0; j < args->if_count; j++) { @@ -778,9 +782,9 @@ static void setup_worker_qconf(app_args_t *args) } /* distribute tx queues among threads */ for (i = 0; i < args->worker_count; i++) { - arg = &global.worker_args[i]; + arg = &global->worker_args[i]; for (j = 0; j < args->if_count; j++) { - port = &global.l3fwd_pktios[j]; + port = &global->l3fwd_pktios[j]; arg->pktio[j].txq_idx = port->txq_idx % port->nb_txq; port->txq_idx++; @@ -796,7 +800,7 @@ static void setup_worker_qconf(app_args_t *args) const char *name; int nb_rxq, nb_txq;
- port = &global.l3fwd_pktios[i]; + port = &global->l3fwd_pktios[i]; name = args->if_names[i]; odp_pktin_queue_param_init(&in_queue_param); odp_pktout_queue_param_init(&out_queue_param); @@ -855,7 +859,7 @@ static void print_qconf_table(app_args_t *args) "port/id", "rxq", "thread");
for (i = 0; i < args->worker_count; i++) { - thr_arg = &global.worker_args[i]; + thr_arg = &global->worker_args[i]; for (j = 0; j < args->if_count; j++) { if (!thr_arg->pktio[j].nb_rxq) continue; @@ -900,7 +904,7 @@ static int print_speed_stats(int num_workers, int duration, int timeout) timeout = 1; } /* Wait for all threads to be ready*/ - odp_barrier_wait(&barrier); + odp_barrier_wait(&global->barrier);
do { pkts = 0; @@ -909,9 +913,9 @@ static int print_speed_stats(int num_workers, int duration, int timeout) sleep(timeout);
for (i = 0; i < num_workers; i++) { - pkts += global.worker_args[i].packets; - rx_drops += global.worker_args[i].rx_drops; - tx_drops += global.worker_args[i].tx_drops; + pkts += global->worker_args[i].packets; + rx_drops += global->worker_args[i].rx_drops; + tx_drops += global->worker_args[i].tx_drops; } if (stats_enabled) { pps = (pkts - pkts_prev) / timeout; @@ -961,17 +965,28 @@ int main(int argc, char **argv) exit(1); }
- /* Clear global argument and initialize the dest mac as 2:0:0:0:0:x */ - memset(&global, 0, sizeof(global)); + /* Reserve memory for args from shared mem */ + shm = odp_shm_reserve("_appl_global_data", sizeof(global_data_t), + ODP_CACHE_LINE_SIZE, 0); + global = odp_shm_addr(shm); + if (global == NULL) { + printf("Error: shared mem alloc failed.\n"); + exit(EXIT_FAILURE); + } + + memset(global, 0, sizeof(global_data_t)); + global->shm = shm; + + /* Initialize the dest mac as 2:0:0:0:0:x */ mac[0] = 2; for (i = 0; i < MAX_NB_PKTIO; i++) { mac[ODPH_ETHADDR_LEN - 1] = (uint8_t)i; - memcpy(global.eth_dest_mac[i].addr, mac, ODPH_ETHADDR_LEN); + memcpy(global->eth_dest_mac[i].addr, mac, ODPH_ETHADDR_LEN); }
/* Initialize the thread arguments */ for (i = 0; i < MAX_NB_WORKER; i++) { - thr_arg = &global.worker_args[i]; + thr_arg = &global->worker_args[i]; for (j = 0; j < MAX_NB_PKTIO; j++) { thr_arg->thr_idx = INVALID_ID; thr_arg->pktio[j].txq_idx = INVALID_ID; @@ -982,7 +997,7 @@ int main(int argc, char **argv) }
/* Parse cmdline arguments */ - args = &global.cmd_args; + args = &global->cmd_args; parse_cmdline_args(argc, argv, args);
/* Init l3fwd table */ @@ -1030,7 +1045,7 @@ int main(int argc, char **argv) char *if_name;
if_name = args->if_names[i]; - port = &global.l3fwd_pktios[i]; + port = &global->l3fwd_pktios[i]; if (create_pktio(if_name, pool, port)) { printf("Error: create pktio %s\n", if_name); exit(1); @@ -1054,9 +1069,9 @@ int main(int argc, char **argv)
/* Decide ip lookup method */ if (args->hash_mode) - global.fwd_func = l3fwd_pkt_hash; + global->fwd_func = l3fwd_pkt_hash; else - global.fwd_func = l3fwd_pkt_lpm; + global->fwd_func = l3fwd_pkt_lpm;
/* Start all the available ports */ for (i = 0; i < args->if_count; i++) { @@ -1065,7 +1080,7 @@ int main(int argc, char **argv) char buf[32];
if_name = args->if_names[i]; - port = &global.l3fwd_pktios[i]; + port = &global->l3fwd_pktios[i]; /* start pktio */ if (odp_pktio_start(port->pktio)) { printf("unable to start pktio: %s\n", if_name); @@ -1082,7 +1097,7 @@ int main(int argc, char **argv) printf("start pktio: %s, mac %s\n", if_name, buf); }
- odp_barrier_init(&barrier, nb_worker + 1); + odp_barrier_init(&global->barrier, nb_worker + 1);
memset(&thr_params, 0, sizeof(thr_params)); thr_params.start = run_worker; @@ -1095,7 +1110,7 @@ int main(int argc, char **argv) struct thread_arg_s *arg; odp_cpumask_t thr_mask;
- arg = &global.worker_args[i]; + arg = &global->worker_args[i]; odp_cpumask_zero(&thr_mask); odp_cpumask_set(&thr_mask, cpu); thr_params.arg = arg; @@ -1105,7 +1120,7 @@ int main(int argc, char **argv) }
print_speed_stats(nb_worker, args->duration, PRINT_INTERVAL); - exit_threads = 1; + global->exit_threads = 1;
/* wait for other threads to join */ for (i = 0; i < nb_worker; i++) @@ -1138,6 +1153,11 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); }
+ if (odp_shm_free(global->shm)) { + printf("Error: shm free global data\n"); + exit(EXIT_FAILURE); + } + if (odp_term_local()) { printf("Error: term local\n"); exit(EXIT_FAILURE); diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c index 7755efcb..9d96dd2c 100644 --- a/example/packet/odp_pktio.c +++ b/example/packet/odp_pktio.c @@ -85,6 +85,8 @@ typedef struct { typedef struct { /** Application (parsed) arguments */ appl_args_t appl; + /** Shm for global data */ + odp_shm_t shm; /** Thread specific arguments */ thread_args_t thread[MAX_WORKERS]; /** Flag to exit worker threads */ @@ -351,15 +353,7 @@ int main(int argc, char *argv[]) odp_pool_param_t params; odp_instance_t instance; odph_odpthread_params_t thr_params; - - args = calloc(1, sizeof(args_t)); - if (args == NULL) { - EXAMPLE_ERR("Error: args mem alloc failed.\n"); - exit(EXIT_FAILURE); - } - - /* Parse and store the application arguments */ - parse_args(argc, argv, &args->appl); + odp_shm_t shm;
/* Init ODP before calling anything else */ if (odp_init_global(&instance, NULL, NULL)) { @@ -373,6 +367,21 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); }
+ /* Reserve memory for args from shared mem */ + shm = odp_shm_reserve("_appl_global_data", sizeof(args_t), + ODP_CACHE_LINE_SIZE, 0); + args = odp_shm_addr(shm); + if (args == NULL) { + EXAMPLE_ERR("Error: shared mem alloc failed.\n"); + exit(EXIT_FAILURE); + } + + memset(args, 0, sizeof(args_t)); + args->shm = shm; + + /* Parse and store the application arguments */ + parse_args(argc, argv, &args->appl); + /* Print both system and application information */ print_info(NO_PATH(argv[0]), &args->appl);
@@ -467,9 +476,14 @@ int main(int argc, char *argv[])
free(args->appl.if_names); free(args->appl.if_str); - free(args);
odp_pool_destroy(pool); + + if (odp_shm_free(args->shm)) { + EXAMPLE_ERR("Error: shm free global data\n"); + exit(EXIT_FAILURE); + } + odp_term_local(); return odp_term_global(instance); } diff --git a/example/switch/odp_switch.c b/example/switch/odp_switch.c index 18771ea4..dab60e83 100644 --- a/example/switch/odp_switch.c +++ b/example/switch/odp_switch.c @@ -61,8 +61,6 @@ typedef struct { char *if_str; /**< Storage for interface names */ } appl_args_t;
-static int exit_threads; /**< Break workers loop if set to 1 */ - /** * Statistics */ @@ -118,6 +116,10 @@ typedef struct { appl_args_t appl; /**< Parsed application arguments */ thread_args_t thread[MAX_WORKERS]; /**< Thread specific arguments */ odp_pool_t pool; /**< Packet pool */ + /** Global barrier to synchronize main and workers */ + odp_barrier_t barrier; + /** Break workers loop if set to 1 */ + int exit_threads; /** Table of pktio handles */ struct { odp_pktio_t pktio; @@ -136,9 +138,6 @@ typedef struct { /** Global pointer to args */ static args_t *gbl_args;
-/** Global barrier to synchronize main and workers */ -static odp_barrier_t barrier; - /** * Calculate MAC table index using Ethernet address hash * @@ -333,7 +332,7 @@ static int print_speed_stats(int num_workers, stats_t (*thr_stats)[MAX_PKTIOS], timeout = 1; } /* Wait for all threads to be ready*/ - odp_barrier_wait(&barrier); + odp_barrier_wait(&gbl_args->barrier);
do { uint64_t rx_pkts[MAX_PKTIOS] = {0}; @@ -595,9 +594,9 @@ static int run_worker(void *arg) pktin = thr_args->rx_pktio[pktio].pktin; port_in = thr_args->rx_pktio[pktio].port_idx;
- odp_barrier_wait(&barrier); + odp_barrier_wait(&gbl_args->barrier);
- while (!exit_threads) { + while (!gbl_args->exit_threads) { int sent; unsigned drops;
@@ -974,7 +973,7 @@ int main(int argc, char **argv)
memset(thread_tbl, 0, sizeof(thread_tbl));
- odp_barrier_init(&barrier, num_workers + 1); + odp_barrier_init(&gbl_args->barrier, num_workers + 1);
stats = gbl_args->stats;
@@ -1014,7 +1013,7 @@ int main(int argc, char **argv)
ret = print_speed_stats(num_workers, gbl_args->stats, gbl_args->appl.time, gbl_args->appl.accuracy); - exit_threads = 1; + gbl_args->exit_threads = 1;
/* Master thread waits for other threads to exit */ for (i = 0; i < num_workers; ++i)
commit 9cbb27956fffac255bde543e6d52ebb3cc6d589d Author: Matias Elo matias.elo@nokia.com Date: Wed Sep 26 16:41:59 2018 +0300
test: performance: enable testing in process mode
Allocate global data from shm. Minor fix to odp_pktio_ordered_run test script.
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/performance/odp_bench_packet.c b/test/performance/odp_bench_packet.c index b4f1905a..a4493139 100644 --- a/test/performance/odp_bench_packet.c +++ b/test/performance/odp_bench_packet.c @@ -130,6 +130,8 @@ typedef struct { bench_info_t *bench; /** Number of benchmark functions */ int num_bench; + /** Break worker loop if set to 1 */ + int exit_thread; struct { /** Test packet length */ uint32_t len; @@ -166,14 +168,10 @@ typedef struct {
/** Global pointer to args */ static args_t *gbl_args; -/** Global barrier to synchronize main and worker */ -static odp_barrier_t barrier; -/** Break worker loop if set to 1 */ -static int exit_thread;
static void sig_handler(int signo ODP_UNUSED) { - exit_thread = 1; + gbl_args->exit_thread = 1; }
/** @@ -188,7 +186,7 @@ static void run_indef(args_t *args, int idx)
printf("Running %s() indefinitely\n", desc);
- while (!exit_thread) { + while (!gbl_args->exit_thread) { int ret;
if (args->bench[idx].init != NULL) @@ -1623,8 +1621,6 @@ int main(int argc, char *argv[])
memset(&worker_thread, 0, sizeof(odph_odpthread_t));
- odp_barrier_init(&barrier, 1 + 1); - signal(SIGINT, sig_handler);
/* Create worker threads */ diff --git a/test/performance/odp_cpu_bench.c b/test/performance/odp_cpu_bench.c index 949825e9..196af346 100644 --- a/test/performance/odp_cpu_bench.c +++ b/test/performance/odp_cpu_bench.c @@ -95,13 +95,13 @@ typedef struct { odp_queue_t queue[MAX_GROUPS][QUEUES_PER_GROUP]; /* Test lookup table */ lookup_entry_t *lookup_tbl; + /* Break workers loop if set to 1 */ + int exit_threads; } args_t;
/* Global pointer to args */ static args_t *gbl_args;
-static volatile int exit_threads; /* Break workers loop if set to 1 */ - static const uint8_t test_udp_packet[] = { 0x00, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x08, 0x00, 0x45, 0x00, @@ -177,7 +177,7 @@ static const uint8_t test_udp_packet[] = {
static void sig_handler(int signo ODP_UNUSED) { - exit_threads = 1; + gbl_args->exit_threads = 1; }
static inline void init_packet(odp_packet_t pkt, uint32_t seq, uint16_t group) @@ -280,7 +280,7 @@ static int run_thread(void *arg) c1 = odp_cpu_cycles(); t1 = odp_time_local();
- while (!exit_threads) { + while (!gbl_args->exit_threads) { odp_event_t event_tbl[MAX_EVENT_BURST]; odp_queue_t dst_queue; int num_events; @@ -474,9 +474,10 @@ static int print_stats(int num_workers, stats_t **thr_stats, int duration,
pkts_prev = pkts; elapsed += accuracy; - } while (!exit_threads && (loop_forever || (elapsed < duration))); + } while (!gbl_args->exit_threads && + (loop_forever || (elapsed < duration)));
- exit_threads = 1; + gbl_args->exit_threads = 1; odp_barrier_wait(&gbl_args->term_barrier);
pkts = 0; diff --git a/test/performance/odp_l2fwd.c b/test/performance/odp_l2fwd.c index 16336392..e1eddb13 100644 --- a/test/performance/odp_l2fwd.c +++ b/test/performance/odp_l2fwd.c @@ -95,13 +95,6 @@ typedef struct { int verbose; /* Verbose output */ } appl_args_t;
-static int exit_threads; /* Break workers loop if set to 1 */ - -static void sig_handler(int signo ODP_UNUSED) -{ - exit_threads = 1; -} - /* Statistics */ typedef union ODP_ALIGNED_CACHE { struct { @@ -175,12 +168,19 @@ typedef struct { * Table index is pktio_index of the API. This is used by the sched * mode. */ uint8_t dst_port_from_idx[MAX_PKTIO_INDEXES]; + /* Break workers loop if set to 1 */ + int exit_threads;
} args_t;
/* Global pointer to args */ static args_t *gbl_args;
+static void sig_handler(int signo ODP_UNUSED) +{ + gbl_args->exit_threads = 1; +} + /* * Drop packets which input parsing marked as containing errors. * @@ -336,7 +336,7 @@ static int run_worker_sched_mode(void *arg) odp_barrier_wait(&gbl_args->init_barrier);
/* Loop packets */ - while (!exit_threads) { + while (!gbl_args->exit_threads) { odp_event_t ev_tbl[MAX_PKT_BURST]; odp_packet_t pkt_tbl[MAX_PKT_BURST]; int sent; @@ -453,7 +453,7 @@ static int run_worker_plain_queue_mode(void *arg) odp_barrier_wait(&gbl_args->init_barrier);
/* Loop packets */ - while (!exit_threads) { + while (!gbl_args->exit_threads) { int sent; unsigned tx_drops; odp_event_t event[MAX_PKT_BURST]; @@ -579,7 +579,7 @@ static int run_worker_direct_mode(void *arg) odp_barrier_wait(&gbl_args->init_barrier);
/* Loop packets */ - while (!exit_threads) { + while (!gbl_args->exit_threads) { int sent; unsigned tx_drops;
@@ -867,7 +867,8 @@ static int print_speed_stats(int num_workers, stats_t **thr_stats, pkts_prev = pkts; } elapsed += timeout; - } while (!exit_threads && (loop_forever || (elapsed < duration))); + } while (!gbl_args->exit_threads && (loop_forever || + (elapsed < duration)));
if (stats_enabled) printf("TEST RESULT: %" PRIu64 " maximum packets per second.\n", @@ -1682,7 +1683,7 @@ int main(int argc, char *argv[]) } }
- exit_threads = 1; + gbl_args->exit_threads = 1; if (gbl_args->appl.in_mode != DIRECT_RECV) odp_barrier_wait(&gbl_args->term_barrier);
diff --git a/test/performance/odp_pktio_ordered.c b/test/performance/odp_pktio_ordered.c index e884d38a..faf41b02 100644 --- a/test/performance/odp_pktio_ordered.c +++ b/test/performance/odp_pktio_ordered.c @@ -148,8 +148,6 @@ typedef struct { char *if_str; /**< Storage for interface names */ } appl_args_t;
-static int exit_threads; /**< Break workers loop if set to 1 */ - /** * Queue context */ @@ -250,14 +248,15 @@ typedef struct { int num_rx_queue; int num_tx_queue; } pktios[MAX_PKTIOS]; + /** Global barrier to synchronize main and workers */ + odp_barrier_t barrier; + /** Break workers loop if set to 1 */ + int exit_threads; } args_t;
/** Global pointer to args */ static args_t *gbl_args;
-/** Global barrier to synchronize main and workers */ -static odp_barrier_t barrier; - /** * Lookup the destination port for a given packet * @@ -537,10 +536,10 @@ static int run_worker(void *arg) gbl_args->pktios[i].num_tx_queue]; } } - odp_barrier_wait(&barrier); + odp_barrier_wait(&gbl_args->barrier);
/* Loop packets */ - while (!exit_threads) { + while (!gbl_args->exit_threads) { pkts = odp_schedule_multi(&queue, ODP_SCHED_NO_WAIT, ev_tbl, MAX_PKT_BURST); if (pkts <= 0) @@ -732,7 +731,7 @@ static int print_speed_stats(int num_workers, stats_t *thr_stats, timeout = 1; } /* Wait for all threads to be ready*/ - odp_barrier_wait(&barrier); + odp_barrier_wait(&gbl_args->barrier);
do { pkts = 0; @@ -1272,7 +1271,7 @@ int main(int argc, char *argv[])
stats = gbl_args->stats;
- odp_barrier_init(&barrier, num_workers + 1); + odp_barrier_init(&gbl_args->barrier, num_workers + 1);
/* Create worker threads */ cpu = odp_cpumask_first(&cpumask); @@ -1315,7 +1314,7 @@ int main(int argc, char *argv[]) for (i = 0; i < if_count; i++) odp_pktio_stop(gbl_args->pktios[i].pktio);
- exit_threads = 1; + gbl_args->exit_threads = 1;
/* Master thread waits for other threads to exit */ for (i = 0; i < num_workers; ++i) diff --git a/test/performance/odp_pktio_ordered_run.sh b/test/performance/odp_pktio_ordered_run.sh index d7f23812..295b8803 100755 --- a/test/performance/odp_pktio_ordered_run.sh +++ b/test/performance/odp_pktio_ordered_run.sh @@ -31,8 +31,7 @@ fi $STDBUF ${TEST_DIR}/odp_pktio_ordered${EXEEXT} \ -i pcap:in=${PCAP_IN}:loops=$LOOPS,pcap:out=${PCAP_OUT} \ -t $DURATION | tee $LOG - -ret=${PIPESTATUS[0]} +ret=$?
if [ $ret -ne 0 ]; then echo "FAIL: no odp_pktio_ordered${EXEEXT}" diff --git a/test/performance/odp_pktio_perf.c b/test/performance/odp_pktio_perf.c index 7ddf8250..7e8a03ee 100644 --- a/test/performance/odp_pktio_perf.c +++ b/test/performance/odp_pktio_perf.c @@ -125,12 +125,18 @@ typedef struct { odp_barrier_t tx_barrier; odp_pktio_t pktio_tx; odp_pktio_t pktio_rx; + /* Pool from which transmitted packets are allocated */ + odp_pool_t transmit_pkt_pool; pkt_rx_stats_t *rx_stats; pkt_tx_stats_t *tx_stats; uint8_t src_mac[ODPH_ETHADDR_LEN]; uint8_t dst_mac[ODPH_ETHADDR_LEN]; uint32_t rx_stats_size; uint32_t tx_stats_size; + /* Indicate to the receivers to shutdown */ + odp_atomic_u32_t shutdown; + /* Sequence number of IP packets */ + odp_atomic_u32_t ODP_ALIGNED_CACHE ip_seq; } test_globals_t;
/* Status of max rate search */ @@ -152,15 +158,6 @@ typedef struct { odp_u32be_t magic; /* Packet header magic number */ } pkt_head_t;
-/* Pool from which transmitted packets are allocated */ -static odp_pool_t transmit_pkt_pool = ODP_POOL_INVALID; - -/* Sequence number of IP packets */ -static odp_atomic_u32_t ip_seq; - -/* Indicate to the receivers to shutdown */ -static odp_atomic_u32_t shutdown; - /* Application global data */ static test_globals_t *gbl_args;
@@ -180,7 +177,7 @@ static odp_packet_t pktio_create_packet(uint32_t seq)
payload_len = sizeof(pkt_hdr) + gbl_args->args.pkt_len;
- pkt = odp_packet_alloc(transmit_pkt_pool, + pkt = odp_packet_alloc(gbl_args->transmit_pkt_pool, payload_len + ODPH_UDPHDR_LEN + ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN);
@@ -261,7 +258,7 @@ static int alloc_packets(odp_packet_t *pkt_tbl, int num_pkts) int n; uint16_t seq;
- seq = odp_atomic_fetch_add_u32(&ip_seq, num_pkts); + seq = odp_atomic_fetch_add_u32(&gbl_args->ip_seq, num_pkts); for (n = 0; n < num_pkts; ++n) { pkt_tbl[n] = pktio_create_packet(seq + n); if (pkt_tbl[n] == ODP_PACKET_INVALID) @@ -453,7 +450,7 @@ static int run_thread_rx(void *arg) } odp_event_free(ev[i]); } - if (n_ev == 0 && odp_atomic_load_u32(&shutdown)) + if (n_ev == 0 && odp_atomic_load_u32(&gbl_args->shutdown)) break; }
@@ -618,7 +615,7 @@ static int run_test_single(odp_cpumask_t *thd_mask_tx, thr_params.thr_type = ODP_THREAD_WORKER; thr_params.instance = gbl_args->instance;
- odp_atomic_store_u32(&shutdown, 0); + odp_atomic_store_u32(&gbl_args->shutdown, 0);
memset(thd_tbl, 0, sizeof(thd_tbl)); memset(gbl_args->rx_stats, 0, gbl_args->rx_stats_size); @@ -652,7 +649,7 @@ static int run_test_single(odp_cpumask_t *thd_mask_tx, odp_time_wait_ns(SHUTDOWN_DELAY_NS);
/* indicate to the receivers to exit */ - odp_atomic_store_u32(&shutdown, 1); + odp_atomic_store_u32(&gbl_args->shutdown, 1);
/* wait for receivers */ odph_odpthreads_join(&thd_tbl[0]); @@ -751,12 +748,13 @@ static int test_init(void) params.pkt.num = PKT_BUF_NUM; params.type = ODP_POOL_PACKET;
- transmit_pkt_pool = odp_pool_create("pkt_pool_transmit", ¶ms); - if (transmit_pkt_pool == ODP_POOL_INVALID) + gbl_args->transmit_pkt_pool = odp_pool_create("pkt_pool_transmit", + ¶ms); + if (gbl_args->transmit_pkt_pool == ODP_POOL_INVALID) LOG_ABORT("Failed to create transmit pool\n");
- odp_atomic_init_u32(&ip_seq, 0); - odp_atomic_init_u32(&shutdown, 0); + odp_atomic_init_u32(&gbl_args->ip_seq, 0); + odp_atomic_init_u32(&gbl_args->shutdown, 0);
iface = gbl_args->args.ifaces[0]; schedule = gbl_args->args.schedule; @@ -892,7 +890,7 @@ static int test_term(void) } }
- if (odp_pool_destroy(transmit_pkt_pool) != 0) { + if (odp_pool_destroy(gbl_args->transmit_pkt_pool) != 0) { LOG_ERR("Failed to destroy transmit pool\n"); ret = -1; }
commit 6b4331e9e3251d54db409a45cac7e5848d30029c Author: Matias Elo matias.elo@nokia.com Date: Wed Sep 26 15:40:11 2018 +0300
validation: timer: allocate global data from shm
Enables testing in process mode.
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/validation/api/timer/timer.c b/test/validation/api/timer/timer.c index b1b760dc..281e02c5 100644 --- a/test/validation/api/timer/timer.c +++ b/test/validation/api/timer/timer.c @@ -17,6 +17,8 @@ #include "odp_cunit_common.h" #include "test_debug.h"
+#define GLOBAL_SHM_NAME "GlobalTimerTest" + #define MAX(a, b) (((a) > (b)) ? (a) : (b))
/* Timeout range in milliseconds (ms) */ @@ -32,25 +34,6 @@ #define USER_PTR ((void *)0xdead) #define TICK_INVALID (~(uint64_t)0)
-/* Barrier for thread synchronisation */ -static odp_barrier_t test_barrier; - -/* Timeout pool handle used by all threads */ -static odp_pool_t tbp; - -/* Timer pool handle used by all threads */ -static odp_timer_pool_t tp; - -/* Count of timeouts delivered too late */ -static odp_atomic_u32_t ndelivtoolate; - -/* Sum of all allocated timers from all threads. Thread-local - * caches may make this number lower than the capacity of the pool */ -static odp_atomic_u32_t timers_allocated; - -/* Timer resolution in nsec */ -static uint64_t resolution_ns; - /* Timer helper structure */ struct test_timer { odp_timer_t tim; /* Timer handle */ @@ -59,6 +42,72 @@ struct test_timer { uint64_t tick; /* Expiration tick or TICK_INVALID */ };
+typedef struct { + /* Timeout pool handle used by all threads */ + odp_pool_t tbp; + /* Timer pool handle used by all threads */ + odp_timer_pool_t tp; + /* Barrier for thread synchronization */ + odp_barrier_t test_barrier; + /* Count of timeouts delivered too late */ + odp_atomic_u32_t ndelivtoolate; + /* Sum of all allocated timers from all threads. Thread-local + * caches may make this number lower than the capacity of the pool */ + odp_atomic_u32_t timers_allocated; +} global_shared_mem_t; + +static global_shared_mem_t *global_mem; + +static int timer_global_init(odp_instance_t *inst) +{ + odp_shm_t global_shm; + + if (0 != odp_init_global(inst, NULL, NULL)) { + fprintf(stderr, "error: odp_init_global() failed.\n"); + return -1; + } + if (0 != odp_init_local(*inst, ODP_THREAD_CONTROL)) { + fprintf(stderr, "error: odp_init_local() failed.\n"); + return -1; + } + + global_shm = odp_shm_reserve(GLOBAL_SHM_NAME, + sizeof(global_shared_mem_t), + ODP_CACHE_LINE_SIZE, ODP_SHM_SW_ONLY); + if (global_shm == ODP_SHM_INVALID) { + fprintf(stderr, "Unable reserve memory for global_shm\n"); + return -1; + } + + global_mem = odp_shm_addr(global_shm); + memset(global_mem, 0, sizeof(global_shared_mem_t)); + + return 0; +} + +static int timer_global_term(odp_instance_t inst) +{ + odp_shm_t shm; + + shm = odp_shm_lookup(GLOBAL_SHM_NAME); + if (0 != odp_shm_free(shm)) { + fprintf(stderr, "error: odp_shm_free() failed.\n"); + return -1; + } + + if (0 != odp_term_local()) { + fprintf(stderr, "error: odp_term_local() failed.\n"); + return -1; + } + + if (0 != odp_term_global(inst)) { + fprintf(stderr, "error: odp_term_global() failed.\n"); + return -1; + } + + return 0; +} + static void timer_test_timeout_pool_alloc(void) { odp_pool_t pool; @@ -540,7 +589,7 @@ static void handle_tmo(odp_event_t ev, bool stale, uint64_t prev_tick) CU_FAIL("odp_timeout_tick() too small tick"); }
- if (tick > odp_timer_current_tick(tp)) + if (tick > odp_timer_current_tick(global_mem->tp)) CU_FAIL("Timeout delivered early");
if (tick < prev_tick) { @@ -548,7 +597,7 @@ static void handle_tmo(odp_event_t ev, bool stale, uint64_t prev_tick) " prev_tick %" PRIu64"\n", tick, prev_tick); /* We don't report late timeouts using CU_FAIL */ - odp_atomic_inc_u32(&ndelivtoolate); + odp_atomic_inc_u32(&global_mem->ndelivtoolate); } }
@@ -579,6 +628,8 @@ static int worker_entrypoint(void *arg TEST_UNUSED) struct timespec ts; uint32_t nstale; odp_timer_set_t timer_rc; + odp_timer_pool_t tp = global_mem->tp; + odp_pool_t tbp = global_mem->tbp;
queue = odp_queue_create("timer_queue", NULL); if (queue == ODP_QUEUE_INVALID) @@ -609,9 +660,9 @@ static int worker_entrypoint(void *arg TEST_UNUSED) allocated = i; if (allocated == 0) CU_FAIL_FATAL("unable to alloc a timer"); - odp_atomic_fetch_add_u32(&timers_allocated, allocated); + odp_atomic_fetch_add_u32(&global_mem->timers_allocated, allocated);
- odp_barrier_wait(&test_barrier); + odp_barrier_wait(&global_mem->test_barrier);
/* Initial set all timers with a random expiration time */ nset = 0; @@ -771,8 +822,12 @@ static void timer_test_odp_timer_all(void) odp_cpumask_t unused; odp_timer_pool_info_t tpinfo; uint64_t ns, tick, ns2; + uint64_t resolution_ns; + uint32_t timers_allocated; pthrd_arg thrdarg; odp_timer_capability_t timer_capa; + odp_pool_t tbp; + odp_timer_pool_t tp;
/* Reserve at least one core for running other processes so the timer * test hopefully can run undisturbed and thus get better timing @@ -792,9 +847,10 @@ static void timer_test_odp_timer_all(void) params.type = ODP_POOL_TIMEOUT; params.tmo.num = (NTIMERS + 1) * num_workers;
- tbp = odp_pool_create("tmo_pool", ¶ms); - if (tbp == ODP_POOL_INVALID) + global_mem->tbp = odp_pool_create("tmo_pool", ¶ms); + if (global_mem->tbp == ODP_POOL_INVALID) CU_FAIL_FATAL("Timeout pool create failed"); + tbp = global_mem->tbp;
/* Create a timer pool */ if (odp_timer_capability(ODP_CLOCK_CPU, &timer_capa)) @@ -807,9 +863,10 @@ static void timer_test_odp_timer_all(void) tparam.num_timers = num_workers * NTIMERS; tparam.priv = 0; tparam.clk_src = ODP_CLOCK_CPU; - tp = odp_timer_pool_create(NAME, &tparam); - if (tp == ODP_TIMER_POOL_INVALID) + global_mem->tp = odp_timer_pool_create(NAME, &tparam); + if (global_mem->tp == ODP_TIMER_POOL_INVALID) CU_FAIL_FATAL("Timer pool create failed"); + tp = global_mem->tp;
/* Start all created timer pools */ odp_timer_pool_start(); @@ -854,13 +911,13 @@ static void timer_test_odp_timer_all(void) }
/* Initialize barrier used by worker threads for synchronization */ - odp_barrier_init(&test_barrier, num_workers); + odp_barrier_init(&global_mem->test_barrier, num_workers);
/* Initialize the shared timeout counter */ - odp_atomic_init_u32(&ndelivtoolate, 0); + odp_atomic_init_u32(&global_mem->ndelivtoolate, 0);
/* Initialize the number of finally allocated elements */ - odp_atomic_init_u32(&timers_allocated, 0); + odp_atomic_init_u32(&global_mem->timers_allocated, 0);
/* Create and start worker threads */ thrdarg.testcase = 0; @@ -870,14 +927,15 @@ static void timer_test_odp_timer_all(void) /* Wait for worker threads to exit */ odp_cunit_thread_exit(&thrdarg); LOG_DBG("Number of timeouts delivered/received too late: %" PRIu32 "\n", - odp_atomic_load_u32(&ndelivtoolate)); + odp_atomic_load_u32(&global_mem->ndelivtoolate));
/* Check some statistics after the test */ if (odp_timer_pool_info(tp, &tpinfo) != 0) CU_FAIL("odp_timer_pool_info"); CU_ASSERT(tpinfo.param.num_timers == (unsigned)num_workers * NTIMERS); CU_ASSERT(tpinfo.cur_timers == 0); - CU_ASSERT(tpinfo.hwm_timers == odp_atomic_load_u32(&timers_allocated)); + timers_allocated = odp_atomic_load_u32(&global_mem->timers_allocated); + CU_ASSERT(tpinfo.hwm_timers == timers_allocated);
/* Destroy timer pool, all timers must have been freed */ odp_timer_pool_destroy(tp); @@ -911,6 +969,9 @@ int main(int argc, char *argv[]) if (odp_cunit_parse_options(argc, argv)) return -1;
+ odp_cunit_register_global_init(timer_global_init); + odp_cunit_register_global_term(timer_global_term); + int ret = odp_cunit_register(timer_suites);
if (ret == 0)
commit da173cd050d227730307850830b1d02a76db6d2a Author: Matias Elo matias.elo@nokia.com Date: Wed Sep 26 14:46:32 2018 +0300
validation: thread: allocate barriers from shm
Enables testing in process mode.
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/validation/api/thread/thread.c b/test/validation/api/thread/thread.c index 2fab1a7d..d977f977 100644 --- a/test/validation/api/thread/thread.c +++ b/test/validation/api/thread/thread.c @@ -11,9 +11,65 @@ #include <mask_common.h> #include <test_debug.h>
-/* Test thread entry and exit synchronization barriers */ -odp_barrier_t bar_entry; -odp_barrier_t bar_exit; +#define GLOBAL_SHM_NAME "GlobalThreadTest" + +typedef struct { + /* Test thread entry and exit synchronization barriers */ + odp_barrier_t bar_entry; + odp_barrier_t bar_exit; +} global_shared_mem_t; + +static global_shared_mem_t *global_mem; + +static int thread_global_init(odp_instance_t *inst) +{ + odp_shm_t global_shm; + + if (0 != odp_init_global(inst, NULL, NULL)) { + fprintf(stderr, "error: odp_init_global() failed.\n"); + return -1; + } + if (0 != odp_init_local(*inst, ODP_THREAD_CONTROL)) { + fprintf(stderr, "error: odp_init_local() failed.\n"); + return -1; + } + + global_shm = odp_shm_reserve(GLOBAL_SHM_NAME, + sizeof(global_shared_mem_t), + ODP_CACHE_LINE_SIZE, ODP_SHM_SW_ONLY); + if (global_shm == ODP_SHM_INVALID) { + fprintf(stderr, "Unable reserve memory for global_shm\n"); + return -1; + } + + global_mem = odp_shm_addr(global_shm); + memset(global_mem, 0, sizeof(global_shared_mem_t)); + + return 0; +} + +static int thread_global_term(odp_instance_t inst) +{ + odp_shm_t shm; + + shm = odp_shm_lookup(GLOBAL_SHM_NAME); + if (0 != odp_shm_free(shm)) { + fprintf(stderr, "error: odp_shm_free() failed.\n"); + return -1; + } + + if (0 != odp_term_local()) { + fprintf(stderr, "error: odp_term_local() failed.\n"); + return -1; + } + + if (0 != odp_term_global(inst)) { + fprintf(stderr, "error: odp_term_global() failed.\n"); + return -1; + } + + return 0; +}
static void thread_test_odp_cpu_id(void) { @@ -36,12 +92,12 @@ static void thread_test_odp_thread_count(void) static int thread_func(void *arg TEST_UNUSED) { /* indicate that thread has started */ - odp_barrier_wait(&bar_entry); + odp_barrier_wait(&global_mem->bar_entry);
CU_ASSERT(odp_thread_type() == ODP_THREAD_WORKER);
/* wait for indication that we can exit */ - odp_barrier_wait(&bar_exit); + odp_barrier_wait(&global_mem->bar_exit);
return CU_get_number_of_failures(); } @@ -54,8 +110,8 @@ static void thread_test_odp_thrmask_worker(void)
CU_ASSERT_FATAL(odp_thread_type() == ODP_THREAD_CONTROL);
- odp_barrier_init(&bar_entry, args.numthrds + 1); - odp_barrier_init(&bar_exit, args.numthrds + 1); + odp_barrier_init(&global_mem->bar_entry, args.numthrds + 1); + odp_barrier_init(&global_mem->bar_exit, args.numthrds + 1);
/* should start out with 0 worker threads */ ret = odp_thrmask_worker(&mask); @@ -70,7 +126,7 @@ static void thread_test_odp_thrmask_worker(void) return;
/* wait for thread(s) to start */ - odp_barrier_wait(&bar_entry); + odp_barrier_wait(&global_mem->bar_entry);
ret = odp_thrmask_worker(&mask); CU_ASSERT(ret == odp_thrmask_count(&mask)); @@ -78,7 +134,7 @@ static void thread_test_odp_thrmask_worker(void) CU_ASSERT(ret <= odp_thread_count_max());
/* allow thread(s) to exit */ - odp_barrier_wait(&bar_exit); + odp_barrier_wait(&global_mem->bar_exit);
odp_cunit_thread_exit(&args); } @@ -132,6 +188,9 @@ int main(int argc, char *argv[]) if (odp_cunit_parse_options(argc, argv)) return -1;
+ odp_cunit_register_global_init(thread_global_init); + odp_cunit_register_global_term(thread_global_term); + ret = odp_cunit_register(thread_suites);
if (ret == 0)
commit d2ae9854243a72b7f7bc8c86a7226035c53c37be Author: Matias Elo matias.elo@nokia.com Date: Wed Sep 26 14:23:28 2018 +0300
validation: atomic: allocate test variables from shm
Enables testing in process mode.
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/validation/api/atomic/atomic.c b/test/validation/api/atomic/atomic.c index 71af2d12..a755aef9 100644 --- a/test/validation/api/atomic/atomic.c +++ b/test/validation/api/atomic/atomic.c @@ -30,26 +30,22 @@ #define CHECK_MAX_MIN (1 << 0) #define CHECK_XCHG (1 << 2)
-static odp_atomic_u32_t a32u; -static odp_atomic_u64_t a64u; -static odp_atomic_u32_t a32u_min; -static odp_atomic_u32_t a32u_max; -static odp_atomic_u64_t a64u_min; -static odp_atomic_u64_t a64u_max; -static odp_atomic_u32_t a32u_xchg; -static odp_atomic_u64_t a64u_xchg; - typedef __volatile uint32_t volatile_u32_t; typedef __volatile uint64_t volatile_u64_t;
typedef struct { - /* Global variables */ + odp_atomic_u64_t a64u; + odp_atomic_u64_t a64u_min; + odp_atomic_u64_t a64u_max; + odp_atomic_u64_t a64u_xchg; + odp_atomic_u32_t a32u; + odp_atomic_u32_t a32u_min; + odp_atomic_u32_t a32u_max; + odp_atomic_u32_t a32u_xchg; + uint32_t g_num_threads; uint32_t g_iterations; uint32_t g_verbose; - uint32_t g_max_num_cores; - - volatile_u32_t global_lock_owner; } global_shared_mem_t;
/* Per-thread memory */ @@ -101,7 +97,7 @@ static void test_atomic_inc_32(void) int i;
for (i = 0; i < CNT; i++) - odp_atomic_inc_u32(&a32u); + odp_atomic_inc_u32(&global_mem->a32u); }
static void test_atomic_inc_64(void) @@ -109,7 +105,7 @@ static void test_atomic_inc_64(void) int i;
for (i = 0; i < CNT; i++) - odp_atomic_inc_u64(&a64u); + odp_atomic_inc_u64(&global_mem->a64u); }
static void test_atomic_dec_32(void) @@ -117,7 +113,7 @@ static void test_atomic_dec_32(void) int i;
for (i = 0; i < CNT; i++) - odp_atomic_dec_u32(&a32u); + odp_atomic_dec_u32(&global_mem->a32u); }
static void test_atomic_dec_64(void) @@ -125,7 +121,7 @@ static void test_atomic_dec_64(void) int i;
for (i = 0; i < CNT; i++) - odp_atomic_dec_u64(&a64u); + odp_atomic_dec_u64(&global_mem->a64u); }
static void test_atomic_fetch_inc_32(void) @@ -133,7 +129,7 @@ static void test_atomic_fetch_inc_32(void) int i;
for (i = 0; i < CNT; i++) - odp_atomic_fetch_inc_u32(&a32u); + odp_atomic_fetch_inc_u32(&global_mem->a32u); }
static void test_atomic_fetch_inc_64(void) @@ -141,7 +137,7 @@ static void test_atomic_fetch_inc_64(void) int i;
for (i = 0; i < CNT; i++) - odp_atomic_fetch_inc_u64(&a64u); + odp_atomic_fetch_inc_u64(&global_mem->a64u); }
static void test_atomic_fetch_dec_32(void) @@ -149,7 +145,7 @@ static void test_atomic_fetch_dec_32(void) int i;
for (i = 0; i < CNT; i++) - odp_atomic_fetch_dec_u32(&a32u); + odp_atomic_fetch_dec_u32(&global_mem->a32u); }
static void test_atomic_fetch_dec_64(void) @@ -157,7 +153,7 @@ static void test_atomic_fetch_dec_64(void) int i;
for (i = 0; i < CNT; i++) - odp_atomic_fetch_dec_u64(&a64u); + odp_atomic_fetch_dec_u64(&global_mem->a64u); }
static void test_atomic_add_32(void) @@ -165,7 +161,7 @@ static void test_atomic_add_32(void) int i;
for (i = 0; i < CNT; i++) - odp_atomic_add_u32(&a32u, ADD_SUB_CNT); + odp_atomic_add_u32(&global_mem->a32u, ADD_SUB_CNT); }
static void test_atomic_add_64(void) @@ -173,7 +169,7 @@ static void test_atomic_add_64(void) int i;
for (i = 0; i < CNT; i++) - odp_atomic_add_u64(&a64u, ADD_SUB_CNT); + odp_atomic_add_u64(&global_mem->a64u, ADD_SUB_CNT); }
static void test_atomic_sub_32(void) @@ -181,7 +177,7 @@ static void test_atomic_sub_32(void) int i;
for (i = 0; i < CNT; i++) - odp_atomic_sub_u32(&a32u, ADD_SUB_CNT); + odp_atomic_sub_u32(&global_mem->a32u, ADD_SUB_CNT); }
static void test_atomic_sub_64(void) @@ -189,7 +185,7 @@ static void test_atomic_sub_64(void) int i;
for (i = 0; i < CNT; i++) - odp_atomic_sub_u64(&a64u, ADD_SUB_CNT); + odp_atomic_sub_u64(&global_mem->a64u, ADD_SUB_CNT); }
static void test_atomic_fetch_add_32(void) @@ -197,7 +193,7 @@ static void test_atomic_fetch_add_32(void) int i;
for (i = 0; i < CNT; i++) - odp_atomic_fetch_add_u32(&a32u, ADD_SUB_CNT); + odp_atomic_fetch_add_u32(&global_mem->a32u, ADD_SUB_CNT); }
static void test_atomic_fetch_add_64(void) @@ -205,7 +201,7 @@ static void test_atomic_fetch_add_64(void) int i;
for (i = 0; i < CNT; i++) - odp_atomic_fetch_add_u64(&a64u, ADD_SUB_CNT); + odp_atomic_fetch_add_u64(&global_mem->a64u, ADD_SUB_CNT); }
static void test_atomic_fetch_sub_32(void) @@ -213,7 +209,7 @@ static void test_atomic_fetch_sub_32(void) int i;
for (i = 0; i < CNT; i++) - odp_atomic_fetch_sub_u32(&a32u, ADD_SUB_CNT); + odp_atomic_fetch_sub_u32(&global_mem->a32u, ADD_SUB_CNT); }
static void test_atomic_fetch_sub_64(void) @@ -221,7 +217,7 @@ static void test_atomic_fetch_sub_64(void) int i;
for (i = 0; i < CNT; i++) - odp_atomic_fetch_sub_u64(&a64u, ADD_SUB_CNT); + odp_atomic_fetch_sub_u64(&global_mem->a64u, ADD_SUB_CNT); }
static void test_atomic_min_32(void) @@ -230,8 +226,8 @@ static void test_atomic_min_32(void) uint32_t tmp;
for (i = 0; i < CNT; i++) { - tmp = odp_atomic_fetch_dec_u32(&a32u); - odp_atomic_min_u32(&a32u_min, tmp); + tmp = odp_atomic_fetch_dec_u32(&global_mem->a32u); + odp_atomic_min_u32(&global_mem->a32u_min, tmp); } }
@@ -241,8 +237,8 @@ static void test_atomic_min_64(void) uint64_t tmp;
for (i = 0; i < CNT; i++) { - tmp = odp_atomic_fetch_dec_u64(&a64u); - odp_atomic_min_u64(&a64u_min, tmp); + tmp = odp_atomic_fetch_dec_u64(&global_mem->a64u); + odp_atomic_min_u64(&global_mem->a64u_min, tmp); } }
@@ -252,8 +248,8 @@ static void test_atomic_max_32(void) uint32_t tmp;
for (i = 0; i < CNT; i++) { - tmp = odp_atomic_fetch_inc_u32(&a32u); - odp_atomic_max_u32(&a32u_max, tmp); + tmp = odp_atomic_fetch_inc_u32(&global_mem->a32u); + odp_atomic_max_u32(&global_mem->a32u_max, tmp); } }
@@ -263,8 +259,8 @@ static void test_atomic_max_64(void) uint64_t tmp;
for (i = 0; i < CNT; i++) { - tmp = odp_atomic_fetch_inc_u64(&a64u); - odp_atomic_max_u64(&a64u_max, tmp); + tmp = odp_atomic_fetch_inc_u64(&global_mem->a64u); + odp_atomic_max_u64(&global_mem->a64u_max, tmp); } }
@@ -272,11 +268,12 @@ static void test_atomic_cas_inc_32(void) { int i; uint32_t old; + odp_atomic_u32_t *a32u = &global_mem->a32u;
for (i = 0; i < CNT; i++) { - old = odp_atomic_load_u32(&a32u); + old = odp_atomic_load_u32(a32u);
- while (odp_atomic_cas_u32(&a32u, &old, old + 1) == 0) + while (odp_atomic_cas_u32(a32u, &old, old + 1) == 0) ; } } @@ -285,11 +282,12 @@ static void test_atomic_cas_dec_32(void) { int i; uint32_t old; + odp_atomic_u32_t *a32u = &global_mem->a32u;
for (i = 0; i < CNT; i++) { - old = odp_atomic_load_u32(&a32u); + old = odp_atomic_load_u32(a32u);
- while (odp_atomic_cas_u32(&a32u, &old, old - 1) == 0) + while (odp_atomic_cas_u32(a32u, &old, old - 1) == 0) ; } } @@ -298,11 +296,12 @@ static void test_atomic_cas_inc_64(void) { int i; uint64_t old; + odp_atomic_u64_t *a64u = &global_mem->a64u;
for (i = 0; i < CNT; i++) { - old = odp_atomic_load_u64(&a64u); + old = odp_atomic_load_u64(a64u);
- while (odp_atomic_cas_u64(&a64u, &old, old + 1) == 0) + while (odp_atomic_cas_u64(a64u, &old, old + 1) == 0) ; } } @@ -311,11 +310,12 @@ static void test_atomic_cas_dec_64(void) { int i; uint64_t old; + odp_atomic_u64_t *a64u = &global_mem->a64u;
for (i = 0; i < CNT; i++) { - old = odp_atomic_load_u64(&a64u); + old = odp_atomic_load_u64(a64u);
- while (odp_atomic_cas_u64(&a64u, &old, old - 1) == 0) + while (odp_atomic_cas_u64(a64u, &old, old - 1) == 0) ; } } @@ -324,66 +324,74 @@ static void test_atomic_xchg_32(void) { uint32_t old, new; int i; + odp_atomic_u32_t *a32u = &global_mem->a32u; + odp_atomic_u32_t *a32u_xchg = &global_mem->a32u_xchg;
for (i = 0; i < CNT; i++) { - new = odp_atomic_fetch_inc_u32(&a32u); - old = odp_atomic_xchg_u32(&a32u_xchg, new); + new = odp_atomic_fetch_inc_u32(a32u); + old = odp_atomic_xchg_u32(a32u_xchg, new);
if (old & 0x1) - odp_atomic_xchg_u32(&a32u_xchg, 0); + odp_atomic_xchg_u32(a32u_xchg, 0); else - odp_atomic_xchg_u32(&a32u_xchg, 1); + odp_atomic_xchg_u32(a32u_xchg, 1); }
- odp_atomic_sub_u32(&a32u, CNT); - odp_atomic_xchg_u32(&a32u_xchg, U32_MAGIC); + odp_atomic_sub_u32(a32u, CNT); + odp_atomic_xchg_u32(a32u_xchg, U32_MAGIC); }
static void test_atomic_xchg_64(void) { uint64_t old, new; int i; + odp_atomic_u64_t *a64u = &global_mem->a64u; + odp_atomic_u64_t *a64u_xchg = &global_mem->a64u_xchg;
for (i = 0; i < CNT; i++) { - new = odp_atomic_fetch_inc_u64(&a64u); - old = odp_atomic_xchg_u64(&a64u_xchg, new); + new = odp_atomic_fetch_inc_u64(a64u); + old = odp_atomic_xchg_u64(a64u_xchg, new);
if (old & 0x1) - odp_atomic_xchg_u64(&a64u_xchg, 0); + odp_atomic_xchg_u64(a64u_xchg, 0); else - odp_atomic_xchg_u64(&a64u_xchg, 1); + odp_atomic_xchg_u64(a64u_xchg, 1); }
- odp_atomic_sub_u64(&a64u, CNT); - odp_atomic_xchg_u64(&a64u_xchg, U64_MAGIC); + odp_atomic_sub_u64(a64u, CNT); + odp_atomic_xchg_u64(a64u_xchg, U64_MAGIC); }
static void test_atomic_non_relaxed_32(void) { int i; uint32_t tmp; + odp_atomic_u32_t *a32u = &global_mem->a32u; + odp_atomic_u32_t *a32u_min = &global_mem->a32u_min; + odp_atomic_u32_t *a32u_max = &global_mem->a32u_max; + odp_atomic_u32_t *a32u_xchg = &global_mem->a32u_xchg;
for (i = 0; i < CNT; i++) { - tmp = odp_atomic_load_acq_u32(&a32u); - odp_atomic_store_rel_u32(&a32u, tmp); + tmp = odp_atomic_load_acq_u32(a32u); + odp_atomic_store_rel_u32(a32u, tmp);
- tmp = odp_atomic_load_acq_u32(&a32u_max); - odp_atomic_add_rel_u32(&a32u_max, 1); + tmp = odp_atomic_load_acq_u32(a32u_max); + odp_atomic_add_rel_u32(a32u_max, 1);
- tmp = odp_atomic_load_acq_u32(&a32u_min); - odp_atomic_sub_rel_u32(&a32u_min, 1); + tmp = odp_atomic_load_acq_u32(a32u_min); + odp_atomic_sub_rel_u32(a32u_min, 1);
- tmp = odp_atomic_load_u32(&a32u_xchg); - while (odp_atomic_cas_acq_u32(&a32u_xchg, &tmp, tmp + 1) == 0) + tmp = odp_atomic_load_u32(a32u_xchg); + while (odp_atomic_cas_acq_u32(a32u_xchg, &tmp, tmp + 1) == 0) ;
- tmp = odp_atomic_load_u32(&a32u_xchg); - while (odp_atomic_cas_rel_u32(&a32u_xchg, &tmp, tmp + 1) == 0) + tmp = odp_atomic_load_u32(a32u_xchg); + while (odp_atomic_cas_rel_u32(a32u_xchg, &tmp, tmp + 1) == 0) ;
- tmp = odp_atomic_load_u32(&a32u_xchg); + tmp = odp_atomic_load_u32(a32u_xchg); /* finally set value for validation */ - while (odp_atomic_cas_acq_rel_u32(&a32u_xchg, &tmp, U32_MAGIC) + while (odp_atomic_cas_acq_rel_u32(a32u_xchg, &tmp, U32_MAGIC) == 0) ; } @@ -393,28 +401,32 @@ static void test_atomic_non_relaxed_64(void) { int i; uint64_t tmp; + odp_atomic_u64_t *a64u = &global_mem->a64u; + odp_atomic_u64_t *a64u_min = &global_mem->a64u_min; + odp_atomic_u64_t *a64u_max = &global_mem->a64u_max; + odp_atomic_u64_t *a64u_xchg = &global_mem->a64u_xchg;
for (i = 0; i < CNT; i++) { - tmp = odp_atomic_load_acq_u64(&a64u); - odp_atomic_store_rel_u64(&a64u, tmp); + tmp = odp_atomic_load_acq_u64(a64u); + odp_atomic_store_rel_u64(a64u, tmp);
- tmp = odp_atomic_load_acq_u64(&a64u_max); - odp_atomic_add_rel_u64(&a64u_max, 1); + tmp = odp_atomic_load_acq_u64(a64u_max); + odp_atomic_add_rel_u64(a64u_max, 1);
- tmp = odp_atomic_load_acq_u64(&a64u_min); - odp_atomic_sub_rel_u64(&a64u_min, 1); + tmp = odp_atomic_load_acq_u64(a64u_min); + odp_atomic_sub_rel_u64(a64u_min, 1);
- tmp = odp_atomic_load_u64(&a64u_xchg); - while (odp_atomic_cas_acq_u64(&a64u_xchg, &tmp, tmp + 1) == 0) + tmp = odp_atomic_load_u64(a64u_xchg); + while (odp_atomic_cas_acq_u64(a64u_xchg, &tmp, tmp + 1) == 0) ;
- tmp = odp_atomic_load_u64(&a64u_xchg); - while (odp_atomic_cas_rel_u64(&a64u_xchg, &tmp, tmp + 1) == 0) + tmp = odp_atomic_load_u64(a64u_xchg); + while (odp_atomic_cas_rel_u64(a64u_xchg, &tmp, tmp + 1) == 0) ;
- tmp = odp_atomic_load_u64(&a64u_xchg); + tmp = odp_atomic_load_u64(a64u_xchg); /* finally set value for validation */ - while (odp_atomic_cas_acq_rel_u64(&a64u_xchg, &tmp, U64_MAGIC) + while (odp_atomic_cas_acq_rel_u64(a64u_xchg, &tmp, U64_MAGIC) == 0) ; } @@ -494,44 +506,46 @@ static void test_atomic_cas_inc_dec_64(void)
static void test_atomic_init(void) { - odp_atomic_init_u32(&a32u, 0); - odp_atomic_init_u64(&a64u, 0); - odp_atomic_init_u32(&a32u_min, 0); - odp_atomic_init_u32(&a32u_max, 0); - odp_atomic_init_u64(&a64u_min, 0); - odp_atomic_init_u64(&a64u_max, 0); - odp_atomic_init_u32(&a32u_xchg, 0); - odp_atomic_init_u64(&a64u_xchg, 0); + odp_atomic_init_u32(&global_mem->a32u, 0); + odp_atomic_init_u64(&global_mem->a64u, 0); + odp_atomic_init_u32(&global_mem->a32u_min, 0); + odp_atomic_init_u32(&global_mem->a32u_max, 0); + odp_atomic_init_u64(&global_mem->a64u_min, 0); + odp_atomic_init_u64(&global_mem->a64u_max, 0); + odp_atomic_init_u32(&global_mem->a32u_xchg, 0); + odp_atomic_init_u64(&global_mem->a64u_xchg, 0); }
static void test_atomic_store(void) { - odp_atomic_store_u32(&a32u, U32_INIT_VAL); - odp_atomic_store_u64(&a64u, U64_INIT_VAL); - odp_atomic_store_u32(&a32u_min, U32_INIT_VAL); - odp_atomic_store_u32(&a32u_max, U32_INIT_VAL); - odp_atomic_store_u64(&a64u_min, U64_INIT_VAL); - odp_atomic_store_u64(&a64u_max, U64_INIT_VAL); - odp_atomic_store_u32(&a32u_xchg, U32_INIT_VAL); - odp_atomic_store_u64(&a64u_xchg, U64_INIT_VAL); + odp_atomic_store_u32(&global_mem->a32u, U32_INIT_VAL); + odp_atomic_store_u64(&global_mem->a64u, U64_INIT_VAL); + odp_atomic_store_u32(&global_mem->a32u_min, U32_INIT_VAL); + odp_atomic_store_u32(&global_mem->a32u_max, U32_INIT_VAL); + odp_atomic_store_u64(&global_mem->a64u_min, U64_INIT_VAL); + odp_atomic_store_u64(&global_mem->a64u_max, U64_INIT_VAL); + odp_atomic_store_u32(&global_mem->a32u_xchg, U32_INIT_VAL); + odp_atomic_store_u64(&global_mem->a64u_xchg, U64_INIT_VAL); }
static void test_atomic_validate(int check) { - CU_ASSERT(U32_INIT_VAL == odp_atomic_load_u32(&a32u)); - CU_ASSERT(U64_INIT_VAL == odp_atomic_load_u64(&a64u)); + CU_ASSERT(U32_INIT_VAL == odp_atomic_load_u32(&global_mem->a32u)); + CU_ASSERT(U64_INIT_VAL == odp_atomic_load_u64(&global_mem->a64u));
if (check & CHECK_MAX_MIN) { - CU_ASSERT(odp_atomic_load_u32(&a32u_max) > - odp_atomic_load_u32(&a32u_min)); + CU_ASSERT(odp_atomic_load_u32(&global_mem->a32u_max) > + odp_atomic_load_u32(&global_mem->a32u_min));
- CU_ASSERT(odp_atomic_load_u64(&a64u_max) > - odp_atomic_load_u64(&a64u_min)); + CU_ASSERT(odp_atomic_load_u64(&global_mem->a64u_max) > + odp_atomic_load_u64(&global_mem->a64u_min)); }
if (check & CHECK_XCHG) { - CU_ASSERT(odp_atomic_load_u32(&a32u_xchg) == U32_MAGIC); - CU_ASSERT(odp_atomic_load_u64(&a64u_xchg) == U64_MAGIC); + CU_ASSERT(odp_atomic_load_u32(&global_mem->a32u_xchg) == + U32_MAGIC); + CU_ASSERT(odp_atomic_load_u64(&global_mem->a64u_xchg) == + U64_MAGIC); } }
commit 84507e04c0d1e1cedaa0b83737c0baa8cdf8d265 Author: Matias Elo matias.elo@nokia.com Date: Mon Oct 1 13:55:40 2018 +0300
linux-gen: socket_mmap: reserve memory from shm
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/include/odp_packet_socket.h b/platform/linux-generic/include/odp_packet_socket.h index 6f9443a3..16cee16b 100644 --- a/platform/linux-generic/include/odp_packet_socket.h +++ b/platform/linux-generic/include/odp_packet_socket.h @@ -20,6 +20,7 @@ #include <odp/api/pool.h> #include <odp/api/packet.h> #include <odp/api/packet_io.h> +#include <odp/api/shared_memory.h>
#include <linux/version.h>
@@ -43,6 +44,7 @@ struct ring { unsigned frame_num; int rd_num;
+ odp_shm_t shm; int sock; int type; int version; diff --git a/platform/linux-generic/pktio/socket_mmap.c b/platform/linux-generic/pktio/socket_mmap.c index 459c6552..03085728 100644 --- a/platform/linux-generic/pktio/socket_mmap.c +++ b/platform/linux-generic/pktio/socket_mmap.c @@ -38,6 +38,7 @@ #include <odp_classification_inlines.h> #include <odp_classification_internal.h> #include <odp/api/hints.h> +#include <odp_global_data.h>
#include <protocols/eth.h> #include <protocols/ip.h> @@ -462,6 +463,8 @@ static int mmap_setup_ring(int sock, struct ring *ring, int type, odp_pool_t pool_hdl, int fanout) { int ret = 0; + int flags = 0; + odp_shm_t shm;
ring->sock = sock; ring->type = type; @@ -477,10 +480,21 @@ static int mmap_setup_ring(int sock, struct ring *ring, int type, }
ring->rd_len = ring->rd_num * sizeof(*ring->rd); - ring->rd = malloc(ring->rd_len); + + if (odp_global_ro.shm_single_va) + flags += ODP_SHM_SINGLE_VA; + + shm = odp_shm_reserve(NULL, ring->rd_len, ODP_CACHE_LINE_SIZE, flags); + + if (shm == ODP_SHM_INVALID) { + ODP_ERR("Reserving shm failed\n"); + return -1; + } + ring->shm = shm; + + ring->rd = odp_shm_addr(shm); if (!ring->rd) { - __odp_errno = errno; - ODP_ERR("malloc(): %s\n", strerror(errno)); + ODP_ERR("Reading shm addr failed\n"); return -1; }
@@ -533,8 +547,10 @@ static int mmap_sock(pkt_sock_mmap_t *pkt_sock)
static int mmap_unmap_sock(pkt_sock_mmap_t *pkt_sock) { - free(pkt_sock->rx_ring.rd); - free(pkt_sock->tx_ring.rd); + if (pkt_sock->rx_ring.shm != ODP_SHM_INVALID) + odp_shm_free(pkt_sock->rx_ring.shm); + if (pkt_sock->tx_ring.shm != ODP_SHM_INVALID) + odp_shm_free(pkt_sock->tx_ring.shm); return munmap(pkt_sock->mmap_base, pkt_sock->mmap_len); }
@@ -605,6 +621,8 @@ static int sock_mmap_open(odp_pktio_t id ODP_UNUSED, pkt_sock->frame_offset = 0;
pkt_sock->pool = pool; + pkt_sock->rx_ring.shm = ODP_SHM_INVALID; + pkt_sock->tx_ring.shm = ODP_SHM_INVALID; pkt_sock->sockfd = mmap_pkt_socket(); if (pkt_sock->sockfd == -1) goto error;
commit c12678f1712dd291c7ce951243b52287f3028883 Author: Matias Elo matias.elo@nokia.com Date: Fri Sep 21 15:50:31 2018 +0300
linux-gen: pcap: allocate tx buffer from stack
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/pktio/pcap.c b/platform/linux-generic/pktio/pcap.c index c6a817fc..9f783403 100644 --- a/platform/linux-generic/pktio/pcap.c +++ b/platform/linux-generic/pktio/pcap.c @@ -56,7 +56,6 @@ typedef struct { void *tx; /**< tx pcap handle */ void *tx_dump; /**< tx pcap dumper handle */ odp_pool_t pool; /**< rx pool */ - unsigned char *buf; /**< per-pktio temp buffer */ int loops; /**< number of times to loop rx pcap */ int loop_cnt; /**< number of loops completed */ odp_bool_t promisc; /**< promiscuous mode state */ @@ -141,12 +140,6 @@ static int _pcapif_init_tx(pkt_pcap_t *pcap) pcap->tx = tx; }
- pcap->buf = malloc(PKTIO_PCAP_MTU); - if (!pcap->buf) { - ODP_ERR("failed to malloc temp buffer\n"); - return -1; - } - pcap->tx_dump = pcap_dump_open(tx, pcap->fname_tx); if (!pcap->tx_dump) { ODP_ERR("failed to open dump file %s (%s)\n", @@ -198,7 +191,6 @@ static int pcapif_close(pktio_entry_t *pktio_entry) if (pcap->rx) pcap_close(pcap->rx);
- free(pcap->buf); free(pcap->fname_rx); free(pcap->fname_tx);
@@ -298,6 +290,7 @@ static int pcapif_recv_pkt(pktio_entry_t *pktio_entry, int index ODP_UNUSED, static int _pcapif_dump_pkt(pkt_pcap_t *pcap, odp_packet_t pkt) { struct pcap_pkthdr hdr; + uint8_t tx_buf[PKTIO_PCAP_MTU];
if (!pcap->tx_dump) return 0; @@ -306,10 +299,10 @@ static int _pcapif_dump_pkt(pkt_pcap_t *pcap, odp_packet_t pkt) hdr.len = hdr.caplen; (void)gettimeofday(&hdr.ts, NULL);
- if (odp_packet_copy_to_mem(pkt, 0, hdr.len, pcap->buf) != 0) + if (odp_packet_copy_to_mem(pkt, 0, hdr.len, tx_buf) != 0) return -1;
- pcap_dump(pcap->tx_dump, &hdr, pcap->buf); + pcap_dump(pcap->tx_dump, &hdr, tx_buf); (void)pcap_dump_flush(pcap->tx_dump);
return 0;
commit 07fb2ebf0a16f9ef54b2bdd15c99e2c46eda3afc Author: Matias Elo matias.elo@nokia.com Date: Thu Sep 20 10:23:17 2018 +0300
linux-gen: hash: allocate crc table memory from shm
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/include/odp_init_internal.h b/platform/linux-generic/include/odp_init_internal.h index 79f710af..5fbf27e3 100644 --- a/platform/linux-generic/include/odp_init_internal.h +++ b/platform/linux-generic/include/odp_init_internal.h @@ -87,6 +87,7 @@ int _odp_ipsec_events_term_global(void); int _odp_cpu_cycles_init_global(void);
int _odp_hash_init_global(void); +int _odp_hash_term_global(void);
#ifdef __cplusplus } diff --git a/platform/linux-generic/odp_hash_crc_gen.c b/platform/linux-generic/odp_hash_crc_gen.c index 1ea6d8cd..93ebe0e9 100644 --- a/platform/linux-generic/odp_hash_crc_gen.c +++ b/platform/linux-generic/odp_hash_crc_gen.c @@ -12,6 +12,7 @@ #include <odp/api/hash.h> #include <odp/api/hints.h> #include <odp/api/rwlock.h> +#include <odp/api/shared_memory.h>
#include <odp_debug_internal.h> #include <odp_init_internal.h> @@ -22,16 +23,40 @@ typedef struct crc_table_t { uint32_t poly; int reflect; odp_rwlock_t rwlock; + odp_shm_t shm;
} crc_table_t;
-static crc_table_t crc_table; +static crc_table_t *crc_table;
int _odp_hash_init_global(void) { - memset(&crc_table, 0, sizeof(crc_table_t)); + odp_shm_t shm;
- odp_rwlock_init(&crc_table.rwlock); + shm = odp_shm_reserve("_odp_hash_crc_gen", sizeof(crc_table_t), + ODP_CACHE_LINE_SIZE, 0); + + crc_table = odp_shm_addr(shm); + + if (crc_table == NULL) { + ODP_ERR("Shm reserve failed for odp_hash_crc_gen\n"); + return -1; + } + + memset(crc_table, 0, sizeof(crc_table_t)); + + crc_table->shm = shm; + odp_rwlock_init(&crc_table->rwlock); + + return 0; +} + +int _odp_hash_term_global(void) +{ + if (odp_shm_free(crc_table->shm)) { + ODP_ERR("Shm free failed for odp_hash_crc_gen\n"); + return -1; + }
return 0; } @@ -98,9 +123,9 @@ static inline void crc_table_gen(uint32_t poly, int reflect, int width) { uint32_t i, crc, bit, shift, msb, mask;
- crc_table.width = width; - crc_table.poly = poly; - crc_table.reflect = reflect; + crc_table->width = width; + crc_table->poly = poly; + crc_table->reflect = reflect;
shift = width - 8; mask = 0xffffffff >> (32 - width); @@ -136,7 +161,7 @@ static inline void crc_table_gen(uint32_t poly, int reflect, int width) } }
- crc_table.crc[i] = crc & mask; + crc_table->crc[i] = crc & mask; } }
@@ -156,9 +181,10 @@ static inline uint32_t crc_calc(const uint8_t *data, uint32_t data_len, byte = data[i];
if (reflect) { - crc = crc_table.crc[(crc ^ byte) & 0xff] ^ (crc >> 8); + crc = crc_table->crc[(crc ^ byte) & 0xff] ^ (crc >> 8); } else { - crc = crc_table.crc[(crc >> shift) ^ byte] ^ (crc << 8); + crc = crc_table->crc[(crc >> shift) ^ byte] ^ + (crc << 8); crc = crc & mask; } } @@ -192,16 +218,16 @@ int odp_hash_crc_gen64(const void *data_ptr, uint32_t data_len, return -1; }
- odp_rwlock_read_lock(&crc_table.rwlock); + odp_rwlock_read_lock(&crc_table->rwlock);
- update_table = (crc_table.width != width) || - (crc_table.poly != poly) || - (crc_table.reflect != reflect); + update_table = (crc_table->width != width) || + (crc_table->poly != poly) || + (crc_table->reflect != reflect);
/* Generate CRC table if not yet generated. */ if (odp_unlikely(update_table)) { - odp_rwlock_read_unlock(&crc_table.rwlock); - odp_rwlock_write_lock(&crc_table.rwlock); + odp_rwlock_read_unlock(&crc_table->rwlock); + odp_rwlock_write_lock(&crc_table->rwlock);
crc_table_gen(poly, reflect, width); } @@ -209,9 +235,9 @@ int odp_hash_crc_gen64(const void *data_ptr, uint32_t data_len, crc = crc_calc(data_ptr, data_len, init_val, reflect, width);
if (odp_unlikely(update_table)) - odp_rwlock_write_unlock(&crc_table.rwlock); + odp_rwlock_write_unlock(&crc_table->rwlock); else - odp_rwlock_read_unlock(&crc_table.rwlock); + odp_rwlock_read_unlock(&crc_table->rwlock);
if (crc_param->xor_out) crc = crc ^ (uint32_t)crc_param->xor_out; diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index 2a4bad2e..dca06641 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -23,12 +23,12 @@ enum init_stage { LIBCONFIG_INIT, CPUMASK_INIT, CPU_CYCLES_INIT, - HASH_INIT, TIME_INIT, SYSINFO_INIT, ISHM_INIT, FDSERVER_INIT, GLOBAL_RW_DATA_INIT, + HASH_INIT, THREAD_INIT, POOL_INIT, QUEUE_INIT, @@ -191,6 +191,13 @@ static int term_global(enum init_stage stage) } /* Fall through */
+ case HASH_INIT: + if (_odp_hash_term_global()) { + ODP_ERR("ODP hash term failed.\n"); + rc = -1; + } + /* Fall through */ + case GLOBAL_RW_DATA_INIT: if (global_rw_data_term()) { ODP_ERR("ODP global RW data term failed.\n"); @@ -226,8 +233,6 @@ static int term_global(enum init_stage stage) } /* Fall through */
- case HASH_INIT: - /* Fall through */ case CPU_CYCLES_INIT: /* Fall through */ case CPUMASK_INIT: @@ -287,12 +292,6 @@ int odp_init_global(odp_instance_t *instance, } stage = CPU_CYCLES_INIT;
- if (_odp_hash_init_global()) { - ODP_ERR("ODP hash init failed.\n"); - goto init_failed; - } - stage = HASH_INIT; - if (odp_time_init_global()) { ODP_ERR("ODP time init failed.\n"); goto init_failed; @@ -323,6 +322,12 @@ int odp_init_global(odp_instance_t *instance, } stage = GLOBAL_RW_DATA_INIT;
+ if (_odp_hash_init_global()) { + ODP_ERR("ODP hash init failed.\n"); + goto init_failed; + } + stage = HASH_INIT; + if (odp_thread_init_global()) { ODP_ERR("ODP thread init failed.\n"); goto init_failed;
commit 8002e2b5ce58a532615f9c630e14c793037f8ef7 Author: Matias Elo matias.elo@nokia.com Date: Wed Sep 19 16:05:27 2018 +0300
linux-gen: ipsec: allocate memory from shm
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_ipsec.c b/platform/linux-generic/odp_ipsec.c index 4fdb4eee..63121744 100644 --- a/platform/linux-generic/odp_ipsec.c +++ b/platform/linux-generic/odp_ipsec.c @@ -27,6 +27,8 @@
#include <string.h>
+static odp_ipsec_config_t *ipsec_config; + int odp_ipsec_capability(odp_ipsec_capability_t *capa) { int rc; @@ -145,14 +147,12 @@ void odp_ipsec_config_init(odp_ipsec_config_t *config) config->inbound.lookup.max_spi = UINT32_MAX; }
-static odp_ipsec_config_t ipsec_config; - int odp_ipsec_config(const odp_ipsec_config_t *config) { if (ODP_CONFIG_IPSEC_SAS > config->max_num_sa) return -1;
- ipsec_config = *config; + *ipsec_config = *config;
return 0; } @@ -788,8 +788,8 @@ static ipsec_sa_t *ipsec_in_single(odp_packet_t pkt, parse_param.proto = state.is_ipv4 ? ODP_PROTO_IPV4 : state.is_ipv6 ? ODP_PROTO_IPV6 : ODP_PROTO_NONE; - parse_param.last_layer = ipsec_config.inbound.parse_level; - parse_param.chksums = ipsec_config.inbound.chksums; + parse_param.last_layer = ipsec_config->inbound.parse_level; + parse_param.chksums = ipsec_config->inbound.chksums;
/* We do not care about return code here. * Parsing error should not result in IPsec error. */ @@ -1309,7 +1309,7 @@ static void ipsec_out_checksums(odp_packet_t pkt, odp_bool_t ipv4_chksum_pkt, udp_chksum_pkt, tcp_chksum_pkt, sctp_chksum_pkt; odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); - odp_ipsec_outbound_config_t outbound = ipsec_config.outbound; + odp_ipsec_outbound_config_t outbound = ipsec_config->outbound;
ipv4_chksum_pkt = OL_TX_CHKSUM_PKT(outbound.chksum.inner_ipv4, state->is_ipv4, @@ -1657,7 +1657,7 @@ int odp_ipsec_in_enq(const odp_packet_t pkt_in[], int num_in, queue = ipsec_sa->queue; } else { result->sa = ODP_IPSEC_SA_INVALID; - queue = ipsec_config.inbound.default_queue; + queue = ipsec_config->inbound.default_queue; }
if (odp_queue_enq(queue, odp_ipsec_packet_to_event(pkt))) { @@ -1900,7 +1900,19 @@ odp_event_t odp_ipsec_packet_to_event(odp_packet_t pkt)
int _odp_ipsec_init_global(void) { - odp_ipsec_config_init(&ipsec_config); + odp_shm_t shm; + + shm = odp_shm_reserve("_odp_ipsec", sizeof(odp_ipsec_config_t), + ODP_CACHE_LINE_SIZE, 0); + + ipsec_config = odp_shm_addr(shm); + + if (ipsec_config == NULL) { + ODP_ERR("Shm reserve failed for odp_ipsec\n"); + return -1; + } + + odp_ipsec_config_init(ipsec_config);
memset(&default_out_opt, 0, sizeof(default_out_opt));
@@ -1913,6 +1925,12 @@ int _odp_ipsec_init_global(void)
int _odp_ipsec_term_global(void) { - /* Do nothing for now */ + odp_shm_t shm = odp_shm_lookup("_odp_ipsec"); + + if (shm == ODP_SHM_INVALID || odp_shm_free(shm)) { + ODP_ERR("Shm free failed for odp_ipsec"); + return -1; + } + return 0; }
commit 984ffe3caae07b8d5cd9dab14b7b93ca7d87a87d Author: Matias Elo matias.elo@nokia.com Date: Tue Sep 18 16:18:06 2018 +0300
linux-gen: timer: move global variables into timer_global_t
Enables using timers in process mode.
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index ef3f7ec1..eeb86353 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -79,10 +79,6 @@ odp_bool_t inline_timers = false; #define IDX2LOCK(idx) (&timer_global->locks[(idx) % NUM_LOCKS]) #endif
-/* Max timer resolution in nanoseconds */ -static uint64_t highest_res_ns = 500; -static uint64_t min_res_ns = INT64_MAX; - /****************************************************************************** * Translation between timeout buffer and timeout header *****************************************************************************/ @@ -211,6 +207,10 @@ typedef struct timer_pool_s { typedef struct timer_global_t { odp_ticketlock_t lock; odp_shm_t shm; + /* Max timer resolution in nanoseconds */ + uint64_t highest_res_ns; + uint64_t min_res_ns; + odp_time_t time_per_ratelimit_period; int num_timer_pools; uint8_t timer_pool_used[MAX_TIMER_POOLS]; timer_pool_t *timer_pool[MAX_TIMER_POOLS]; @@ -848,8 +848,6 @@ static unsigned process_timer_pools(void) return nexp; }
-static odp_time_t time_per_ratelimit_period; - unsigned _timer_run(void) { static __thread odp_time_t last_timer_run; @@ -870,7 +868,7 @@ unsigned _timer_run(void)
now = odp_time_global(); if (odp_time_cmp(odp_time_diff(now, last_timer_run), - time_per_ratelimit_period) == -1) + timer_global->time_per_ratelimit_period) == -1) return 0; last_timer_run = now;
@@ -973,7 +971,7 @@ static int timer_res_init(void) /* Timer resolution start from 1ms */ res = ODP_TIME_MSEC_IN_NS; /* Set initial value of timer_res */ - highest_res_ns = res; + timer_global->highest_res_ns = res; sigemptyset(&sigset); /* Add SIGUSR1 to sigset */ sigaddset(&sigset, SIGUSR1); @@ -1006,13 +1004,13 @@ static int timer_res_init(void) } } /* Set timer_res */ - highest_res_ns = res; + timer_global->highest_res_ns = res; /* Test the next timer resolution candidate */ res /= 10; }
timer_res_init_done: - highest_res_ns *= TIMER_RES_ROUNDUP_FACTOR; + timer_global->highest_res_ns *= TIMER_RES_ROUNDUP_FACTOR; if (timer_delete(timerid) != 0) ODP_ABORT("timer_delete() returned error %s\n", strerror(errno)); @@ -1084,7 +1082,7 @@ int odp_timer_capability(odp_timer_clk_src_t clk_src, int ret = 0;
if (clk_src == ODP_CLOCK_CPU) { - capa->highest_res_ns = highest_res_ns; + capa->highest_res_ns = timer_global->highest_res_ns; } else { ODP_ERR("ODP timer system doesn't support external clock source currently\n"); ret = -1; @@ -1095,15 +1093,15 @@ int odp_timer_capability(odp_timer_clk_src_t clk_src, odp_timer_pool_t odp_timer_pool_create(const char *name, const odp_timer_pool_param_t *param) { - if (param->res_ns < highest_res_ns) { + if (param->res_ns < timer_global->highest_res_ns) { __odp_errno = EINVAL; return ODP_TIMER_POOL_INVALID; }
- if (min_res_ns > param->res_ns) { - min_res_ns = param->res_ns; - time_per_ratelimit_period = - odp_time_global_from_ns(min_res_ns / 2); + if (timer_global->min_res_ns > param->res_ns) { + timer_global->min_res_ns = param->res_ns; + timer_global->time_per_ratelimit_period = + odp_time_global_from_ns(timer_global->min_res_ns / 2); }
return timer_pool_new(name, param); @@ -1311,6 +1309,8 @@ int odp_timer_init_global(const odp_init_t *params) memset(timer_global, 0, sizeof(timer_global_t)); odp_ticketlock_init(&timer_global->lock); timer_global->shm = shm; + timer_global->highest_res_ns = 500; + timer_global->min_res_ns = INT64_MAX;
#ifndef ODP_ATOMIC_U128 uint32_t i; @@ -1325,8 +1325,8 @@ int odp_timer_init_global(const odp_init_t *params) !params->not_used.feat.schedule && !params->not_used.feat.timer;
- time_per_ratelimit_period = - odp_time_global_from_ns(min_res_ns / 2); + timer_global->time_per_ratelimit_period = + odp_time_global_from_ns(timer_global->min_res_ns / 2);
if (!inline_timers) { timer_res_init();
commit 194f82dac1ff10500ea10d2f25f9c010d67c6e5a Author: Matias Elo matias.elo@nokia.com Date: Tue Sep 18 16:11:03 2018 +0300
linux-gen: timer: move global variable 'locks' into timer_global_t
Enables using timers in process mode.
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index fb73697f..ef3f7ec1 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -76,8 +76,7 @@ odp_bool_t inline_timers = false;
#ifndef ODP_ATOMIC_U128 #define NUM_LOCKS 1024 -static _odp_atomic_flag_t locks[NUM_LOCKS]; /* Multiple locks per cache line! */ -#define IDX2LOCK(idx) (&locks[(idx) % NUM_LOCKS]) +#define IDX2LOCK(idx) (&timer_global->locks[(idx) % NUM_LOCKS]) #endif
/* Max timer resolution in nanoseconds */ @@ -215,6 +214,10 @@ typedef struct timer_global_t { int num_timer_pools; uint8_t timer_pool_used[MAX_TIMER_POOLS]; timer_pool_t *timer_pool[MAX_TIMER_POOLS]; +#ifndef ODP_ATOMIC_U128 + /* Multiple locks per cache line! */ + _odp_atomic_flag_t ODP_ALIGNED_CACHE locks[NUM_LOCKS]; +#endif
} timer_global_t;
@@ -1312,7 +1315,7 @@ int odp_timer_init_global(const odp_init_t *params) #ifndef ODP_ATOMIC_U128 uint32_t i; for (i = 0; i < NUM_LOCKS; i++) - _odp_atomic_flag_clear(&locks[i]); + _odp_atomic_flag_clear(&timer_global->locks[i]); #else ODP_DBG("Using lock-less timer implementation\n"); #endif
commit bfc46064595db98814a70a048ad9d4de70d12e56 Author: Matias Elo matias.elo@nokia.com Date: Tue Sep 18 15:47:40 2018 +0300
linux-gen: timer: allocate global memory from shm
Enables using timers in process mode.
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index e8682237..fb73697f 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -211,21 +211,22 @@ typedef struct timer_pool_s {
typedef struct timer_global_t { odp_ticketlock_t lock; + odp_shm_t shm; int num_timer_pools; uint8_t timer_pool_used[MAX_TIMER_POOLS]; timer_pool_t *timer_pool[MAX_TIMER_POOLS];
} timer_global_t;
-static timer_global_t timer_global; +static timer_global_t *timer_global;
static inline timer_pool_t *handle_to_tp(odp_timer_t hdl) { uint32_t tp_idx = _odp_typeval(hdl) >> INDEX_BITS; if (odp_likely(tp_idx < MAX_TIMER_POOLS)) { - timer_pool_t *tp = timer_global.timer_pool[tp_idx]; + timer_pool_t *tp = timer_global->timer_pool[tp_idx]; if (odp_likely(tp != NULL)) - return timer_global.timer_pool[tp_idx]; + return timer_global->timer_pool[tp_idx]; } ODP_ABORT("Invalid timer handle %#x\n", hdl); } @@ -262,25 +263,25 @@ static odp_timer_pool_t timer_pool_new(const char *name, if (odp_global_ro.shm_single_va) flags |= ODP_SHM_SINGLE_VA;
- odp_ticketlock_lock(&timer_global.lock); + odp_ticketlock_lock(&timer_global->lock);
- if (timer_global.num_timer_pools >= MAX_TIMER_POOLS) { - odp_ticketlock_unlock(&timer_global.lock); + if (timer_global->num_timer_pools >= MAX_TIMER_POOLS) { + odp_ticketlock_unlock(&timer_global->lock); ODP_DBG("No more free timer pools\n"); return ODP_TIMER_POOL_INVALID; }
for (i = 0; i < MAX_TIMER_POOLS; i++) { - if (timer_global.timer_pool_used[i] == 0) { - timer_global.timer_pool_used[i] = 1; + if (timer_global->timer_pool_used[i] == 0) { + timer_global->timer_pool_used[i] = 1; break; } }
tp_idx = i; - timer_global.num_timer_pools++; + timer_global->num_timer_pools++;
- odp_ticketlock_unlock(&timer_global.lock); + odp_ticketlock_unlock(&timer_global->lock);
sz0 = ROUNDUP_CACHE_LINE(sizeof(timer_pool_t)); sz1 = ROUNDUP_CACHE_LINE(sizeof(tick_buf_t) * param->num_timers); @@ -327,9 +328,9 @@ static odp_timer_pool_t timer_pool_new(const char *name, } tp->tp_idx = tp_idx; odp_spinlock_init(&tp->lock); - odp_ticketlock_lock(&timer_global.lock); - timer_global.timer_pool[tp_idx] = tp; - odp_ticketlock_unlock(&timer_global.lock); + odp_ticketlock_lock(&timer_global->lock); + timer_global->timer_pool[tp_idx] = tp; + odp_ticketlock_unlock(&timer_global->lock); if (!inline_timers) { if (tp->param.clk_src == ODP_CLOCK_CPU) itimer_init(tp); @@ -381,12 +382,12 @@ static void odp_timer_pool_del(timer_pool_t *tp)
odp_spinlock_unlock(&tp->lock);
- odp_ticketlock_lock(&timer_global.lock); + odp_ticketlock_lock(&timer_global->lock); shm = tp->shm; - timer_global.timer_pool[tp->tp_idx] = NULL; - timer_global.timer_pool_used[tp->tp_idx] = 0; - timer_global.num_timer_pools--; - odp_ticketlock_unlock(&timer_global.lock); + timer_global->timer_pool[tp->tp_idx] = NULL; + timer_global->timer_pool_used[tp->tp_idx] = 0; + timer_global->num_timer_pools--; + odp_ticketlock_unlock(&timer_global->lock);
rc = odp_shm_free(shm);
@@ -808,7 +809,7 @@ static unsigned process_timer_pools(void) unsigned nexp = 0;
for (size_t i = 0; i < MAX_TIMER_POOLS; i++) { - tp = timer_global.timer_pool[i]; + tp = timer_global->timer_pool[i];
if (tp == NULL) continue; @@ -853,7 +854,7 @@ unsigned _timer_run(void) CONFIG_TIMER_RUN_RATELIMIT_ROUNDS; odp_time_t now;
- if (timer_global.num_timer_pools == 0) + if (timer_global->num_timer_pools == 0) return 0;
/* Rate limit how often this thread checks the timer pools. */ @@ -1292,8 +1293,21 @@ void odp_timeout_free(odp_timeout_t tmo)
int odp_timer_init_global(const odp_init_t *params) { - memset(&timer_global, 0, sizeof(timer_global_t)); - odp_ticketlock_init(&timer_global.lock); + odp_shm_t shm; + + shm = odp_shm_reserve("_odp_timer", sizeof(timer_global_t), + ODP_CACHE_LINE_SIZE, 0); + + timer_global = odp_shm_addr(shm); + + if (timer_global == NULL) { + ODP_ERR("Shm reserve failed for odp_timer\n"); + return -1; + } + + memset(timer_global, 0, sizeof(timer_global_t)); + odp_ticketlock_init(&timer_global->lock); + timer_global->shm = shm;
#ifndef ODP_ATOMIC_U128 uint32_t i; @@ -1321,5 +1335,10 @@ int odp_timer_init_global(const odp_init_t *params)
int odp_timer_term_global(void) { + if (odp_shm_free(timer_global->shm)) { + ODP_ERR("Shm free failed for odp_timer\n"); + return -1; + } + return 0; }
commit bb3a47d7eb62cfe50b111b357435f8bd554f374f Author: Matias Elo matias.elo@nokia.com Date: Tue Sep 25 14:05:01 2018 +0300
linux-gen: dpdk: move dpdk_initialized global var into odp_global_data_rw_t
‘dpdk_initialized’ is modified after global init.
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/include/odp_global_data.h b/platform/linux-generic/include/odp_global_data.h index f3ddae41..f1be1502 100644 --- a/platform/linux-generic/include/odp_global_data.h +++ b/platform/linux-generic/include/odp_global_data.h @@ -68,6 +68,7 @@ struct odp_global_data_rw_t { int inotify_watch_fd; pthread_t inotify_thread; int inotify_pcapng_is_running; + odp_bool_t dpdk_initialized; };
extern struct odp_global_data_ro_t odp_global_ro; diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c index f1ace71f..578a94b0 100644 --- a/platform/linux-generic/pktio/dpdk.c +++ b/platform/linux-generic/pktio/dpdk.c @@ -139,9 +139,6 @@ static inline pkt_dpdk_t *pkt_priv(pktio_entry_t *pktio_entry)
static int disable_pktio; /** !0 this pktio disabled, 0 enabled */
-/* Has dpdk_pktio_init() been called */ -static odp_bool_t dpdk_initialized; - #ifndef RTE_BUILD_SHARED_LIB #define MEMPOOL_OPS(hdl) \ extern void mp_hdlr_init_##hdl(void) @@ -1260,7 +1257,7 @@ static void dpdk_mempool_free(struct rte_mempool *mp, void *arg ODP_UNUSED)
static int dpdk_pktio_term(void) { - if (!dpdk_initialized) + if (!odp_global_rw->dpdk_initialized) return 0;
#if RTE_VERSION >= RTE_VERSION_NUM(17, 8, 0, 0) @@ -1433,9 +1430,9 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED,
/* Initialize DPDK here instead of odp_init_global() to enable running * 'make check' without root privileges */ - if (dpdk_initialized == 0) { + if (odp_global_rw->dpdk_initialized == 0) { dpdk_pktio_init(); - dpdk_initialized = 1; + odp_global_rw->dpdk_initialized = 1; }
/* Init pktio entry */
commit 22dcddaa3dcc82f88b4e9b97a6aa6deb632269f6 Author: Matias Elo matias.elo@nokia.com Date: Tue Sep 25 13:52:15 2018 +0300
linux-gen: pcapng: move global data into odp_global_data_rw_t
Pcapng global variables are modified after global init.
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/include/odp_global_data.h b/platform/linux-generic/include/odp_global_data.h index d647bb5e..f3ddae41 100644 --- a/platform/linux-generic/include/odp_global_data.h +++ b/platform/linux-generic/include/odp_global_data.h @@ -58,17 +58,16 @@ struct odp_global_data_ro_t { int num_cpus_installed; config_t libconfig_default; config_t libconfig_runtime; - int inotify_pcapng_fd; - int inotify_watch_fd; - pthread_t inotify_thread; - int inotify_pcapng_is_running; odp_random_kind_t ipsec_rand_kind; };
/* Modifiable global data. Memory region is shared and synchronized amongst all * worker processes. */ struct odp_global_data_rw_t { - int dummy; + int inotify_pcapng_fd; + int inotify_watch_fd; + pthread_t inotify_thread; + int inotify_pcapng_is_running; };
extern struct odp_global_data_ro_t odp_global_ro; diff --git a/platform/linux-generic/odp_pcapng.c b/platform/linux-generic/odp_pcapng.c index 07784c17..21fa7b2c 100644 --- a/platform/linux-generic/odp_pcapng.c +++ b/platform/linux-generic/odp_pcapng.c @@ -120,13 +120,13 @@ static void *inotify_update(void *arg) while (1) { offset = 0; FD_ZERO(&rfds); - FD_SET(odp_global_ro.inotify_pcapng_fd, &rfds); + FD_SET(odp_global_rw->inotify_pcapng_fd, &rfds); time.tv_sec = 2; time.tv_usec = 0; - select(odp_global_ro.inotify_pcapng_fd + 1, &rfds, NULL, + select(odp_global_rw->inotify_pcapng_fd + 1, &rfds, NULL, NULL, &time); - if (FD_ISSET(odp_global_ro.inotify_pcapng_fd, &rfds)) { - rdlen = read(odp_global_ro.inotify_pcapng_fd, + if (FD_ISSET(odp_global_rw->inotify_pcapng_fd, &rfds)) { + rdlen = read(odp_global_rw->inotify_pcapng_fd, buffer, INOTIFY_BUF_LEN); while (offset < rdlen) { int qidx; @@ -219,23 +219,23 @@ int pcapng_prepare(pktio_entry_t *entry) }
/* already running from a previous pktio */ - if (odp_global_ro.inotify_pcapng_is_running == 1) + if (odp_global_rw->inotify_pcapng_is_running == 1) return 0;
- odp_global_ro.inotify_pcapng_fd = -1; - odp_global_ro.inotify_watch_fd = -1; + odp_global_rw->inotify_pcapng_fd = -1; + odp_global_rw->inotify_watch_fd = -1;
- odp_global_ro.inotify_pcapng_fd = inotify_init(); - if (odp_global_ro.inotify_pcapng_fd == -1) { + odp_global_rw->inotify_pcapng_fd = inotify_init(); + if (odp_global_rw->inotify_pcapng_fd == -1) { ODP_ERR("can't init inotify. pcap disabled\n"); goto out_destroy; }
- odp_global_ro.inotify_watch_fd = - inotify_add_watch(odp_global_ro.inotify_pcapng_fd, + odp_global_rw->inotify_watch_fd = + inotify_add_watch(odp_global_rw->inotify_pcapng_fd, PCAPNG_WATCH_DIR, IN_CLOSE | IN_OPEN);
- if (odp_global_ro.inotify_watch_fd == -1) { + if (odp_global_rw->inotify_watch_fd == -1) { ODP_ERR("can't register inotify for %s. pcap disabled\n", strerror(errno)); goto out_destroy; @@ -243,12 +243,12 @@ int pcapng_prepare(pktio_entry_t *entry)
/* create a thread to poll inotify triggers */ pthread_attr_init(&attr); - ret = pthread_create(&odp_global_ro.inotify_thread, &attr, + ret = pthread_create(&odp_global_rw->inotify_thread, &attr, inotify_update, entry); if (ret) ODP_ERR("can't start inotify thread. pcap disabled\n"); else - odp_global_ro.inotify_pcapng_is_running = 1; + odp_global_rw->inotify_pcapng_is_running = 1;
return ret;
@@ -265,24 +265,24 @@ void pcapng_destroy(pktio_entry_t *entry) unsigned int max_queue = MAX(entry->s.num_in_queue, entry->s.num_out_queue);
- if (odp_global_ro.inotify_pcapng_is_running == 1) { - ret = pthread_cancel(odp_global_ro.inotify_thread); + if (odp_global_rw->inotify_pcapng_is_running == 1) { + ret = pthread_cancel(odp_global_rw->inotify_thread); if (ret) ODP_ERR("can't cancel inotify thread %s\n", strerror(errno)); }
/* fd's will be -1 in case of any failure */ - ret = inotify_rm_watch(odp_global_ro.inotify_pcapng_fd, - odp_global_ro.inotify_watch_fd); + ret = inotify_rm_watch(odp_global_rw->inotify_pcapng_fd, + odp_global_rw->inotify_watch_fd); if (ret) ODP_ERR("can't deregister inotify %s\n", strerror(errno));
- if (odp_global_ro.inotify_pcapng_fd != -1) - close(odp_global_ro.inotify_pcapng_fd); + if (odp_global_rw->inotify_pcapng_fd != -1) + close(odp_global_rw->inotify_pcapng_fd);
- if (odp_global_ro.inotify_watch_fd != -1) - close(odp_global_ro.inotify_watch_fd); + if (odp_global_rw->inotify_watch_fd != -1) + close(odp_global_rw->inotify_watch_fd);
for (i = 0; i < max_queue; i++) { char pcapng_name[128];
commit 9a4f8305e9c90f0ca0e7e4c240eb88d81b864ae0 Author: Matias Elo matias.elo@nokia.com Date: Tue Sep 25 12:53:53 2018 +0300
linux-gen: split global data into RO and RW structs
RW global data is allocated from shm to enable process mode support.
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/include/odp_debug_internal.h b/platform/linux-generic/include/odp_debug_internal.h index 2e92dd74..4dbe01b5 100644 --- a/platform/linux-generic/include/odp_debug_internal.h +++ b/platform/linux-generic/include/odp_debug_internal.h @@ -34,14 +34,14 @@ extern "C" { #define ODP_ASSERT(cond) \ do { if ((ODP_DEBUG == 1) && (!(cond))) { \ ODP_ERR("%s\n", #cond); \ - odp_global_data.abort_fn(); } \ + odp_global_ro.abort_fn(); } \ } while (0)
/** * This macro is used to indicate when a given function is not implemented */ #define ODP_UNIMPLEMENTED() \ - odp_global_data.log_fn(ODP_LOG_UNIMPLEMENTED, \ + odp_global_ro.log_fn(ODP_LOG_UNIMPLEMENTED, \ "%s:%d:The function %s() is not implemented\n", \ __FILE__, __LINE__, __func__) /** @@ -66,14 +66,14 @@ extern "C" { #define ODP_ABORT(fmt, ...) \ do { \ ODP_LOG(ODP_LOG_ABORT, fmt, ##__VA_ARGS__); \ - odp_global_data.abort_fn(); \ + odp_global_ro.abort_fn(); \ } while (0)
/** * ODP LOG macro. */ #define ODP_LOG(level, fmt, ...) \ - odp_global_data.log_fn(level, "%s:%d:%s():" fmt, __FILE__, \ + odp_global_ro.log_fn(level, "%s:%d:%s():" fmt, __FILE__, \ __LINE__, __func__, ##__VA_ARGS__)
/** @@ -81,7 +81,7 @@ extern "C" { * specifically for dumping internal data. */ #define ODP_PRINT(fmt, ...) \ - odp_global_data.log_fn(ODP_LOG_PRINT, fmt, ##__VA_ARGS__) + odp_global_ro.log_fn(ODP_LOG_PRINT, fmt, ##__VA_ARGS__)
#ifdef __cplusplus } diff --git a/platform/linux-generic/include/odp_global_data.h b/platform/linux-generic/include/odp_global_data.h index 7b9e4653..d647bb5e 100644 --- a/platform/linux-generic/include/odp_global_data.h +++ b/platform/linux-generic/include/odp_global_data.h @@ -37,7 +37,9 @@ typedef struct { char *default_huge_page_dir; } hugepage_info_t;
-struct odp_global_data_s { +/* Read-only global data. Members should not be modified after global init + * to enable process more support. */ +struct odp_global_data_ro_t { /* directory for odp mmaped files */ char *shm_dir; /* overload default with env */ @@ -63,7 +65,14 @@ struct odp_global_data_s { odp_random_kind_t ipsec_rand_kind; };
-extern struct odp_global_data_s odp_global_data; +/* Modifiable global data. Memory region is shared and synchronized amongst all + * worker processes. */ +struct odp_global_data_rw_t { + int dummy; +}; + +extern struct odp_global_data_ro_t odp_global_ro; +extern struct odp_global_data_rw_t *odp_global_rw;
#ifdef __cplusplus } diff --git a/platform/linux-generic/odp_cpumask.c b/platform/linux-generic/odp_cpumask.c index 1b384d4e..551a80d8 100644 --- a/platform/linux-generic/odp_cpumask.c +++ b/platform/linux-generic/odp_cpumask.c @@ -236,8 +236,8 @@ static int get_available_cpus(void) int ret;
/* Clear the global cpumasks for control and worker CPUs */ - odp_cpumask_zero(&odp_global_data.control_cpus); - odp_cpumask_zero(&odp_global_data.worker_cpus); + odp_cpumask_zero(&odp_global_ro.control_cpus); + odp_cpumask_zero(&odp_global_ro.worker_cpus);
CPU_ZERO(&cpuset); ret = sched_getaffinity(0, sizeof(cpuset), &cpuset); @@ -249,12 +249,12 @@ static int get_available_cpus(void)
for (cpu_idnum = 0; cpu_idnum < CPU_SETSIZE - 1; cpu_idnum++) { if (CPU_ISSET(cpu_idnum, &cpuset)) { - odp_global_data.num_cpus_installed++; + odp_global_ro.num_cpus_installed++; /* Add the CPU to our default cpumasks */ - odp_cpumask_set(&odp_global_data.control_cpus, - (int)cpu_idnum); - odp_cpumask_set(&odp_global_data.worker_cpus, - (int)cpu_idnum); + odp_cpumask_set(&odp_global_ro.control_cpus, + (int)cpu_idnum); + odp_cpumask_set(&odp_global_ro.worker_cpus, + (int)cpu_idnum); } }
@@ -269,8 +269,8 @@ static int get_available_cpus(void) */ static void init_default_control_cpumask(int worker_cpus_default) { - odp_cpumask_t *control_mask = &odp_global_data.control_cpus; - odp_cpumask_t *worker_mask = &odp_global_data.worker_cpus; + odp_cpumask_t *control_mask = &odp_global_ro.control_cpus; + odp_cpumask_t *worker_mask = &odp_global_ro.worker_cpus; int i;
/* (Bits for all available CPUs are SET in control cpumask) */ @@ -281,7 +281,7 @@ static void init_default_control_cpumask(int worker_cpus_default) * If only one or two CPUs installed, use CPU 0 for control. * Otherwise leave it for the kernel and start with CPU 1. */ - if (odp_global_data.num_cpus_installed < 3) { + if (odp_global_ro.num_cpus_installed < 3) { /* * If only two CPUS, use CPU 0 for control and * use CPU 1 for workers. @@ -294,7 +294,7 @@ static void init_default_control_cpumask(int worker_cpus_default) * reserve remaining CPUs for workers */ odp_cpumask_clr(control_mask, 0); - for (i = 2; i < odp_global_data.num_cpus_installed; i++) + for (i = 2; i < odp_global_ro.num_cpus_installed; i++) if (odp_cpumask_isset(worker_mask, i)) odp_cpumask_clr(control_mask, i); } @@ -303,7 +303,7 @@ static void init_default_control_cpumask(int worker_cpus_default) * The worker cpumask was specified so first ensure * the control cpumask does not overlap any worker CPUs */ - for (i = 0; i < odp_global_data.num_cpus_installed; i++) + for (i = 0; i < odp_global_ro.num_cpus_installed; i++) if (odp_cpumask_isset(worker_mask, i)) odp_cpumask_clr(control_mask, i);
@@ -311,7 +311,7 @@ static void init_default_control_cpumask(int worker_cpus_default) * If only one or two CPUs installed, * ensure availability of CPU 0 for control threads */ - if (odp_global_data.num_cpus_installed < 3) { + if (odp_global_ro.num_cpus_installed < 3) { odp_cpumask_set(control_mask, 0); odp_cpumask_clr(control_mask, 1); } else { @@ -337,8 +337,8 @@ static void init_default_control_cpumask(int worker_cpus_default) */ static void init_default_worker_cpumask(int control_cpus_default) { - odp_cpumask_t *control_mask = &odp_global_data.control_cpus; - odp_cpumask_t *worker_mask = &odp_global_data.worker_cpus; + odp_cpumask_t *control_mask = &odp_global_ro.control_cpus; + odp_cpumask_t *worker_mask = &odp_global_ro.worker_cpus; int i;
/* (Bits for all available CPUs are SET in worker cpumask) */ @@ -348,10 +348,10 @@ static void init_default_worker_cpumask(int control_cpus_default) * The control cpumask was also unspecified... * CPU 0 is only used for workers on uniprocessor systems */ - if (odp_global_data.num_cpus_installed > 1) + if (odp_global_ro.num_cpus_installed > 1) odp_cpumask_clr(worker_mask, 0);
- if (odp_global_data.num_cpus_installed > 2) + if (odp_global_ro.num_cpus_installed > 2) /* * If three or more CPUs, reserve CPU 0 for kernel, * reserve CPU 1 for control, and @@ -363,7 +363,7 @@ static void init_default_worker_cpumask(int control_cpus_default) * The control cpumask was specified so first ensure * the worker cpumask does not overlap any control CPUs */ - for (i = 0; i < odp_global_data.num_cpus_installed; i++) + for (i = 0; i < odp_global_ro.num_cpus_installed; i++) if (odp_cpumask_isset(control_mask, i)) odp_cpumask_clr(worker_mask, i);
@@ -371,7 +371,7 @@ static void init_default_worker_cpumask(int control_cpus_default) * If only one CPU installed, use CPU 0 for workers * even though it is used for control as well. */ - if (odp_global_data.num_cpus_installed < 2) + if (odp_global_ro.num_cpus_installed < 2) odp_cpumask_set(worker_mask, 0); else odp_cpumask_clr(worker_mask, 0); @@ -386,8 +386,8 @@ static void init_default_worker_cpumask(int control_cpus_default) */ int odp_cpumask_init_global(const odp_init_t *params) { - odp_cpumask_t *control_mask = &odp_global_data.control_cpus; - odp_cpumask_t *worker_mask = &odp_global_data.worker_cpus; + odp_cpumask_t *control_mask = &odp_global_ro.control_cpus; + odp_cpumask_t *worker_mask = &odp_global_ro.worker_cpus; odp_cpumask_t check_mask; int control_cpus_default = 1; int worker_cpus_default = 1; diff --git a/platform/linux-generic/odp_cpumask_task.c b/platform/linux-generic/odp_cpumask_task.c index c1b79f07..c269116c 100644 --- a/platform/linux-generic/odp_cpumask_task.c +++ b/platform/linux-generic/odp_cpumask_task.c @@ -23,20 +23,20 @@ int odp_cpumask_default_worker(odp_cpumask_t *mask, int num) * If no user supplied number or it's too large, then attempt * to use all CPUs */ - cpu = odp_cpumask_count(&odp_global_data.worker_cpus); + cpu = odp_cpumask_count(&odp_global_ro.worker_cpus); if (0 == num || cpu < num) num = cpu;
/* build the mask, allocating down from highest numbered CPU */ odp_cpumask_zero(mask); for (cpu = 0, i = CPU_SETSIZE - 1; i >= 0 && cpu < num; --i) { - if (odp_cpumask_isset(&odp_global_data.worker_cpus, i)) { + if (odp_cpumask_isset(&odp_global_ro.worker_cpus, i)) { odp_cpumask_set(mask, i); cpu++; } }
- odp_cpumask_and(&overlap, mask, &odp_global_data.control_cpus); + odp_cpumask_and(&overlap, mask, &odp_global_ro.control_cpus); if (odp_cpumask_count(&overlap)) ODP_DBG("\n\tWorker CPUs overlap with control CPUs...\n" "\tthis will likely have a performance impact on the worker threads.\n"); @@ -59,7 +59,7 @@ int odp_cpumask_default_control(odp_cpumask_t *mask, int num) * If user supplied number is too large, then attempt * to use all installed control CPUs */ - cpu = odp_cpumask_count(&odp_global_data.control_cpus); + cpu = odp_cpumask_count(&odp_global_ro.control_cpus); if (cpu < num) num = cpu; } @@ -67,13 +67,13 @@ int odp_cpumask_default_control(odp_cpumask_t *mask, int num) /* build the mask, allocating upwards from lowest numbered CPU */ odp_cpumask_zero(mask); for (cpu = 0, i = 0; i < CPU_SETSIZE && cpu < num; i++) { - if (odp_cpumask_isset(&odp_global_data.control_cpus, i)) { + if (odp_cpumask_isset(&odp_global_ro.control_cpus, i)) { odp_cpumask_set(mask, i); cpu++; } }
- odp_cpumask_and(&overlap, mask, &odp_global_data.worker_cpus); + odp_cpumask_and(&overlap, mask, &odp_global_ro.worker_cpus); if (odp_cpumask_count(&overlap)) ODP_DBG("\n\tControl CPUs overlap with worker CPUs...\n" "\tthis will likely have a performance impact on the worker threads.\n"); @@ -83,8 +83,8 @@ int odp_cpumask_default_control(odp_cpumask_t *mask, int num)
int odp_cpumask_all_available(odp_cpumask_t *mask) { - odp_cpumask_or(mask, &odp_global_data.worker_cpus, - &odp_global_data.control_cpus); + odp_cpumask_or(mask, &odp_global_ro.worker_cpus, + &odp_global_ro.control_cpus);
return odp_cpumask_count(mask); } diff --git a/platform/linux-generic/odp_fdserver.c b/platform/linux-generic/odp_fdserver.c index 0c9cc50e..232d7f4e 100644 --- a/platform/linux-generic/odp_fdserver.c +++ b/platform/linux-generic/odp_fdserver.c @@ -249,9 +249,9 @@ static int get_socket(void)
/* construct the named socket path: */ snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCK_FORMAT, - odp_global_data.shm_dir, - odp_global_data.uid, - odp_global_data.main_pid); + odp_global_ro.shm_dir, + odp_global_ro.uid, + odp_global_ro.main_pid);
s_sock = socket(AF_UNIX, SOCK_STREAM, 0); if (s_sock == -1) { @@ -566,16 +566,16 @@ int _odp_fdserver_init_global(void) int res;
snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCKDIR_FORMAT, - odp_global_data.shm_dir, - odp_global_data.uid); + odp_global_ro.shm_dir, + odp_global_ro.uid);
mkdir(sockpath, 0744);
/* construct the server named socket path: */ snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCK_FORMAT, - odp_global_data.shm_dir, - odp_global_data.uid, - odp_global_data.main_pid); + odp_global_ro.shm_dir, + odp_global_ro.uid, + odp_global_ro.main_pid);
/* create UNIX domain socket: */ sock = socket(AF_UNIX, SOCK_STREAM, 0); @@ -692,17 +692,17 @@ int _odp_fdserver_term_global(void)
/* construct the server named socket path: */ snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCK_FORMAT, - odp_global_data.shm_dir, - odp_global_data.uid, - odp_global_data.main_pid); + odp_global_ro.shm_dir, + odp_global_ro.uid, + odp_global_ro.main_pid);
/* delete the UNIX domain socket: */ unlink(sockpath);
/* delete shm files directory */ snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCKDIR_FORMAT, - odp_global_data.shm_dir, - odp_global_data.uid); + odp_global_ro.shm_dir, + odp_global_ro.uid); rmdir(sockpath);
return 0; diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index 28f94cd3..2a4bad2e 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -9,6 +9,7 @@ #include <odp_posix_extensions.h>
#include <odp/api/init.h> +#include <odp/api/shared_memory.h> #include <odp_debug_internal.h> #include <odp_init_internal.h> #include <odp_schedule_if.h> @@ -27,6 +28,7 @@ enum init_stage { SYSINFO_INIT, ISHM_INIT, FDSERVER_INIT, + GLOBAL_RW_DATA_INIT, THREAD_INIT, POOL_INIT, QUEUE_INIT, @@ -44,13 +46,51 @@ enum init_stage { ALL_INIT /* All init stages completed */ };
-struct odp_global_data_s odp_global_data; +struct odp_global_data_ro_t odp_global_ro; +struct odp_global_data_rw_t *odp_global_rw;
void odp_init_param_init(odp_init_t *param) { memset(param, 0, sizeof(odp_init_t)); }
+static int global_rw_data_init(void) +{ + odp_shm_t shm; + + shm = odp_shm_reserve("_odp_global_rw_data", + sizeof(struct odp_global_data_rw_t), + ODP_CACHE_LINE_SIZE, 0); + + odp_global_rw = odp_shm_addr(shm); + if (odp_global_rw == NULL) { + ODP_ERR("Global RW data shm reserve failed.\n"); + return -1; + } + + memset(odp_global_rw, 0, sizeof(struct odp_global_data_rw_t)); + + return 0; +} + +static int global_rw_data_term(void) +{ + odp_shm_t shm; + + shm = odp_shm_lookup("_odp_global_rw_data"); + if (shm == ODP_SHM_INVALID) { + ODP_ERR("Unable to find global RW data shm.\n"); + return -1; + } + + if (odp_shm_free(shm)) { + ODP_ERR("Global RW data shm free failed.\n"); + return -1; + } + + return 0; +} + static int term_global(enum init_stage stage) { int rc = 0; @@ -151,6 +191,13 @@ static int term_global(enum init_stage stage) } /* Fall through */
+ case GLOBAL_RW_DATA_INIT: + if (global_rw_data_term()) { + ODP_ERR("ODP global RW data term failed.\n"); + rc = -1; + } + /* Fall through */ + case FDSERVER_INIT: if (_odp_fdserver_term_global()) { ODP_ERR("ODP fdserver term failed.\n"); @@ -208,18 +255,18 @@ int odp_init_global(odp_instance_t *instance, const odp_init_t *params, const odp_platform_init_t *platform_params ODP_UNUSED) { - memset(&odp_global_data, 0, sizeof(struct odp_global_data_s)); - odp_global_data.main_pid = getpid(); + memset(&odp_global_ro, 0, sizeof(struct odp_global_data_ro_t)); + odp_global_ro.main_pid = getpid();
enum init_stage stage = NO_INIT; - odp_global_data.log_fn = odp_override_log; - odp_global_data.abort_fn = odp_override_abort; + odp_global_ro.log_fn = odp_override_log; + odp_global_ro.abort_fn = odp_override_abort;
if (params != NULL) { if (params->log_fn != NULL) - odp_global_data.log_fn = params->log_fn; + odp_global_ro.log_fn = params->log_fn; if (params->abort_fn != NULL) - odp_global_data.abort_fn = params->abort_fn; + odp_global_ro.abort_fn = params->abort_fn; }
if (_odp_libconfig_init_global()) { @@ -270,6 +317,12 @@ int odp_init_global(odp_instance_t *instance, } stage = FDSERVER_INIT;
+ if (global_rw_data_init()) { + ODP_ERR("ODP global RW data init failed.\n"); + goto init_failed; + } + stage = GLOBAL_RW_DATA_INIT; + if (odp_thread_init_global()) { ODP_ERR("ODP thread init failed.\n"); goto init_failed; @@ -351,7 +404,7 @@ int odp_init_global(odp_instance_t *instance, } stage = IPSEC_INIT;
- *instance = (odp_instance_t)odp_global_data.main_pid; + *instance = (odp_instance_t)odp_global_ro.main_pid;
return 0;
@@ -362,7 +415,7 @@ init_failed:
int odp_term_global(odp_instance_t instance) { - if (instance != (odp_instance_t)odp_global_data.main_pid) { + if (instance != (odp_instance_t)odp_global_ro.main_pid) { ODP_ERR("Bad instance.\n"); return -1; } @@ -441,7 +494,7 @@ int odp_init_local(odp_instance_t instance, odp_thread_type_t thr_type) { enum init_stage stage = NO_INIT;
- if (instance != (odp_instance_t)odp_global_data.main_pid) { + if (instance != (odp_instance_t)odp_global_ro.main_pid) { ODP_ERR("Bad instance.\n"); goto init_fail; } diff --git a/platform/linux-generic/odp_ipsec.c b/platform/linux-generic/odp_ipsec.c index 1bc549c2..4fdb4eee 100644 --- a/platform/linux-generic/odp_ipsec.c +++ b/platform/linux-generic/odp_ipsec.c @@ -1005,7 +1005,7 @@ static int ipsec_out_iv(ipsec_state_t *state, uint32_t len;
len = odp_random_data(state->iv, ipsec_sa->esp_iv_len, - odp_global_data.ipsec_rand_kind); + odp_global_ro.ipsec_rand_kind);
if (len != ipsec_sa->esp_iv_len) return -1; @@ -1904,9 +1904,9 @@ int _odp_ipsec_init_global(void)
memset(&default_out_opt, 0, sizeof(default_out_opt));
- odp_global_data.ipsec_rand_kind = ODP_RANDOM_CRYPTO; - if (odp_global_data.ipsec_rand_kind > odp_random_max_kind()) - odp_global_data.ipsec_rand_kind = odp_random_max_kind(); + odp_global_ro.ipsec_rand_kind = ODP_RANDOM_CRYPTO; + if (odp_global_ro.ipsec_rand_kind > odp_random_max_kind()) + odp_global_ro.ipsec_rand_kind = odp_random_max_kind();
return 0; } diff --git a/platform/linux-generic/odp_ishm.c b/platform/linux-generic/odp_ishm.c index 1ed60c5f..1a4ca947 100644 --- a/platform/linux-generic/odp_ishm.c +++ b/platform/linux-generic/odp_ishm.c @@ -306,8 +306,8 @@ static void hp_init(void)
if (_odp_libconfig_lookup_ext_int("shm", NULL, "single_va", &single_va)) { - odp_global_data.shm_single_va = single_va; - ODP_DBG("Shm single VA: %d\n", odp_global_data.shm_single_va); + odp_global_ro.shm_single_va = single_va; + ODP_DBG("Shm single VA: %d\n", odp_global_ro.shm_single_va); }
if (!_odp_libconfig_lookup_ext_int("shm", NULL, "num_cached_hp", @@ -320,14 +320,14 @@ static void hp_init(void)
ODP_DBG("Init HP cache with up to %d pages\n", count);
- if (!odp_global_data.hugepage_info.default_huge_page_dir) { + if (!odp_global_ro.hugepage_info.default_huge_page_dir) { ODP_ERR("No huge page dir\n"); return; }
snprintf(dir, ISHM_FILENAME_MAXLEN, "%s/%s", - odp_global_data.hugepage_info.default_huge_page_dir, - odp_global_data.uid); + odp_global_ro.hugepage_info.default_huge_page_dir, + odp_global_ro.uid);
if (mkdir(dir, 0744) != 0) { if (errno != EEXIST) { @@ -339,7 +339,7 @@ static void hp_init(void) snprintf(filename, ISHM_FILENAME_MAXLEN, "%s/odp-%d-ishm_cached", dir, - odp_global_data.main_pid); + odp_global_ro.main_pid);
addr = mmap(NULL, sizeof(struct huge_page_cache) + sizeof(int) * count, @@ -431,7 +431,7 @@ static void *alloc_fragment(uintptr_t size, int block_index, intptr_t align, ishm_fragment_t *rem_fragmnt; uintptr_t border;/* possible start of new fragment (next alignement) */ intptr_t left; /* room remaining after, if the segment is allocated */ - uintptr_t remainder = odp_global_data.shm_max_memory; + uintptr_t remainder = odp_global_ro.shm_max_memory;
/* * search for the best bit, i.e. search for the unallocated fragment @@ -607,22 +607,22 @@ static int create_file(int block_index, huge_flag_t huge, uint64_t len,
/* huge dir must be known to create files there!: */ if ((huge == HUGE) && - (!odp_global_data.hugepage_info.default_huge_page_dir)) + (!odp_global_ro.hugepage_info.default_huge_page_dir)) return -1;
if (huge == HUGE) snprintf(dir, ISHM_FILENAME_MAXLEN, "%s/%s", - odp_global_data.hugepage_info.default_huge_page_dir, - odp_global_data.uid); + odp_global_ro.hugepage_info.default_huge_page_dir, + odp_global_ro.uid); else snprintf(dir, ISHM_FILENAME_MAXLEN, "%s/%s", - odp_global_data.shm_dir, - odp_global_data.uid); + odp_global_ro.shm_dir, + odp_global_ro.uid);
snprintf(filename, ISHM_FILENAME_MAXLEN, ISHM_FILENAME_FORMAT, dir, - odp_global_data.main_pid, + odp_global_ro.main_pid, (name && name[0]) ? name : seq_string);
mkdir(dir, 0744); @@ -651,9 +651,9 @@ static int create_file(int block_index, huge_flag_t huge, uint64_t len, memcpy(new_block->filename, filename, ISHM_FILENAME_MAXLEN); snprintf(new_block->exptname, ISHM_FILENAME_MAXLEN, ISHM_EXPTNAME_FORMAT, - odp_global_data.shm_dir, - odp_global_data.uid, - odp_global_data.main_pid, + odp_global_ro.shm_dir, + odp_global_ro.uid, + odp_global_ro.main_pid, (name && name[0]) ? name : seq_string); export_file = fopen(new_block->exptname, "w"); if (export_file == NULL) { @@ -1223,8 +1223,8 @@ int _odp_ishm_find_exported(const char *remote_name, pid_t external_odp_pid, /* try to read the block description file: */ snprintf(export_filename, ISHM_FILENAME_MAXLEN, ISHM_EXPTNAME_FORMAT, - odp_global_data.shm_dir, - odp_global_data.uid, + odp_global_ro.shm_dir, + odp_global_ro.uid, external_odp_pid, remote_name);
@@ -1618,7 +1618,7 @@ int _odp_ishm_cleanup_files(const char *dirpath) int p_len; int f_len;
- snprintf(userdir, PATH_MAX, "%s/%s", dirpath, odp_global_data.uid); + snprintf(userdir, PATH_MAX, "%s/%s", dirpath, odp_global_ro.uid);
dir = opendir(userdir); if (!dir) { @@ -1627,7 +1627,7 @@ int _odp_ishm_cleanup_files(const char *dirpath) dirpath, strerror(errno)); return 0; } - snprintf(prefix, PATH_MAX, _ODP_FILES_FMT, odp_global_data.main_pid); + snprintf(prefix, PATH_MAX, _ODP_FILES_FMT, odp_global_ro.main_pid); p_len = strlen(prefix); while ((e = readdir(dir)) != NULL) { if (strncmp(e->d_name, prefix, p_len) == 0) { @@ -1657,7 +1657,7 @@ int _odp_ishm_init_global(const odp_init_t *init) void *spce_addr; int i; uid_t uid; - char *hp_dir = odp_global_data.hugepage_info.default_huge_page_dir; + char *hp_dir = odp_global_ro.hugepage_info.default_huge_page_dir; uint64_t align; uint64_t max_memory = ODP_CONFIG_ISHM_VA_PREALLOC_SZ; uint64_t internal = ODP_CONFIG_ISHM_VA_PREALLOC_SZ / 8; @@ -1666,27 +1666,27 @@ int _odp_ishm_init_global(const odp_init_t *init) if (init && init->shm.max_memory) max_memory = init->shm.max_memory + internal;
- odp_global_data.shm_max_memory = max_memory; - odp_global_data.shm_max_size = max_memory - internal; - odp_global_data.main_pid = getpid(); - odp_global_data.shm_dir = getenv("ODP_SHM_DIR"); - if (odp_global_data.shm_dir) { - odp_global_data.shm_dir_from_env = 1; + odp_global_ro.shm_max_memory = max_memory; + odp_global_ro.shm_max_size = max_memory - internal; + odp_global_ro.main_pid = getpid(); + odp_global_ro.shm_dir = getenv("ODP_SHM_DIR"); + if (odp_global_ro.shm_dir) { + odp_global_ro.shm_dir_from_env = 1; } else { - odp_global_data.shm_dir = + odp_global_ro.shm_dir = calloc(1, sizeof(ISHM_FILENAME_NORMAL_PAGE_DIR)); - sprintf(odp_global_data.shm_dir, "%s", + sprintf(odp_global_ro.shm_dir, "%s", ISHM_FILENAME_NORMAL_PAGE_DIR); - odp_global_data.shm_dir_from_env = 0; + odp_global_ro.shm_dir_from_env = 0; }
- ODP_DBG("ishm: using dir %s\n", odp_global_data.shm_dir); + ODP_DBG("ishm: using dir %s\n", odp_global_ro.shm_dir);
uid = getuid(); - snprintf(odp_global_data.uid, UID_MAXLEN, "%d", + snprintf(odp_global_ro.uid, UID_MAXLEN, "%d", uid);
- if ((syscall(SYS_gettid)) != odp_global_data.main_pid) { + if ((syscall(SYS_gettid)) != odp_global_ro.main_pid) { ODP_ERR("ishm init must be performed by the main " "ODP process!\n."); return -1; @@ -1701,7 +1701,7 @@ int _odp_ishm_init_global(const odp_init_t *init) align = odp_sys_huge_page_size(); }
- _odp_ishm_cleanup_files(odp_global_data.shm_dir); + _odp_ishm_cleanup_files(odp_global_ro.shm_dir);
/* allocate space for the internal shared mem block table: */ addr = mmap(NULL, sizeof(ishm_table_t), @@ -1791,7 +1791,7 @@ int _odp_ishm_init_local(void) * Do not re-run this for the main ODP process, as it has already * been done in advance at _odp_ishm_init_global() time: */ - if ((getpid() == odp_global_data.main_pid) && + if ((getpid() == odp_global_ro.main_pid) && (syscall(SYS_gettid) == getpid())) return 0;
@@ -1874,7 +1874,7 @@ int _odp_ishm_term_global(void) int index; ishm_block_t *block;
- if ((getpid() != odp_global_data.main_pid) || + if ((getpid() != odp_global_ro.main_pid) || (syscall(SYS_gettid) != getpid())) ODP_ERR("odp_term_global() must be performed by the main " "ODP process!\n."); @@ -1908,8 +1908,8 @@ int _odp_ishm_term_global(void) if (_odp_ishmphy_unbook_va()) ret |= -1;
- if (!odp_global_data.shm_dir_from_env) - free(odp_global_data.shm_dir); + if (!odp_global_ro.shm_dir_from_env) + free(odp_global_ro.shm_dir);
hp_term();
diff --git a/platform/linux-generic/odp_libconfig.c b/platform/linux-generic/odp_libconfig.c index 8caf9a53..baf825bb 100644 --- a/platform/linux-generic/odp_libconfig.c +++ b/platform/linux-generic/odp_libconfig.c @@ -23,8 +23,8 @@ int _odp_libconfig_init_global(void) const char *vers_rt; const char *ipml; const char *ipml_rt; - config_t *config = &odp_global_data.libconfig_default; - config_t *config_rt = &odp_global_data.libconfig_runtime; + config_t *config = &odp_global_ro.libconfig_default; + config_t *config_rt = &odp_global_ro.libconfig_runtime;
config_init(config); config_init(config_rt); @@ -75,8 +75,8 @@ fail:
int _odp_libconfig_term_global(void) { - config_destroy(&odp_global_data.libconfig_default); - config_destroy(&odp_global_data.libconfig_runtime); + config_destroy(&odp_global_ro.libconfig_default); + config_destroy(&odp_global_ro.libconfig_runtime);
return 0; } @@ -86,11 +86,11 @@ int _odp_libconfig_lookup_int(const char *path, int *value) int ret_def = CONFIG_FALSE; int ret_rt = CONFIG_FALSE;
- ret_def = config_lookup_int(&odp_global_data.libconfig_default, path, + ret_def = config_lookup_int(&odp_global_ro.libconfig_default, path, value);
/* Runtime option overrides default value */ - ret_rt = config_lookup_int(&odp_global_data.libconfig_runtime, path, + ret_rt = config_lookup_int(&odp_global_ro.libconfig_runtime, path, value);
return (ret_def == CONFIG_TRUE || ret_rt == CONFIG_TRUE) ? 1 : 0; @@ -105,9 +105,9 @@ int _odp_libconfig_lookup_array(const char *path, int value[], int max_num)
for (j = 0; j < 2; j++) { if (j == 0) - config = &odp_global_data.libconfig_default; + config = &odp_global_ro.libconfig_default; else - config = &odp_global_data.libconfig_runtime; + config = &odp_global_ro.libconfig_runtime;
setting = config_lookup(config, path);
@@ -162,11 +162,11 @@ int _odp_libconfig_lookup_ext_int(const char *base_path, const char *name, int *value) { - if (lookup_int(&odp_global_data.libconfig_runtime, + if (lookup_int(&odp_global_ro.libconfig_runtime, base_path, local_path, name, value)) return 1;
- if (lookup_int(&odp_global_data.libconfig_default, + if (lookup_int(&odp_global_ro.libconfig_default, base_path, local_path, name, value)) return 1;
diff --git a/platform/linux-generic/odp_pcapng.c b/platform/linux-generic/odp_pcapng.c index b8d29e5a..07784c17 100644 --- a/platform/linux-generic/odp_pcapng.c +++ b/platform/linux-generic/odp_pcapng.c @@ -74,7 +74,7 @@ static void get_pcapng_fifo_name(char *pcapng_entry, size_t len, char *pktio_name, int qidx) { snprintf(pcapng_entry, len, "%d-%s-flow-%d", - odp_global_data.main_pid, pktio_name, qidx); + odp_global_ro.main_pid, pktio_name, qidx); pcapng_entry[len - 1] = 0; }
@@ -120,13 +120,13 @@ static void *inotify_update(void *arg) while (1) { offset = 0; FD_ZERO(&rfds); - FD_SET(odp_global_data.inotify_pcapng_fd, &rfds); + FD_SET(odp_global_ro.inotify_pcapng_fd, &rfds); time.tv_sec = 2; time.tv_usec = 0; - select(odp_global_data.inotify_pcapng_fd + 1, &rfds, NULL, + select(odp_global_ro.inotify_pcapng_fd + 1, &rfds, NULL, NULL, &time); - if (FD_ISSET(odp_global_data.inotify_pcapng_fd, &rfds)) { - rdlen = read(odp_global_data.inotify_pcapng_fd, + if (FD_ISSET(odp_global_ro.inotify_pcapng_fd, &rfds)) { + rdlen = read(odp_global_ro.inotify_pcapng_fd, buffer, INOTIFY_BUF_LEN); while (offset < rdlen) { int qidx; @@ -219,23 +219,23 @@ int pcapng_prepare(pktio_entry_t *entry) }
/* already running from a previous pktio */ - if (odp_global_data.inotify_pcapng_is_running == 1) + if (odp_global_ro.inotify_pcapng_is_running == 1) return 0;
- odp_global_data.inotify_pcapng_fd = -1; - odp_global_data.inotify_watch_fd = -1; + odp_global_ro.inotify_pcapng_fd = -1; + odp_global_ro.inotify_watch_fd = -1;
- odp_global_data.inotify_pcapng_fd = inotify_init(); - if (odp_global_data.inotify_pcapng_fd == -1) { + odp_global_ro.inotify_pcapng_fd = inotify_init(); + if (odp_global_ro.inotify_pcapng_fd == -1) { ODP_ERR("can't init inotify. pcap disabled\n"); goto out_destroy; }
- odp_global_data.inotify_watch_fd = - inotify_add_watch(odp_global_data.inotify_pcapng_fd, + odp_global_ro.inotify_watch_fd = + inotify_add_watch(odp_global_ro.inotify_pcapng_fd, PCAPNG_WATCH_DIR, IN_CLOSE | IN_OPEN);
- if (odp_global_data.inotify_watch_fd == -1) { + if (odp_global_ro.inotify_watch_fd == -1) { ODP_ERR("can't register inotify for %s. pcap disabled\n", strerror(errno)); goto out_destroy; @@ -243,12 +243,12 @@ int pcapng_prepare(pktio_entry_t *entry)
/* create a thread to poll inotify triggers */ pthread_attr_init(&attr); - ret = pthread_create(&odp_global_data.inotify_thread, &attr, + ret = pthread_create(&odp_global_ro.inotify_thread, &attr, inotify_update, entry); if (ret) ODP_ERR("can't start inotify thread. pcap disabled\n"); else - odp_global_data.inotify_pcapng_is_running = 1; + odp_global_ro.inotify_pcapng_is_running = 1;
return ret;
@@ -265,24 +265,24 @@ void pcapng_destroy(pktio_entry_t *entry) unsigned int max_queue = MAX(entry->s.num_in_queue, entry->s.num_out_queue);
- if (odp_global_data.inotify_pcapng_is_running == 1) { - ret = pthread_cancel(odp_global_data.inotify_thread); + if (odp_global_ro.inotify_pcapng_is_running == 1) { + ret = pthread_cancel(odp_global_ro.inotify_thread); if (ret) ODP_ERR("can't cancel inotify thread %s\n", strerror(errno)); }
/* fd's will be -1 in case of any failure */ - ret = inotify_rm_watch(odp_global_data.inotify_pcapng_fd, - odp_global_data.inotify_watch_fd); + ret = inotify_rm_watch(odp_global_ro.inotify_pcapng_fd, + odp_global_ro.inotify_watch_fd); if (ret) ODP_ERR("can't deregister inotify %s\n", strerror(errno));
- if (odp_global_data.inotify_pcapng_fd != -1) - close(odp_global_data.inotify_pcapng_fd); + if (odp_global_ro.inotify_pcapng_fd != -1) + close(odp_global_ro.inotify_pcapng_fd);
- if (odp_global_data.inotify_watch_fd != -1) - close(odp_global_data.inotify_watch_fd); + if (odp_global_ro.inotify_watch_fd != -1) + close(odp_global_ro.inotify_watch_fd);
for (i = 0; i < max_queue; i++) { char pcapng_name[128]; diff --git a/platform/linux-generic/odp_pool.c b/platform/linux-generic/odp_pool.c index 5cb423b9..bb6aa98b 100644 --- a/platform/linux-generic/odp_pool.c +++ b/platform/linux-generic/odp_pool.c @@ -595,7 +595,7 @@ odp_pool_t odp_pool_create(const char *name, odp_pool_param_t *params)
if (params->type == ODP_POOL_PACKET) shm_flags = ODP_SHM_PROC; - if (odp_global_data.shm_single_va) + if (odp_global_ro.shm_single_va) shm_flags |= ODP_SHM_SINGLE_VA;
return pool_create(name, params, shm_flags); diff --git a/platform/linux-generic/odp_shared_memory.c b/platform/linux-generic/odp_shared_memory.c index 7bd323c9..5345cee8 100644 --- a/platform/linux-generic/odp_shared_memory.c +++ b/platform/linux-generic/odp_shared_memory.c @@ -49,7 +49,7 @@ int odp_shm_capability(odp_shm_capability_t *capa) memset(capa, 0, sizeof(odp_shm_capability_t));
capa->max_blocks = ODP_CONFIG_SHM_BLOCKS; - capa->max_size = odp_global_data.shm_max_size; + capa->max_size = odp_global_ro.shm_max_size; capa->max_align = 0;
return 0; diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c index 608fa51e..733c3528 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -47,7 +47,7 @@ */ static int sysconf_cpu_count(void) { - return odp_global_data.num_cpus_installed; + return odp_global_ro.num_cpus_installed; }
#if defined __x86_64__ || defined __i386__ || defined __OCTEON__ || \ @@ -339,16 +339,16 @@ int odp_system_info_init(void) int i; FILE *file;
- memset(&odp_global_data.system_info, 0, sizeof(system_info_t)); + memset(&odp_global_ro.system_info, 0, sizeof(system_info_t));
- odp_global_data.system_info.page_size = ODP_PAGE_SIZE; + odp_global_ro.system_info.page_size = ODP_PAGE_SIZE;
/* By default, read max frequency from a cpufreq file */ for (i = 0; i < CONFIG_NUM_CPU; i++) { uint64_t cpu_hz_max = read_cpufreq("cpuinfo_max_freq", i);
if (cpu_hz_max) - odp_global_data.system_info.cpu_hz_max[i] = cpu_hz_max; + odp_global_ro.system_info.cpu_hz_max[i] = cpu_hz_max; }
file = fopen("/proc/cpuinfo", "rt"); @@ -358,16 +358,16 @@ int odp_system_info_init(void) }
/* Read CPU model, and set max cpu frequency if not set from cpufreq. */ - cpuinfo_parser(file, &odp_global_data.system_info); + cpuinfo_parser(file, &odp_global_ro.system_info);
fclose(file);
- if (systemcpu(&odp_global_data.system_info)) { + if (systemcpu(&odp_global_ro.system_info)) { ODP_ERR("systemcpu failed\n"); return -1; }
- system_hp(&odp_global_data.hugepage_info); + system_hp(&odp_global_ro.hugepage_info);
return 0; } @@ -377,7 +377,7 @@ int odp_system_info_init(void) */ int odp_system_info_term(void) { - free(odp_global_data.hugepage_info.default_huge_page_dir); + free(odp_global_ro.hugepage_info.default_huge_page_dir);
return 0; } @@ -417,14 +417,14 @@ uint64_t odp_cpu_hz_max(void) uint64_t odp_cpu_hz_max_id(int id) { if (id >= 0 && id < CONFIG_NUM_CPU) - return odp_global_data.system_info.cpu_hz_max[id]; + return odp_global_ro.system_info.cpu_hz_max[id]; else return 0; }
uint64_t odp_sys_huge_page_size(void) { - return odp_global_data.hugepage_info.default_huge_page_size; + return odp_global_ro.hugepage_info.default_huge_page_size; }
static int pagesz_compare(const void *pagesz1, const void *pagesz2) @@ -466,7 +466,7 @@ int odp_sys_huge_page_size_all(uint64_t size[], int num)
uint64_t odp_sys_page_size(void) { - return odp_global_data.system_info.page_size; + return odp_global_ro.system_info.page_size; }
const char *odp_cpu_model_str(void) @@ -477,19 +477,19 @@ const char *odp_cpu_model_str(void) const char *odp_cpu_model_str_id(int id) { if (id >= 0 && id < CONFIG_NUM_CPU) - return odp_global_data.system_info.model_str[id]; + return odp_global_ro.system_info.model_str[id]; else return NULL; }
int odp_sys_cache_line_size(void) { - return odp_global_data.system_info.cache_line_size; + return odp_global_ro.system_info.cache_line_size; }
int odp_cpu_count(void) { - return odp_global_data.system_info.cpu_count; + return odp_global_ro.system_info.cpu_count; }
void odp_sys_info_print(void) diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index 87d42f7c..e8682237 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -259,7 +259,7 @@ static odp_timer_pool_t timer_pool_new(const char *name, size_t sz0, sz1, sz2; uint32_t flags = ODP_SHM_SW_ONLY;
- if (odp_global_data.shm_single_va) + if (odp_global_ro.shm_single_va) flags |= ODP_SHM_SINGLE_VA;
odp_ticketlock_lock(&timer_global.lock); diff --git a/platform/linux-generic/odp_traffic_mngr.c b/platform/linux-generic/odp_traffic_mngr.c index 7ca1a4ce..cf2ce83e 100644 --- a/platform/linux-generic/odp_traffic_mngr.c +++ b/platform/linux-generic/odp_traffic_mngr.c @@ -2346,7 +2346,7 @@ static void *tm_system_thread(void *arg) uint32_t destroying, work_queue_cnt, timer_cnt; int rc;
- rc = odp_init_local((odp_instance_t)odp_global_data.main_pid, + rc = odp_init_local((odp_instance_t)odp_global_ro.main_pid, ODP_THREAD_WORKER); ODP_ASSERT(rc == 0); tm_group = arg; diff --git a/platform/linux-generic/pktio/ipc.c b/platform/linux-generic/pktio/ipc.c index 553ac4c3..74af0b97 100644 --- a/platform/linux-generic/pktio/ipc.c +++ b/platform/linux-generic/pktio/ipc.c @@ -233,7 +233,7 @@ static void _ipc_export_pool(struct pktio_info *pinfo,
snprintf(pinfo->slave.pool_name, ODP_POOL_NAME_LEN, "%s", _ipc_odp_buffer_pool_shm_name(pool_hdl)); - pinfo->slave.pid = odp_global_data.main_pid; + pinfo->slave.pid = odp_global_ro.main_pid; pinfo->slave.block_size = pool->block_size; pinfo->slave.base_addr = pool->base_addr; } diff --git a/platform/linux-generic/pktio/ring.c b/platform/linux-generic/pktio/ring.c index 6e03b44c..488dc1a1 100644 --- a/platform/linux-generic/pktio/ring.c +++ b/platform/linux-generic/pktio/ring.c @@ -172,7 +172,7 @@ _ring_create(const char *name, unsigned count, unsigned flags) shm_flag = ODP_SHM_PROC | ODP_SHM_EXPORT; else shm_flag = 0; - if (odp_global_data.shm_single_va) + if (odp_global_ro.shm_single_va) shm_flag |= ODP_SHM_SINGLE_VA;
/* count must be a power of 2 */
-----------------------------------------------------------------------
Summary of changes: .travis.yml | 15 ++ example/classifier/odp_classifier.c | 7 +- example/generator/odp_generator.c | 15 +- example/ipsec/odp_ipsec.c | 125 ++++++------ example/ipsec_api/odp_ipsec.c | 117 ++++++----- example/ipsec_offload/odp_ipsec_offload.c | 98 ++++----- example/l2fwd_simple/odp_l2fwd_simple.c | 102 ++++++---- example/l3fwd/odp_l3fwd.c | 112 ++++++----- example/packet/odp_pktio.c | 34 +++- example/switch/odp_switch.c | 19 +- helper/threads.c | 9 + .../linux-generic/include/odp_debug_internal.h | 10 +- platform/linux-generic/include/odp_global_data.h | 15 +- platform/linux-generic/include/odp_init_internal.h | 1 + platform/linux-generic/include/odp_packet_socket.h | 2 + platform/linux-generic/odp_cpumask.c | 42 ++-- platform/linux-generic/odp_cpumask_task.c | 16 +- platform/linux-generic/odp_fdserver.c | 26 +-- platform/linux-generic/odp_hash_crc_gen.c | 60 ++++-- platform/linux-generic/odp_init.c | 96 +++++++-- platform/linux-generic/odp_ipsec.c | 44 ++-- platform/linux-generic/odp_ishm.c | 76 +++---- platform/linux-generic/odp_libconfig.c | 20 +- platform/linux-generic/odp_pcapng.c | 46 ++--- platform/linux-generic/odp_pool.c | 2 +- platform/linux-generic/odp_shared_memory.c | 2 +- platform/linux-generic/odp_system_info.c | 28 +-- platform/linux-generic/odp_timer.c | 110 ++++++---- platform/linux-generic/odp_traffic_mngr.c | 2 +- platform/linux-generic/pktio/dpdk.c | 9 +- platform/linux-generic/pktio/ipc.c | 2 +- platform/linux-generic/pktio/pcap.c | 13 +- platform/linux-generic/pktio/ring.c | 2 +- platform/linux-generic/pktio/socket_mmap.c | 28 ++- .../test/mmap_vlan_ins/mmap_vlan_ins.c | 51 +++-- platform/linux-generic/test/process-mode.conf | 10 + platform/linux-generic/test/ring/ring_stress.c | 61 ++++-- test/performance/odp_bench_packet.c | 12 +- test/performance/odp_cpu_bench.c | 13 +- test/performance/odp_l2fwd.c | 25 +-- test/performance/odp_pktio_ordered.c | 19 +- test/performance/odp_pktio_ordered_run.sh | 3 +- test/performance/odp_pktio_perf.c | 36 ++-- test/validation/api/atomic/atomic.c | 224 +++++++++++---------- test/validation/api/thread/thread.c | 77 ++++++- test/validation/api/timer/timer.c | 125 +++++++++--- 46 files changed, 1184 insertions(+), 777 deletions(-) create mode 100644 platform/linux-generic/test/process-mode.conf
hooks/post-receive