All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Schwender <schwenderjonathan@gmail.com>
To: jkacur@redhat.com, williams@redhat.com
Cc: linux-rt-users@vger.kernel.org
Subject: [PATCH v4 1/2] cyclictest: Move main pid setaffinity handling into a function
Date: Tue, 18 May 2021 10:37:11 +0200	[thread overview]
Message-ID: <20210518083712.8237-2-schwenderjonathan@gmail.com> (raw)
In-Reply-To: <20210518083712.8237-1-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>
---
 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");
 }
 
+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


  reply	other threads:[~2021-05-18  8:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-18  8:37 [PATCH v4 0/2] rt-tests: cyclictest: Add option to specify main pid affinity Jonathan Schwender
2021-05-18  8:37 ` Jonathan Schwender [this message]
2021-05-21 20:19   ` [PATCH v4 1/2] cyclictest: Move main pid setaffinity handling into a function John Kacur
2021-05-22  7:35     ` Jonathan Schwender
2021-05-18  8:37 ` [PATCH v4 2/2] cyclictest: Add --mainaffinity=[CPUSET] option Jonathan Schwender
2021-05-19 15:55   ` Daniel Wagner
2021-05-22  8:13     ` Jonathan Schwender
2021-05-21 20:21   ` John Kacur
2021-05-21 20:24   ` John Kacur
2021-05-22  7:57     ` Jonathan Schwender

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210518083712.8237-2-schwenderjonathan@gmail.com \
    --to=schwenderjonathan@gmail.com \
    --cc=jkacur@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.