@@ -1778,13 +1778,7 @@ int main(int argc, char **argv)
/* Restrict the main pid to the affinity specified by the user */
if (affinity_mask) {
- int res;
-
- errno = 0;
- res = numa_sched_setaffinity(getpid(), affinity_mask);
- if (res != 0)
- warn("Couldn't setaffinity in main thread: %s\n", strerror(errno));
-
+ try_numa_sched_setaffinity(getpid(), affinity_mask);
if (verbose)
printf("Using %u cpus.\n",
numa_bitmask_weight(affinity_mask));
@@ -18,4 +18,6 @@ int cpu_for_thread_ua(int thread_num, int max_cpus);
int parse_cpumask(char *str, int max_cpus, struct bitmask **cpumask);
+void try_numa_sched_setaffinity(__pid_t pid, struct bitmask *cpumask);
+
#endif
@@ -133,3 +133,14 @@ int parse_cpumask(char *str, int max_cpus, struct bitmask **cpumask)
return 0;
}
+
+void try_numa_sched_setaffinity(__pid_t pid, struct bitmask *cpumask)
+{
+ int res;
+
+ errno = 0;
+ res = numa_sched_setaffinity(pid, cpumask);
+ if (res != 0)
+ warn("Couldn't setaffinity for thread %d: %s\n", pid,
+ strerror(errno));
+}
Move error handling for setting the affinity of the main pid into a separate function. This prevents duplicating the code in the next commit, where the main thread pid can be restricted to one of two bitmasks depending on the passed parameters. After feedback from John Kacur, the function is now located in src/lib/rt-numa.c. This allows other tests to reuse this, if they also prefer to warn if numa_sched_setaffinity fails. Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> --- src/cyclictest/cyclictest.c | 8 +------- src/include/rt-numa.h | 2 ++ src/lib/rt-numa.c | 11 +++++++++++ 3 files changed, 14 insertions(+), 7 deletions(-)