Re: [PATCH] sched/fair: Optimize select_idle_cpu

From: Valentin Schneider
Date: Fri Dec 13 2019 - 06:28:22 EST


On 13/12/2019 09:57, chengjian (D) wrote:
>
> in select_idle_smt()
>
> /*
> Â* Scan the local SMT mask for idle CPUs.
> Â*/
> static int select_idle_smt(struct task_struct *p, int target)
> {
> ÂÂÂ int cpu, si_cpu = -1;
>
> ÂÂÂ if (!static_branch_likely(&sched_smt_present))
> ÂÂÂÂÂÂÂ return -1;
>
> ÂÂÂ for_each_cpu(cpu, cpu_smt_mask(target)) {
> ÂÂÂÂÂÂÂ if (!cpumask_test_cpu(cpu, p->cpus_ptr))
> ÂÂÂÂÂÂÂÂÂÂÂ continue;
> ÂÂÂÂÂÂÂ if (available_idle_cpu(cpu))
> ÂÂÂÂÂÂÂÂÂÂÂ return cpu;
> ÂÂÂÂÂÂÂ if (si_cpu == -1 && sched_idle_cpu(cpu))
> ÂÂÂÂÂÂÂÂÂÂÂ si_cpu = cpu;
> ÂÂÂ }
>
> ÂÂÂ return si_cpu;
> }
>
>
> Why don't we do the same thing in this function,
>
> although cpu_smt_present () often has few CPUs.
>
> it is better to determine the 'p->cpus_ptr' first.
>
>

Like you said the gains here would probably be small - the highest SMT
count I'm aware of is SMT8 (POWER9). Still, if we end up with both
select_idle_core() and select_idle_cpu() using that pattern, it would make
sense IMO to align select_idle_smt() with those.

>
>
>