Skip to content

Commit 16b7069

Browse files
committed
Merge tag 'sched_ext-for-6.16-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext
Pull sched_ext fixes from Tejun Heo: "Two fixes in the built-in idle selection helpers: - Fix prev_cpu handling to guarantee that idle selection never returns a CPU that's not allowed - Skip cross-node search when !NUMA which could lead to infinite looping due to a bug in NUMA iterator" * tag 'sched_ext-for-6.16-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext: sched_ext: idle: Skip cross-node search with !CONFIG_NUMA sched_ext: idle: Properly handle invalid prev_cpu during idle selection
2 parents 3719a04 + 9960be7 commit 16b7069

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

kernel/sched/ext_idle.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ static s32 pick_idle_cpu_in_node(const struct cpumask *cpus_allowed, int node, u
138138
goto retry;
139139
}
140140

141+
#ifdef CONFIG_NUMA
141142
/*
142143
* Tracks nodes that have not yet been visited when searching for an idle
143144
* CPU across all available nodes.
@@ -186,6 +187,13 @@ static s32 pick_idle_cpu_from_online_nodes(const struct cpumask *cpus_allowed, i
186187

187188
return cpu;
188189
}
190+
#else
191+
static inline s32
192+
pick_idle_cpu_from_online_nodes(const struct cpumask *cpus_allowed, int node, u64 flags)
193+
{
194+
return -EBUSY;
195+
}
196+
#endif
189197

190198
/*
191199
* Find an idle CPU in the system, starting from @node.
@@ -447,10 +455,17 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags,
447455
const struct cpumask *llc_cpus = NULL, *numa_cpus = NULL;
448456
const struct cpumask *allowed = cpus_allowed ?: p->cpus_ptr;
449457
int node = scx_cpu_node_if_enabled(prev_cpu);
458+
bool is_prev_allowed;
450459
s32 cpu;
451460

452461
preempt_disable();
453462

463+
/*
464+
* Check whether @prev_cpu is still within the allowed set. If not,
465+
* we can still try selecting a nearby CPU.
466+
*/
467+
is_prev_allowed = cpumask_test_cpu(prev_cpu, allowed);
468+
454469
/*
455470
* Determine the subset of CPUs usable by @p within @cpus_allowed.
456471
*/
@@ -465,21 +480,6 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags,
465480
cpu = -EBUSY;
466481
goto out_enable;
467482
}
468-
469-
/*
470-
* If @prev_cpu is not in the allowed CPUs, skip topology
471-
* optimizations and try to pick any idle CPU usable by the
472-
* task.
473-
*
474-
* If %SCX_OPS_BUILTIN_IDLE_PER_NODE is enabled, prioritize
475-
* the current node, as it may optimize some waker->wakee
476-
* workloads.
477-
*/
478-
if (!cpumask_test_cpu(prev_cpu, allowed)) {
479-
node = scx_cpu_node_if_enabled(smp_processor_id());
480-
cpu = scx_pick_idle_cpu(allowed, node, flags);
481-
goto out_enable;
482-
}
483483
}
484484

485485
/*
@@ -525,7 +525,7 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags,
525525
* then avoid a migration.
526526
*/
527527
cpu = smp_processor_id();
528-
if (cpus_share_cache(cpu, prev_cpu) &&
528+
if (is_prev_allowed && cpus_share_cache(cpu, prev_cpu) &&
529529
scx_idle_test_and_clear_cpu(prev_cpu)) {
530530
cpu = prev_cpu;
531531
goto out_unlock;
@@ -562,7 +562,8 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags,
562562
/*
563563
* Keep using @prev_cpu if it's part of a fully idle core.
564564
*/
565-
if (cpumask_test_cpu(prev_cpu, idle_cpumask(node)->smt) &&
565+
if (is_prev_allowed &&
566+
cpumask_test_cpu(prev_cpu, idle_cpumask(node)->smt) &&
566567
scx_idle_test_and_clear_cpu(prev_cpu)) {
567568
cpu = prev_cpu;
568569
goto out_unlock;
@@ -611,7 +612,7 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags,
611612
/*
612613
* Use @prev_cpu if it's idle.
613614
*/
614-
if (scx_idle_test_and_clear_cpu(prev_cpu)) {
615+
if (is_prev_allowed && scx_idle_test_and_clear_cpu(prev_cpu)) {
615616
cpu = prev_cpu;
616617
goto out_unlock;
617618
}

0 commit comments

Comments
 (0)