Re: [RFC PATCH] sched/feec: Simplify the traversal of pd'cpus
From: Dietmar Eggemann
Date: Thu Aug 14 2025 - 04:49:27 EST
On 12.08.25 10:33, Xuewen Yan wrote:
> Now we use for_each_cpu() to traversal all pd's cpus,
> it is in order to compute the pd_cap. This approach may
> result in some unnecessary judgments.
> We can simply calculate pd_cap as follows:
>
> pd_cap = cpu_actual_cap * cpumask_weight(pd_cpus);
>
> Then we can AND pd'scpus, sd's cpus and task's cpus_ptr
> before traversing, which can save some unnecessary judgment.
>
> Signed-off-by: Xuewen Yan <xuewen.yan@xxxxxxxxxx>
> ---
> kernel/sched/fair.c | 14 ++++----------
> 1 file changed, 4 insertions(+), 10 deletions(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index b173a059315c..e47fe94d6889 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -8330,18 +8330,12 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
Just a thought ...
for (; pd; pd = pd->next)
cpumask_and(cpus, sched_domain_span(sd), p->cpus_ptr); <-- (1)
cpumask_and(cpus, perf_domain_span(pd), cpu_online_mask);
if (cpumask_empty(cpus))
continue; <-- (2)
Can you not mask cpus already early in the pd loop (1) and then profit
from (2) in these rare cases? IIRC, the sd only plays a role here in
exclusive cpusets scenarios which I don't thing anybody deploys with EAS?
> cpu_actual_cap = get_actual_cpu_capacity(cpu);
>
> eenv.cpu_cap = cpu_actual_cap;
> - eenv.pd_cap = 0;
> + eenv.pd_cap = cpu_actual_cap * cpumask_weight(cpus);
>
> - for_each_cpu(cpu, cpus) {
> - struct rq *rq = cpu_rq(cpu);
> -
> - eenv.pd_cap += cpu_actual_cap;
> -
> - if (!cpumask_test_cpu(cpu, sched_domain_span(sd)))
> - continue;
> + cpumask_and(cpus, cpus, sched_domain_span(sd));
>
> - if (!cpumask_test_cpu(cpu, p->cpus_ptr))
> - continue;
> + for_each_cpu_and(cpu, cpus, p->cpus_ptr) {
> + struct rq *rq = cpu_rq(cpu);
>
> util = cpu_util(cpu, p, cpu, 0);
> cpu_cap = capacity_of(cpu);