aboutsummaryrefslogtreecommitdiff
path: root/example/packet
diff options
context:
space:
mode:
authorRobbie King <robking@cisco.com>2015-01-14 23:48:26 +0100
committerMaxim Uvarov <maxim.uvarov@linaro.org>2015-01-16 17:33:19 +0300
commit38e36ef15500a3517a635a258bba3fea263cc555 (patch)
treee8996aea5d6a527e66d4a58db2ffca05b6e8ecf0 /example/packet
parent5e47a0cf301367e47a3e1dfefbd6c5b4677916b8 (diff)
helper: linux: use cpumask in linux thread/proc
Move away from specifying a core count and allow the user to specify a mask. Signed-off-by: Robbie King <robking@cisco.com> Signed-off-by: Anders Roxell <anders.roxell@linaro.org> Reviewed-by: Petri Savolainen <petri.savolainen@linaro.org> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'example/packet')
-rw-r--r--example/packet/odp_pktio.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c
index 0d5918a..4a392af 100644
--- a/example/packet/odp_pktio.c
+++ b/example/packet/odp_pktio.c
@@ -279,9 +279,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) {
@@ -307,27 +308,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(&cpumask, cpumaskstr, sizeof(cpumaskstr));
- 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;
@@ -349,13 +344,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];
@@ -370,8 +365,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 */