Skip to content

Commit fde7d64

Browse files
arighihtejun
authored andcommitted
sched_ext: idle: Fix scx_bpf_pick_any_cpu_node() behavior
When %SCX_PICK_IDLE_IN_NODE is specified, scx_bpf_pick_any_cpu_node() should always return a CPU from the specified node, regardless of its idle state. Also clarify this logic in the function documentation. Fixes: 0105921 ("sched_ext: idle: Introduce node-aware idle cpu kfunc helpers") Signed-off-by: Andrea Righi <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 0e9b4c1 commit fde7d64

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

kernel/sched/ext_idle.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,8 +1029,9 @@ __bpf_kfunc s32 scx_bpf_pick_idle_cpu(const struct cpumask *cpus_allowed,
10291029
* empty.
10301030
*
10311031
* The search starts from @node and proceeds to other online NUMA nodes in
1032-
* order of increasing distance (unless SCX_PICK_IDLE_IN_NODE is specified,
1033-
* in which case the search is limited to the target @node).
1032+
* order of increasing distance (unless %SCX_PICK_IDLE_IN_NODE is specified,
1033+
* in which case the search is limited to the target @node, regardless of
1034+
* the CPU idle state).
10341035
*
10351036
* If ops.update_idle() is implemented and %SCX_OPS_KEEP_BUILTIN_IDLE is not
10361037
* set, this function can't tell which CPUs are idle and will always pick any
@@ -1049,7 +1050,10 @@ __bpf_kfunc s32 scx_bpf_pick_any_cpu_node(const struct cpumask *cpus_allowed,
10491050
if (cpu >= 0)
10501051
return cpu;
10511052

1052-
cpu = cpumask_any_distribute(cpus_allowed);
1053+
if (flags & SCX_PICK_IDLE_IN_NODE)
1054+
cpu = cpumask_any_and_distribute(cpumask_of_node(node), cpus_allowed);
1055+
else
1056+
cpu = cpumask_any_distribute(cpus_allowed);
10531057
if (cpu < nr_cpu_ids)
10541058
return cpu;
10551059
else

0 commit comments

Comments
 (0)