Bug 292615 - cpufreq changes causes AMD 4750U to run 11x slower
Summary: cpufreq changes causes AMD 4750U to run 11x slower
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 16.0-CURRENT
Hardware: amd64 Any
: --- Affects Some People
Assignee: Olivier Certner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-01-20 18:30 UTC by Martin Cracauer
Modified: 2026-02-20 10:35 UTC (History)
9 users (show)

See Also:


Attachments
Local patch to add tunable disabling CPPC. (1.55 KB, patch)
2026-01-20 19:01 UTC, Cy Schubert
no flags Details | Diff
Logs of some hwpstate_amd's sysctl knobs from Martin Cracauer (4.05 KB, text/plain)
2026-01-22 10:40 UTC, Olivier Certner
no flags Details
Patch to avoid using CPPC_CAPABILITY_1 values in CPPC_REQUEST when not initialized (2.21 KB, patch)
2026-01-22 15:16 UTC, Olivier Certner
no flags Details | Diff
New patch with more diagnostic output (15.80 KB, patch)
2026-01-23 09:16 UTC, Olivier Certner
no flags Details | Diff
acpidump -dt (98.48 KB, application/x-gzip)
2026-01-24 20:40 UTC, Martin Cracauer
no flags Details
debug patch output 2 (43.62 KB, text/plain)
2026-01-24 20:51 UTC, Martin Cracauer
no flags Details
debug patch output 2 (46.49 KB, text/plain)
2026-01-24 22:25 UTC, Martin Cracauer
no flags Details
New patch with more diagnostic output (15.80 KB, patch)
2026-01-27 02:03 UTC, Mark Linimon
no flags Details | Diff
output from latest patch (46.49 KB, text/plain)
2026-01-27 06:58 UTC, Martin Cracauer
no flags Details
Patch with candidate fix and more knobs (23.98 KB, patch)
2026-01-27 15:53 UTC, Olivier Certner
no flags Details | Diff
Results from last patch (45.80 KB, text/plain)
2026-01-27 16:18 UTC, Martin Cracauer
no flags Details
More polished patch (25.26 KB, patch)
2026-01-30 10:14 UTC, Olivier Certner
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Cracauer 2026-01-20 18:30:50 UTC
Commit to cpufreq 3e6e4e4a0d42fa24f3b2a1c087e9ad25f9594081 "hwpstate: add CPPC support for pstate driver on AMD"

causes my laptop to run at 399 MHz, about 11 times slower than before the commit.

It is a Thinkpad T1 gen 1 AMD Ryzen 7 PRO 4750U with Radeon Graphics (1696.91-MHz K8-class CPU).                                                     

Dmesg from a kernel before that commit:
https://www.cons.org/goodkernel.dmesg

Dmesg from a kernel after that commit:
https://www.cons.org/badkernel.dmesg
Comment 1 Cy Schubert freebsd_committer freebsd_triage 2026-01-20 19:01:55 UTC
Created attachment 267335 [details]
Local patch to add tunable disabling CPPC.

I had a different problem, which I had sent a private email to aokblast and lwhsu about. My email is copied here as it describes my problem:

Just an FYI, my Framework 13 with AMD CPU runs hot with this patch when 
performing buildworld. This is because I use powerd(8) to limit its 
frequency to 2200. This patch of course disallows powerd to control CPU 
frequency (as it should because PSTATE is incompatible with Cool`n'Quiet.

I've cobbled a simple patch to disable CPPC in loader.conf, restoring my 
desire to run my Framework 13 CPU at a maximum 2200 using powerd. Are you 
interested in the patch? If yes, I can either submit a phabricator revision 
or send it to you.

My Framework 13 with AMD Ryzen 7 7840U consistently ran at 98C to 100C temperatures during buildworld and while building ports after the CPPC commit. I applied a local patch that adds a tunable to disable CPPC. I use powerd to limit the frequency of my Ryzen to 2200 MHz thereby reducing its temperature to between 45C and 55C.

My local patch is attached.
Comment 2 Cy Schubert freebsd_committer freebsd_triage 2026-01-20 19:09:14 UTC
With CPPC my Ryzen does run within the max boost frequency. I don't think we should revert the CPPC commit but I do think we should apply my patch and default to either CPPC enabled or CPPC disabled.

I will submit a review for my tunable.
Comment 3 Cy Schubert freebsd_committer freebsd_triage 2026-01-20 19:12:36 UTC
See https://reviews.freebsd.org/D54803 for the review.
Comment 4 Cy Schubert freebsd_committer freebsd_triage 2026-01-20 19:17:41 UTC
We can discuss the merits of the patch in Phabricator. I've asked a question there for people to weigh in on.
Comment 5 Martin Cracauer 2026-01-20 19:52:32 UTC
Cy's patch, when turning the tuneable off, fixes the slowdown.
Comment 6 commit-hook freebsd_committer freebsd_triage 2026-01-22 04:44:40 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=ad9932995cf8f93143ff033712016d95b5cb7a50

commit ad9932995cf8f93143ff033712016d95b5cb7a50
Author:     Cy Schubert <cy@FreeBSD.org>
AuthorDate: 2026-01-05 04:53:51 +0000
Commit:     Cy Schubert <cy@FreeBSD.org>
CommitDate: 2026-01-22 04:36:33 +0000

    hwpstate: Add CPPC enable tunable

    The Framework 13 runs very hot the maximum frequency is possible. By
    disabling CPPC (reverting to Cool`n'Quiet 2.0) we can use powerd to
    limit the CPU frequency to 2200, thereby reducing the CPU temperature.

    Some systems may run slower with CPPC enabled. See PR/292615 for that
    bug.

    Those experiencing either of these issues may add the following to
    their loader.conf or device.hints to disable CPPC:

    machdep.hwpstate_amd_cppc_enable="0"

    PR:                     292615
    Reviewed by:            lwhsu, olce
    Differential revision:  https://reviews.freebsd.org/D54803

 sys/x86/cpufreq/hwpstate_amd.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
Comment 7 Olivier Certner freebsd_committer freebsd_triage 2026-01-22 10:40:52 UTC
Created attachment 267379 [details]
Logs of some hwpstate_amd's sysctl knobs from Martin Cracauer
Comment 8 Martin Cracauer 2026-01-22 11:18:43 UTC
What would be involved in making CPPC actually work on the 4750 AMD?
Comment 9 Olivier Certner freebsd_committer freebsd_triage 2026-01-22 11:25:55 UTC
Doing a summary of the discussion in revision https://reviews.freebsd.org/D54803, for more details see there.  Will follow-up on it in the next comment.

I asked Martin if lowering EPP would fix the diminished performance issue.  This is not the case.  I then asked him to report the content of `debug.hwpstate_amd0`.  Results so far are in the 'cracauer-epp.log' file I have just attached to this bug.

I asked Cy to raise EPP to see if that would prevent its processor from getting hot during buildworld, and to report the content of `debug.hwpstate_amd0`, but didn't get adequate feedback so far, except for some description of frequencies and temperatures, still in the context of a buildworld IIUC, reproduced here for convenience:
"""
I use powerd to limit the CPU frequency on this machine. If I don't limit the CPU frequency, i.e. let it go to 3300 MHz the machine will run hot at almost 100C. When I limit the frequency to 2200 MHz using powerd a buildworld will run between 45C and 55C. It's currently idling at 32.6C.

When CPPC is enabled the CPU will run as high as 4300 MHz or higher as the CPU supports frequency boost higher than baseline frequency. Again it will max out at 100C after which it will reduce its frequency to run at 98C. Certainly not healthy for the CPU. BTW, this is a Framework 13 laptop. I doubt the cooling was designed properly to support such a CPU.
"""
Comment 10 Olivier Certner freebsd_committer freebsd_triage 2026-01-22 13:57:30 UTC
(In reply to Martin Cracauer from comment #8)

That's exactly what we are trying to discover here.

(In reply to Olivier Certner from comment #9)

Following-up on feedback.

* For Martin:

The output strangely shows that the content of the CPPC_CAPABILITY_1 register is 0, which seems wrong, as if it has not been initialized (contrary to what the AMD's APM says).  We are using some of the values in there (so, all 0s in this case) to then program CPPC_REQUEST (but programming it with these 0s shouldn't be a problem, again according to the APM).

Here's what we first could do (other ideas welcome).  Going to produce a patch that, when CPPC_CAPABILITY_1 is not initialized, does not use its values to set CPPC_REQUEST, which I'll ask you to test.  Probably going to add more debug knobs in a second step.

Some problem I'm facing is that, if CPPC_CAPABILITY_1 is not initialized despite CPPC having being enabled via CPPC_ENABLE, I was considering declaring that CPPC support is broken, but that is too late at this point, since we are not supposed to be able to fallback to regular P-states once CPPC has been enabled (according to the APM, it cannot be disabled).  But I need to enable it and then read CPPC_CAPABILITY_1 to see whether it is initialized correctly (it is supposed to be 0 before CPPC is enabled).

* For Cy:

I'm hearing you, but have a hard time finding anything you reported really problematic.  That CPU temperature can reach 100°C and then cause frequency throttling during buildworld isn't at all surprising to me.  This is, e.g., what I've been observing on a few Intel laptops of mine.  Maybe your Framework does not handle it gracefully, but then that looks like a platform problem more than anything else.  You shouldn't be doing what you're doing with powerd and regular P-states in the first place, irrespective of CPPC support.

So, at the moment, I don't think the default value of the new knob should be changed.

* More generally:

I'm also starting to wonder if we may not be doing it wrong with that AMD-specific implementation that short-circuits ACPI.  Even if that is what we also have been doing with Intel processors.

I'll try to look around in other OSes to see what they are doing.

Any ideas welcome.
Comment 11 Martin Cracauer 2026-01-22 14:02:05 UTC
Happy to test anything. I also have a spare one of these laptops where you can get a root account with reboot allowance.
Comment 12 Alexander Ziaee freebsd_committer freebsd_triage 2026-01-22 14:28:10 UTC
Hey guys. Can we get some documentation?

"hwpstate_amd_cppc_enable: Set 1 (default) to enable AMD CPPC, 0 to disable"

This is just restating the name of the knob. What does cppc do?
Comment 13 Cy Schubert freebsd_committer freebsd_triage 2026-01-22 14:48:44 UTC
(In reply to Olivier Certner from comment #10)

This is my point. The Framework 13 laptop is likely not designed for sustained heavy CPU load at full speed with workloads like a buildworld. This is why I limit the CPU frequency on the AMD laptop. WRT one of my Intel laptops, the HP 840 runs significantly cooler during buildworld when Turbo Boost is disabled in the BIOS. Cooling wasn't much of an issue for my other older Intel laptops.

My AMD servers in my basement have no cooling issues. Only the laptops. This is to be expected with laptops and the limited space designers have to work within them.
Comment 14 Olivier Certner freebsd_committer freebsd_triage 2026-01-22 14:58:02 UTC
(In reply to Cy Schubert from comment #13)

But I'm experiencing what you're seeing on your Framework 13 on various Dell Intel laptops, and that has never caused any problem, such as degrading the machine (at least AFAICT), except that, of course, CPUs throttle their frequency to avoid passing 100°C.  It's a design problem in the sense that they cannot sustain their highest frequency for long, but not in the sense that the hardware is going to be destroyed.  Perhaps that diminishes its lifetime, I don't know.  Is it what you are after, or are you just trying to limit the temperature because the laptop can become hard to touch?
Comment 15 Olivier Certner freebsd_committer freebsd_triage 2026-01-22 15:01:13 UTC
(In reply to Alexander Ziaee from comment #12)

Something like: "Set 1 (default) to use AMD CPPC if present, else 0 to fallback to regular P-states."?

I don't think we should explain what CPPC or P-states are here.  But we could link to hwpstate_amd(4) manual page which... doesn't exist yet (there is a hwpstate_intel(4) one though).

To our defense, we expect to significantly move parts in hwpstate_amd(4) in the coming weeks, so I don't think it's necessarily worth doing now, but indeed we should not forget about it.
Comment 16 Olivier Certner freebsd_committer freebsd_triage 2026-01-22 15:16:28 UTC
Created attachment 267384 [details]
Patch to avoid using CPPC_CAPABILITY_1 values in CPPC_REQUEST when not initialized

(In reply to Martin Cracauer from comment #11)

Could you test the following patch, and dump again the sysctl knobs as you did previously?
Comment 17 Martin Cracauer 2026-01-22 15:32:32 UTC
(In reply to Olivier Certner from comment #16)

No change in output compared to epp.log
Comment 18 Cy Schubert freebsd_committer freebsd_triage 2026-01-22 15:53:55 UTC
(In reply to Cy Schubert from comment #13)

Though 100C doesn't destroy the CPU, frequently running it at that temperature will reduce its lifetime. And I'm loathed to spend the money until I decide to.
Comment 19 Olivier Certner freebsd_committer freebsd_triage 2026-01-23 09:10:30 UTC
(In reply to Cy Schubert from comment #18)

FWIW, from glancing online at Reddit and Stack Overflow, it seems the consensus is that, as long as these CPUs are running under their max designed temperature (100°C for Intel laptop CPUs I have seen), they will last for their designed time, which is said to be 10+ (in admittedly very few posts).  There are some "reports" of earlier MacBooks running mostly at ~100°C for years and not getting broken.  For my personal uses, I'm still unclear if forcing lower frequencies would be worth it.
Comment 20 Olivier Certner freebsd_committer freebsd_triage 2026-01-23 09:16:53 UTC
Created attachment 267406 [details]
New patch with more diagnostic output

(In reply to Martin Cracauer from comment #17)

Ack.

I have attached a new patch which is more involved, and will print much more diagnostic.  Otherwise, it won't change the behavior.  It's untested as I don't have an AMD laptop, hopefully it will work on the first run but there's a non-zero risk of panic.

Could you please test it, this time:
1. Report the output of all `debug.hwpstate_amdX` knobs, not only the first one.
2. Trying also some values higher than 50 for EPP, and in particular 100.

Thanks.
Comment 21 Alexander Ziaee freebsd_committer freebsd_triage 2026-01-23 16:41:01 UTC
(In reply to Olivier Certner from comment #15)

I think that would be perfect.
Comment 22 ShengYi Hung freebsd_committer freebsd_triage 2026-01-24 10:06:15 UTC
(In reply to Olivier Certner from comment #20)

Sorry for the late reply since I am a career soldier currently...

Cy's case is easier to solve. We can read the Lowest Frequency and Nominal Frequency in ACPI _CPC object then do interpolation for other Frequency (High and Guaranteed). When getting all of the frequency and cppc value, we can make cpufreq mutable and allow to powerd(8) to modify the value in both amd's and intel's case. I have a WIP generic CPPC (fully relies on the _CPC object) driver which can be used in aarch64 and amd64 platforms but some ACPI features are missing in FreeBSD. I am still working on this.

For Martin's case, could you please provide the result of acpidump -dt? There might be some hints in the _CPC object.
Comment 23 ShengYi Hung freebsd_committer freebsd_triage 2026-01-24 10:11:36 UTC
(In reply to ShengYi Hung from comment #22)

To be specific, my guess is that Highest Performance, Nominal Performance, Lowest Nonlinear Performance, Lowest Performance elements in _CPC object might provide the correct value in some UEFI/firmware setup.
Comment 24 Martin Cracauer 2026-01-24 20:39:26 UTC
(In reply to ShengYi Hung from comment #22)

acpidump -dt output attached as requested.
Comment 25 Martin Cracauer 2026-01-24 20:40:35 UTC
Created attachment 267452 [details]
acpidump -dt

acpidump -dt
Comment 26 Martin Cracauer 2026-01-24 20:51:30 UTC
Created attachment 267453 [details]
debug patch output 2

(In reply to Olivier Certner from comment #20)
> Could you please test it, this time:
> 1. Report the output of all `debug.hwpstate_amdX` knobs, not only the first one.
> 2. Trying also some values higher than 50 for EPP, and in particular 100.
Comment 27 Martin Cracauer 2026-01-24 22:25:53 UTC
Created attachment 267461 [details]
debug patch output 2

Disregard previous attachment, new patch didn't stick.
Comment 28 ShengYi Hung freebsd_committer freebsd_triage 2026-01-25 07:06:37 UTC
(In reply to Martin Cracauer from comment #24)

CPPC is available on your CPU but is unavailable on your machine since _CPC object does not exist.

See also: https://www.reddit.com/r/thinkpad/comments/w862zy/cppcpstate_on_thinkpad_e14g2_amd/

We can parse DSDT to see if the _CPC object does exist. If not, we rollback to legacy pstate driver and we don't need the knob anymore.
Comment 29 Olivier Certner freebsd_committer freebsd_triage 2026-01-26 17:41:49 UTC
(In reply to ShengYi Hung from comment #22)

> Sorry for the late reply since I am a career soldier currently...

I heard that this was temporary and hope you'll return soon.

> Cy's case is easier to solve. We can read the Lowest Frequency and Nominal Frequency in ACPI _CPC object then do interpolation for other Frequency (High and Guaranteed). When getting all of the frequency and cppc value, we can make cpufreq mutable and allow to powerd(8) to modify the value in both amd's and intel's case. I have a WIP generic CPPC (fully relies on the _CPC object) driver which can be used in aarch64 and amd64 platforms but some ACPI features are missing in FreeBSD. I am still working on this.

I don't think we can actually allow to modify the current frequency with good effect, and even if we could hack something that feels like a dead end.

The frequency as currently reported by 'hwpstate_amd' in CPPC mode is an estimate based on a delay loop.  Moreover, even if AMD's APM states there is a direct mapping between the performance values and the actual CPU frequencies (which varies among their processors), it is unclear if we can derive it with confidence, and even if we can, how are we going to use the performance level a given frequency would map to?  We could naturally use it as the desired performance value, but then the hardware only takes that value as a hint, whether we are in autonomous mode or not, and we don't know how much it can deviate from the desired value.  Other values having influence are the minimum and maximum performance, so if we exactly want a given frequency, we can probably set these to the mapped performance value, in addition to the desired value (if we ought to believe the ACPI spec), but then that completely defeats the purpose of CPPC, basically turning it into regular P-states.  At this point, it seems better to just deactivate CPPC than to activate it.

Additionally, I don't think there is any guarantee that this frequency <-> perf level mapping will continue to exist in future AMD processors.  And I don't think such a mapping necessarily exists for Intel processors (we should strive to be consistent in the controls/reports we provide).

As CPPC is standardized by ACPI, I think we should rather amend cpufreq(4) to support CPPC controls and then teach powerd(8) about them, when CPPC's autonomous mode is not used.  When CPPC's autonomous mode is on, it's likely that we won't need powerd(8) at all.

What could probably solve Cy's case is the ability to tweak the maximum performance level.  As a next step, I'll see to add such a control knob.

It's true that there should be, according to the APM,  on AMD processors.  However, allowing to set it is basically incompatible with  . EPP value and the actual CPU frequency is said to , given that I doubt that we should allow the frequency to be changed. doubt that allowing to set a frequency among those reported by 'hwpstate_amd'.  Since Efficiency/Performance Preference frameworks, both for Intel and AMD
Comment 30 Olivier Certner freebsd_committer freebsd_triage 2026-01-26 17:43:15 UTC
(In reply to Olivier Certner from comment #29)

Last paragraph in this comment is a leftover that should have been deleted.  It makes no sense as is.
Comment 31 Olivier Certner freebsd_committer freebsd_triage 2026-01-26 17:54:40 UTC
(In reply to ShengYi Hung from comment #28)

It seems to me unclear that absence of a _CPC object does necessarily indicate that CPPC is not supported at the processor level.  AMD's APM does not seem to imply that there should be some collaboration between the platform and the CPU to use CPPC.  In other words, programming the CPU directly should be enough.
Comment 32 Olivier Certner freebsd_committer freebsd_triage 2026-01-26 18:08:22 UTC
(In reply to Martin Cracauer from comment #27)

Preparing a patch that may fix your issue.  Will post it tomorrow.
Comment 33 Mark Linimon freebsd_committer freebsd_triage 2026-01-27 02:03:38 UTC
Created attachment 267532 [details]
New patch with more diagnostic output

^Triage: canonicalize the diff output directories because otherwise patchQA.py
gets confused.
Comment 34 Martin Cracauer 2026-01-27 06:58:47 UTC
Created attachment 267534 [details]
output from latest patch

for val in 0 10 25 37 50 75 100 125 ; do
    for file in `shellsupport -c 0 15` ; do
        sudo sysctl dev.hwpstate_amd.$file.epp=$val
    done
    for file in `shellsupport -c 0 15` ; do
        sudo sysctl debug.hwpstate_amd$file
    done
    #dmesg | tail
done
Comment 35 Olivier Certner freebsd_committer freebsd_triage 2026-01-27 15:53:25 UTC
Created attachment 267549 [details]
Patch with candidate fix and more knobs

This new patch (untested on real hardware) essentially does two things:
1. A potential fix for Martin's case, where the CPPC_CAPABILITY_1 was not filled up correctly after initialization (to 0).  The original values of min and max performance in CPPC_REQUEST seem inconsistent (as the min value is lower than the max one; unless AMD's APM is wrong...), so the plan of leaving them untouched does not work (confirmed by Martin's experiments).  When the min and max performance values in CPPC_CAPABILITY_1 are not sorted correctly or are equal (covers the above-mentioned case of staying at 0), use values as suggested by the ACPI spec for generic CPPC (0 for min, 255 for max).
2. I have added knobs to control the min, max and desired performance levels in the CPPC_REQUEST register.

To follow, instructions on what to report.
Comment 36 Olivier Certner freebsd_committer freebsd_triage 2026-01-27 15:57:20 UTC
- For Cy: Could you try disabling powerd(8) entirely and enabling back CPPC (so, do not set the knob you introduced), and then lowering the value of the max performance knob (but it must stay greater than that of the min performance)?  Also, could you please give the output of the `debug.hwpstate_amdX` knobs before and after tuning?  And also the dmesg messages related to 'hwpstate_amd'?

- For Martin: Test if this new patch fixes your problem.  Also, please report the debug knobs as usual, and please also include dmesg messages related to 'hwpstate_amd' as well.
Comment 37 Olivier Certner freebsd_committer freebsd_triage 2026-01-27 16:02:33 UTC
Oh, forgot to say that I changed the scale of the 'epp' knobs.  The range is now 0 to 255, not 0 to 100 anymore.  This is to be able to get/set the exact EPP value in the CPPC_REQUEST register.
Comment 38 Martin Cracauer 2026-01-27 16:18:42 UTC
Created attachment 267550 [details]
Results from last patch

Results from last patch:

1) debug output attached

2) hw.clockrate is now 1696 (up from 399)

3) benchmarked speed is still low, unchanged

4) dmesg:

hwpstate_amd0: <AMD Collaborative Processor Performance Control (CPPC)> on cpu0
hwpstate_amd0: 
CPU0: Initial MSR values after CPPC enable
CPPC_CAPABILITY_1: 0000000000000000
        Highest Performance: 000
        Guaranteed Performance: 000
        Efficient Performance: 000
        Lowest Performance: 000

CPPC_REQUEST: 0x0000000000fff0
        Efficiency / Energy Preference: 000
        Desired Performance: 000
        Minimum Performance: 255
        Maximum Performance: 240

cpufreq0: <CPU frequency control> on cpu0
hwpstate_amd1: 
CPU1: Initial MSR values after CPPC enable
CPPC_CAPABILITY_1: 0000000000000000
        Highest Performance: 000
        Guaranteed Performance: 000
        Efficient Performance: 000
        Lowest Performance: 000

CPPC_REQUEST: 0x0000000000fff0
        Efficiency / Energy Preference: 000
        Desired Performance: 000
        Minimum Performance: 255
        Maximum Performance: 240

cpufreq1: <CPU frequency control> on cpu1


[repeated for all CPUs]
Comment 39 Olivier Certner freebsd_committer freebsd_triage 2026-01-27 16:25:53 UTC
(In reply to Martin Cracauer from comment #38)

Not sure how it's possible that the benchmarked speed can be unchanged while the frequency is higher?  That seems weird.

Can you now try leaving the 'epp' knob at 0, and now have the 'min_perf' vary from 0 to 255 and see if that makes a difference?
Comment 40 Olivier Certner freebsd_committer freebsd_triage 2026-01-27 16:29:29 UTC
(In reply to Martin Cracauer from comment #38)

And, while here, could you also try swapping the 'min_perf' and 'max_perf' values (so having 'min_perf' at 255 always, and 'max_perf' set to various values between 0 and 255)?  I'd also like to confirm whether AMD's APM is right here (e.g., it has these two fields in the CPPC_REQUEST register swapped compared to Intel's).
Comment 41 Olivier Certner freebsd_committer freebsd_triage 2026-01-27 17:12:27 UTC
(In reply to Olivier Certner from comment #39)

Sorry, it's `desired_perf` that should be varied from 0 to 255.  You can additionally set `min_perf` to the same value as `desired_perf` (ideally, second raw of tests).

`desired_perf` is supposed to always be in the `min_perf`->`max_perf` range (inclusive).
Comment 42 Cy Schubert freebsd_committer freebsd_triage 2026-01-27 22:13:44 UTC
(In reply to Olivier Certner from comment #36)

I've applied the patch, enabled CPPC and disabled powerd. Reduxing max_perf to 90 reduces the frequency to approximately where I had it with powerd. Though it's running a little hotter, but I did stress the CPU more than a buildworld would have.

I notice that the CPU frequency stays in the 2000-2400 range with the patch enabled and max_perf set to 90 and min_perf set to 1. Occasionally dev.cpu.0.freq will drop to 1600. This suggests that the CPU's own frequency measurements and controls are more sensitive than powerd's are.
Comment 43 Cy Schubert freebsd_committer freebsd_triage 2026-01-27 22:24:50 UTC
Setting dev.hwpstate_amd.0.epp="255" helps reduce CPU frequency when it's idling.
Comment 44 Martin Cracauer 2026-01-29 20:28:13 UTC
(In reply to Olivier Certner from comment #41)

I varied min_perf and desired_perf, with epp=0.

min_perf at 255, 128 and 8 has no effect, slow performance.

Setting min_perf and desired_perf at the same time to 255 gives full performance. Same for min=0 desired=255.

hw.clockrate is always at 1696 during all these experiments.
Comment 45 Martin Cracauer 2026-01-29 20:31:35 UTC
Setting desired_perf to 128 leads to 1/2 of full performance, as I would expect.

I can't find my powermeter, otherwise I could give consumption information. Might find it later.
Comment 46 ShengYi Hung freebsd_committer freebsd_triage 2026-01-30 08:14:13 UTC
(In reply to Olivier Certner from comment #31)

AMD does not require but ACPI spec[1] does require:

If the platform supports CPPC, the _CPC object must exist under all processor objects. That is, OSPM is not expected to support mixed mode (CPPC & legacy PSS, _PCT, _PPC) operation.


And in AMD's APR document[2]:

AMD’s Collaborative Processor Performance Control (CPPC) feature is an implementation of the 
Collaborative Processor Performance Control standard, first introduced in the Advanced 
Configuration and Power Interface (ACPI) Specification Revision 5.0. CPPC provides a framework 
for managing the performance and power efficiency of SOCs in collaboration with Operating System 
Power Management (OSPM) software

[1]: https://uefi.org/specs/ACPI/6.5/08_Processor_Configuration_and_Control.html?highlight=cppc

[2]:
https://docs.amd.com/v/u/en-US/40332-PUB_4.08

I think this implies that _CPC must exisit is a pre-requirement of AMD CPPC.

I don't know any AMD engineer who can verify it, maybe the FreeBSD Foundation knows?
Comment 47 ShengYi Hung freebsd_committer freebsd_triage 2026-01-30 08:18:23 UTC
(In reply to ShengYi Hung from comment #46)

To be clear, what I mean is that you can still set the MSR to enable and tweak CPPC but the safe value (max, min performance) is not guaranteed by the manufacturer. I am not sure if we should enable CPPC in this case.
Comment 48 Olivier Certner freebsd_committer freebsd_triage 2026-01-30 10:10:04 UTC
(In reply to ShengYi Hung from comment #46)

> If the platform supports CPPC, the _CPC object must exist under all processor objects. That is, OSPM is not expected to support mixed mode (CPPC & legacy PSS, _PCT, _PPC) operation.

Yes, but I do not read it as the requirement we are discussing.

"Platform supports CPPC" to me seems likely to mean the ACPI platform, and that passage seems about saying that it is not possible for some processors (in the ACPI space) to have a `_CPC` object while others do not.

Also, "OSPM is not expected to support mixed mode" is not the same thing as the mix being forbidden, and they talk about a slightly different mix (using CPPC via `_CPC`, which we are not doing).  (I'll have to check if we can ensure "acpi_perf" is disabled when using CPPC; regardless of the presence of `_CPC`, "acpi_perf" could be enabled, which we may not want.)

I guess what happened is that AMD started to include CPPC in its processors, as it was a prerequisite, but board/firmware manufacturers understandably lagged.


(In reply to ShengYi Hung from comment #47)

After all, AMD's CPPC was implemented in order to allow support of ACPI's CPPC, so given the ACPI spec says we can have 0 as a minimum performance value and all 1s as the maximum one, I'm pretty sure these must be supported by AMD (and Intel) as well, and are thus safe.  The (admittedly very limited) experience we have so far with Martin seems to confirm that.


Having an AMD engineer confirm all that would be a plus.
Comment 49 Olivier Certner freebsd_committer freebsd_triage 2026-01-30 10:14:24 UTC
Created attachment 267614 [details]
More polished patch

Only visible change with this patch (on no errors) should be that the initial content of some CPPC registers is not dumped in dmesg when attaching (but that can be toggled on via the 'debug.hwpstate_verbose' sysctl knob).

It would be great if you could test it to confirm it works as the previous one.

Will comment on Cy's and Martin's feedbacks later, as I'm about to travel.
Comment 50 Martin Cracauer 2026-01-30 15:57:55 UTC
(In reply to Olivier Certner from comment #49)

Yes, it works like the previous one.

The CPU is slow by default but the desired setting can bring it to full speed.
Comment 51 Martin Cracauer 2026-01-30 22:05:47 UTC
(In reply to Martin Cracauer from comment #50)

Spoke too soon. While the host is back to default speed with desired=255 a VM in bhyve is not. It took 6 hours for a `make buildworld buildkernel` when it should have been 2 in the VM.
Comment 52 Martin Cracauer 2026-01-30 23:55:43 UTC
(In reply to Martin Cracauer from comment #51)

ZHm. My single-core benchmark inside bhyve is normal speed.

The make -j 16 world took 6 hours, though.

Is it possible that number of loaded cores plays a roll here?
Comment 53 Olivier Certner freebsd_committer freebsd_triage 2026-01-31 10:29:06 UTC
(In reply to Martin Cracauer from comment #50)

> Yes, it works like the previous one.

Thank you.

> The CPU is slow by default but the desired setting can bring it to full speed.

I have been wanting to bring the topic of the default settings on the table, now that it seems that you (Cy and you) have found settings that suit your scenarios (but perhaps not completely according to comments #51 and #52).

Currently, we are just setting EPP to the medium value of 128 ("balanced hint"), as Intel's hardware does by default, and desired performance to 0 (autonomous mode) as hwpstate_intel is doing.

But we may want to be more aggressive towards performance, instead letting the users tune for efficiency and lower power consumption?  That's the default strategy for, I think, Speedstep, Powernow and modern AMD P-states (but not for Intel HWP, as just explained).  With ACPI, we could obtain the machine profile (desktop, laptop) and perhaps have different defaults depending on it.

It seems you get bad performance also when setting just EPP to 0, but I'm unsure what you benchmarked exactly.  The report in comment #38 was made with EPP set to 0, or just the stock driver value (128)?  Also, you said there that you observed a higher frequency, but didn't find a performance difference, which is very weird; in the meantime, did you re-run these experiments, to be sure there's actually no difference?

(In reply to Martin Cracauer from comment #52)

To get the absolutely maximum performance at all times, the settings would be:
- EPP: 0
- Desired perf: 255
- Min perf: 255
- Max perf: 255

> Is it possible that number of loaded cores plays a roll here?

A build has frequent small pauses for I/O, so it could be that the CPUs temporarily reduce their frequency on no load, increasing the latency of resume to load.

You said in comment #44 than having min perf to 0 didn't seem to make a difference, but for your latest VM benchmark, please make sure you also set min perf to 255 and check if it makes a difference there.
Comment 54 Martin Cracauer 2026-01-31 19:45:22 UTC
(In reply to Olivier Certner from comment #53)

In no particular order:

1) hw.clockrate is 1696 since your first patch.  Regardless if whether the performance of my quick benchmark is slow or normal

2) my quick benchmark is a single core compiler run (the SBCL Lisp compiler). If should not be structurally different from a gcc or clang run

3) I dunno what is up with the `make -j 16 world` inside the bhyve VM. I need to go backwards to see under which conditions I got 2 hours. No fiddling with the sysctls here improved the situation, in fact I am now up to 7 from 6 hours since I set min_perf to 255

4) my `make world` shouldn't have too much disk wait. CPU time is reported at near 1600%. The machine has 48 GB RAM and a fast, modern SSD (WD sn850x).

7:39:08 27548.94 real 429597.96 user 6419.11 sys 1582% CPU 111554/527182387 faults


I can offer again an account on this machine so that you can have a look around if you like. That's what the thing is for.
Comment 55 Martin Cracauer 2026-01-31 23:45:47 UTC
We should disregard my notes about the 6-hour make world. It happens with a FreeBSD-15 kernel, too. I now have a better multiprocesscore benchmark that properly gets faster and slower with my other (single-core) benchmark.
Comment 56 Olivier Certner freebsd_committer freebsd_triage 2026-02-03 16:38:11 UTC
(In reply to Martin Cracauer from comment #11)

May we arrange some spare laptop access?  If yes, you can mail me the details at olce@.  I'd like to confirm some things.
Comment 57 commit-hook freebsd_committer freebsd_triage 2026-02-11 20:44:39 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=7689e68506a900de4ba79924d781f092bb9d0335

commit 7689e68506a900de4ba79924d781f092bb9d0335
Author:     Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2026-01-27 12:39:40 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2026-02-11 20:43:21 +0000

    hwpstate_amd(4): Add knobs to get/set all fields of CPPC_REQUEST

    This will allow experimentations and finer-grained tuning to the full
    extent allowed by the hardware, which is especially important given that
    the spec leaves to hardware implementors an important leeway in
    interpreting CPPC's numeric parameters, causing the same settings to
    have different effects on different CPU models.

    PR:             292615
    Reviewed by:    aokblast (older version)
    Relnotes:       yes
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D55010

 sys/x86/cpufreq/hwpstate_amd.c | 54 ++++++++++++++++++++++++++++++++----------
 1 file changed, 42 insertions(+), 12 deletions(-)
Comment 58 commit-hook freebsd_committer freebsd_triage 2026-02-11 20:44:42 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=8aac1e9b028e5bd2e249023687effd98739358a6

commit 8aac1e9b028e5bd2e249023687effd98739358a6
Author:     Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2026-01-29 16:23:54 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2026-02-11 20:42:15 +0000

    hwpstate_amd(4): Register dump: Fine-grained error reporting

    If some of the registers cannot be read, report that but continue trying
    reading the others.  This also has the side benefit of simplifying code.

    While here, use sbuf_new_for_sysctl(), and rename 'res' and 'ret', which
    are to contain error values, to 'error'.

    While here, remove the test on getting the per-cpu structure, as if it
    is not present we would have already crashed on device attach.

    While here, fix format for printing the CPU ID.

    PR:             292615
    Reviewed by:    aokblast (older version)
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D55005

 sys/x86/cpufreq/hwpstate_amd.c | 112 ++++++++++++++++++++++++++---------------
 1 file changed, 72 insertions(+), 40 deletions(-)
Comment 59 commit-hook freebsd_committer freebsd_triage 2026-02-11 20:44:43 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=951788e3733e415ca4721c0a63454937dcb29b2c

commit 951788e3733e415ca4721c0a63454937dcb29b2c
Author:     Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2026-01-27 11:44:29 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2026-02-11 20:43:21 +0000

    hwpstate_amd(4): 'epp' sysctl leaf to operate on real EPP hardware values

    We were using percents, for compatibility with hwpstate_intel(4), but
    this looses granularity that might be important in some scenarios or
    with specific CPU models.

    For consistency, hwpstate_intel(4) should be changed accordingly, at the
    expense of breaking compatibility.

    For release notes: Introduction of hwpstate_amd(4) deserves a release
    note, even if the original commit was not tagged.  Functionality
    introduced by recent commits tagged with "Relnotes" should be mentioned
    along that one.

    PR:             292615
    Reviewed by:    aokblast
    Relnotes:       yes
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D55009

 sys/x86/cpufreq/hwpstate_amd.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)
Comment 60 commit-hook freebsd_committer freebsd_triage 2026-02-11 20:44:45 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=bd58239d3653dab7cd3999cad222f695a49a7e3b

commit bd58239d3653dab7cd3999cad222f695a49a7e3b
Author:     Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2026-01-29 17:37:20 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2026-02-11 20:43:20 +0000

    hwpstate_amd(4): attach(): More diagnostic on CPPC enable

    When the 'debug.hwpstate_verbose' tunable/sysctl knob is set, dump the
    initial content of the CPPC_CAPABILITY_1 and CPPC_REQUEST registers.

    If, after enabling CPPC, reading/writing some MSR fails during the attach
    sequence, print a diagnostic.  However, once CPPC is enabled, we cannot
    go back (disabling it is impossible), so we'll attach even if fiddling
    with other MSRs failed.

    While here, move diagnostic printing on attach out of the callback that
    is executed on (potentially) another CPU and with interrupts disabled,
    putting it into the attach routine itself.

    While here, fix format for printing the CPU ID.

    PR:             292615
    Reviewed by:    aokblast (older version)
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D55006

 sys/x86/cpufreq/hwpstate_amd.c | 133 ++++++++++++++++++++++++++---------------
 1 file changed, 84 insertions(+), 49 deletions(-)
Comment 61 commit-hook freebsd_committer freebsd_triage 2026-02-11 20:44:46 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=df7b4dcdb8ff32a735916b50a473424b543c1e5e

commit df7b4dcdb8ff32a735916b50a473424b543c1e5e
Author:     Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2026-01-29 21:14:48 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2026-02-11 20:43:20 +0000

    hwpstate_amd(4): Sane defaults for min/max perf on insane capabilities

    If the CPPC_CAPABILITY_1 register stays at its reset value (0) even
    after enabling CPPC, as observed in the field (see the referenced PR
    below), use sane min/max performance limits as hinted by the ACPI spec,
    i.e., all 0s for the minimum value and all 1s for the maximum one.

    While here, let's cope upfront with some more insane situations, where
    the minimum value would be greater than the maximum one, but also if
    they would be equal which does not seem to make sense at all in the CPPC
    frame (and, anyway, in this case, the actual minimum and maximum values
    we program should have no effect at all).  That last case actually also
    covers the one exposed in the previous paragraph.

    PR:             292615
    Reviewed by:    aokblast
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D55007

 sys/x86/cpufreq/hwpstate_amd.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)
Comment 62 Olivier Certner freebsd_committer freebsd_triage 2026-02-20 10:35:52 UTC
Forgot to tag commit https://cgit.freebsd.org/src/commit/?id=80d32a6b1d73e0c8 with this bug.

So, for now, we have chosen to set maximum performance by default on CPPC enable so as to minimize regression cases, as this is what all cpufreq(4) drivers currently do (to the notable exception of hwpstate_intel(4), which we plan to change).  We might revise this policy later.

The only remaining "regression" is that people have to opt-out of CPPC to use powerd(8) as the latter is not compatible with it.  But we encourage people using powerd(8) to try first CPPC and explore its tuning, as we hope it will give better results and control in common use cases (a view which cracauer@'s and cy@'s experiences reported in this bug seem to support; and we have similar experience on the Intel side with hwpstate_intel(4), although that's only remotely relevant).

We have plans to make powerd(8) compatible with CPPC, but it's unclear who (ShengYi? myself?) will do the work and in which time frame it will materialize.