Make signaltest a bit more userfriendly and move all threads on the same CPU the default behavior. Signed-off-by: Daniel Wagner <dwagner@xxxxxxx> --- v2: fix compile warnings src/include/rt-numa.h | 1 + src/lib/rt-numa.c | 22 ++++++++++++++++++++++ src/signaltest/signaltest.c | 4 +--- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/include/rt-numa.h b/src/include/rt-numa.h index ca86a45dab3a..f52de1ca68d7 100644 --- a/src/include/rt-numa.h +++ b/src/include/rt-numa.h @@ -15,6 +15,7 @@ int numa_initialize(void); 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 max_cpus); 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 76f8bd2f0ebe..49cebdf9e801 100644 --- a/src/lib/rt-numa.c +++ b/src/lib/rt-numa.c @@ -87,6 +87,28 @@ int cpu_for_thread_ua(int thread_num, int max_cpus) return 0; } +int cpu_for_thread(int max_cpus) +{ + int res, i; + pthread_t thread; + cpu_set_t cpuset; + + thread = pthread_self(); + CPU_ZERO(&cpuset); + + res = pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset); + if (res != 0) + fatal("pthread_getaffinity_np failed: %s\n", strerror(res)); + + for (i = 0; i < max_cpus; i++) { + if (CPU_ISSET(i, &cpuset)) + return i; + } + + fprintf(stderr, "Bug in cpu mask handling code.\n"); + return 0; +} + /* * 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 e19877a395ba..5aa0003501b3 100644 --- a/src/signaltest/signaltest.c +++ b/src/signaltest/signaltest.c @@ -301,8 +301,6 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus) if (numa_initialize()) fatal("Couldn't initilize libnuma"); numa = 1; - if (setaffinity == AFFINITY_UNSPECIFIED) - setaffinity = AFFINITY_USEALL; } if (option_affinity) { @@ -404,7 +402,7 @@ int main(int argc, char **argv) switch (setaffinity) { case AFFINITY_UNSPECIFIED: - cpu = -1; + cpu = cpu_for_thread(max_cpus); break; case AFFINITY_SPECIFIED: cpu = cpu_for_thread_sp(i, max_cpus, affinity_mask); -- 2.29.2