diff mbox series

[1/3] cyclictest: Move main pid setaffinity handling into a function

Message ID 20210616231800.19228-1-jkacur@redhat.com
State New
Headers show
Series [1/3] cyclictest: Move main pid setaffinity handling into a function | expand

Commit Message

John Kacur June 16, 2021, 11:17 p.m. UTC
From: Jonathan Schwender <schwenderjonathan@gmail.com>

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>
---
 src/cyclictest/cyclictest.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

Comments

Daniel Wagner June 17, 2021, 6:41 a.m. UTC | #1
On Wed, Jun 16, 2021 at 07:17:58PM -0400, John Kacur wrote:
> From: Jonathan Schwender <schwenderjonathan@gmail.com>

> 

> 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>
Daniel Wagner June 17, 2021, 6:42 a.m. UTC | #2
On Wed, Jun 16, 2021 at 07:17:59PM -0400, John Kacur wrote:
> From: Jonathan Schwender <schwenderjonathan@gmail.com>

> 

> This allows the user to specify a separate cpuset for the main pid,

> e.g. on a housekeeping CPU.

> If --mainaffinity is not specified, but --affinity is, then the

> current behaviour is preserved and the main thread is bound

> to the cpuset specified by --affinity

> 

> Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>

> - Little fix-up applying patch

> Signed-off-by: John Kacur <jkacur@redhat.com>


Reviewed-by: Daniel Wagner <dwagner@suse.de>
diff mbox series

Patch

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index a561443fa67b..edb0c707d35c 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));