summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Schwender <schwenderjonathan@gmail.com>2021-05-18 10:37:11 +0200
committerJohn Kacur <jkacur@redhat.com>2021-06-17 09:02:28 -0400
commit5290b62d3e9099e144b2369f3d835fab5d8e415f (patch)
treeb1fe24706a838f9a3a2ef5be12637b63250e273f
parentfca9fc32b0e6b2bf202787e25f4bda279c4d0ca7 (diff)
downloadrt-tests-5290b62d3e9099e144b2369f3d835fab5d8e415f.tar.gz
cyclictest: Move main pid setaffinity handling into a function
Move error handling for setting the affinity of the main thread 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. Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> Signed-off-by: John Kacur <jkacur@redhat.com> Reviewed-by: Daniel Wagner <dwagner@suse.de>
-rw-r--r--src/cyclictest/cyclictest.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index a561443..edb0c70 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -1768,6 +1768,17 @@ static void write_stats(FILE *f, void *data)
fprintf(f, " }\n");
}
+static void set_main_thread_affinity(struct bitmask *cpumask)
+{
+ int res;
+
+ errno = 0;
+ res = numa_sched_setaffinity(getpid(), cpumask);
+ if (res != 0)
+ warn("Couldn't setaffinity in main thread: %s\n",
+ strerror(errno));
+}
+
int main(int argc, char **argv)
{
sigset_t sigset;
@@ -1792,13 +1803,7 @@ int main(int argc, char **argv)
/* Restrict the main pid to the affinity specified by the user */
if (affinity_mask != NULL) {
- 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));
-
+ set_main_thread_affinity(affinity_mask);
if (verbose)
printf("Using %u cpus.\n",
numa_bitmask_weight(affinity_mask));