Signed-off-by: Robbie King <[email protected]>
---
 example/generator/odp_generator.c         | 42 ++++++++++++++++---------------
 example/ipsec/odp_ipsec.c                 | 30 +++++++++++-----------
 example/l2fwd/odp_l2fwd.c                 | 39 +++++++++++++---------------
 example/packet/odp_pktio.c                | 30 ++++++++++------------
 example/timer/odp_timer_test.c            | 23 ++++++++---------
 test/api_test/odp_common.c                |  7 +++++-
 test/performance/odp_scheduling.c         | 26 ++++++++-----------
 test/validation/common/odp_cunit_common.c |  7 +++++-
 8 files changed, 100 insertions(+), 104 deletions(-)

diff --git a/example/generator/odp_generator.c 
b/example/generator/odp_generator.c
index c3f1783..f1adf89 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -544,9 +544,10 @@ int main(int argc, char *argv[])
        int num_workers;
        int i;
        int first_cpu;
-       int cpu_count;
        odp_shm_t shm;
+       odp_coremask_t coremask;
        odp_buffer_pool_param_t params;
+       char coremaskstr[64];
 
        /* Init ODP before calling anything else */
        if (odp_init_global(NULL, NULL)) {
@@ -582,31 +583,26 @@ 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 = 0;
        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;
+       odph_linux_coremask_create(&num_workers, &first_cpu, &coremask);
+       odp_coremask_to_str(coremaskstr, sizeof(coremaskstr), &coremask);
 
-       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", first_cpu);
+       printf("core mask:          %s\n", coremaskstr);
 
        /* Create packet pool */
        params.buf_size  = SHM_PKT_POOL_BUF_SIZE;
@@ -629,28 +625,32 @@ int main(int argc, char *argv[])
        memset(thread_tbl, 0, sizeof(thread_tbl));
 
        if (args->appl.mode == APPL_MODE_PING) {
+               odp_coremask_t core0_mask;
+
+               /* Previous code forced both threads to core 0 */
+               odp_coremask_zero(&core0_mask);
+               odp_coremask_set(0, &core0_mask);
+
                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], &core0_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], &core0_mask,
                                          gen_send_thread, &args->thread[0]);
 
                /* only wait send thread to join */
                num_workers = 1;
        } else {
                for (i = 0; i < num_workers; ++i) {
+                       odp_coremask_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,8 +670,10 @@ 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_coremask_next_core(&thd_mask, &coremask);
+                       odph_linux_pthread_create(&thread_tbl[i],
+                                                 &thd_mask,
+                                                 thr_run_func,
                                                  &args->thread[i]);
                }
        }
diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
index 7a0fbef..7306d1e 100644
--- a/example/ipsec/odp_ipsec.c
+++ b/example/ipsec/odp_ipsec.c
@@ -1173,10 +1173,11 @@ main(int argc, char *argv[])
        int num_workers;
        int i;
        int first_cpu;
-       int cpu_count;
        int stream_count;
        odp_shm_t shm;
+       odp_coremask_t coremask;
        odp_buffer_pool_param_t params;
+       char coremaskstr[64];
 
        /* Init ODP before calling anything else */
        if (odp_init_global(NULL, NULL)) {
@@ -1214,26 +1215,25 @@ 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 = 0;
        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);
+       first_cpu = 1;
+       odph_linux_coremask_create(&num_workers, &first_cpu, &coremask);
+       odp_coremask_to_str(coremaskstr, sizeof(coremaskstr), &coremask);
+
+       printf("num worker threads: %i\n", num_workers);
+       printf("first CPU:          %i\n", first_cpu);
+       printf("core mask:          %s\n", coremaskstr);
+
+       /* 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 +1285,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, &coremask,
                                  pktio_thread, NULL);
 
        /*
diff --git a/example/l2fwd/odp_l2fwd.c b/example/l2fwd/odp_l2fwd.c
index 209b0bd..ec17cb1 100644
--- a/example/l2fwd/odp_l2fwd.c
+++ b/example/l2fwd/odp_l2fwd.c
@@ -289,10 +289,11 @@ int main(int argc, char *argv[])
        odp_buffer_pool_t pool;
        int i;
        int first_cpu;
-       int cpu_count;
        int num_workers;
        odp_shm_t shm;
+       odp_coremask_t coremask;
        odp_buffer_pool_param_t params;
+       char coremaskstr[64];
 
        /* Init ODP before calling anything else */
        if (odp_init_global(NULL, NULL)) {
@@ -323,16 +324,22 @@ 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 = 0;
        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
+        */
+       first_cpu = 1;
+       odph_linux_coremask_create(&num_workers, &first_cpu, &coremask);
+       odp_coremask_to_str(coremaskstr, sizeof(coremaskstr), &coremask);
 
-       printf("Num worker threads: %i\n", num_workers);
+       printf("num worker threads: %i\n", num_workers);
+       printf("first CPU:          %i\n", first_cpu);
+       printf("core mask:          %s\n", coremaskstr);
 
        if (num_workers < gbl_args->appl.if_count) {
                EXAMPLE_ERR("Error: CPU count %d less than interface count\n",
@@ -344,16 +351,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;
@@ -381,10 +378,8 @@ int main(int argc, char *argv[])
 
        /* Create worker threads */
        for (i = 0; i < num_workers; ++i) {
+               odp_coremask_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,7 +388,9 @@ 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_coremask_next_core(&thd_mask, &coremask);
+               odph_linux_pthread_create(&thread_tbl[i], &thd_mask,
+                                         thr_run_func,
                                          &gbl_args->thread[i]);
        }
 
diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c
index b162fac..eeaacca 100644
--- a/example/packet/odp_pktio.c
+++ b/example/packet/odp_pktio.c
@@ -279,8 +279,9 @@ int main(int argc, char *argv[])
        int num_workers;
        int i;
        int first_cpu;
-       int cpu_count;
+       odp_coremask_t coremask;
        odp_buffer_pool_param_t params;
+       char coremaskstr[64];
 
        args = calloc(1, sizeof(args_t));
        if (args == NULL) {
@@ -306,27 +307,22 @@ 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 = 0;
        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;
+       odph_linux_coremask_create(&num_workers, &first_cpu, &coremask);
+       odp_coremask_to_str(coremaskstr, sizeof(coremaskstr), &coremask);
 
-       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", first_cpu);
+       printf("core mask:          %s\n", coremaskstr);
 
        /* Create packet pool */
        params.buf_size  = SHM_PKT_POOL_BUF_SIZE;
@@ -349,12 +345,10 @@ int main(int argc, char *argv[])
        /* Create and init worker threads */
        memset(thread_tbl, 0, sizeof(thread_tbl));
        for (i = 0; i < num_workers; ++i) {
+               odp_coremask_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,7 +363,9 @@ 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_coremask_next_core(&thd_mask, &coremask);
+               odph_linux_pthread_create(&thread_tbl[i], &thd_mask,
+                                         thr_run_func,
                                          &args->thread[i]);
        }
 
diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c
index 5de499b..dbef917 100644
--- a/example/timer/odp_timer_test.c
+++ b/example/timer/odp_timer_test.c
@@ -306,6 +306,8 @@ int main(int argc, char *argv[])
        odp_buffer_pool_param_t params;
        odp_timer_pool_param_t tparams;
        odp_timer_pool_info_t tpinfo;
+       odp_coremask_t coremask;
+       char coremaskstr[64];
 
        printf("\nODP timer example starts\n");
 
@@ -336,28 +338,23 @@ 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 = 0;
        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;
+       odph_linux_coremask_create(&num_workers, &first_cpu, &coremask);
+       odp_coremask_to_str(coremaskstr, sizeof(coremaskstr), &coremask);
 
-       if (odp_sys_cpu_count() == 1)
-               first_cpu = 0;
-
+       printf("num worker threads: %i\n", num_workers);
        printf("first CPU:          %i\n", first_cpu);
+       printf("core mask:          %s\n", coremaskstr);
+
        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 +441,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, &coremask,
                                  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..d37e325 100644
--- a/test/api_test/odp_common.c
+++ b/test/api_test/odp_common.c
@@ -73,8 +73,13 @@ int odp_test_global_init(void)
 /** create test thread */
 int odp_test_thread_create(void *func_ptr(void *), pthrd_arg *arg)
 {
+       int num_threads = arg->numthrds;
+       int first_cpu = 0;
+       odp_coremask_t coremask;
+
        /* Create and init additional threads */
-       odph_linux_pthread_create(thread_tbl, arg->numthrds, 0, func_ptr,
+       odph_linux_coremask_create(&num_threads, &first_cpu, &coremask);
+       odph_linux_pthread_create(thread_tbl, &coremask, func_ptr,
                                  (void *)arg);
 
        return 0;
diff --git a/test/performance/odp_scheduling.c 
b/test/performance/odp_scheduling.c
index ba7528d..faae9ac 100644
--- a/test/performance/odp_scheduling.c
+++ b/test/performance/odp_scheduling.c
@@ -953,6 +953,7 @@ int main(int argc, char *argv[])
        odph_linux_pthread_t thread_tbl[MAX_WORKERS];
        test_args_t args;
        int num_workers;
+       odp_coremask_t coremask;
        odp_buffer_pool_t pool;
        odp_queue_t queue;
        int i, j;
@@ -961,6 +962,7 @@ int main(int argc, char *argv[])
        odp_shm_t shm;
        test_globals_t *globals;
        odp_buffer_pool_param_t params;
+       char coremaskstr[64];
 
        printf("\nODP example starts\n\n");
 
@@ -1000,29 +1002,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 = 0;
        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;
+       odph_linux_coremask_create(&num_workers, &first_cpu, &coremask);
+       odp_coremask_to_str(coremaskstr, sizeof(coremaskstr), &coremask);
 
-       if (odp_sys_cpu_count() == 1)
-               first_cpu = 0;
-
+       printf("num worker threads: %i\n", num_workers);
        printf("first CPU:          %i\n", first_cpu);
-
+       printf("core mask:          %s\n", coremaskstr);
 
        /* Test cycle count accuracy */
        test_time();
@@ -1111,8 +1106,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, &coremask);
 
                if (ret < 0) {
                        LOG_ERR("Fork workers failed %i\n", ret);
@@ -1130,7 +1124,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, &coremask,
                                          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..217633c 100644
--- a/test/validation/common/odp_cunit_common.c
+++ b/test/validation/common/odp_cunit_common.c
@@ -20,8 +20,13 @@ static odph_linux_pthread_t thread_tbl[MAX_WORKERS];
 /** create test thread */
 int odp_cunit_thread_create(void *func_ptr(void *), pthrd_arg *arg)
 {
+       int num_threads = arg->numthrds;
+       int first_cpu = 0;
+       odp_coremask_t coremask;
+
        /* Create and init additional threads */
-       odph_linux_pthread_create(thread_tbl, arg->numthrds, 0, func_ptr,
+       odph_linux_coremask_create(&num_threads, &first_cpu, &coremask);
+       odph_linux_pthread_create(thread_tbl, &coremask, func_ptr,
                                  (void *)arg);
 
        return 0;
-- 
1.9.3


_______________________________________________
lng-odp mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to