Skip to contentSkip to conversation

rt-numa: Use a reasonable default max CPU value.

PATCH New John Kacur 1 participant 1 message Jan 19, 2023

lore
Share & tools
lore

John Kacur

author
#0 lore raw

PATCH 1/1 rt-numa: Use a reasonable default max CPU value.

From: Sebastian Andrzej Siewior <[email protected]>

numa_num_task_cpus() returns here > 100 CPUs while the system has only 32 populated. The BIOS assumes that I can probably use larger CPUs (with more cores) on the socket so the number of "configured CPUs" is rather high.

It makes sense to use the current affinity instead of looking at the number of possible CPUs which could be brought online. It still depends on the affinity of the created threads if the additional CPUs can be used. In a container setup this may not be the case.

Use sched_getaffinity() to figure out the number of possible CPUs.

- Edited the commit message to remove reference to -S

---
 src/lib/rt-numa.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
src/lib/rt-numa.c +10 -1
index 3eead80c3b2b..1b09cff8d948 100644
@@ -35,10 +35,19 @@ int numa_initialize(void)
 
 int get_available_cpus(struct bitmask *cpumask)
 {
+	cpu_set_t cpuset;
+	int ret;
+
 	if (cpumask)
 		return numa_bitmask_weight(cpumask);
 
-	return numa_num_task_cpus();
+	CPU_ZERO(&cpuset);
+
+	ret = sched_getaffinity(0, sizeof(cpu_set_t), &cpuset);
+	if (ret < 0)
+		fatal("sched_getaffinity failed: %m\n");
+
+	return CPU_COUNT(&cpuset);
 }
 
 int cpu_for_thread_sp(int thread_num, int max_cpus, struct bitmask *cpumask)
Signature · 1 line
2.39.0