Re: [PATCH] sched/fair: Fix nohz.next_balance update

From: Peng Liu
Date: Fri May 08 2020 - 09:01:38 EST


On Tue, May 05, 2020 at 04:27:11PM +0200, Vincent Guittot wrote:
> Le mardi 05 mai 2020 à 21:40:56 (+0800), Peng Liu a écrit :
>

[...]

>
> Your proposal below looks quite complex. IMO, one solution would be to move the
> update of nohz.next_balance before calling rebalance_domains(this_rq, CPU_IDLE)
> so you are back to the previous behavior.
>
> The only difference is that in case of an break because of need_resched, it
> doesn't update nohz.next_balance. But on the other hand, we haven't yet
> finished run rebalance_domains for all CPUs and some load_balance are still
> pending. In fact, this will be done during next tick by an idle CPU.
>
> So I would be in favor of something as simple as :
>

Vincent, could you refine this patch with some changelog?
And have my reported-by if possible.

> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 04098d678f3b..e028bc1c4744 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -10457,6 +10457,14 @@ static bool _nohz_idle_balance(struct rq *this_rq, unsigned int flags,
> }
> }
>
> + /*
> + * next_balance will be updated only when there is a need.
> + * When the CPU is attached to null domain for ex, it will not be
> + * updated.
> + */
> + if (likely(update_next_balance))
> + nohz.next_balance = next_balance;
> +
> /* Newly idle CPU doesn't need an update */
> if (idle != CPU_NEWLY_IDLE) {
> update_blocked_averages(this_cpu);
> @@ -10477,14 +10485,6 @@ static bool _nohz_idle_balance(struct rq *this_rq, unsigned int flags,
> if (has_blocked_load)
> WRITE_ONCE(nohz.has_blocked, 1);
>
> - /*
> - * next_balance will be updated only when there is a need.
> - * When the CPU is attached to null domain for ex, it will not be
> - * updated.
> - */
> - if (likely(update_next_balance))
> - nohz.next_balance = next_balance;
> -
> return ret;
> }
>