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, Daniel Wagner <dwagner@suse.de>
Subject: [rt-tests v1 6/6] oslat: Use parse_cpumask() from rt-numa.h
Date: Fri, 13 Nov 2020 22:09:10 +0100	[thread overview]
Message-ID: <20201113210910.21807-7-dwagner@suse.de> (raw)
In-Reply-To: <20201113210910.21807-1-dwagner@suse.de>

Use the common parse_cpumask() helper and use struct bitmask directly
instead transforming it into a CPU_SET first.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
 src/oslat/oslat.c | 55 +++++++++++++++--------------------------------
 1 file changed, 17 insertions(+), 38 deletions(-)

diff --git a/src/oslat/oslat.c b/src/oslat/oslat.c
index b2aa15001be2..5b7e0d5b5d5c 100644
--- a/src/oslat/oslat.c
+++ b/src/oslat/oslat.c
@@ -42,6 +42,7 @@
 #include <sys/syscall.h>
 
 #include "rt-utils.h"
+#include "rt-numa.h"
 #include "error.h"
 
 #ifdef __GNUC__
@@ -542,37 +543,6 @@ static void usage(int error)
 	exit(error);
 }
 
-/* TODO: use libnuma? */
-static int parse_cpu_list(char *cpu_list, cpu_set_t *cpu_set)
-{
-	struct bitmask *cpu_mask;
-	int i, n_cores;
-
-	n_cores = sysconf(_SC_NPROCESSORS_CONF);
-
-	if (!cpu_list) {
-		for (i = 0; i < n_cores; i++)
-			CPU_SET(i, cpu_set);
-		return n_cores;
-	}
-
-	cpu_mask = numa_parse_cpustring_all(cpu_list);
-	if (cpu_mask) {
-		for (i = 0; i < n_cores; i++) {
-			if (numa_bitmask_isbitset(cpu_mask, i))
-				CPU_SET(i, cpu_set);
-		}
-		numa_bitmask_free(cpu_mask);
-	} else {
-		warn("Unknown cpu-list: %s, using all available cpus\n", cpu_list);
-		for (i = 0; i < n_cores; i++)
-			CPU_SET(i, cpu_set);
-	}
-
-	return n_cores;
-}
-
-
 static int workload_select(char *name)
 {
 	int i = 0;
@@ -745,15 +715,18 @@ int main(int argc, char *argv[])
 {
 	struct thread *threads;
 	int i, n_cores;
-	cpu_set_t cpu_set;
+	struct bitmask *cpu_set = NULL;
+	int max_cpus = sysconf(_SC_NPROCESSORS_ONLN);
 
 #ifdef FRC_MISSING
 	printf("This architecture is not yet supported. "
 	       "Please implement frc() function first for %s.\n", argv[0]);
 	return 0;
 #endif
-
-	CPU_ZERO(&cpu_set);
+	if (numa_available() == -1) {
+		printf("ERROR: Could not initialize libnuma\n");
+		exit(1);
+	}
 
 	g.app_name = argv[0];
 	g.rtprio = 0;
@@ -768,16 +741,22 @@ int main(int argc, char *argv[])
 
 	TEST(mlockall(MCL_CURRENT | MCL_FUTURE) == 0);
 
-	n_cores = parse_cpu_list(g.cpu_list, &cpu_set);
+	if (!g.cpu_list)
+		g.cpu_list = strdup("all");
+	if (parse_cpumask(g.cpu_list, max_cpus, &cpu_set))
+		exit(1);
+	n_cores = numa_bitmask_weight(cpu_set);
 
-	TEST(threads = calloc(1, CPU_COUNT(&cpu_set) * sizeof(threads[0])));
+	TEST(threads = calloc(1, n_cores * sizeof(threads[0])));
 	for (i = 0; i < n_cores; ++i)
-		if (CPU_ISSET(i, &cpu_set) && move_to_core(i) == 0)
+		if (numa_bitmask_isbitset(cpu_set, i) && move_to_core(i) == 0)
 			threads[g.n_threads_total++].core_i = i;
 
-	if (CPU_ISSET(0, &cpu_set) && g.rtprio)
+	if (numa_bitmask_isbitset(cpu_set, 0) && g.rtprio)
 		printf("WARNING: Running SCHED_FIFO workload on CPU 0 may hang the thread\n");
 
+	numa_bitmask_free(cpu_set);
+
 	TEST(move_to_core(g.cpu_main_thread) == 0);
 
 	signal(SIGALRM, handle_alarm);
-- 
2.29.2


  parent reply	other threads:[~2020-11-13 21:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-13 21:09 [rt-tests v1 0/6] Move common code to helper libraries Daniel Wagner
2020-11-13 21:09 ` [rt-tests v1 1/6] rt-utils: Introduce parse_mem_string() Daniel Wagner
2020-11-18 20:59   ` John Kacur
2020-11-13 21:09 ` [rt-tests v1 2/6] oslat: Use string parser utilies Daniel Wagner
2020-11-18 21:00   ` John Kacur
2020-11-13 21:09 ` [rt-tests v1 3/6] cyclictest: Remove deadcode checking for NUMA Daniel Wagner
2020-11-18 21:01   ` John Kacur
2020-11-13 21:09 ` [rt-tests v1 4/6] rt-numa: Introduce NUMA helpers Daniel Wagner
2020-11-18 21:09   ` John Kacur
2020-11-19  8:21     ` Daniel Wagner
2020-11-13 21:09 ` [rt-tests v1 5/6] cyclictest: Use parse_cpumask() from rt-numa.h Daniel Wagner
2020-11-18 21:10   ` John Kacur
2020-11-18 21:17   ` John Kacur
2020-11-13 21:09 ` Daniel Wagner [this message]
2020-11-18 21:18   ` [rt-tests v1 6/6] oslat: " John Kacur
2021-02-10 16:07   ` Peter Xu
2021-02-10 16:29     ` Daniel Wagner

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=20201113210910.21807-7-dwagner@suse.de \
    --to=dwagner@suse.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