linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Doug Smythies <dsmythies@telus.net>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	linux-pm@vger.kernel.org,
	"the arch/x86 maintainers" <x86@kernel.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	yang.jie@linux.intel.com, linux-kernel@vger.kernel.org,
	Eric Dumazet <edumazet@google.com>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Viresh Kumar <viresh.kumar@linaro.org>
Subject: Re: [PATCH] x86/aperfmperf: Make stale CPU frequency response within limits.
Date: Tue, 25 Jul 2023 20:31:29 +0200	[thread overview]
Message-ID: <CAJZ5v0hqPb1+tzGiOCSKr=4QcjnRKT5Gd8FcNbD_Gz5CnAw8tw@mail.gmail.com> (raw)
In-Reply-To: <006901d9be8c$f4439930$dccacb90$@telus.net>

On Tue, Jul 25, 2023 at 2:14 AM Doug Smythies <dsmythies@telus.net> wrote:
>
> Currently, when the CPU frequency is stale the nominal clock frequency
> is returned by calls to arch_freq_get_on_cpu(). Some users are
> confused by the high reported frequency when their system is idle
> and/or it is above a reduced maximum they set.
>
> This patch will return the policy minimum as the stale frequency reply
> from arch_freq_get_on_cpu().
>
> Reported-by: Yang Jie <yang.jie@linux.intel.com>
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=217597
> Signed-off-by: Doug Smythies <dsmythies@telus.net>
> ---
>  arch/x86/kernel/cpu/aperfmperf.c | 13 +++++--------
>  drivers/cpufreq/cpufreq.c        | 18 ++++++++++++++++++
>  include/linux/cpufreq.h          |  5 +++++
>  3 files changed, 28 insertions(+), 8 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/aperfmperf.c b/arch/x86/kernel/cpu/aperfmperf.c
> index fdbb5f07448f..44cc96864d94 100644
> --- a/arch/x86/kernel/cpu/aperfmperf.c
> +++ b/arch/x86/kernel/cpu/aperfmperf.c
> @@ -418,9 +418,10 @@ unsigned int arch_freq_get_on_cpu(int cpu)
>         unsigned long last;
>         u64 acnt, mcnt;
>
> -       if (!cpu_feature_enabled(X86_FEATURE_APERFMPERF))
> -               goto fallback;
> -
> +       if (!cpu_feature_enabled(X86_FEATURE_APERFMPERF)){
> +               freq = cpufreq_quick_get(cpu);
> +               return freq ? freq : cpufreq_quick_get_min(cpu);
> +       }
>         do {
>                 seq = raw_read_seqcount_begin(&s->seq);
>                 last = s->last_update;
> @@ -433,13 +434,9 @@ unsigned int arch_freq_get_on_cpu(int cpu)
>          * which covers idle and NOHZ full CPUs.
>          */
>         if (!mcnt || (jiffies - last) > MAX_SAMPLE_AGE)
> -               goto fallback;
> +               return cpufreq_quick_get_min(cpu);
>
>         return div64_u64((cpu_khz * acnt), mcnt);
> -
> -fallback:
> -       freq = cpufreq_quick_get(cpu);
> -       return freq ? freq : cpu_khz;

It looks to me like modifying cpufreq_quick_get) to return policy->min
if policy->cur is 0 would work in a similar way, wouldn't it?

>  }
>
>  static int __init bp_init_aperfmperf(void)
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 50bbc969ffe5..a0b24f61a5b0 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -1796,6 +1796,24 @@ unsigned int cpufreq_quick_get_max(unsigned int cpu)
>  }
>  EXPORT_SYMBOL(cpufreq_quick_get_max);
>
> +/**
> + * cpufreq_quick_get_min - return the min frequency for a given CPU
> + * @cpu: CPU number
> + */
> +unsigned int cpufreq_quick_get_min(unsigned int cpu)
> +{
> +       struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
> +       unsigned int ret_freq = 0;
> +
> +       if (policy) {
> +               ret_freq = policy->min;
> +               cpufreq_cpu_put(policy);
> +       }
> +
> +       return ret_freq;
> +}
> +EXPORT_SYMBOL(cpufreq_quick_get_min);
> +
>  /**
>   * cpufreq_get_hw_max_freq - get the max hardware frequency of the CPU
>   * @cpu: CPU number
> diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
> index 172ff51c1b2a..c74dcb5f9263 100644
> --- a/include/linux/cpufreq.h
> +++ b/include/linux/cpufreq.h
> @@ -220,6 +220,7 @@ static inline bool policy_is_shared(struct cpufreq_policy *policy)
>  unsigned int cpufreq_get(unsigned int cpu);
>  unsigned int cpufreq_quick_get(unsigned int cpu);
>  unsigned int cpufreq_quick_get_max(unsigned int cpu);
> +unsigned int cpufreq_quick_get_min(unsigned int cpu);
>  unsigned int cpufreq_get_hw_max_freq(unsigned int cpu);
>  void disable_cpufreq(void);
>
> @@ -250,6 +251,10 @@ static inline unsigned int cpufreq_quick_get_max(unsigned int cpu)
>  {
>         return 0;
>  }
> +static inline unsigned int cpufreq_quick_get_min(unsigned int cpu)
> +{
> +       return 0;
> +}
>  static inline unsigned int cpufreq_get_hw_max_freq(unsigned int cpu)
>  {
>         return 0;
> --
> 2.25.1
>
>

  reply	other threads:[~2023-07-25 18:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-25  0:14 [PATCH] x86/aperfmperf: Make stale CPU frequency response within limits Doug Smythies
2023-07-25 18:31 ` Rafael J. Wysocki [this message]
2023-07-25 19:11   ` Doug Smythies
2023-07-26 14:43     ` Rafael J. Wysocki
2023-08-08 16:22       ` Doug Smythies

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='CAJZ5v0hqPb1+tzGiOCSKr=4QcjnRKT5Gd8FcNbD_Gz5CnAw8tw@mail.gmail.com' \
    --to=rafael@kernel.org \
    --cc=dsmythies@telus.net \
    --cc=edumazet@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=viresh.kumar@linaro.org \
    --cc=x86@kernel.org \
    --cc=yang.jie@linux.intel.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).