* [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* Re: [PATCH sched_ext/for-7.5] sched_ext/idle: Skip nodes without CPUs
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
1 sibling, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-29 16:47 UTC (permalink / raw)
To: Cheng-Yang Chou, sched-ext
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] sched_ext: missed update_idle_cpu_nodes() on hotplug during
enable
--
commit 49bd96c9c4b1ca8a5782568b9a5893b41d485588
Author: Cheng-Yang Chou <yphbchou0911@gmail.com>
sched_ext/idle: Skip nodes without CPUs
This commit maintains a nodemask of NUMA nodes that have at least one
active CPU (scx_idle_cpu_nodes) and restricts cross-node idle CPU
searches in pick_idle_cpu_from_online_nodes() to those nodes instead of
all online nodes.
> diff --git a/kernel/sched/ext/idle.c b/kernel/sched/ext/idle.c
> index 922fbc3065ccf..73af83231f747 100644
> --- a/kernel/sched/ext/idle.c
> +++ b/kernel/sched/ext/idle.c
[ ... ]
> @@ -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();
> }
>
> /*
[Severity: Medium]
Can scx_idle_cpu_nodes become stale if a CPU hotplug event occurs while
a scheduler is being enabled?
scx_root_enable_workfn() calls scx_idle_update_selcpu_topology() right
before cpus_read_unlock(), well before enabling __scx_enabled:
kernel/sched/ext/ext.c:scx_root_enable_workfn() {
...
for (i = SCX_OPI_CPU_HOTPLUG_BEGIN; i < SCX_OPI_CPU_HOTPLUG_END; i++)
if (((void (**)(void))ops)[i])
set_bit(i, sch->has_op);
ret = check_hotplug_seq(sch, ops);
if (ret) {
cpus_read_unlock();
goto err_disable;
}
scx_idle_update_selcpu_topology(ops);
cpus_read_unlock();
...
}
If a CPU comes online or goes offline after cpus_read_unlock() and
before static_branch_enable(&__scx_enabled) (while tasks are being
initialized), handle_hotplug() skips scx_idle_update_selcpu_topology()
because scx_enabled() is still false:
kernel/sched/ext/ext.c:handle_hotplug() {
...
if (unlikely(!sch))
return;
if (scx_enabled())
scx_idle_update_selcpu_topology(&sch->ops);
...
}
When the scheduler has ops.cpu_online or ops.cpu_offline defined, the
hotplug transition is accepted without aborting enablement, leaving
scx_idle_cpu_nodes out of sync with cpu_active_mask once the scheduler
goes live. If the first active CPU on a node came online during that
window, pick_idle_cpu_from_online_nodes() will skip that node until the
next hotplug event.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261129163536.15478-1-yphbchou0911@gmail.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH sched_ext/for-7.5] sched_ext/idle: Skip nodes without CPUs
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
1 sibling, 1 reply; 4+ messages in thread
From: Tejun Heo @ 2026-11-29 16:59 UTC (permalink / raw)
To: Cheng-Yang Chou
Cc: sched-ext, David Vernet, Andrea Righi, Changwoo Min,
Ching-Chun Huang, Chia-Ping Tsai, chengyang.chou
Hello, Cheng-Yang.
On Mon, Nov 30, 2026 at 12:35:20AM +0800, Cheng-Yang Chou wrote:
> 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.
AFAICS, with numa=fake, cpu_to_node() puts every CPU on node 0 but
numa_add_cpu() also sets the CPU in cpumask_of_node() of every emulated
node, so all eight nodes claim the same CPUs and have N_CPU set. No real
topology looks like that and it doesn't make sense for a testing feature
to break that. That looks like a bug in the NUMA emulation to me.
rpi5 seems to be the only real user of fake NUMA. How about fixing the
NUMA emulation and then switching sched_ext to walk node_states[N_CPU]
instead of N_ONLINE?
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH sched_ext/for-7.5] sched_ext/idle: Skip nodes without CPUs
2026-11-29 16:59 ` Tejun Heo
@ 2026-11-30 18:03 ` Cheng-Yang Chou
0 siblings, 0 replies; 4+ messages in thread
From: Cheng-Yang Chou @ 2026-11-30 18:03 UTC (permalink / raw)
To: Tejun Heo
Cc: sched-ext, David Vernet, Andrea Righi, Changwoo Min,
Ching-Chun Huang, Chia-Ping Tsai, chengyang.chou
Hi Tejun,
On Sun, Nov 29, 2026 at 06:59:50AM -1000, Tejun Heo wrote:
> Hello, Cheng-Yang.
>
> On Mon, Nov 30, 2026 at 12:35:20AM +0800, Cheng-Yang Chou wrote:
> > 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.
>
> AFAICS, with numa=fake, cpu_to_node() puts every CPU on node 0 but
> numa_add_cpu() also sets the CPU in cpumask_of_node() of every emulated
> node, so all eight nodes claim the same CPUs and have N_CPU set. No real
> topology looks like that and it doesn't make sense for a testing feature
> to break that. That looks like a bug in the NUMA emulation to me.
Thanks for the explanation.
>
> rpi5 seems to be the only real user of fake NUMA. How about fixing the
> NUMA emulation and then switching sched_ext to walk node_states[N_CPU]
> instead of N_ONLINE?
>
Make sense, will do. Start looking at the NUMA code now :)
--
Thanks,
Cheng-Yang
^ permalink raw reply [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