public inbox for linux-rt-users@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rt-numa: Use a reasonable default max CPU value.
@ 2023-01-12 10:00 Sebastian Andrzej Siewior
  2023-01-16 18:15 ` John Kacur
  0 siblings, 1 reply; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2023-01-12 10:00 UTC (permalink / raw)
  To: John Kacur; +Cc: Clark Williams, linux-rt-users

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.
For default configuration, only with the -S option, it makes sense to
use the current affinity instead 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.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 src/lib/rt-numa.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/lib/rt-numa.c b/src/lib/rt-numa.c
index 3eead80c3b2b3..1b09cff8d9485 100644
--- a/src/lib/rt-numa.c
+++ b/src/lib/rt-numa.c
@@ -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)
-- 
2.39.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread
* [PATCH] rt-numa: Use a reasonable default max CPU value.
@ 2023-01-19 19:51 John Kacur
  0 siblings, 0 replies; 7+ messages in thread
From: John Kacur @ 2023-01-19 19:51 UTC (permalink / raw)
  To: RT; +Cc: Sebastian Andrzej Siewior, John Kacur

From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

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.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
- Edited the commit message to remove reference to -S
Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/lib/rt-numa.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/lib/rt-numa.c b/src/lib/rt-numa.c
index 3eead80c3b2b..1b09cff8d948 100644
--- a/src/lib/rt-numa.c
+++ b/src/lib/rt-numa.c
@@ -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)
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-01-19 19:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-12 10:00 [PATCH] rt-numa: Use a reasonable default max CPU value Sebastian Andrzej Siewior
2023-01-16 18:15 ` John Kacur
2023-01-16 18:41   ` Ahmed S. Darwish
2023-01-16 18:58     ` John Kacur
2023-01-17  8:52       ` Sebastian Andrzej Siewior
2023-01-17 22:50         ` John Kacur
  -- strict thread matches above, loose matches on Subject: below --
2023-01-19 19:51 John Kacur

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox