Thread (2 messages) 2 messages, 2 authors, 2021-01-22
STALE2011d

[PATCH] cyclictest: Fix --affinity when intermediate CPUs are offline

From: Jonathan Schwender <hidden>
Date: 2021-01-14 11:51:41
Subsystem: the rest · Maintainer: Linus Torvalds

Use max_cpus = sysconf(_SC_NPROCESSORS_CONF) to determine the number of
the maximum CPU (+1).
The cpu_for_thread_*() functions check the first max_cpus bits
in the cpuset / cpumask.
This fixes failing to set the affinity to CPUs >= num_online_cpus,
if some intermediate CPU is offline, e.g. on an AMD system
with nosmt.

Signed-off-by: Jonathan Schwender <redacted>
---
 src/cyclictest/cyclictest.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index f38c453..b104e4c 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -1741,7 +1741,8 @@ int main(int argc, char **argv)
 	int signum = SIGALRM;
 	int mode;
 	int cpu;
-	int max_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+	int max_cpus = sysconf(_SC_NPROCESSORS_CONF);
+	int online_cpus = sysconf(_SC_NPROCESSORS_ONLN);
 	int i, ret = -1;
 	int status;
 
@@ -1750,8 +1751,10 @@ int main(int argc, char **argv)
 	if (check_privs())
 		exit(EXIT_FAILURE);
 
-	if (verbose)
+	if (verbose) {
 		printf("Max CPUs = %d\n", max_cpus);
+		printf("Online CPUs = %d\n", online_cpus);
+	}
 
 	/* Restrict the main pid to the affinity specified by the user */
 	if (affinity_mask != NULL) {
-- 
2.29.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help