@@ -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);
@@ -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
@@ -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);
Make signaltest a bit more userfriendly and move all threads on the same CPU the default behavior. Signed-off-by: Daniel Wagner <dwagner@suse.de> --- 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(-)