Skip to contentSkip to conversation

cyclictest: Fix --affinity when intermediate CPUs are offline

PATCH In review Jonathan Schwender 2 participants 2 messages Jan 14, 2021 – Jan 22, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cyclictest: Fix --affinity when intermediate CPUs are offline

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.

---
 src/cyclictest/cyclictest.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
src/cyclictest/cyclictest.c +5 -2
index f38c453..b104e4c 100644
@@ -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) {
Signature · 1 line
2.29.2
#1 lore raw
Quoted 43 lines · Jonathan Schwender

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.

---
 src/cyclictest/cyclictest.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
src/cyclictest/cyclictest.c +5 -2
index f38c453..b104e4c 100644
@@ -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) {
Signature · 1 line
2.29.2

Thanks