Skip to content

Commit 60588bf

Browse files
Cheng JianPeter Zijlstra
authored andcommitted
sched/fair: Optimize select_idle_cpu
select_idle_cpu() will scan the LLC domain for idle CPUs, it's always expensive. so the next commit : 1ad3aaf ("sched/core: Implement new approach to scale select_idle_cpu()") introduces a way to limit how many CPUs we scan. But it consume some CPUs out of 'nr' that are not allowed for the task and thus waste our attempts. The function always return nr_cpumask_bits, and we can't find a CPU which our task is allowed to run. Cpumask may be too big, similar to select_idle_core(), use per_cpu_ptr 'select_idle_mask' to prevent stack overflow. Fixes: 1ad3aaf ("sched/core: Implement new approach to scale select_idle_cpu()") Signed-off-by: Cheng Jian <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Srikar Dronamraju <[email protected]> Reviewed-by: Vincent Guittot <[email protected]> Reviewed-by: Valentin Schneider <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 45178ac commit 60588bf

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

kernel/sched/fair.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5828,6 +5828,7 @@ static inline int select_idle_smt(struct task_struct *p, int target)
58285828
*/
58295829
static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, int target)
58305830
{
5831+
struct cpumask *cpus = this_cpu_cpumask_var_ptr(select_idle_mask);
58315832
struct sched_domain *this_sd;
58325833
u64 avg_cost, avg_idle;
58335834
u64 time, cost;
@@ -5859,11 +5860,11 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, int t
58595860

58605861
time = cpu_clock(this);
58615862

5862-
for_each_cpu_wrap(cpu, sched_domain_span(sd), target) {
5863+
cpumask_and(cpus, sched_domain_span(sd), p->cpus_ptr);
5864+
5865+
for_each_cpu_wrap(cpu, cpus, target) {
58635866
if (!--nr)
58645867
return si_cpu;
5865-
if (!cpumask_test_cpu(cpu, p->cpus_ptr))
5866-
continue;
58675868
if (available_idle_cpu(cpu))
58685869
break;
58695870
if (si_cpu == -1 && sched_idle_cpu(cpu))

0 commit comments

Comments
 (0)