stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: z00314508 <zhengzucheng@huawei.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Len Brown <len.brown@intel.com>,
	Linux PM <linux-pm@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Stable <stable@vger.kernel.org>
Subject: Re: [PATCH] cpufreq: fix cpufreq_get() can't get correct CPU frequency
Date: Fri, 11 Mar 2022 16:52:59 +0100	[thread overview]
Message-ID: <CAJZ5v0jponp=ijVx6W=eNEGrfTKh0KbGmOQG_V0P-Mq366559g@mail.gmail.com> (raw)
In-Reply-To: <20220311081111.159639-1-zhengzucheng@huawei.com>

On Fri, Mar 11, 2022 at 9:11 AM z00314508 <zhengzucheng@huawei.com> wrote:
>
> From: Zucheng Zheng <zhengzucheng@huawei.com>
>
> On some specific platforms, the cpufreq driver does not define
> cpufreq_driver.get() routine (eg:x86 intel_pstate driver), as a

I guess you mean the cpufreq driver ->get callback.

No, intel_pstate doesn't implement it, because it cannot reliably
return the current CPU frequency.

> result, the cpufreq_get() can't get the correct CPU frequency.

No, it can't, if intel_pstate is the driver, but what's the problem?
This function is only called in one place in the kernel and not on x8
even.

> Modern x86 processors include the hardware needed to accurately
> calculate frequency over an interval -- APERF, MPERF and the TSC.

You can compute the average frequency over an interval, but ->get is
expected to return the actual current frequency at the time call time.

> Here we use arch_freq_get_on_cpu() in preference to any driver
> driver-specific cpufreq_driver.get() routine to get CPU frequency.
>
> Fixes: f8475cef9008 ("x86: use common aperfmperf_khz_on_cpu() to calculate KHz using APERF/MPERF")

No kidding.

> Signed-off-by: Zucheng Zheng <zhengzucheng@huawei.com>
> ---
>  drivers/cpufreq/cpufreq.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 80f535cc8a75..d777257b4454 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -1806,10 +1806,14 @@ unsigned int cpufreq_get(unsigned int cpu)
>  {
>         struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
>         unsigned int ret_freq = 0;
> +       unsigned int freq;
>
>         if (policy) {
>                 down_read(&policy->rwsem);
> -               if (cpufreq_driver->get)
> +               freq = arch_freq_get_on_cpu(policy->cpu);
> +               if (freq)
> +                       ret_freq = freq;
> +               else if (cpufreq_driver->get)

Again, what problem exactly does this address?

>                         ret_freq = __cpufreq_get(policy);
>                 up_read(&policy->rwsem);
>
> --

  parent reply	other threads:[~2022-03-11 15:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-11  8:11 [PATCH] cpufreq: fix cpufreq_get() can't get correct CPU frequency z00314508
2022-03-11  8:33 ` Greg KH
2022-03-11 15:52 ` Rafael J. Wysocki [this message]
2022-03-15  2:30   ` zhengzucheng
2022-03-15 10:47     ` Rafael J. Wysocki

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='CAJZ5v0jponp=ijVx6W=eNEGrfTKh0KbGmOQG_V0P-Mq366559g@mail.gmail.com' \
    --to=rafael@kernel.org \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=viresh.kumar@linaro.org \
    --cc=zhengzucheng@huawei.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).