Linux Power Management development
 help / color / mirror / Atom feed
From: "Gautham R. Shenoy" <gautham.shenoy@amd.com>
To: Manu Bretelle <chantr4@gmail.com>
Cc: Mario Limonciello <mario.limonciello@amd.com>,
	Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Adam Clark <Adam.Clark@amd.com>
Subject: Re: [PATCH] acpi-cpufreq: Fix max-frequency computation
Date: Wed, 28 May 2025 17:27:38 +0530	[thread overview]
Message-ID: <aDb6Mgg3TqyR2IRT@BLRRASHENOY1.amd.com> (raw)
In-Reply-To: <aDaB63tDvbdcV0cg@HQ-GR2X1W2P57>

Hello Manu,

On Tue, May 27, 2025 at 08:24:27PM -0700, Manu Bretelle wrote:
> On Mon, Jan 13, 2025 at 10:11:07AM +0530, Gautham R. Shenoy wrote:
> > commit 3c55e94c0ade ("cpufreq: ACPI: Extend frequency tables to cover
> > boost frequencies") introduces an assumption in
> > acpi_cpufreq_cpu_init() that the first entry in the P-state table is
> > the nominal frequency. This assumption is incorrect. The frequency
> > corresponding to the P0 P-State need not be the same as the nominal
> > frequency advertised via CPPC.
> > 
> > Since the driver is using the CPPC.highest_perf and CPPC.nominal_perf
> > to compute the boost-ratio, it makes sense to use CPPC.nominal_freq to
> > compute the max-frequency. CPPC.nominal_freq is advertised on
> > platforms supporting CPPC revisions 3 or higher.
> > 
> > Hence, fallback to using the first entry in the P-State table only on
> > platforms that do not advertise CPPC.nominal_freq.
> > 
> 
> Gautham, this got recently pulled in 5.15.179 [0] but it seems to have broken
> what max CPU get reported.

Thanks for reporting this.

> 
> I hit the issue on Ubuntu 22.04 with kernel 5.15.0-140-generic. My read from [1]
> is that that kernel is pretty much 5.15.79.
> I rebuilt it with this patch removed and max CPU now show as before.
> 
> Here some output that may help, which is what is mostly down to what is reported
> by /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq . Posting the whole
> lscpu hoping that contain more useful data. Happy to provide more if needed.
> 
> Ubuntu 22.04 with 5.15.0-140-generic (affected, note CPU max MHz: 2000.0000):
> 
>     $ lscpu
>     Architecture:             x86_64
>       CPU op-mode(s):         32-bit, 64-bit
>       Address sizes:          48 bits physical, 48 bits virtual
>       Byte Order:             Little Endian
>     CPU(s):                   128
>       On-line CPU(s) list:    0-127
>     Vendor ID:                AuthenticAMD
>       Model name:             AMD EPYC 7713P 64-Core Processor
>         CPU family:           25
>         Model:                1
>         Thread(s) per core:   2
>         Core(s) per socket:   64
>         Socket(s):            1
>         Stepping:             1
>         Frequency boost:      enabled
>         CPU max MHz:          2000.0000
>         CPU min MHz:          1500.0000

[..snip..]

> 
> With 5.15.0-999-generic (5.15.0-140-generic without this patch), max CPU is back
> to 3720.7029, which is also what I get with 5.15.0-139-generic.
> 
>     $ lscpu
>     Architecture:             x86_64
>       CPU op-mode(s):         32-bit, 64-bit
>       Address sizes:          48 bits physical, 48 bits virtual
>       Byte Order:             Little Endian
>     CPU(s):                   128
>       On-line CPU(s) list:    0-127
>     Vendor ID:                AuthenticAMD
>       Model name:             AMD EPYC 7713P 64-Core Processor
>         CPU family:           25
>         Model:                1
>         Thread(s) per core:   2
>         Core(s) per socket:   64
>         Socket(s):            1
>         Stepping:             1
>         Frequency boost:      enabled
>         CPU max MHz:          3720.7029
>         CPU min MHz:          1500.0000
[..snip..]

> 
> 
> Thought to post here instead of [0] to get your thought on this. Am I missing
> something simple to get the right value? Or should this be pulled out of 5.15
> LTS?

No, the patch has a bug. The nominal_frequency returned from the
get_max_boost_ratio() function was in MHz, while cpufreq maintains
frequencies in KHz due to which the computed max_frequency was
incorrect and thus as a fallback, cpufreq reported P0 frequency as the
cpuinfo_max_freq.

Can you please try the following patch on top of the original one?


------------------------x8------------------------------------------------

From 13d5c28823ed03353059801281d3b22e9f139a8d Mon Sep 17 00:00:00 2001
From: "Gautham R. Shenoy" <gautham.shenoy@amd.com>
Date: Wed, 28 May 2025 16:43:33 +0530
Subject: [PATCH] acpi-cpufreq: Fix nominal_freq units to KHz in get_max_boost_ratio()

commit 083466754596 ("cpufreq: ACPI: Fix max-frequency computation")
modified get_max_boost_ratio() to return the nominal_freq advertised
in the _CPC object for the purposes of computing the maximum
frequency. The frequencies advertised in _CPC objects are in MHz but
cpufreq expects the frequency to be in KHz. Because the
nominal_frequency was not converted to KHz, the cpuinfo_max_frequency
that got computed was incorrect and the cpufreq reported the P0
frequency as the cpuinfo_max_freq.

Fix this by returning nominal_freq in KHz in get_max_boost_ratio()

Reported-by: Manu Bretelle <chantr4@gmail.com>
Closes: https://lore.kernel.org/lkml/aDaB63tDvbdcV0cg@HQ-GR2X1W2P57/
Fixes: 083466754596 ("cpufreq: ACPI: Fix max-frequency computation")
Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
---
 drivers/cpufreq/acpi-cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
index d26b610e4f24..76768fe213a9 100644
--- a/drivers/cpufreq/acpi-cpufreq.c
+++ b/drivers/cpufreq/acpi-cpufreq.c
@@ -660,7 +660,7 @@ static u64 get_max_boost_ratio(unsigned int cpu, u64 *nominal_freq)
 	nominal_perf = perf_caps.nominal_perf;
 
 	if (nominal_freq)
-		*nominal_freq = perf_caps.nominal_freq;
+		*nominal_freq = perf_caps.nominal_freq * 1000;
 
 	if (!highest_perf || !nominal_perf) {
 		pr_debug("CPU%d: highest or nominal performance missing\n", cpu);
-- 
2.34.1


-- 
Thanks and Regards
gautham.

  reply	other threads:[~2025-05-28 11:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-13  4:41 [PATCH] acpi-cpufreq: Fix max-frequency computation Gautham R. Shenoy
2025-01-13 14:22 ` Mario Limonciello
2025-01-14 20:12   ` Rafael J. Wysocki
2025-05-28  3:24 ` Manu Bretelle
2025-05-28 11:57   ` Gautham R. Shenoy [this message]
2025-05-28 16:39     ` Manu Bretelle

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=aDb6Mgg3TqyR2IRT@BLRRASHENOY1.amd.com \
    --to=gautham.shenoy@amd.com \
    --cc=Adam.Clark@amd.com \
    --cc=Dhananjay.Ugwekar@amd.com \
    --cc=chantr4@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=rafael@kernel.org \
    --cc=viresh.kumar@linaro.org \
    /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