Re: [PATCH] sched/fair: fix sgc->{min,max}_capacity miscalculate

From: Valentin Schneider
Date: Fri Jan 03 2020 - 09:44:05 EST


On 03/01/2020 14:21, Peng Liu wrote:
> Thanks for your patient explanation, and the picture is intuitive
> and clear. Indeed, the group in lowest domain only contains one CPU, and
> the only CPU in the first group should be the rq's CPU. So, I wonder if
> we can do like this?
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 2d170b5da0e3..c9d7613c74d2 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -7793,9 +7793,6 @@ void update_group_capacity(struct sched_domain *sd, int cpu)
> */
>
> for_each_cpu(cpu, sched_group_span(sdg)) {
> - struct sched_group_capacity *sgc;
> - struct rq *rq = cpu_rq(cpu);
> -
> /*
> * build_sched_domains() -> init_sched_groups_capacity()
> * gets here before we've attached the domains to the
> @@ -7807,15 +7804,11 @@ void update_group_capacity(struct sched_domain *sd, int cpu)
> * This avoids capacity from being 0 and
> * causing divide-by-zero issues on boot.
> */
> - if (unlikely(!rq->sd)) {
> - capacity += capacity_of(cpu);
> - } else {
> - sgc = rq->sd->groups->sgc;
> - capacity += sgc->capacity;
> - }
> + unsigned long cpu_cap = capacity_of(cpu);
>
> - min_capacity = min(capacity, min_capacity);
> - max_capacity = max(capacity, max_capacity);
> + min_capacity = min(cpu_cap, min_capacity);
> + max_capacity = max(cpu_cap, max_capacity);
> + capacity += cpu_cap;
> }
> } else {
> /*
>

Yep, if we refactor it to always use capacity_of() we'd end up with
something like this. The comment block could be updated (or removed) as
well.

There must be (or have been) a reason to use the sched_group_capacity
structure, but I'm not aware of it and I don't have time right now to dig
through the git history to figure it out. I didn't see anyone suggesting
or talking about this simplification in the discussion thread of

9abf24d46518 ("sched: Check sched_domain before computing group power")

What you can try is sending that as the v2, and see if anyone screams. FWIW
you can add this to it too:

Reviewed-by: Valentin Schneider <valentin.schneider@xxxxxxx>