public inbox for linux-rt-users@vger.kernel.org
 help / color / mirror / Atom feed
From: Daniel Wagner <dwagner@suse.de>
To: Clark Williams <williams@redhat.com>, John Kacur <jkacur@redhat.com>
Cc: linux-rt-users@vger.kernel.org,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Daniel Wagner <dwagner@suse.de>
Subject: [rt-tests v1 3/3] signaltest: Set affintiy on default
Date: Sun, 15 Nov 2020 19:40:59 +0100	[thread overview]
Message-ID: <20201115184059.7286-4-dwagner@suse.de> (raw)
In-Reply-To: <20201115184059.7286-1-dwagner@suse.de>

Make signaltest a bit more userfriendly and move all threads on the
same CPU the default behavior.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
 src/include/rt-numa.h       |  1 +
 src/lib/rt-numa.c           | 22 ++++++++++++++++++++++
 src/signaltest/signaltest.c |  4 +---
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/src/include/rt-numa.h b/src/include/rt-numa.h
index ca86a45dab3a..f52de1ca68d7 100644
--- a/src/include/rt-numa.h
+++ b/src/include/rt-numa.h
@@ -15,6 +15,7 @@ int numa_initialize(void);
 int get_available_cpus(struct bitmask *cpumask);
 int cpu_for_thread_sp(int thread_num, int max_cpus, struct bitmask *cpumask);
 int cpu_for_thread_ua(int thread_num, int max_cpus);
+int cpu_for_thread(int max_cpus);
 
 int parse_cpumask(char *str, int max_cpus, struct bitmask **cpumask);
 
diff --git a/src/lib/rt-numa.c b/src/lib/rt-numa.c
index 76f8bd2f0ebe..7147ea7ea4b2 100644
--- a/src/lib/rt-numa.c
+++ b/src/lib/rt-numa.c
@@ -87,6 +87,28 @@ int cpu_for_thread_ua(int thread_num, int max_cpus)
 	return 0;
 }
 
+int cpu_for_thread(int max_cpus)
+{
+	int res, num_cpus, i, m, cpu;
+	pthread_t thread;
+	cpu_set_t cpuset;
+
+	thread = pthread_self();
+	CPU_ZERO(&cpuset);
+
+	res = pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
+	if (res != 0)
+		fatal("pthread_getaffinity_np failed: %s\n", strerror(res));
+
+	for (i = 0, cpu = 0; i < max_cpus; i++) {
+		if (CPU_ISSET(i, &cpuset))
+			return i;
+	}
+
+	fprintf(stderr, "Bug in cpu mask handling code.\n");
+	return 0;
+}
+
 /*
  * After this function is called, affinity_mask is the intersection of
  * the user supplied affinity mask and the affinity mask from the run
diff --git a/src/signaltest/signaltest.c b/src/signaltest/signaltest.c
index e19877a395ba..5aa0003501b3 100644
--- a/src/signaltest/signaltest.c
+++ b/src/signaltest/signaltest.c
@@ -301,8 +301,6 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus)
 		if (numa_initialize())
 			fatal("Couldn't initilize libnuma");
 		numa = 1;
-		if (setaffinity == AFFINITY_UNSPECIFIED)
-			setaffinity = AFFINITY_USEALL;
 	}
 
 	if (option_affinity) {
@@ -404,7 +402,7 @@ int main(int argc, char **argv)
 
 		switch (setaffinity) {
 		case AFFINITY_UNSPECIFIED:
-			cpu = -1;
+			cpu = cpu_for_thread(max_cpus);
 			break;
 		case AFFINITY_SPECIFIED:
 			cpu = cpu_for_thread_sp(i, max_cpus, affinity_mask);
-- 
2.29.2


      parent reply	other threads:[~2020-11-15 18:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-15 18:40 [rt-tests v1 0/3] Teach signaltest affinity Daniel Wagner
2020-11-15 18:40 ` [rt-tests v1 1/3] rt-numa: Move thread placement code to rt-numa library Daniel Wagner
2020-11-20 21:38   ` John Kacur
2020-11-15 18:40 ` [rt-tests v1 2/3] signaltest: Implement thread placing Daniel Wagner
2020-11-20 21:44   ` John Kacur
2020-11-15 18:40 ` Daniel Wagner [this message]

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=20201115184059.7286-4-dwagner@suse.de \
    --to=dwagner@suse.de \
    --cc=bigeasy@linutronix.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox