linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vincent Guittot <vincent.guittot@linaro.org>
To: Qais Yousef <qyousef@layalina.io>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
	Lukasz Luba <lukasz.luba@arm.com>, Wei Wang <wvw@google.com>,
	Xuewen Yan <xuewen.yan94@gmail.com>, Hank <han.lin@mediatek.com>,
	Jonathan JMChen <Jonathan.JMChen@mediatek.com>
Subject: Re: [PATCH v3 2/2] sched/fair: Fixes for capacity inversion detection
Date: Fri, 13 Jan 2023 09:14:15 +0100	[thread overview]
Message-ID: <CAKfTPtD2kHJUc_my21Wu2c4jZhb0z3vFceF1QfiPMKN6mWQgbQ@mail.gmail.com> (raw)
In-Reply-To: <20230112122708.330667-3-qyousef@layalina.io>

On Thu, 12 Jan 2023 at 13:27, Qais Yousef <qyousef@layalina.io> wrote:
>
> Traversing the Perf Domains requires rcu_read_lock() to be held and is
> conditional on sched_energy_enabled(). Ensure right protections applied.
>
> Also skip capacity inversion detection for our own pd; which was an
> error.
>
> Fixes: 44c7b80bffc3 ("sched/fair: Detect capacity inversion")
> Reported-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
> Signed-off-by: Qais Yousef (Google) <qyousef@layalina.io>

Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>

> ---
>  kernel/sched/fair.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 5a8e75d4a17b..34239d3118f0 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -8992,16 +8992,23 @@ static void update_cpu_capacity(struct sched_domain *sd, int cpu)
>          *   * Thermal pressure will impact all cpus in this perf domain
>          *     equally.
>          */
> -       if (static_branch_unlikely(&sched_asym_cpucapacity)) {
> +       if (sched_energy_enabled()) {
>                 unsigned long inv_cap = capacity_orig - thermal_load_avg(rq);
> -               struct perf_domain *pd = rcu_dereference(rq->rd->pd);
> +               struct perf_domain *pd;
> +
> +               rcu_read_lock();
>
> +               pd = rcu_dereference(rq->rd->pd);
>                 rq->cpu_capacity_inverted = 0;
>
>                 for (; pd; pd = pd->next) {
>                         struct cpumask *pd_span = perf_domain_span(pd);
>                         unsigned long pd_cap_orig, pd_cap;
>
> +                       /* We can't be inverted against our own pd */
> +                       if (cpumask_test_cpu(cpu_of(rq), pd_span))
> +                               continue;
> +
>                         cpu = cpumask_any(pd_span);
>                         pd_cap_orig = arch_scale_cpu_capacity(cpu);
>
> @@ -9026,6 +9033,8 @@ static void update_cpu_capacity(struct sched_domain *sd, int cpu)
>                                 break;
>                         }
>                 }
> +
> +               rcu_read_unlock();
>         }
>
>         trace_sched_cpu_capacity_tp(rq);
> --
> 2.25.1
>

      reply	other threads:[~2023-01-13  8:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-12 12:27 [PATCH v3 0/2] Fixes for uclamp and capacity inversion detection Qais Yousef
2023-01-12 12:27 ` [PATCH v3 1/2] sched/uclamp: Fix a uninitialized variable warnings Qais Yousef
2023-01-13  8:13   ` Vincent Guittot
2023-01-12 12:27 ` [PATCH v3 2/2] sched/fair: Fixes for capacity inversion detection Qais Yousef
2023-01-13  8:14   ` Vincent Guittot [this message]

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=CAKfTPtD2kHJUc_my21Wu2c4jZhb0z3vFceF1QfiPMKN6mWQgbQ@mail.gmail.com \
    --to=vincent.guittot@linaro.org \
    --cc=Jonathan.JMChen@mediatek.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=han.lin@mediatek.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=qyousef@layalina.io \
    --cc=rafael@kernel.org \
    --cc=viresh.kumar@linaro.org \
    --cc=wvw@google.com \
    --cc=xuewen.yan94@gmail.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).