Bug 215800 - amd-pstate does not allow to set arbitrary maximum CPU frequency above 2200MHz for a desktop Zen 3 CPU
Summary: amd-pstate does not allow to set arbitrary maximum CPU frequency above 2200MH...
Status: RESOLVED DUPLICATE of bug 217931
Alias: None
Product: Power Management
Classification: Unclassified
Component: cpufreq (show other bugs)
Hardware: AMD Linux
: P1 normal
Assignee: linux-pm@vger.kernel.org
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-04-05 01:16 UTC by Artem S. Tashkinov
Modified: 2023-12-09 11:02 UTC (History)
7 users (show)

See Also:
Kernel Version: 5.18.3
Subsystem:
Regression: No
Bisected commit-id:


Attachments
Max freq (39.08 KB, image/png)
2022-04-12 07:25 UTC, Joe
Details
/sys/devices/system/cpu/cpufreq (1.92 KB, application/x-bzip)
2022-04-13 07:12 UTC, Artem S. Tashkinov
Details
Power Options Processor Power Management in Windows.png (31.55 KB, image/png)
2023-08-08 17:58 UTC, Artem S. Tashkinov
Details

Description Artem S. Tashkinov 2022-04-05 01:16:02 UTC
For my Ryzen 7 5800X I've tried (under root) numbers from 600 000 to 2 200 000 and they all work:

echo $number | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq

However anything above 2 200 000 instead makes the CPU stay at 2.2GHz.

This is after booting with acpi-cpufreq and loading amd-pstate with replace=1.

Even switching to the performance governor keeps all the cores at 2.2GHz.

I've also tried the userspace governor and again only frequencies up to 2.2GHz work. Anything above will be ignored.

I've tried to fix the issue by `cat cpuinfo_max_freq > scaling_max_freq` but that didn't work.

That looks like a bug.
Comment 1 Artem S. Tashkinov 2022-04-05 01:31:14 UTC
So, now I have this and all the cores are stuck at 2.2GHz:

/sys/devices/system/cpu/cpu0/cpufreq:

amd_pstate_highest_perf:166
scaling_min_freq:550000
scaling_available_governors:conservative ondemand userspace powersave performance schedutil 
scaling_governor:ondemand
cpuinfo_max_freq:4929000
amd_pstate_lowest_nonlinear_freq:1752000
amd_pstate_max_freq:4929000
related_cpus:0
scaling_cur_freq:2190255
scaling_setspeed:<unsupported>
affected_cpus:0
scaling_max_freq:4929000
cpuinfo_transition_latency:131072
scaling_driver:amd-pstate
cpuinfo_min_freq:550000
Comment 2 Artem S. Tashkinov 2022-04-11 07:22:25 UTC
Huang Rui,

Could you check, please?
Comment 3 Huang Rui 2022-04-11 13:33:41 UTC
Hi Artem,

Thanks for the report. Can you print: "lscpu | grep cppc"?
Comment 4 Artem S. Tashkinov 2022-04-11 16:28:37 UTC
> Thanks for the report. Can you print: "lscpu | grep cppc"?

# lscpu | grep -i cppc
returns nothing.

# lscpu --version
lscpu from util-linux 2.37.4

I've loading the amd-pstate driver prior to running it.
Comment 5 Joe 2022-04-12 03:25:39 UTC
"I've tried to fix the issue by `cat cpuinfo_max_freq > scaling_max_freq` but that didn't work. "

cat does not work. Please use "echo $number > scaling_max_freq".
Comment 6 Artem S. Tashkinov 2022-04-12 04:15:20 UTC
(In reply to Joe from comment #5)
> "I've tried to fix the issue by `cat cpuinfo_max_freq > scaling_max_freq`
> but that didn't work. "
> 
> cat does not work. Please use "echo $number > scaling_max_freq".

From the original post:

> For my Ryzen 7 5800X I've tried (under root) numbers from 600 000 to 2 200
> 000 and they all work:
> 
> echo $number | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq
> 
> However anything above 2 200 000 instead makes the CPU stay at 2.2GHz.

Echoing the number manually didn't work either.
Comment 7 Joe 2022-04-12 07:25:30 UTC
Created attachment 300747 [details]
Max freq
Comment 8 Joe 2022-04-12 07:26:34 UTC
Attach is the operation step on my side. It works with root privilege.
Comment 9 Artem S. Tashkinov 2022-04-12 08:46:39 UTC
(In reply to Joe from comment #7)
> Created attachment 300747 [details]
> Max freq

Changing scaling_max_freq makes the CPU stay at frequencies 2.2GHz or below.

Enter e.g. 3000000 (3GHz) as scaling_max_freq for all cores, then observe that scaling_cur_freq never exceeds 2.2GHz.
Comment 10 Artem S. Tashkinov 2022-04-12 08:50:44 UTC
Even restoring scaling_max_freq by setting it to cpuinfo_max_freq doesn't fix the issue.

Again, I'm repeating what I already said in the original bug report.



> For my Ryzen 7 5800X I've tried (under root) numbers from 600 000 to 2 200
> 000 and they all work:
> 
> echo $number | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq
> 
> However anything above 2 200 000 instead makes **the CPU stay at 2.2GHz**.

Don't mind scaling_max_freq, it's scaling_cur_freq that never exceeds 2.2GHz!
Comment 11 Joe 2022-04-13 06:50:53 UTC
OK, so it seems you change the scaling_max_freq to 2.2G, after that, even you change back to 3G or cpuinfo_max_freq, the scaling_cur_freq is still less than 2.2GHz.

I tried 2 devices on my local, can not reproduce this issue.

After you set scaling_max_freq to 3G or higher, You can try to run "stress --cpu 128" with increasing the workload to check if the scaling_cur_freq can exceeds 2.2GHz.
Comment 12 Artem S. Tashkinov 2022-04-13 07:06:44 UTC
(In reply to Joe from comment #11)
> OK, so it seems you change the scaling_max_freq to 2.2G, after that, even
> you change back to 3G or cpuinfo_max_freq, the scaling_cur_freq is still
> less than 2.2GHz.
> 
> I tried 2 devices on my local, can not reproduce this issue.
> 
> After you set scaling_max_freq to 3G or higher, You can try to run "stress
> --cpu 128" with increasing the workload to check if the scaling_cur_freq can
> exceeds 2.2GHz.

I've run tests now a dozen times already: once I change cpuinfo_max_freq my CPU never goes above 2.2GHz no matter what I do even if I restore the value stored in this variable/file.

This is further corroborated by more than halved performance and decreased power consumption - it doesn't go above ~55W.
Comment 13 Artem S. Tashkinov 2022-04-13 07:12:04 UTC
Created attachment 300750 [details]
/sys/devices/system/cpu/cpufreq

The entire /sys/devices/system/cpu/cpufreq tar.bz2'ed after running an intensive MT task for a few minutes.
Comment 14 Artem S. Tashkinov 2022-04-13 09:41:43 UTC
Here's another weirdness/quirk:

After suspending and resuming the maximum CPU frequency increases to 3800MHz (which is the base frequency for Ryzen 7 5800X).

Boost is _enabled_.

Not sure if it warrants yet another bug report.

Let's limit them to three.
Comment 15 perry_yuan 2022-05-17 08:07:17 UTC
(In reply to Artem S. Tashkinov from comment #0)
> For my Ryzen 7 5800X I've tried (under root) numbers from 600 000 to 2 200
> 000 and they all work:
> 
> echo $number | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq
> 
> However anything above 2 200 000 instead makes the CPU stay at 2.2GHz.
> 
> This is after booting with acpi-cpufreq and loading amd-pstate with
> replace=1.
> 
> Even switching to the performance governor keeps all the cores at 2.2GHz.
> 
> I've also tried the userspace governor and again only frequencies up to
> 2.2GHz work. Anything above will be ignored.
> 
> I've tried to fix the issue by `cat cpuinfo_max_freq > scaling_max_freq` but
> that didn't work.
> 
> That looks like a bug.

Could you help to try the below kernel ?
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/drivers/cpufreq/amd-pstate.c?h=next-20220516

I tried this kernel, but 5950x cannot reproduce the issue as yours.
Comment 16 Artem S. Tashkinov 2022-05-17 08:25:29 UTC
(In reply to perry_yuan from comment #15)
> 
> Could you help to try the below kernel ?
> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/
> drivers/cpufreq/amd-pstate.c?h=next-20220516
> 
> I tried this kernel, but 5950x cannot reproduce the issue as yours.

Does this patch require enabling debugging in the kernel? I'm not sure how I am supposed to share (debug) data once I've applied it.
Comment 17 perry_yuan 2022-05-19 02:34:52 UTC
(In reply to Artem S. Tashkinov from comment #16)
> (In reply to perry_yuan from comment #15)
> > 
> > Could you help to try the below kernel ?
> > https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/
> > drivers/cpufreq/amd-pstate.c?h=next-20220516
> > 
> > I tried this kernel, but 5950x cannot reproduce the issue as yours.
> 
> Does this patch require enabling debugging in the kernel? I'm not sure how I
> am supposed to share (debug) data once I've applied it.

Hi Artem.
I mean you could build the kernel and install it on your system.
and switch the governor , capture the min/max log ,etc.

I do not find the reproducing way, but I still want to try to reproduce the issue if you can confirm the kernel link has same problem.

Perry.
Comment 18 perry_yuan 2022-05-19 02:41:42 UTC
(In reply to Artem S. Tashkinov from comment #0)
> For my Ryzen 7 5800X I've tried (under root) numbers from 600 000 to 2 200
> 000 and they all work:
> 
> echo $number | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq
> 
> However anything above 2 200 000 instead makes the CPU stay at 2.2GHz.
> 
> This is after booting with acpi-cpufreq and loading amd-pstate with
> replace=1.
> 
> Even switching to the performance governor keeps all the cores at 2.2GHz.
> 
> I've also tried the userspace governor and again only frequencies up to
> 2.2GHz work. Anything above will be ignored.
> 
> I've tried to fix the issue by `cat cpuinfo_max_freq > scaling_max_freq` but
> that didn't work.
> 
> That looks like a bug.

I would like to confirm which kernel version or patch cause the regression,
so need you help to verify the regression root cause, then I will reproduce the issue to fix it on my side.

 
Perry
Comment 19 Artem S. Tashkinov 2022-06-12 14:34:53 UTC
All the same with 5.18.3.

Steps to reproduce:

echo 3000000 | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq

Now all the CPU cores are stuck below 2.2GHz.

This is after `modprobe amd-pstate replace=1`

I really don't understand what else I can do. This is reproducible with a single command on my Ryzen 7 5800X CPU.
Comment 20 Artem S. Tashkinov 2022-06-12 14:54:27 UTC
> capture the min/max log

Now idea how to do that, where is it logged.

/sys/devices/system/cpu/cpu0/acpi_cppc contains this:

feedback_ctrs:ref:1185870842796 del:939045433401
lowest_nonlinear_perf:59
highest_perf:186
nominal_freq:3801
lowest_freq:550
nominal_perf:128
lowest_perf:19
reference_perf:128
wraparound_time:18446744073709551615

No idea what highest_perf is - it's a read only value anyways. No idea what its scale is, 0-255? Why is so below the maximum value?
Comment 21 Artem S. Tashkinov 2022-06-12 15:04:24 UTC
/sys/devices/system/cpu/cpufreq/policy0

amd_pstate_highest_perf:166
scaling_min_freq:550000
scaling_available_governors:conservative ondemand userspace powersave performance schedutil 
scaling_governor:ondemand
cpuinfo_max_freq:4929000
amd_pstate_lowest_nonlinear_freq:1752000
amd_pstate_max_freq:4929000
related_cpus:0
scaling_cur_freq:1247422
scaling_setspeed:<unsupported>
affected_cpus:0
scaling_max_freq:1600000
cpuinfo_transition_latency:131072
scaling_driver:amd-pstate
cpuinfo_min_freq:550000

Why do I have two wildly different amd_pstate_highest_perf=166 and highest_perf=186?

What's the relationship between the two?

Anyways, the issue remains. As far as I can see https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/drivers/cpufreq/amd-pstate.c has seen near zero activity for the past three months.
Comment 22 perry_yuan 2022-07-05 01:14:55 UTC
(In reply to Artem S. Tashkinov from comment #21)
> /sys/devices/system/cpu/cpufreq/policy0
> 
> amd_pstate_highest_perf:166
> scaling_min_freq:550000
> scaling_available_governors:conservative ondemand userspace powersave
> performance schedutil 
> scaling_governor:ondemand
> cpuinfo_max_freq:4929000
> amd_pstate_lowest_nonlinear_freq:1752000
> amd_pstate_max_freq:4929000
> related_cpus:0
> scaling_cur_freq:1247422
> scaling_setspeed:<unsupported>
> affected_cpus:0
> scaling_max_freq:1600000
> cpuinfo_transition_latency:131072
> scaling_driver:amd-pstate
> cpuinfo_min_freq:550000
> 
> Why do I have two wildly different amd_pstate_highest_perf=166 and
> highest_perf=186?
> 
> What's the relationship between the two?
> 
> Anyways, the issue remains. As far as I can see
> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/
> drivers/cpufreq/amd-pstate.c has seen near zero activity for the past three
> months.
 modprobe amd-pstate replace=1(In reply to Artem S. Tashkinov from comment #19)
> All the same with 5.18.3.
> 
> Steps to reproduce:
> 
> echo 3000000 | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq
> 
> Now all the CPU cores are stuck below 2.2GHz.
> 
> This is after `modprobe amd-pstate replace=1`
> 
> I really don't understand what else I can do. This is reproducible with a
> single command on my Ryzen 7 5800X CPU.

Please drop the replace parameter when loading driver, that patch is not merged by upstream yet.
Comment 23 Artem S. Tashkinov 2022-07-06 22:10:38 UTC
(In reply to perry_yuan from comment #22)
> Please drop the replace parameter when loading driver, that patch is not
> merged by upstream yet.

This is reproducible when booting with the amd-pstate driver.
Comment 24 Artem S. Tashkinov 2022-09-19 12:08:48 UTC
Is this driver (development) dead now that there's a new AMD driver for CPPC?
Comment 25 Artem S. Tashkinov 2023-07-07 13:27:04 UTC
In kernel 6.3.12 limiting CPU frequency doesn't work at all:

echo 3000000 | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq

Average across all cores and maximum frequencies that I observe now are: 3726MHz and 4898MHz.
Comment 26 Artem S. Tashkinov 2023-07-07 13:30:04 UTC
amd_pstate_highest_perf is readonly, I cannot write to it.

/sys/devices/system/cpu/cpufreq/policy0 $ grep -r . 
energy_performance_available_preferences:default performance balance_performance balance_power power 
amd_pstate_highest_perf:166
scaling_min_freq:550000
scaling_available_governors:performance powersave
scaling_governor:powersave
cpuinfo_max_freq:4929000
amd_pstate_lowest_nonlinear_freq:1752000
amd_pstate_max_freq:4929000
related_cpus:0
scaling_cur_freq:550000
scaling_setspeed:<unsupported>
affected_cpus:0
scaling_max_freq:3000000
cpuinfo_transition_latency:0
energy_performance_preference:performance
scaling_driver:amd-pstate-epp
cpuinfo_min_freq:550000
Comment 27 Artem S. Tashkinov 2023-07-07 13:35:59 UTC
I've even tried this:

echo 600000 | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq

Zero effect. scaling_max_freq is ignored.
Comment 28 Mario Limonciello (AMD) 2023-07-07 14:51:53 UTC
When you're using active mode (EPP), the hardware is choosing frequencies and software only provides a hint to set bias.

You can read a little bit more about active mode at https://www.kernel.org/doc/html/latest/admin-guide/pm/amd-pstate.html

What you should be doing isn't trying to set specific frequency targets, but rather you should change the values of 'energy_performance_preference' to meet the needs for your workload.
Comment 29 Artem S. Tashkinov 2023-07-07 15:07:04 UTC
(In reply to Mario Limonciello (AMD) from comment #28)
> When you're using active mode (EPP), the hardware is choosing frequencies
> and software only provides a hint to set bias.
> 
> You can read a little bit more about active mode at
> https://www.kernel.org/doc/html/latest/admin-guide/pm/amd-pstate.html
> 
> What you should be doing isn't trying to set specific frequency targets, but
> rather you should change the values of 'energy_performance_preference' to
> meet the needs for your workload.

Thanks Mario.

Would be great if the documentation was updated in this case and the variable removed altogether if the amd-pstate driver is active. I know it's possible.

It's a little bit confusing though, as in Windows I can perfectly set minimum and maximum CPU frequencies and I totally expected this driver to actually allow that.

Now you're saying I need to work with "energy_performance_preference" which doesn't even look like something I can properly configure.

Lastly the documentation mentions: energy_performance_available_preferences, the file that I don't have.

In short it looks like everything is in a deep state of flux.

Lastly there's no boost configuration support which is available both for acpi-cpufreq and Intel's native CPPC driver.

I'll retest the drive in a year. I don't like anything about how it works, functions and its configuration options. It's worse than acpi-cpufreq from seemingly any PoV. Maybe there are some advantages for APUs but on my desktop I only see major disadvantages.
Comment 30 Mario Limonciello (AMD) 2023-07-07 15:23:55 UTC
> It's a little bit confusing though, as in Windows I can perfectly set minimum
> and maximum CPU frequencies and I totally expected this driver to actually
> allow that.

I suppose I'm confused as well.  Windows should be using EPP as well, and various software constructs like the power slider will be changing that bias.

Maybe you can better explain exactly what you do in Windows and exactly what is happening.

> Lastly the documentation mentions: energy_performance_available_preferences,
> the file that I don't have.

Eh?  Didn't your above comment show this:

/sys/devices/system/cpu/cpufreq/policy0 $ grep -r . 
energy_performance_available_preferences:default performance balance_performance balance_power power 

> Lastly there's no boost configuration support which is available both for
> acpi-cpufreq and Intel's native CPPC driver.

Something seems quite wrong if you're not getting boost support.
It registers for boost, see https://github.com/torvalds/linux/blob/v6.4/drivers/cpufreq/amd-pstate.c#L1121

> It's worse than acpi-cpufreq from seemingly any PoV. Maybe there are some
> advantages for APUs but on my desktop I only see major disadvantages

I /suspect/ what you'll want to do is change the scaling_governor from 'powersave' to 'performance' for your desktop use case.
Comment 31 Artem S. Tashkinov 2023-08-08 17:58:46 UTC
Created attachment 304797 [details]
Power Options Processor Power Management in Windows.png

(In reply to Mario Limonciello (AMD) from comment #30)
> > It's a little bit confusing though, as in Windows I can perfectly set
> minimum
> > and maximum CPU frequencies and I totally expected this driver to actually
> > allow that.
> 
> I suppose I'm confused as well.  Windows should be using EPP as well, and
> various software constructs like the power slider will be changing that bias.
> 
> Maybe you can better explain exactly what you do in Windows and exactly what
> is happening.

In Windows I'm free to set minimum and maximum CPU clock speeds to my liking.

Why is it necessary?

1) For instance you want to do benchmarking at certain clock speeds which are not known to be hitting TDP/TTP/temperature limits, thus they show the true potential of your CPU.

2) For instance you want to make you CPU run cooler with a very precise control.

> 
> > Lastly the documentation mentions:
> energy_performance_available_preferences,
> > the file that I don't have.
> 
> Eh?  Didn't your above comment show this:
> 
> /sys/devices/system/cpu/cpufreq/policy0 $ grep -r . 
> energy_performance_available_preferences:default performance
> balance_performance balance_power power 
> 
> > Lastly there's no boost configuration support which is available both for
> > acpi-cpufreq and Intel's native CPPC driver.
> 
> Something seems quite wrong if you're not getting boost support.
> It registers for boost, see
> https://github.com/torvalds/linux/blob/v6.4/drivers/cpufreq/amd-pstate.
> c#L1121

Will recheck in 6.4.x soon.

> 
> > It's worse than acpi-cpufreq from seemingly any PoV. Maybe there are some
> > advantages for APUs but on my desktop I only see major disadvantages
> 
> I /suspect/ what you'll want to do is change the scaling_governor from
> 'powersave' to 'performance' for your desktop use case.

These two options are very coarse vs. being simply able to set maximum clock speeds.
Comment 32 Artem S. Tashkinov 2023-09-15 10:22:21 UTC
In kernel 6.5 the values of /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq are simply ignored.

Looks like setting the maximum operating CPU frequency is no longer supported.
Comment 33 Artem S. Tashkinov 2023-09-20 11:07:36 UTC

*** This bug has been marked as a duplicate of bug 217931 ***

Note You need to log in before you can comment on or make changes to this bug.