Add an simpler wrapper which calls the right implementation depending on if the cpumask is valid or not. Reviewed-by: Daniel Wagner <dwagner@xxxxxxx> --- src/cyclictest/cyclictest.c | 6 +----- src/include/rt-numa.h | 3 +-- src/lib/rt-numa.c | 13 ++++++++++--- src/signaltest/signaltest.c | 6 +----- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c index a6364c8e04c0..092534abb709 100644 --- a/src/cyclictest/cyclictest.c +++ b/src/cyclictest/cyclictest.c @@ -1884,11 +1884,7 @@ int main(int argc, char **argv) if (status != 0) fatal("error from pthread_attr_init for thread %d: %s\n", i, strerror(status)); - if (affinity_mask) - cpu = cpu_for_thread_sp(i, max_cpus, affinity_mask); - else - cpu = cpu_for_thread_ua(i, max_cpus); - + cpu = cpu_for_thread(i, max_cpus, affinity_mask); if (verbose) printf("Thread %d using cpu %d.\n", i, cpu); diff --git a/src/include/rt-numa.h b/src/include/rt-numa.h index 54f5c3a240e9..189da3a804e1 100644 --- a/src/include/rt-numa.h +++ b/src/include/rt-numa.h @@ -5,8 +5,7 @@ #include <numa.h> int get_available_cpus(struct bitmask *cpumask); -int cpu_for_thread_sp(int thread_num, int max_cpus, struct bitmask *cpumask); -int cpu_for_thread_ua(int thread_num, int max_cpus); +int cpu_for_thread(int thread_num, int max_cpus, struct bitmask *cpumask); int parse_cpumask(char *str, int max_cpus, struct bitmask **cpumask); diff --git a/src/lib/rt-numa.c b/src/lib/rt-numa.c index db5178f93043..a246dbca7291 100644 --- a/src/lib/rt-numa.c +++ b/src/lib/rt-numa.c @@ -21,7 +21,7 @@ int get_available_cpus(struct bitmask *cpumask) return numa_num_task_cpus(); } -int cpu_for_thread_sp(int thread_num, int max_cpus, struct bitmask *cpumask) +static int cpu_for_thread_sp(int thread_num, int max_cpus, struct bitmask *cpumask) { unsigned int m, cpu, i, num_cpus; @@ -44,8 +44,7 @@ int cpu_for_thread_sp(int thread_num, int max_cpus, struct bitmask *cpumask) return 0; } -/* cpu_for_thread AFFINITY_USEALL */ -int cpu_for_thread_ua(int thread_num, int max_cpus) +static int cpu_for_thread_ua(int thread_num, int max_cpus) { int res, num_cpus, i, m, cpu; pthread_t thread; @@ -73,6 +72,14 @@ int cpu_for_thread_ua(int thread_num, int max_cpus) return 0; } +int cpu_for_thread(int thread_num, int max_cpus, struct bitmask *cpumask) +{ + if (cpumask) + return cpu_for_thread_sp(thread_num, max_cpus, cpumask); + else + return cpu_for_thread_ua(thread_num, max_cpus); +} + /* * After this function is called, affinity_mask is the intersection of * the user supplied affinity mask and the affinity mask from the run diff --git a/src/signaltest/signaltest.c b/src/signaltest/signaltest.c index 41ebb2c87a2f..2ea5e6b58946 100644 --- a/src/signaltest/signaltest.c +++ b/src/signaltest/signaltest.c @@ -373,11 +373,7 @@ int main(int argc, char **argv) par[i].bufmsk = VALBUF_SIZE - 1; } - if (affinity_mask) - cpu = cpu_for_thread_sp(i, max_cpus, affinity_mask); - else - cpu = cpu_for_thread_ua(i, max_cpus); - + cpu = cpu_for_thread(i, max_cpus, affinity_mask); if (verbose) printf("Thread %d using cpu %d.\n", i, cpu); -- 2.29.2