Signed-off-by: Robbie King <[email protected]>
---
example/generator/odp_generator.c | 48 +++++++++++++++++--------------
example/ipsec/odp_ipsec.c | 30 +++++++++----------
example/l2fwd/odp_l2fwd.c | 43 ++++++++++++++-------------
example/packet/odp_pktio.c | 37 ++++++++++++------------
example/timer/odp_timer_test.c | 25 +++++++---------
test/api_test/odp_common.c | 13 +++++----
test/performance/odp_scheduling.c | 30 +++++++------------
test/validation/common/odp_cunit_common.c | 5 +++-
8 files changed, 112 insertions(+), 119 deletions(-)
diff --git a/example/generator/odp_generator.c
b/example/generator/odp_generator.c
index c3f1783..03aba41 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -543,10 +543,10 @@ int main(int argc, char *argv[])
odp_buffer_pool_t pool;
int num_workers;
int i;
- int first_cpu;
- int cpu_count;
odp_shm_t shm;
+ odp_cpumask_t cpumask;
odp_buffer_pool_param_t params;
+ char cpumaskstr[64];
/* Init ODP before calling anything else */
if (odp_init_global(NULL, NULL)) {
@@ -582,31 +582,25 @@ int main(int argc, char *argv[])
/* Print both system and application information */
print_info(NO_PATH(argv[0]), &args->appl);
- cpu_count = odp_sys_cpu_count();
- num_workers = cpu_count;
-
+ /* Default to system CPU count unless user specified */
+ num_workers = MAX_WORKERS;
if (args->appl.cpu_count)
num_workers = args->appl.cpu_count;
- if (num_workers > MAX_WORKERS)
- num_workers = MAX_WORKERS;
-
/* ping mode need two worker */
if (args->appl.mode == APPL_MODE_PING)
num_workers = 2;
- printf("Num worker threads: %i\n", num_workers);
-
/*
* By default CPU #0 runs Linux kernel background tasks.
* Start mapping thread from CPU #1
*/
- first_cpu = 1;
-
- if (cpu_count == 1)
- first_cpu = 0;
+ num_workers = odph_linux_cpumask_default(&cpumask, num_workers);
+ odp_cpumask_to_str(cpumaskstr, sizeof(cpumaskstr), &cpumask);
- printf("First CPU: %i\n\n", first_cpu);
+ printf("num worker threads: %i\n", num_workers);
+ printf("first CPU: %i\n", odp_cpumask_first(&cpumask));
+ printf("cpu mask: %s\n", cpumaskstr);
/* Create packet pool */
params.buf_size = SHM_PKT_POOL_BUF_SIZE;
@@ -629,28 +623,33 @@ int main(int argc, char *argv[])
memset(thread_tbl, 0, sizeof(thread_tbl));
if (args->appl.mode == APPL_MODE_PING) {
+ odp_cpumask_t cpu0_mask;
+
+ /* Previous code forced both threads to CPU 0 */
+ odp_cpumask_zero(&cpu0_mask);
+ odp_cpumask_set(&cpu0_mask, 0);
+
args->thread[1].pktio_dev = args->appl.if_names[0];
args->thread[1].pool = pool;
args->thread[1].mode = args->appl.mode;
- odph_linux_pthread_create(&thread_tbl[1], 1, 0,
+ odph_linux_pthread_create(&thread_tbl[1], &cpu0_mask,
gen_recv_thread, &args->thread[1]);
args->thread[0].pktio_dev = args->appl.if_names[0];
args->thread[0].pool = pool;
args->thread[0].mode = args->appl.mode;
- odph_linux_pthread_create(&thread_tbl[0], 1, 0,
+ odph_linux_pthread_create(&thread_tbl[0], &cpu0_mask,
gen_send_thread, &args->thread[0]);
/* only wait send thread to join */
num_workers = 1;
} else {
+ int cpu = odp_cpumask_first(&cpumask);
for (i = 0; i < num_workers; ++i) {
+ odp_cpumask_t thd_mask;
void *(*thr_run_func) (void *);
- int cpu;
int if_idx;
- cpu = (first_cpu + i) % cpu_count;
-
if_idx = i % args->appl.if_count;
args->thread[i].pktio_dev = args->appl.if_names[if_idx];
@@ -670,9 +669,14 @@ int main(int argc, char *argv[])
* because each thread might get different arguments.
* Calls odp_thread_create(cpu) for each thread
*/
- odph_linux_pthread_create(&thread_tbl[i], 1,
- cpu, thr_run_func,
+ odp_cpumask_zero(&thd_mask);
+ odp_cpumask_set(&thd_mask, cpu);
+ odph_linux_pthread_create(&thread_tbl[i],
+ &thd_mask,
+ thr_run_func,
&args->thread[i]);
+ cpu = odp_cpumask_next(&cpumask, cpu);
+
}
}
diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
index 7a0fbef..5d7bca0 100644
--- a/example/ipsec/odp_ipsec.c
+++ b/example/ipsec/odp_ipsec.c
@@ -1172,11 +1172,11 @@ main(int argc, char *argv[])
odph_linux_pthread_t thread_tbl[MAX_WORKERS];
int num_workers;
int i;
- int first_cpu;
- int cpu_count;
int stream_count;
odp_shm_t shm;
+ odp_cpumask_t cpumask;
odp_buffer_pool_param_t params;
+ char cpumaskstr[64];
/* Init ODP before calling anything else */
if (odp_init_global(NULL, NULL)) {
@@ -1214,26 +1214,24 @@ main(int argc, char *argv[])
/* Print both system and application information */
print_info(NO_PATH(argv[0]), &args->appl);
- cpu_count = odp_sys_cpu_count();
- num_workers = cpu_count;
-
+ /* Default to system CPU count unless user specified */
+ num_workers = MAX_WORKERS;
if (args->appl.cpu_count)
num_workers = args->appl.cpu_count;
- if (num_workers > MAX_WORKERS)
- num_workers = MAX_WORKERS;
-
- printf("Num worker threads: %i\n", num_workers);
-
- /* Create a barrier to synchronize thread startup */
- odp_barrier_init(&sync_barrier, num_workers);
-
/*
* By default CPU #0 runs Linux kernel background tasks.
* Start mapping thread from CPU #1
*/
- first_cpu = (1 == cpu_count) ? 0 : 1;
- printf("First CPU: %i\n\n", first_cpu);
+ num_workers = odph_linux_cpumask_default(&cpumask, num_workers);
+ odp_cpumask_to_str(cpumaskstr, sizeof(cpumaskstr), &cpumask);
+
+ printf("num worker threads: %i\n", 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);
/* Create packet buffer pool */
params.buf_size = SHM_PKT_POOL_BUF_SIZE;
@@ -1285,7 +1283,7 @@ main(int argc, char *argv[])
/*
* Create and init worker threads
*/
- odph_linux_pthread_create(thread_tbl, num_workers, first_cpu,
+ odph_linux_pthread_create(thread_tbl, &cpumask,
pktio_thread, NULL);
/*
diff --git a/example/l2fwd/odp_l2fwd.c b/example/l2fwd/odp_l2fwd.c
index 209b0bd..b9fa84d 100644
--- a/example/l2fwd/odp_l2fwd.c
+++ b/example/l2fwd/odp_l2fwd.c
@@ -288,11 +288,12 @@ int main(int argc, char *argv[])
odph_linux_pthread_t thread_tbl[MAX_WORKERS];
odp_buffer_pool_t pool;
int i;
- int first_cpu;
- int cpu_count;
+ int cpu;
int num_workers;
odp_shm_t shm;
+ odp_cpumask_t cpumask;
odp_buffer_pool_param_t params;
+ char cpumaskstr[64];
/* Init ODP before calling anything else */
if (odp_init_global(NULL, NULL)) {
@@ -323,16 +324,21 @@ int main(int argc, char *argv[])
/* Print both system and application information */
print_info(NO_PATH(argv[0]), &gbl_args->appl);
- cpu_count = odp_sys_cpu_count();
- num_workers = cpu_count;
-
+ /* Default to system CPU count unless user specified */
+ num_workers = MAX_WORKERS;
if (gbl_args->appl.cpu_count)
num_workers = gbl_args->appl.cpu_count;
- if (num_workers > MAX_WORKERS)
- num_workers = MAX_WORKERS;
+ /*
+ * By default CPU #0 runs Linux kernel background tasks.
+ * Start mapping thread from CPU #1
+ */
+ num_workers = odph_linux_cpumask_default(&cpumask, num_workers);
+ odp_cpumask_to_str(cpumaskstr, sizeof(cpumaskstr), &cpumask);
- printf("Num worker threads: %i\n", num_workers);
+ printf("num worker threads: %i\n", num_workers);
+ printf("first CPU: %i\n", odp_cpumask_first(&cpumask));
+ printf("cpu mask: %s\n", cpumaskstr);
if (num_workers < gbl_args->appl.if_count) {
EXAMPLE_ERR("Error: CPU count %d less than interface count\n",
@@ -344,16 +350,6 @@ int main(int argc, char *argv[])
gbl_args->appl.if_count);
exit(EXIT_FAILURE);
}
- /*
- * By default CPU #0 runs Linux kernel background tasks.
- * Start mapping thread from CPU #1
- */
- first_cpu = 1;
-
- if (cpu_count == 1)
- first_cpu = 0;
-
- printf("First cpu: %i\n\n", first_cpu);
/* Create packet pool */
params.buf_size = SHM_PKT_POOL_BUF_SIZE;
@@ -380,11 +376,10 @@ int main(int argc, char *argv[])
memset(thread_tbl, 0, sizeof(thread_tbl));
/* Create worker threads */
+ cpu = odp_cpumask_first(&cpumask);
for (i = 0; i < num_workers; ++i) {
+ odp_cpumask_t thd_mask;
void *(*thr_run_func) (void *);
- int cpu;
-
- cpu = (first_cpu + i) % cpu_count;
if (gbl_args->appl.mode == APPL_MODE_PKT_BURST)
thr_run_func = pktio_ifburst_thread;
@@ -393,8 +388,12 @@ int main(int argc, char *argv[])
gbl_args->thread[i].src_idx = i % gbl_args->appl.if_count;
- odph_linux_pthread_create(&thread_tbl[i], 1, cpu, thr_run_func,
+ odp_cpumask_zero(&thd_mask);
+ odp_cpumask_set(&thd_mask, cpu);
+ odph_linux_pthread_create(&thread_tbl[i], &thd_mask,
+ thr_run_func,
&gbl_args->thread[i]);
+ cpu = odp_cpumask_next(&thd_mask, cpu);
}
/* Master thread waits for other threads to exit */
diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c
index b162fac..7b96a9a 100644
--- a/example/packet/odp_pktio.c
+++ b/example/packet/odp_pktio.c
@@ -278,9 +278,10 @@ int main(int argc, char *argv[])
odp_buffer_pool_t pool;
int num_workers;
int i;
- int first_cpu;
- int cpu_count;
+ int cpu;
+ odp_cpumask_t cpumask;
odp_buffer_pool_param_t params;
+ char cpumaskstr[64];
args = calloc(1, sizeof(args_t));
if (args == NULL) {
@@ -306,27 +307,21 @@ int main(int argc, char *argv[])
/* Print both system and application information */
print_info(NO_PATH(argv[0]), &args->appl);
- cpu_count = odp_sys_cpu_count();
- num_workers = cpu_count;
-
+ /* Default to system CPU count unless user specified */
+ num_workers = MAX_WORKERS;
if (args->appl.cpu_count)
num_workers = args->appl.cpu_count;
- if (num_workers > MAX_WORKERS)
- num_workers = MAX_WORKERS;
-
- printf("Num worker threads: %i\n", num_workers);
-
/*
* By default CPU #0 runs Linux kernel background tasks.
* Start mapping thread from CPU #1
*/
- first_cpu = 1;
+ num_workers = odph_linux_cpumask_default(&cpumask, num_workers);
+ odp_cpumask_to_str(cpumaskstr, sizeof(cpumaskstr), &cpumask);
- if (cpu_count == 1)
- first_cpu = 0;
-
- printf("First CPU: %i\n\n", first_cpu);
+ printf("num worker threads: %i\n", num_workers);
+ printf("first CPU: %i\n", odp_cpumask_first(&cpumask));
+ printf("cpu mask: %s\n", cpumaskstr);
/* Create packet pool */
params.buf_size = SHM_PKT_POOL_BUF_SIZE;
@@ -348,13 +343,13 @@ int main(int argc, char *argv[])
/* Create and init worker threads */
memset(thread_tbl, 0, sizeof(thread_tbl));
+
+ cpu = odp_cpumask_first(&cpumask);
for (i = 0; i < num_workers; ++i) {
+ odp_cpumask_t thd_mask;
void *(*thr_run_func) (void *);
- int cpu;
int if_idx;
- cpu = (first_cpu + i) % cpu_count;
-
if_idx = i % args->appl.if_count;
args->thread[i].pktio_dev = args->appl.if_names[if_idx];
@@ -369,8 +364,12 @@ int main(int argc, char *argv[])
* because each thread might get different arguments.
* Calls odp_thread_create(cpu) for each thread
*/
- odph_linux_pthread_create(&thread_tbl[i], 1, cpu, thr_run_func,
+ odp_cpumask_zero(&thd_mask);
+ odp_cpumask_set(&thd_mask, cpu);
+ odph_linux_pthread_create(&thread_tbl[i], &thd_mask,
+ thr_run_func,
&args->thread[i]);
+ cpu = odp_cpumask_next(&cpumask, cpu);
}
/* Master thread waits for other threads to exit */
diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c
index 5de499b..562a211 100644
--- a/example/timer/odp_timer_test.c
+++ b/example/timer/odp_timer_test.c
@@ -300,12 +300,13 @@ int main(int argc, char *argv[])
test_args_t args;
int num_workers;
odp_queue_t queue;
- int first_cpu;
uint64_t cycles, ns;
odp_queue_param_t param;
odp_buffer_pool_param_t params;
odp_timer_pool_param_t tparams;
odp_timer_pool_info_t tpinfo;
+ odp_cpumask_t cpumask;
+ char cpumaskstr[64];
printf("\nODP timer example starts\n");
@@ -336,28 +337,22 @@ int main(int argc, char *argv[])
printf("\n");
- /* A worker thread per CPU */
- num_workers = odp_sys_cpu_count();
-
+ /* Default to system CPU count unless user specified */
+ num_workers = MAX_WORKERS;
if (args.cpu_count)
num_workers = args.cpu_count;
- /* force to max CPU count */
- if (num_workers > MAX_WORKERS)
- num_workers = MAX_WORKERS;
-
- printf("num worker threads: %i\n", num_workers);
-
/*
* By default CPU #0 runs Linux kernel background tasks.
* Start mapping thread from CPU #1
*/
- first_cpu = 1;
+ num_workers = odph_linux_cpumask_default(&cpumask, num_workers);
+ odp_cpumask_to_str(cpumaskstr, sizeof(cpumaskstr), &cpumask);
- if (odp_sys_cpu_count() == 1)
- first_cpu = 0;
+ printf("num worker threads: %i\n", num_workers);
+ printf("first CPU: %i\n", odp_cpumask_first(&cpumask));
+ printf("cpu mask: %s\n", cpumaskstr);
- printf("first CPU: %i\n", first_cpu);
printf("resolution: %i usec\n", args.resolution_us);
printf("min timeout: %i usec\n", args.min_us);
printf("max timeout: %i usec\n", args.max_us);
@@ -444,7 +439,7 @@ int main(int argc, char *argv[])
odp_barrier_init(&test_barrier, num_workers);
/* Create and launch worker threads */
- odph_linux_pthread_create(thread_tbl, num_workers, first_cpu,
+ odph_linux_pthread_create(thread_tbl, &cpumask,
run_thread, &args);
/* Wait for worker threads to exit */
diff --git a/test/api_test/odp_common.c b/test/api_test/odp_common.c
index e585ef5..bed99a1 100644
--- a/test/api_test/odp_common.c
+++ b/test/api_test/odp_common.c
@@ -29,15 +29,15 @@ __thread test_shared_data_t *test_shared_data;
/**< pointer to shared data *
*/
void odp_print_system_info(void)
{
- odp_coremask_t coremask;
+ odp_cpumask_t cpumask;
char str[32];
memset(str, 1, sizeof(str));
- odp_coremask_zero(&coremask);
+ odp_cpumask_zero(&cpumask);
- odp_coremask_from_str("0x1", &coremask);
- odp_coremask_to_str(str, sizeof(str), &coremask);
+ odp_cpumask_from_str("0x1", &cpumask);
+ odp_cpumask_to_str(str, sizeof(str), &cpumask);
printf("\n");
printf("ODP system info\n");
@@ -73,8 +73,11 @@ int odp_test_global_init(void)
/** create test thread */
int odp_test_thread_create(void *func_ptr(void *), pthrd_arg *arg)
{
+ odp_cpumask_t cpumask;
+
/* Create and init additional threads */
- odph_linux_pthread_create(thread_tbl, arg->numthrds, 0, func_ptr,
+ odph_linux_cpumask_default(&cpumask, arg->numthrds);
+ odph_linux_pthread_create(thread_tbl, &cpumask, func_ptr,
(void *)arg);
return 0;
diff --git a/test/performance/odp_scheduling.c
b/test/performance/odp_scheduling.c
index ba7528d..20089c4 100644
--- a/test/performance/odp_scheduling.c
+++ b/test/performance/odp_scheduling.c
@@ -953,14 +953,15 @@ int main(int argc, char *argv[])
odph_linux_pthread_t thread_tbl[MAX_WORKERS];
test_args_t args;
int num_workers;
+ odp_cpumask_t cpumask;
odp_buffer_pool_t pool;
odp_queue_t queue;
int i, j;
int prios;
- int first_cpu;
odp_shm_t shm;
test_globals_t *globals;
odp_buffer_pool_param_t params;
+ char cpumaskstr[64];
printf("\nODP example starts\n\n");
@@ -1000,29 +1001,21 @@ int main(int argc, char *argv[])
printf("\n");
- /* A worker thread per CPU */
- num_workers = odp_sys_cpu_count();
-
+ /* Default to system CPU count unless user specified */
+ num_workers = MAX_WORKERS;
if (args.cpu_count)
num_workers = args.cpu_count;
- /* force to max CPU count */
- if (num_workers > MAX_WORKERS)
- num_workers = MAX_WORKERS;
-
- printf("num worker threads: %i\n", num_workers);
-
/*
* By default CPU #0 runs Linux kernel background tasks.
* Start mapping thread from CPU #1
*/
- first_cpu = 1;
-
- if (odp_sys_cpu_count() == 1)
- first_cpu = 0;
-
- printf("first CPU: %i\n", first_cpu);
+ num_workers = odph_linux_cpumask_default(&cpumask, num_workers);
+ odp_cpumask_to_str(cpumaskstr, sizeof(cpumaskstr), &cpumask);
+ printf("num worker threads: %i\n", num_workers);
+ printf("first CPU: %i\n", odp_cpumask_first(&cpumask));
+ printf("cpu mask: %s\n", cpumaskstr);
/* Test cycle count accuracy */
test_time();
@@ -1111,8 +1104,7 @@ int main(int argc, char *argv[])
odph_linux_process_t proc[MAX_WORKERS];
/* Fork worker processes */
- ret = odph_linux_process_fork_n(proc, num_workers,
- first_cpu);
+ ret = odph_linux_process_fork_n(proc, &cpumask);
if (ret < 0) {
LOG_ERR("Fork workers failed %i\n", ret);
@@ -1130,7 +1122,7 @@ int main(int argc, char *argv[])
} else {
/* Create and launch worker threads */
- odph_linux_pthread_create(thread_tbl, num_workers, first_cpu,
+ odph_linux_pthread_create(thread_tbl, &cpumask,
run_thread, NULL);
/* Wait for worker threads to terminate */
diff --git a/test/validation/common/odp_cunit_common.c
b/test/validation/common/odp_cunit_common.c
index 2fab033..4d05b95 100644
--- a/test/validation/common/odp_cunit_common.c
+++ b/test/validation/common/odp_cunit_common.c
@@ -20,8 +20,11 @@ static odph_linux_pthread_t thread_tbl[MAX_WORKERS];
/** create test thread */
int odp_cunit_thread_create(void *func_ptr(void *), pthrd_arg *arg)
{
+ odp_cpumask_t cpumask;
+
/* Create and init additional threads */
- odph_linux_pthread_create(thread_tbl, arg->numthrds, 0, func_ptr,
+ odph_linux_cpumask_default(&cpumask, arg->numthrds);
+ odph_linux_pthread_create(thread_tbl, &cpumask, func_ptr,
(void *)arg);
return 0;
--
1.9.1
_______________________________________________
lng-odp mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/lng-odp