Message ID | 20210518083712.8237-2-schwenderjonathan@gmail.com |
---|---|
State | New |
Headers | show |
Series | rt-tests: cyclictest: Add option to specify main pid affinity | expand |
On Tue, 18 May 2021, Jonathan Schwender wrote: > 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> > --- > src/cyclictest/cyclictest.c | 19 ++++++++++++------- > 1 file changed, 12 insertions(+), 7 deletions(-) > > diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c > index 59dda19..3bab3b2 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"); > } > How about set_thread_affinity() since you want to use the function for the main thread plus other threads. > +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)); > -- > 2.31.1 > >
Am 21.05.2021 um 22:19 schrieb John Kacur: > How about set_thread_affinity() since you want to use the function > for the main thread plus other threads. > >> +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)); >> +} >> + >> Actually, I only intended to use this for the main thread. I didn't touch the affinity setting of the timerthreads (and don't see a need to). I'm not familiar with the whole cyclictest code and all options. Did you have any specific threads in mind that also use numa_sched_setaffinity() and could use this function? Maybe you got that impression from the previous v3 iteration, where I moved the functionality to rt_numa and added a parameter for the pid/tid. My motivation there was mainly, that if I'm moving it into a library, then I should probably add a parameter for the pid to the function in case someone has a usecase for that.
diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c index 59dda19..3bab3b2 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));
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> --- src/cyclictest/cyclictest.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)