Sched_ext development
 help / color / mirror / Atom feed
* [PATCH sched_ext/for-7.5] sched_ext/idle: Skip nodes without CPUs
@ 2026-11-29 16:35 Cheng-Yang Chou
  2026-11-29 16:47 ` sashiko-bot
  2026-11-29 16:59 ` Tejun Heo
  0 siblings, 2 replies; 4+ messages in thread
From: Cheng-Yang Chou @ 2026-11-29 16:35 UTC (permalink / raw)
  To: sched-ext, Tejun Heo, David Vernet, Andrea Righi, Changwoo Min
  Cc: Ching-Chun Huang, Chia-Ping Tsai, chengyang.chou, Cheng-Yang Chou

With SCX_OPS_BUILTIN_IDLE_PER_NODE, a CPU is tracked in the idle
cpumask of cpu_to_node(cpu). When the starting node has no idle CPU,
pick_idle_cpu_from_online_nodes() walks the other online nodes in
distance order. Nodes that own no CPU can't have an idle one, but the
walk still visits them.

On a Raspberry Pi 5, the firmware adds numa=fake=8. That gives eight
online nodes, but cpu_to_node() puts every CPU in node 0, so a search
that leaves node 0 visits seven nodes that can't have an idle CPU.

Walk only the nodes that have an active CPU, kept up to date across
CPU hotplug. Nothing changes when every online node has an active CPU.
On that rpi, five hackbench -p -g 10 -l 10000 runs under scx_simple gave
these means (ops.select_cpu() time per call, run time):

                  global idle cpumask   per-node idle cpumasks
  before          135ns, 7.39s          484ns, 7.49s
  after           134ns, 7.35s          141ns, 7.39s

With the patch, the per-node cost is close to the global one. The walk
itself came up before and was left alone because the node count is
usually low [1]. This doesn't change the walk. It only skips nodes that
can't have an idle CPU able to take tasks.

[1] https://lore.kernel.org/all/abmQRgwQZhZk9-_S@slm.duckdns.org/

Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
I'm not sure why the rpi does this, but I don't think this fix only
matters downstream. Nothing changes when every online node has an
active CPU, and other setups may run into the same problem as the rpi.

 kernel/sched/ext/idle.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/ext/idle.c b/kernel/sched/ext/idle.c
index 922fbc3065cc..73af83231f74 100644
--- a/kernel/sched/ext/idle.c
+++ b/kernel/sched/ext/idle.c
@@ -145,6 +145,24 @@ static s32 pick_idle_cpu_in_node(const struct cpumask *cpus_allowed, int node, u
  */
 static DEFINE_PER_CPU(nodemask_t, per_cpu_unvisited);
 
+/*
+ * Nodes with an active CPU. Idle CPUs are tracked per cpu_to_node(), so other
+ * nodes can't have one that can take tasks. Updated on enable and on CPU
+ * hotplug after cpu_active_mask changes.
+ */
+static nodemask_t scx_idle_cpu_nodes;
+
+static void update_idle_cpu_nodes(void)
+{
+	nodemask_t nodes = NODE_MASK_NONE;
+	s32 cpu;
+
+	for_each_cpu(cpu, cpu_active_mask)
+		node_set(cpu_to_node(cpu), nodes);
+
+	nodes_copy(scx_idle_cpu_nodes, nodes);
+}
+
 /*
  * Search for an idle CPU across all nodes, excluding @node.
  */
@@ -168,10 +186,10 @@ static s32 pick_idle_cpu_from_online_nodes(const struct cpumask *cpus_allowed, i
 	unvisited = this_cpu_ptr(&per_cpu_unvisited);
 
 	/*
-	 * Restrict the search to the online nodes (excluding the current
-	 * node that has been visited already).
+	 * Restrict the search to the nodes with active CPUs (excluding the
+	 * current node that has been visited already).
 	 */
-	nodes_copy(*unvisited, node_states[N_ONLINE]);
+	nodes_copy(*unvisited, scx_idle_cpu_nodes);
 	node_clear(node, *unvisited);
 
 	/*
@@ -198,6 +216,8 @@ static s32 pick_idle_cpu_from_online_nodes(const struct cpumask *cpus_allowed, i
 	return cpu;
 }
 #else
+static inline void update_idle_cpu_nodes(void) {}
+
 static inline s32
 pick_idle_cpu_from_online_nodes(const struct cpumask *cpus_allowed, int node, u64 flags)
 {
@@ -414,6 +434,8 @@ void scx_idle_update_selcpu_topology(struct sched_ext_ops *ops)
 		static_branch_enable_cpuslocked(&scx_selcpu_topo_numa);
 	else
 		static_branch_disable_cpuslocked(&scx_selcpu_topo_numa);
+
+	update_idle_cpu_nodes();
 }
 
 /*

base-commit: 95a4df9944cd5d57a92662269114ba99cb972394
-- 
2.56.0


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

end of thread, other threads:[~2026-11-30 18:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 16:35 [PATCH sched_ext/for-7.5] sched_ext/idle: Skip nodes without CPUs Cheng-Yang Chou
2026-11-29 16:47 ` sashiko-bot
2026-11-29 16:59 ` Tejun Heo
2026-11-30 18:03   ` Cheng-Yang Chou

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