linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joel Fernandes <joel@joelfernandes.org>
To: Vincent Guittot <vincent.guittot@linaro.org>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Daniel Bristot de Oliveira <bristot@redhat.com>,
	Valentin Schneider <vschneid@redhat.com>,
	"Vineeth Pillai (Google)" <vineeth@bitbyteword.org>,
	Suleiman Souhlal <suleiman@google.com>,
	Frederic Weisbecker <frederic@kernel.org>,
	"Paul E . McKenney" <paulmck@kernel.org>
Subject: Re: [PATCH 3/3] sched: Update ->next_balance correctly during newidle balance
Date: Thu, 9 Nov 2023 07:31:36 -0500	[thread overview]
Message-ID: <CAEXW_YRt2guqmrL1iZwECnEJf-xdwrDrPrmfgdWYzcPTsA22+A@mail.gmail.com> (raw)
In-Reply-To: <20231109100254.GA111915@google.com>

On Thu, Nov 9, 2023 at 5:02 AM Joel Fernandes <joel@joelfernandes.org> wrote:
[...]
> > > things worse for power on ARM where you have uclamp stuff happening in the
> > > load balance paths which is quite heavy when I last traced that..
> > >
> > > Further, we have observed in our tracing on real device that the update of
> > > rq->next_balance from the newidle path is itself buggy... we observed that
> > > because newidle balance may not update rq->last_balance, it is possible that
> > > rq->next_balance when updated by update_next_balance() will be updated to a
> > > value that is in the past and it will be stuck there for a long time! Perhaps
> > > we should investigate more and fix that bug separately. Vineeth could provide
> > > more details on the "getting stuck in the past" behavior as well.
> >
> > sd->last_balance reflects last time an idle/busy load_balance happened
> > (newly idle is out of the scope for the points that I mentioned
> > previously).  So if no load balance happens for a while, the
> > rq->next_balance can be in the past but I don't see a problem here. It
> > just means that a load balance hasn't happened for a while. It can
> > even move backward if it has been set when busy but the cpu is now
> > idle
>
> Sure, but I think it should at least set it by get_sd_balance_interval() into
> the future. Like so (untested)? Let me know what you think and thanks!

Btw, I also drew a graph showing the issue without patch:
https://i.imgur.com/RgTr45l.png

Each "x" mark is run_rebalance_domains() running on a CPU. As can be
seen, there were some 10 occurrences in a span of 15ms in one
instance.

Thanks,

 - Joel


> ---8<-----------------------
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index a3318aeff9e8..0d6667d31c51 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -11314,6 +11314,30 @@ get_sd_balance_interval(struct sched_domain *sd, int cpu_busy)
>         return interval;
>  }
>
> +/*
> + * Update the next balance from newidle balance.
> + * The update of next_balance from newidle balance tries to make sure that
> + * we don't trigger periodic balance too far in the future on a now-idle
> + * system.  This is just like update_next_balance except that since
> + * sd->last_balance may not have been updated for a while, we're careful to
> + * not set next_balance in the past.
> + */
> +static inline void
> +update_next_balance_newidle(struct sched_domain *sd, unsigned long *next_balance)
> +{
> +       unsigned long interval, next;
> +
> +       /* used by new idle balance, so cpu_busy = 0 */
> +       interval = get_sd_balance_interval(sd, 0);
> +       next = sd->last_balance + interval;
> +
> +       next = max(next, jiffies + interval);
> +
> +       if (time_after(*next_balance, next)) {
> +               *next_balance = next;
> +       }
> +}
> +
>  static inline void
>  update_next_balance(struct sched_domain *sd, unsigned long *next_balance)
>  {
> @@ -12107,7 +12131,7 @@ static int newidle_balance(struct rq *this_rq, struct rq_flags *rf)
>             (sd && this_rq->avg_idle < sd->max_newidle_lb_cost)) {
>
>                 if (sd)
> -                       update_next_balance(sd, &next_balance);
> +                       update_next_balance_newidle(sd, &next_balance);
>                 rcu_read_unlock();
>
>                 goto out;
> @@ -12124,7 +12148,7 @@ static int newidle_balance(struct rq *this_rq, struct rq_flags *rf)
>                 int continue_balancing = 1;
>                 u64 domain_cost;
>
> -               update_next_balance(sd, &next_balance);
> +               update_next_balance_newidle(sd, &next_balance);
>
>                 if (this_rq->avg_idle < curr_cost + sd->max_newidle_lb_cost)
>                         break;

  reply	other threads:[~2023-11-09 12:31 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-20  1:40 [PATCH 1/3] sched/nohz: Update nohz.next_balance directly without IPIs (v2) Joel Fernandes (Google)
2023-10-20  1:40 ` [PATCH 2/3] sched/nohz: Update comments about NEWILB_KICK Joel Fernandes (Google)
2023-10-20  7:51   ` Ingo Molnar
2023-10-20  8:02   ` [tip: sched/core] " tip-bot2 for Joel Fernandes (Google)
2023-10-20  1:40 ` [PATCH 3/3] sched: Update ->next_balance correctly during newidle balance Joel Fernandes (Google)
2023-10-20  7:53   ` Ingo Molnar
2023-10-20 13:48     ` Vincent Guittot
2023-10-21  6:50       ` Ingo Molnar
2023-10-20  8:02   ` [tip: sched/core] sched/fair: " tip-bot2 for Vineeth Pillai (Google)
2023-10-20 13:40   ` [PATCH 3/3] sched: " Vincent Guittot
2023-10-20 13:56     ` Ingo Molnar
2023-10-20 15:50       ` Joel Fernandes
2023-10-22  0:28     ` Joel Fernandes
2023-10-26 14:23       ` Vincent Guittot
2023-11-09 10:02         ` Joel Fernandes
2023-11-09 12:31           ` Joel Fernandes [this message]
2023-11-14 15:43           ` Vincent Guittot
2023-11-14 17:43             ` Joel Fernandes
2023-10-20  4:17 ` [PATCH 1/3] sched/nohz: Update nohz.next_balance directly without IPIs (v2) Joel Fernandes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEXW_YRt2guqmrL1iZwECnEJf-xdwrDrPrmfgdWYzcPTsA22+A@mail.gmail.com \
    --to=joel@joelfernandes.org \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=frederic@kernel.org \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=suleiman@google.com \
    --cc=vincent.guittot@linaro.org \
    --cc=vineeth@bitbyteword.org \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).