From 684bed4b3a752ed7b9b2a3319dd0fe211ef87ee0 Mon Sep 17 00:00:00 2001 From: Juri Lelli Date: Sat, 5 Oct 2013 17:17:57 +0200 Subject: clean cpuset mask before using it --- src/rt-app.c | 28 +++++++++++++++------------- src/rt-app_parse_config.c | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/rt-app.c b/src/rt-app.c index 69e169b..298d498 100644 --- a/src/rt-app.c +++ b/src/rt-app.c @@ -138,6 +138,21 @@ void *thread_body(void *arg) #endif int ret, i = 0; int j; + + /* set thread affinity */ + if (data->cpuset != NULL) + { + log_notice("[%d] setting cpu affinity to CPU(s) %s", data->ind, + data->cpuset_str); + ret = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), + data->cpuset); + if (ret < 0) { + errno = ret; + perror("pthread_setaffinity_np"); + exit(EXIT_FAILURE); + } + } + /* set scheduling policy and print pretty info on stdout */ log_notice("[%d] Using %s policy:", data->ind, data->sched_policy_descr); switch (data->sched_policy) @@ -235,19 +250,6 @@ void *thread_body(void *arg) exit(EXIT_FAILURE); } } - /* set thread affinity */ - if (data->cpuset != NULL) - { - log_notice("[%d] setting cpu affinity to CPU(s) %s", data->ind, - data->cpuset_str); - ret = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), - data->cpuset); - if (ret < 0) { - errno = ret; - perror("pthread_setaffinity_np"); - exit(EXIT_FAILURE); - } - } if (data->wait_before_start > 0) { log_notice("[%d] Waiting %ld usecs... ", data->ind, diff --git a/src/rt-app_parse_config.c b/src/rt-app_parse_config.c index 3652f52..1e4d42f 100644 --- a/src/rt-app_parse_config.c +++ b/src/rt-app_parse_config.c @@ -172,7 +172,6 @@ parse_resources(struct json_object *resources, rtapp_options_t *opts) for (i = 0; i < res; i++) { pthread_mutexattr_init(&opts->resources[i].mtx_attr); if (opts->pi_enabled) { - printf("pi enabled\n"); pthread_mutexattr_setprotocol( &opts->resources[i].mtx_attr, PTHREAD_PRIO_INHERIT); @@ -398,6 +397,7 @@ parse_thread_data(char *name, struct json_object *obj, int idx, log_info(PIN "key: cpus %s", data->cpuset_str); data->cpuset = malloc(sizeof(cpu_set_t)); cpuset = json_object_get_array(cpuset_obj); + CPU_ZERO(data->cpuset); for (i=0; i < json_object_array_length(cpuset_obj); i++) { cpu = json_object_array_get_idx(cpuset_obj, i); cpu_idx = json_object_get_int(cpu); -- cgit v1.2.3