Page MenuHomeFreeBSD

hwpstate: add CPPC support for pstate driver on AMD
AcceptedPublic

Authored by aokblast on Mar 31 2025, 10:04 AM.
Tags
None
Referenced Files
F122081696: D49587.id156851.diff
Wed, Jul 2, 2:47 AM
F122074443: D49587.id156850.diff
Wed, Jul 2, 1:17 AM
F122026370: D49587.id155939.diff
Tue, Jul 1, 1:56 PM
F122023872: D49587.id152964.diff
Tue, Jul 1, 1:25 PM
Unknown Object (File)
Tue, Jul 1, 12:54 AM
Unknown Object (File)
Mon, Jun 30, 3:02 PM
Unknown Object (File)
Mon, Jun 30, 9:46 AM
Unknown Object (File)
Sun, Jun 29, 3:01 PM
Subscribers

Details

Reviewers
cem
markj
olce
khng
Summary

hwpstate: add CPPC support for pstate driver on AMD

Implement CPPC interface for AMD Pstate Driver.
This feature is only enabled when the CPUID shows it support CPPC.

The CPPC is implemneted by the following steps:

  1. Write MSR to enable it.
  2. Read capability registert which indicates binary value of levels

about lowest, best energy efficient, guarantee, and max performance.

  1. Write request register with epp in energy balanced mode. And let

CPU and firmware to enter autonomous mode.

Also, create a sysctl to allow userspace to change epp value

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 64695
Build 61579: arc lint + arc unit

Event Timeline

use wildcard to generate correct number of devices

  • atkbd: fix first keystroke force reset

Reset to the correct version

Use balanced mode as the default epp

In general, please include some summary of the code changes in the review description. This makes reviewing easier: I can quickly understand what the change is supposed to do, and then I can compare the code changes with your description to look for discrepancies.

sys/x86/cpufreq/hwpstate_amd.c
235

The sysctl_handle_int() call doesn't need to be inside the sched_bind() section, it should be moved earlier.

406
622
680–689

There should be an extra newline after local variable declarations.

sys/x86/x86/identcpu.c
1694

The AND is redundant. Is there a typo here?

move set_autonomous mode into attach

This revision is now accepted and ready to land.Thu, Jun 12, 10:42 PM

I'd like the opportunity to review this (next week).

I'd like the opportunity to review this (next week).

Of course. Not hurry. I just want to make more people engage in:).

Added a bunch of inline comments. Most important things:

  • Support for PSTATE_CPPC_PKG_CTRL (in software, because contrary to Intel, there is no per-package MSR).
  • In sysctl_epp_select(), one of the guard tests seems wrong.

There are a few places I didn't review in depth, I may return to them beginning of next week.

sys/x86/cpufreq/hwpstate_amd.c
104–108

Could you rename the AMD_CPPC_ prefix to AMD_CPPC_CAPS_1_, just to make it apparent that these are applicable (only) to the CAPS 1 MSR?

109–112

Same here please, AMD_CPPC_ => AMD_CPPC_REQUEST_.

237–243

You're basically open-coding some AMD_CPPC_ macros (those to prefix with AMD_CPPC_CAPS_1_) here. Please use the macros instead.

246–248

That second read actually reads the same MSR. I think you should completely remove data2 and use data instead. This distinction made sense in the Intel case as there is a specific MSR targeted at the package (MSR_IA32_HWP_REQUEST_PKG) but there's no such thing in AMD processors.

Even if there is no specific hardware support for package control on AMD processors, I think that providing this functionality to users is beneficial, in that it simplifies a lot the configuration of the "baseline" case where all cores are set to the same value.

296

You probably meant PSTATE_CPPC here, as bailing out in the case of PSTATE_CPPC_PKG_CTRL does not seem to make sense.

302–306

This is in the wrong place. It must be moved between the lines val = ((r >> 24) & 0xFFULL) * 100 / 0xff; and if (val > 100) {.

314

It would be better to use AMD_CPPC_REQUEST_ENERGY_PERF_BITS here, even if that's more verbose. With it, we immediately know that the code is correct without having to check if the shift and mask are correct.

If you find that too verbose, factor out the formula into a macro.

314–315

Missing input/output at this point (see previous comment).

316–329

Generally, support for PSTATE_CPPC_PKG_CTRL is missing (as said above, I think this functionality is

We may want to mimick what happens in the Intel counterpart, which means that setting the knob for one core should affect all the other cores. If so, basically, when PSTATE_CPPC_PKG_CTRL is set, we have to loop over all CPUs for the setting part.

322–323

Same as above, it would be preferable to use a macro based only on AMD_CPPC_REQUEST_ENERGY_PERF_BITS and avoid the hardcoded 24.

394

Aren't we supposed to use MSR C001_0280 ("Performance Time Stamp Counter (CU_PTSC)") here? Or are we sure the regular TSC is just invariant if PSTATE_CPPC_PWR_CALC is set?

But maybe that's not worth bothering, as it appears most AMD processors do not support PSTATE_CPPC_PWR_CALC (i.e., only some of family 16h do, skimming various PPR manuals).

572–579

Similarly as above, I'd prefer macros here on the right-hand side of |=, and no hardcoded shifts (and proper mask applied to the new value, just in case, even though you aptly chose uint8_t as the type for the cppc_settings fields).

673–674

Since you (rightly) added an occurrence of a call to device_set_desc() earlier, you can remove this one (redundant).