* [PATCH v2 0/9] amd-pstate: Introduce AMD CPPC Performance Priority
@ 2026-03-11 14:01 Gautham R. Shenoy
2026-03-11 14:01 ` [PATCH v2 1/9] amd-pstate: Fix memory leak in amd_pstate_epp_cpu_init() Gautham R. Shenoy
` (8 more replies)
0 siblings, 9 replies; 18+ messages in thread
From: Gautham R. Shenoy @ 2026-03-11 14:01 UTC (permalink / raw)
To: Mario Limonciello, Rafael J . Wysocki, Viresh Kumar,
K Prateek Nayak
Cc: linux-kernel, linux-pm, Gautham R. Shenoy
Hello,
This is the v2 of the patchset to add support to the amd-pstate driver
for a new feature named "CPPC Performance Priority" that will be
available on some of the future AMD processors.
Details of the feature can be found in the AMD Publication titled
"AMD64 Collaborative Processor Performance Control (CPPC) Performance
Priority" (https://docs.amd.com/v/u/en-US/69206_1.10_AMD64_CPPC_PUB)
v1 --> v2 Changes:
* Picked up the Reviewed-by: tags from Boris and Mario for a couple of patches.
* Defined AMD_CPPC_FLOOR_PERF_CNT_MASK via GENMASK_ULL() instead of
GENMASK() to fix the build errors reported by the kernel test robot
(https://lore.kernel.org/lkml/202603070431.ykswVnpp-lkp@intel.com/)
* Moved the code from amd_pstate_cache_cppc_req2() into
amd_pstate_init_floor_perf() since there are no other callers of
amd_pstate_cache_cppc_req2().
* Cached the user requested amd_pstate_floor_freq into
cpudata->floor_freq [Prateek] and return the same when the user
reads the syfs file.
Description:
This feature allows userspace to specify different floor performance
levels for different CPUs. The platform firmware takes these different
floor performance levels into consideration while throttling the CPUs
under power/thermal constraints.
The presence of this feature is advertised through bit 16 of EDX
register for CPUID leaf 0x80000007. The number of distinct floor
performance levels supported on the platform will be advertised
through the bits 32:39 of the MSR_AMD_CPPC_CAP1. Bits 0:7 of a new MSR
MSR_AMD_CPPC_REQ2 (0xc00102b5) will be used to specify the desired
floor performance level for that CPU.
Key changes made by this patchset:
* Fix a memory leak bug and a control-flow bug.
* Plumb in proper visibility controls for the freq_attr attributes
so that only relevant attributes can be made visible depending on
the underlying platform and the current amd-pstate driver mode.
* Add support for the new CPUID bits, the new MSR and parsing bits
32:39 of MSR_AMD_CPPC_CAP1.
* Set the default value for MSR_AMD_CPPC_REQ2[0:7] (Floor perf) to
CPPC.nominal_perf when the value at boot-time is lower than
CPPC.lowest_perf
* Add sysfs support for floor_freq and floor_count
* Introduce a tracepoint trace_amd_pstate_cppc_req2 for tracking
the updates to MSR_AMD_CPPC_REQ2.
* Add documentation for amd_pstate_floor_{freq,count}
Gautham R. Shenoy (9):
amd-pstate: Fix memory leak in amd_pstate_epp_cpu_init()
amd-pstate: Update cppc_req_cached in fast_switch case
amd-pstate: Make certain freq_attrs conditionally visible
x86/cpufeatures: Add AMD CPPC Performance Priority feature.
amd-pstate: Add support for CPPC_REQ2 and FLOOR_PERF
amd-pstate: Add sysfs support for floor_freq and floor_count
amd-pstate: Introduce a tracepoint trace_amd_pstate_cppc_req2()
Documentation/amd-pstate: List prefcore related sysfs files
Documentation/amd-pstate: Add documentation for amd_pstate_floor_{freq,count}
Documentation/admin-guide/pm/amd-pstate.rst | 47 +++-
arch/x86/include/asm/cpufeatures.h | 2 +-
arch/x86/include/asm/msr-index.h | 5 +
arch/x86/kernel/cpu/scattered.c | 1 +
drivers/cpufreq/amd-pstate-trace.h | 35 +++
drivers/cpufreq/amd-pstate.c | 254 +++++++++++++++++---
drivers/cpufreq/amd-pstate.h | 7 +
tools/arch/x86/include/asm/cpufeatures.h | 2 +-
8 files changed, 313 insertions(+), 40 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v2 1/9] amd-pstate: Fix memory leak in amd_pstate_epp_cpu_init()
2026-03-11 14:01 [PATCH v2 0/9] amd-pstate: Introduce AMD CPPC Performance Priority Gautham R. Shenoy
@ 2026-03-11 14:01 ` Gautham R. Shenoy
2026-03-11 14:01 ` [PATCH v2 2/9] amd-pstate: Update cppc_req_cached in fast_switch case Gautham R. Shenoy
` (7 subsequent siblings)
8 siblings, 0 replies; 18+ messages in thread
From: Gautham R. Shenoy @ 2026-03-11 14:01 UTC (permalink / raw)
To: Mario Limonciello, Rafael J . Wysocki, Viresh Kumar,
K Prateek Nayak
Cc: linux-kernel, linux-pm, Gautham R. Shenoy, Mario Limonciello
On failure to set the epp, the function amd_pstate_epp_cpu_init()
returns with an error code without freeing the cpudata object that was
allocated at the beginning of the function.
Ensure that the cpudata object is freed before returning from the
function.
This memory leak was discovered by Claude Opus 4.6 with the aid of
Chris Mason's AI review-prompts
(https://github.com/masoncl/review-prompts/tree/main/kernel).
Assisted-by: Claude:claude-opus-4.6 review-prompts/linux
Fixes: f9a378ff6443 ("cpufreq/amd-pstate: Set different default EPP policy for Epyc and Ryzen")
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
---
drivers/cpufreq/amd-pstate.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 5aa9fcd80cf51..d57969c72c9dc 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -1533,7 +1533,7 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
ret = amd_pstate_set_epp(policy, cpudata->epp_default);
if (ret)
- return ret;
+ goto free_cpudata1;
current_pstate_driver->adjust_perf = NULL;
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v2 2/9] amd-pstate: Update cppc_req_cached in fast_switch case
2026-03-11 14:01 [PATCH v2 0/9] amd-pstate: Introduce AMD CPPC Performance Priority Gautham R. Shenoy
2026-03-11 14:01 ` [PATCH v2 1/9] amd-pstate: Fix memory leak in amd_pstate_epp_cpu_init() Gautham R. Shenoy
@ 2026-03-11 14:01 ` Gautham R. Shenoy
2026-03-12 20:41 ` Mario Limonciello (AMD) (kernel.org)
2026-03-11 14:01 ` [PATCH v2 3/9] amd-pstate: Make certain freq_attrs conditionally visible Gautham R. Shenoy
` (6 subsequent siblings)
8 siblings, 1 reply; 18+ messages in thread
From: Gautham R. Shenoy @ 2026-03-11 14:01 UTC (permalink / raw)
To: Mario Limonciello, Rafael J . Wysocki, Viresh Kumar,
K Prateek Nayak
Cc: linux-kernel, linux-pm, Gautham R. Shenoy
The function msr_update_perf() does not cache the new value that is
written to MSR_AMD_CPPC_REQ into the variable cpudata->cppc_req_cached
when the update is happening from the fast path.
Fix that by caching the value everytime the MSR_AMD_CPPC_REQ gets
updated.
This issue was discovered by Claude Opus 4.6 with the aid of Chris
Mason's AI review-prompts
(https://github.com/masoncl/review-prompts/tree/main/kernel).
Assisted-by: Claude:claude-opus-4.6 review-prompts/linux
Fixes: fff395796917 ("cpufreq/amd-pstate: Always write EPP value when updating perf")
Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
---
drivers/cpufreq/amd-pstate.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index d57969c72c9dc..24cdeffbcd40e 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -261,7 +261,6 @@ static int msr_update_perf(struct cpufreq_policy *policy, u8 min_perf,
if (fast_switch) {
wrmsrq(MSR_AMD_CPPC_REQ, value);
- return 0;
} else {
int ret = wrmsrq_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value);
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v2 3/9] amd-pstate: Make certain freq_attrs conditionally visible
2026-03-11 14:01 [PATCH v2 0/9] amd-pstate: Introduce AMD CPPC Performance Priority Gautham R. Shenoy
2026-03-11 14:01 ` [PATCH v2 1/9] amd-pstate: Fix memory leak in amd_pstate_epp_cpu_init() Gautham R. Shenoy
2026-03-11 14:01 ` [PATCH v2 2/9] amd-pstate: Update cppc_req_cached in fast_switch case Gautham R. Shenoy
@ 2026-03-11 14:01 ` Gautham R. Shenoy
2026-03-12 6:49 ` Gautham R. Shenoy
2026-03-12 20:46 ` Mario Limonciello (AMD) (kernel.org)
2026-03-11 14:01 ` [PATCH v2 4/9] x86/cpufeatures: Add AMD CPPC Performance Priority feature Gautham R. Shenoy
` (5 subsequent siblings)
8 siblings, 2 replies; 18+ messages in thread
From: Gautham R. Shenoy @ 2026-03-11 14:01 UTC (permalink / raw)
To: Mario Limonciello, Rafael J . Wysocki, Viresh Kumar,
K Prateek Nayak
Cc: linux-kernel, linux-pm, Gautham R. Shenoy
Certain amd_pstate freq_attrs such as amd_pstate_hw_prefcore and
amd_pstate_prefcore_ranking are enabled even when preferred core is
not supported on the platform.
Similarly there are common freq_attrs between the amd-pstate and the
amd-pstate-epp drivers (eg: amd_pstate_max_freq,
amd_pstate_lowest_non_linear_freq, etc.) but are duplicated in two
different freq_attr structs.
Unify all the attributes in a single place and associate each of them
with a visibility function that determines whether the attribute
should be visible based on the underlying platform support and the
current amd_pstate mode.
Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
---
drivers/cpufreq/amd-pstate.c | 123 ++++++++++++++++++++++++++---------
1 file changed, 92 insertions(+), 31 deletions(-)
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 24cdeffbcd40e..fb5d7bb320c15 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -1220,12 +1220,86 @@ static ssize_t show_energy_performance_preference(
return sysfs_emit(buf, "%s\n", energy_perf_strings[preference]);
}
+cpufreq_freq_attr_ro(amd_pstate_max_freq);
+cpufreq_freq_attr_ro(amd_pstate_lowest_nonlinear_freq);
+
+cpufreq_freq_attr_ro(amd_pstate_highest_perf);
+cpufreq_freq_attr_ro(amd_pstate_prefcore_ranking);
+cpufreq_freq_attr_ro(amd_pstate_hw_prefcore);
+cpufreq_freq_attr_rw(energy_performance_preference);
+cpufreq_freq_attr_ro(energy_performance_available_preferences);
+
+struct freq_attr_visibility {
+ struct freq_attr *attr;
+ bool (*visibility_fn)(void);
+};
+
+/* For attributes which are always visible */
+static bool always_visible(void)
+{
+ return true;
+}
+
+/* Determines whether prefcore related attributes should be visible */
+static bool prefcore_visibility(void)
+{
+ return amd_pstate_prefcore;
+}
+
+/* Determines whether energy performance preference should be visible */
+static bool epp_visibility(void)
+{
+ return cppc_state == AMD_PSTATE_ACTIVE;
+}
+
+static struct freq_attr_visibility amd_pstate_attr_visibility[] = {
+ {&amd_pstate_max_freq, always_visible},
+ {&amd_pstate_lowest_nonlinear_freq, always_visible},
+ {&amd_pstate_highest_perf, always_visible},
+ {&amd_pstate_prefcore_ranking, prefcore_visibility},
+ {&amd_pstate_hw_prefcore, prefcore_visibility},
+ {&energy_performance_preference, epp_visibility},
+ {&energy_performance_available_preferences, epp_visibility},
+};
+
+static struct freq_attr **get_freq_attrs(void)
+{
+ bool attr_visible[ARRAY_SIZE(amd_pstate_attr_visibility)];
+ struct freq_attr **attrs;
+ int i, j, count;
+
+ for (i = 0, count = 0; i < ARRAY_SIZE(amd_pstate_attr_visibility); i++) {
+ struct freq_attr_visibility *v = &amd_pstate_attr_visibility[i];
+
+ attr_visible[i] = v->visibility_fn();
+ if (attr_visible[i])
+ count++;
+ }
+
+ /* amd_pstate_{max_freq, lowest_nonlinear_freq, highest_freq} should always be visible */
+ BUG_ON(!count);
+
+ attrs = kcalloc(count + 1, sizeof(struct freq_attr *), GFP_KERNEL);
+ if (!attrs)
+ return ERR_PTR(-ENOMEM);
+
+ for (i = 0, j = 0; i < ARRAY_SIZE(amd_pstate_attr_visibility); i++) {
+ if (!attr_visible[i])
+ continue;
+
+ attrs[j++] = amd_pstate_attr_visibility[i].attr;
+ }
+
+ return attrs;
+}
+
static void amd_pstate_driver_cleanup(void)
{
if (amd_pstate_prefcore)
sched_clear_itmt_support();
cppc_state = AMD_PSTATE_DISABLE;
+ kfree(current_pstate_driver->attr);
current_pstate_driver = NULL;
}
@@ -1250,6 +1324,7 @@ static int amd_pstate_set_driver(int mode_idx)
static int amd_pstate_register_driver(int mode)
{
+ struct freq_attr **attr = NULL;
int ret;
ret = amd_pstate_set_driver(mode);
@@ -1258,6 +1333,22 @@ static int amd_pstate_register_driver(int mode)
cppc_state = mode;
+ /*
+ * Note: It is important to compute the attrs _after_
+ * re-initializing the cppc_state. Some attributes become
+ * visible only when cppc_state is AMD_PSTATE_ACTIVE.
+ */
+ attr = get_freq_attrs();
+ if (IS_ERR(attr)) {
+ ret = (int) PTR_ERR(attr);
+ pr_err("Couldn't compute freq_attrs for current mode %s [%d]\n",
+ amd_pstate_get_mode_string(cppc_state), ret);
+ amd_pstate_driver_cleanup();
+ return ret;
+ }
+
+ current_pstate_driver->attr = attr;
+
/* at least one CPU supports CPB */
current_pstate_driver->boost_enabled = cpu_feature_enabled(X86_FEATURE_CPB);
@@ -1399,37 +1490,9 @@ static ssize_t prefcore_show(struct device *dev,
return sysfs_emit(buf, "%s\n", str_enabled_disabled(amd_pstate_prefcore));
}
-cpufreq_freq_attr_ro(amd_pstate_max_freq);
-cpufreq_freq_attr_ro(amd_pstate_lowest_nonlinear_freq);
-
-cpufreq_freq_attr_ro(amd_pstate_highest_perf);
-cpufreq_freq_attr_ro(amd_pstate_prefcore_ranking);
-cpufreq_freq_attr_ro(amd_pstate_hw_prefcore);
-cpufreq_freq_attr_rw(energy_performance_preference);
-cpufreq_freq_attr_ro(energy_performance_available_preferences);
static DEVICE_ATTR_RW(status);
static DEVICE_ATTR_RO(prefcore);
-static struct freq_attr *amd_pstate_attr[] = {
- &amd_pstate_max_freq,
- &amd_pstate_lowest_nonlinear_freq,
- &amd_pstate_highest_perf,
- &amd_pstate_prefcore_ranking,
- &amd_pstate_hw_prefcore,
- NULL,
-};
-
-static struct freq_attr *amd_pstate_epp_attr[] = {
- &amd_pstate_max_freq,
- &amd_pstate_lowest_nonlinear_freq,
- &amd_pstate_highest_perf,
- &amd_pstate_prefcore_ranking,
- &amd_pstate_hw_prefcore,
- &energy_performance_preference,
- &energy_performance_available_preferences,
- NULL,
-};
-
static struct attribute *pstate_global_attributes[] = {
&dev_attr_status.attr,
&dev_attr_prefcore.attr,
@@ -1696,7 +1759,6 @@ static struct cpufreq_driver amd_pstate_driver = {
.set_boost = amd_pstate_set_boost,
.update_limits = amd_pstate_update_limits,
.name = "amd-pstate",
- .attr = amd_pstate_attr,
};
static struct cpufreq_driver amd_pstate_epp_driver = {
@@ -1712,7 +1774,6 @@ static struct cpufreq_driver amd_pstate_epp_driver = {
.update_limits = amd_pstate_update_limits,
.set_boost = amd_pstate_set_boost,
.name = "amd-pstate-epp",
- .attr = amd_pstate_epp_attr,
};
/*
@@ -1858,7 +1919,7 @@ static int __init amd_pstate_init(void)
return ret;
global_attr_free:
- cpufreq_unregister_driver(current_pstate_driver);
+ amd_pstate_unregister_driver(0);
return ret;
}
device_initcall(amd_pstate_init);
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v2 4/9] x86/cpufeatures: Add AMD CPPC Performance Priority feature
2026-03-11 14:01 [PATCH v2 0/9] amd-pstate: Introduce AMD CPPC Performance Priority Gautham R. Shenoy
` (2 preceding siblings ...)
2026-03-11 14:01 ` [PATCH v2 3/9] amd-pstate: Make certain freq_attrs conditionally visible Gautham R. Shenoy
@ 2026-03-11 14:01 ` Gautham R. Shenoy
2026-03-11 14:01 ` [PATCH v2 5/9] amd-pstate: Add support for CPPC_REQ2 and FLOOR_PERF Gautham R. Shenoy
` (4 subsequent siblings)
8 siblings, 0 replies; 18+ messages in thread
From: Gautham R. Shenoy @ 2026-03-11 14:01 UTC (permalink / raw)
To: Mario Limonciello, Rafael J . Wysocki, Viresh Kumar,
K Prateek Nayak
Cc: linux-kernel, linux-pm, Gautham R. Shenoy, H. Peter Anvin,
Borislav Petkov, Dave Hansen, Thomas Gleixner, Ingo Molnar, x86
Some future AMD processors have feature named "CPPC Performance
Priority" which lets userspace specify different floor performance
levels for different CPUs. The platform firmware takes these different
floor performance levels into consideration while throttling the CPUs
under power/thermal constraints. The presence of this feature is
indicated by bit 16 of the EDX register for CPUID leaf
0x80000007. More details can be found in AMD Publication titled "AMD64
Collaborative Processor Performance Control (CPPC) Performance
Priority" Revision 1.10.
Define a new feature bit named X86_FEATURE_CPPC_PERF_PRIO to map to
CPUID 0x80000007.EDX[16].
Reviewed-by: Borislav Petkov (AMD) <bp@alien8.de>
Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
---
Link to AMD publication describing this feature: https://docs.amd.com/v/u/en-US/69206_1.10_AMD64_CPPC_PUB
arch/x86/include/asm/cpufeatures.h | 2 +-
arch/x86/kernel/cpu/scattered.c | 1 +
tools/arch/x86/include/asm/cpufeatures.h | 2 +-
3 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
index dbe104df339b8..86d17b195e794 100644
--- a/arch/x86/include/asm/cpufeatures.h
+++ b/arch/x86/include/asm/cpufeatures.h
@@ -415,7 +415,7 @@
*/
#define X86_FEATURE_OVERFLOW_RECOV (17*32+ 0) /* "overflow_recov" MCA overflow recovery support */
#define X86_FEATURE_SUCCOR (17*32+ 1) /* "succor" Uncorrectable error containment and recovery */
-
+#define X86_FEATURE_CPPC_PERF_PRIO (17*32+ 2) /* CPPC Floor Perf support */
#define X86_FEATURE_SMCA (17*32+ 3) /* "smca" Scalable MCA */
/* Intel-defined CPU features, CPUID level 0x00000007:0 (EDX), word 18 */
diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c
index 42c7eac0c387b..837d6a4b0c282 100644
--- a/arch/x86/kernel/cpu/scattered.c
+++ b/arch/x86/kernel/cpu/scattered.c
@@ -52,6 +52,7 @@ static const struct cpuid_bit cpuid_bits[] = {
{ X86_FEATURE_CPB, CPUID_EDX, 9, 0x80000007, 0 },
{ X86_FEATURE_PROC_FEEDBACK, CPUID_EDX, 11, 0x80000007, 0 },
{ X86_FEATURE_AMD_FAST_CPPC, CPUID_EDX, 15, 0x80000007, 0 },
+ { X86_FEATURE_CPPC_PERF_PRIO, CPUID_EDX, 16, 0x80000007, 0 },
{ X86_FEATURE_MBA, CPUID_EBX, 6, 0x80000008, 0 },
{ X86_FEATURE_X2AVIC_EXT, CPUID_ECX, 6, 0x8000000a, 0 },
{ X86_FEATURE_COHERENCY_SFW_NO, CPUID_EBX, 31, 0x8000001f, 0 },
diff --git a/tools/arch/x86/include/asm/cpufeatures.h b/tools/arch/x86/include/asm/cpufeatures.h
index c3b53beb13007..1f1aeeb151337 100644
--- a/tools/arch/x86/include/asm/cpufeatures.h
+++ b/tools/arch/x86/include/asm/cpufeatures.h
@@ -414,7 +414,7 @@
*/
#define X86_FEATURE_OVERFLOW_RECOV (17*32+ 0) /* "overflow_recov" MCA overflow recovery support */
#define X86_FEATURE_SUCCOR (17*32+ 1) /* "succor" Uncorrectable error containment and recovery */
-
+#define X86_FEATURE_CPPC_PERF_PRIO (17*32+ 2) /* CPPC Floor Perf support */
#define X86_FEATURE_SMCA (17*32+ 3) /* "smca" Scalable MCA */
/* Intel-defined CPU features, CPUID level 0x00000007:0 (EDX), word 18 */
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v2 5/9] amd-pstate: Add support for CPPC_REQ2 and FLOOR_PERF
2026-03-11 14:01 [PATCH v2 0/9] amd-pstate: Introduce AMD CPPC Performance Priority Gautham R. Shenoy
` (3 preceding siblings ...)
2026-03-11 14:01 ` [PATCH v2 4/9] x86/cpufeatures: Add AMD CPPC Performance Priority feature Gautham R. Shenoy
@ 2026-03-11 14:01 ` Gautham R. Shenoy
2026-03-12 20:49 ` Mario Limonciello (AMD) (kernel.org)
2026-03-11 14:01 ` [PATCH v2 6/9] amd-pstate: Add sysfs support for floor_freq and floor_count Gautham R. Shenoy
` (3 subsequent siblings)
8 siblings, 1 reply; 18+ messages in thread
From: Gautham R. Shenoy @ 2026-03-11 14:01 UTC (permalink / raw)
To: Mario Limonciello, Rafael J . Wysocki, Viresh Kumar,
K Prateek Nayak
Cc: linux-kernel, linux-pm, Gautham R. Shenoy
Some future AMD processors have feature named "CPPC Performance
Priority" which lets userspace specify different floor performance
levels for different CPUs. The platform firmware takes these different
floor performance levels into consideration while throttling the CPUs
under power/thermal constraints. The presence of this feature is
indicated by bit 16 of the EDX register for CPUID leaf
0x80000007. More details can be found in AMD Publication titled "AMD64
Collaborative Processor Performance Control (CPPC) Performance
Priority" Revision 1.10.
The number of distinct floor performance levels supported on the
platform will be advertised through the bits 32:39 of the
MSR_AMD_CPPC_CAP1. Bits 0:7 of a new MSR MSR_AMD_CPPC_REQ2
(0xc00102b5) will be used to specify the desired floor performance
level for that CPU.
Add support for the aforementioned MSR_AMD_CPPC_REQ2, and macros for
parsing and updating the relevant bits from MSR_AMD_CPPC_CAP1 and
MSR_AMD_CPPC_REQ2.
On boot if the default value of the MSR_AMD_CPPC_REQ2[7:0] (Floor
Perf) is lower than CPPC.lowest_perf, and thus invalid, initialize it
to MSR_AMD_CPPC_CAP1.nominal_perf which is a sane default value.
Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
---
Link to AMD publication describing this feature: https://docs.amd.com/v/u/en-US/69206_1.10_AMD64_CPPC_PUB
arch/x86/include/asm/msr-index.h | 5 +++
drivers/cpufreq/amd-pstate.c | 70 ++++++++++++++++++++++++++++++++
drivers/cpufreq/amd-pstate.h | 5 +++
3 files changed, 80 insertions(+)
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index 6673601246b38..e126c7fb69cf6 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -765,12 +765,14 @@
#define MSR_AMD_CPPC_CAP2 0xc00102b2
#define MSR_AMD_CPPC_REQ 0xc00102b3
#define MSR_AMD_CPPC_STATUS 0xc00102b4
+#define MSR_AMD_CPPC_REQ2 0xc00102b5
/* Masks for use with MSR_AMD_CPPC_CAP1 */
#define AMD_CPPC_LOWEST_PERF_MASK GENMASK(7, 0)
#define AMD_CPPC_LOWNONLIN_PERF_MASK GENMASK(15, 8)
#define AMD_CPPC_NOMINAL_PERF_MASK GENMASK(23, 16)
#define AMD_CPPC_HIGHEST_PERF_MASK GENMASK(31, 24)
+#define AMD_CPPC_FLOOR_PERF_CNT_MASK GENMASK_ULL(39, 32)
/* Masks for use with MSR_AMD_CPPC_REQ */
#define AMD_CPPC_MAX_PERF_MASK GENMASK(7, 0)
@@ -778,6 +780,9 @@
#define AMD_CPPC_DES_PERF_MASK GENMASK(23, 16)
#define AMD_CPPC_EPP_PERF_MASK GENMASK(31, 24)
+/* Masks for use with MSR_AMD_CPPC_REQ2 */
+#define AMD_CPPC_FLOOR_PERF_MASK GENMASK(7, 0)
+
/* AMD Performance Counter Global Status and Control MSRs */
#define MSR_AMD64_PERF_CNTR_GLOBAL_STATUS 0xc0000300
#define MSR_AMD64_PERF_CNTR_GLOBAL_CTL 0xc0000301
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index fb5d7bb320c15..3122ad5af6f47 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -329,6 +329,63 @@ static inline int amd_pstate_set_epp(struct cpufreq_policy *policy, u8 epp)
return static_call(amd_pstate_set_epp)(policy, epp);
}
+static int amd_pstate_set_floor_perf(struct cpufreq_policy *policy, u8 perf)
+{
+ struct amd_cpudata *cpudata = policy->driver_data;
+ u64 value, prev;
+ int ret;
+
+ if (!cpu_feature_enabled(X86_FEATURE_CPPC_PERF_PRIO))
+ return 0;
+
+ value = prev = READ_ONCE(cpudata->cppc_req2_cached);
+ FIELD_MODIFY(AMD_CPPC_FLOOR_PERF_MASK, &value, perf);
+
+ if (value == prev)
+ return 0;
+
+ ret = wrmsrq_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ2, value);
+ if (ret) {
+ pr_err("failed to set CPPC REQ2 value. Error (%d)\n", ret);
+ return ret;
+ }
+
+ WRITE_ONCE(cpudata->cppc_req2_cached, value);
+
+ return ret;
+}
+
+static int amd_pstate_init_floor_perf(struct cpufreq_policy *policy)
+{
+ struct amd_cpudata *cpudata = policy->driver_data;
+ u8 floor_perf;
+ u64 value;
+ int ret;
+
+ if (!cpu_feature_enabled(X86_FEATURE_CPPC_PERF_PRIO))
+ return 0;
+
+ ret = rdmsrq_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ2, &value);
+ if (ret) {
+ pr_err("failed to read CPPC REQ2 value. Error (%d)\n", ret);
+ return ret;
+ }
+
+ WRITE_ONCE(cpudata->cppc_req2_cached, value);
+ floor_perf = FIELD_GET(AMD_CPPC_FLOOR_PERF_MASK,
+ cpudata->cppc_req2_cached);
+
+ /* Set a sane value for floor_perf if the default value is invalid */
+ if (floor_perf < cpudata->perf.lowest_perf) {
+ floor_perf = cpudata->perf.nominal_perf;
+ ret = amd_pstate_set_floor_perf(policy, floor_perf);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
static int shmem_set_epp(struct cpufreq_policy *policy, u8 epp)
{
struct amd_cpudata *cpudata = policy->driver_data;
@@ -426,6 +483,7 @@ static int msr_init_perf(struct amd_cpudata *cpudata)
perf.lowest_perf = FIELD_GET(AMD_CPPC_LOWEST_PERF_MASK, cap1);
WRITE_ONCE(cpudata->perf, perf);
WRITE_ONCE(cpudata->prefcore_ranking, FIELD_GET(AMD_CPPC_HIGHEST_PERF_MASK, cap1));
+ WRITE_ONCE(cpudata->floor_perf_cnt, FIELD_GET(AMD_CPPC_FLOOR_PERF_CNT_MASK, cap1));
return 0;
}
@@ -1036,6 +1094,12 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
if (cpu_feature_enabled(X86_FEATURE_CPPC))
policy->fast_switch_possible = true;
+ ret = amd_pstate_init_floor_perf(policy);
+ if (ret) {
+ dev_err(dev, "Failed to initialize Floor Perf (%d)\n", ret);
+ goto free_cpudata1;
+ }
+
ret = freq_qos_add_request(&policy->constraints, &cpudata->req[0],
FREQ_QOS_MIN, FREQ_QOS_MIN_DEFAULT_VALUE);
if (ret < 0) {
@@ -1597,6 +1661,12 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
if (ret)
goto free_cpudata1;
+ ret = amd_pstate_init_floor_perf(policy);
+ if (ret) {
+ dev_err(dev, "Failed to initialize Floor Perf (%d)\n", ret);
+ goto free_cpudata1;
+ }
+
current_pstate_driver->adjust_perf = NULL;
return 0;
diff --git a/drivers/cpufreq/amd-pstate.h b/drivers/cpufreq/amd-pstate.h
index cb45fdca27a6c..0c587ca200199 100644
--- a/drivers/cpufreq/amd-pstate.h
+++ b/drivers/cpufreq/amd-pstate.h
@@ -62,9 +62,12 @@ struct amd_aperf_mperf {
* @cpu: CPU number
* @req: constraint request to apply
* @cppc_req_cached: cached performance request hints
+ * @cppc_req2_cached: cached value of MSR_AMD_CPPC_REQ2
* @perf: cached performance-related data
* @prefcore_ranking: the preferred core ranking, the higher value indicates a higher
* priority.
+ * @floor_perf_cnt: Cached value of the number of distinct floor
+ * performance levels supported
* @min_limit_freq: Cached value of policy->min (in khz)
* @max_limit_freq: Cached value of policy->max (in khz)
* @nominal_freq: the frequency (in khz) that mapped to nominal_perf
@@ -87,10 +90,12 @@ struct amd_cpudata {
struct freq_qos_request req[2];
u64 cppc_req_cached;
+ u64 cppc_req2_cached;
union perf_cached perf;
u8 prefcore_ranking;
+ u8 floor_perf_cnt;
u32 min_limit_freq;
u32 max_limit_freq;
u32 nominal_freq;
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v2 6/9] amd-pstate: Add sysfs support for floor_freq and floor_count
2026-03-11 14:01 [PATCH v2 0/9] amd-pstate: Introduce AMD CPPC Performance Priority Gautham R. Shenoy
` (4 preceding siblings ...)
2026-03-11 14:01 ` [PATCH v2 5/9] amd-pstate: Add support for CPPC_REQ2 and FLOOR_PERF Gautham R. Shenoy
@ 2026-03-11 14:01 ` Gautham R. Shenoy
2026-03-12 20:57 ` Mario Limonciello (AMD) (kernel.org)
2026-03-12 21:24 ` Mario Limonciello (AMD) (kernel.org)
2026-03-11 14:01 ` [PATCH v2 7/9] amd-pstate: Introduce a tracepoint trace_amd_pstate_cppc_req2() Gautham R. Shenoy
` (2 subsequent siblings)
8 siblings, 2 replies; 18+ messages in thread
From: Gautham R. Shenoy @ 2026-03-11 14:01 UTC (permalink / raw)
To: Mario Limonciello, Rafael J . Wysocki, Viresh Kumar,
K Prateek Nayak
Cc: linux-kernel, linux-pm, Gautham R. Shenoy
When Floor Performance feature is supported by the platform, expose
two sysfs files:
* amd_pstate_floor_freq to allow userspace to request the floor
frequency for each CPU.
* amd_pstate_floor_count which advertises the number of distinct
levels of floor frequencies supported on this platform.
Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
---
drivers/cpufreq/amd-pstate.c | 50 ++++++++++++++++++++++++++++++++++++
drivers/cpufreq/amd-pstate.h | 2 ++
2 files changed, 52 insertions(+)
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 3122ad5af6f47..54b650f3b4e78 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -383,6 +383,8 @@ static int amd_pstate_init_floor_perf(struct cpufreq_policy *policy)
return ret;
}
+ cpudata->floor_freq = perf_to_freq(cpudata->perf, cpudata->nominal_freq,
+ floor_perf);
return 0;
}
@@ -1284,6 +1286,44 @@ static ssize_t show_energy_performance_preference(
return sysfs_emit(buf, "%s\n", energy_perf_strings[preference]);
}
+static ssize_t store_amd_pstate_floor_freq(struct cpufreq_policy *policy,
+ const char *buf, size_t count)
+{
+ struct amd_cpudata *cpudata = policy->driver_data;
+ union perf_cached perf = READ_ONCE(cpudata->perf);
+ unsigned int freq;
+ u8 floor_perf;
+ int ret;
+
+ ret = kstrtouint(buf, 0, &freq);
+ if (ret)
+ return ret;
+
+ floor_perf = freq_to_perf(perf, cpudata->nominal_freq, freq);
+ ret = amd_pstate_set_floor_perf(policy, floor_perf);
+
+ if (!ret)
+ cpudata->floor_freq = freq;
+
+ return ret ?: count;
+}
+
+static ssize_t show_amd_pstate_floor_freq(struct cpufreq_policy *policy, char *buf)
+{
+ struct amd_cpudata *cpudata = policy->driver_data;
+
+ return sysfs_emit(buf, "%u\n", cpudata->floor_freq);
+}
+
+
+static ssize_t show_amd_pstate_floor_count(struct cpufreq_policy *policy, char *buf)
+{
+ struct amd_cpudata *cpudata = policy->driver_data;
+ u8 count = cpudata->floor_perf_cnt;
+
+ return sysfs_emit(buf, "%u\n", count);
+}
+
cpufreq_freq_attr_ro(amd_pstate_max_freq);
cpufreq_freq_attr_ro(amd_pstate_lowest_nonlinear_freq);
@@ -1292,6 +1332,8 @@ cpufreq_freq_attr_ro(amd_pstate_prefcore_ranking);
cpufreq_freq_attr_ro(amd_pstate_hw_prefcore);
cpufreq_freq_attr_rw(energy_performance_preference);
cpufreq_freq_attr_ro(energy_performance_available_preferences);
+cpufreq_freq_attr_rw(amd_pstate_floor_freq);
+cpufreq_freq_attr_ro(amd_pstate_floor_count);
struct freq_attr_visibility {
struct freq_attr *attr;
@@ -1316,6 +1358,12 @@ static bool epp_visibility(void)
return cppc_state == AMD_PSTATE_ACTIVE;
}
+/* Determines whether amd_pstate_floor_freq related attributes should be visible */
+static bool floor_freq_visibility(void)
+{
+ return cpu_feature_enabled(X86_FEATURE_CPPC_PERF_PRIO);
+}
+
static struct freq_attr_visibility amd_pstate_attr_visibility[] = {
{&amd_pstate_max_freq, always_visible},
{&amd_pstate_lowest_nonlinear_freq, always_visible},
@@ -1324,6 +1372,8 @@ static struct freq_attr_visibility amd_pstate_attr_visibility[] = {
{&amd_pstate_hw_prefcore, prefcore_visibility},
{&energy_performance_preference, epp_visibility},
{&energy_performance_available_preferences, epp_visibility},
+ {&amd_pstate_floor_freq, floor_freq_visibility},
+ {&amd_pstate_floor_count, floor_freq_visibility},
};
static struct freq_attr **get_freq_attrs(void)
diff --git a/drivers/cpufreq/amd-pstate.h b/drivers/cpufreq/amd-pstate.h
index 0c587ca200199..ab4caea39f0e8 100644
--- a/drivers/cpufreq/amd-pstate.h
+++ b/drivers/cpufreq/amd-pstate.h
@@ -72,6 +72,7 @@ struct amd_aperf_mperf {
* @max_limit_freq: Cached value of policy->max (in khz)
* @nominal_freq: the frequency (in khz) that mapped to nominal_perf
* @lowest_nonlinear_freq: the frequency (in khz) that mapped to lowest_nonlinear_perf
+ * @floor_freq: Cached value of the user requested floor_freq
* @cur: Difference of Aperf/Mperf/tsc count between last and current sample
* @prev: Last Aperf/Mperf/tsc count value read from register
* @freq: current cpu frequency value (in khz)
@@ -100,6 +101,7 @@ struct amd_cpudata {
u32 max_limit_freq;
u32 nominal_freq;
u32 lowest_nonlinear_freq;
+ u32 floor_freq;
struct amd_aperf_mperf cur;
struct amd_aperf_mperf prev;
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v2 7/9] amd-pstate: Introduce a tracepoint trace_amd_pstate_cppc_req2()
2026-03-11 14:01 [PATCH v2 0/9] amd-pstate: Introduce AMD CPPC Performance Priority Gautham R. Shenoy
` (5 preceding siblings ...)
2026-03-11 14:01 ` [PATCH v2 6/9] amd-pstate: Add sysfs support for floor_freq and floor_count Gautham R. Shenoy
@ 2026-03-11 14:01 ` Gautham R. Shenoy
2026-03-11 14:01 ` [PATCH v2 8/9] Documentation/amd-pstate: List prefcore related sysfs files Gautham R. Shenoy
2026-03-11 14:01 ` [PATCH v2 9/9] Documentation/amd-pstate: Add documentation for amd_pstate_floor_{freq,count} Gautham R. Shenoy
8 siblings, 0 replies; 18+ messages in thread
From: Gautham R. Shenoy @ 2026-03-11 14:01 UTC (permalink / raw)
To: Mario Limonciello, Rafael J . Wysocki, Viresh Kumar,
K Prateek Nayak
Cc: linux-kernel, linux-pm, Gautham R. Shenoy
Introduce a new tracepoint trace_amd_pstate_cppc_req2() to track
updates to MSR_AMD_CPPC_REQ2.
Invoke this while changing the Floor Perf.
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
---
drivers/cpufreq/amd-pstate-trace.h | 35 ++++++++++++++++++++++++++++++
drivers/cpufreq/amd-pstate.c | 14 +++++++++---
2 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/drivers/cpufreq/amd-pstate-trace.h b/drivers/cpufreq/amd-pstate-trace.h
index 32e1bdc588c52..91fa073b2be48 100644
--- a/drivers/cpufreq/amd-pstate-trace.h
+++ b/drivers/cpufreq/amd-pstate-trace.h
@@ -133,6 +133,41 @@ TRACE_EVENT(amd_pstate_epp_perf,
)
);
+TRACE_EVENT(amd_pstate_cppc_req2,
+
+ TP_PROTO(unsigned int cpu_id,
+ u8 floor_perf,
+ bool changed,
+ int err_code
+ ),
+
+ TP_ARGS(cpu_id,
+ floor_perf,
+ changed,
+ err_code),
+
+ TP_STRUCT__entry(
+ __field(unsigned int, cpu_id)
+ __field(u8, floor_perf)
+ __field(bool, changed)
+ __field(int, err_code)
+ ),
+
+ TP_fast_assign(
+ __entry->cpu_id = cpu_id;
+ __entry->floor_perf = floor_perf;
+ __entry->changed = changed;
+ __entry->err_code = err_code;
+ ),
+
+ TP_printk("cpu%u: floor_perf=%u, changed=%u (error = %d)",
+ __entry->cpu_id,
+ __entry->floor_perf,
+ __entry->changed,
+ __entry->err_code
+ )
+);
+
#endif /* _AMD_PSTATE_TRACE_H */
/* This part must be outside protection */
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 54b650f3b4e78..a79c6213a67e4 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -333,6 +333,7 @@ static int amd_pstate_set_floor_perf(struct cpufreq_policy *policy, u8 perf)
{
struct amd_cpudata *cpudata = policy->driver_data;
u64 value, prev;
+ bool changed;
int ret;
if (!cpu_feature_enabled(X86_FEATURE_CPPC_PERF_PRIO))
@@ -341,17 +342,24 @@ static int amd_pstate_set_floor_perf(struct cpufreq_policy *policy, u8 perf)
value = prev = READ_ONCE(cpudata->cppc_req2_cached);
FIELD_MODIFY(AMD_CPPC_FLOOR_PERF_MASK, &value, perf);
- if (value == prev)
- return 0;
+ changed = value != prev;
+ if (!changed) {
+ ret = 0;
+ goto out_trace;
+ }
ret = wrmsrq_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ2, value);
if (ret) {
+ changed = false;
pr_err("failed to set CPPC REQ2 value. Error (%d)\n", ret);
- return ret;
+ goto out_trace;
}
WRITE_ONCE(cpudata->cppc_req2_cached, value);
+out_trace:
+ if (trace_amd_pstate_cppc_req2_enabled())
+ trace_amd_pstate_cppc_req2(cpudata->cpu, perf, changed, ret);
return ret;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v2 8/9] Documentation/amd-pstate: List prefcore related sysfs files
2026-03-11 14:01 [PATCH v2 0/9] amd-pstate: Introduce AMD CPPC Performance Priority Gautham R. Shenoy
` (6 preceding siblings ...)
2026-03-11 14:01 ` [PATCH v2 7/9] amd-pstate: Introduce a tracepoint trace_amd_pstate_cppc_req2() Gautham R. Shenoy
@ 2026-03-11 14:01 ` Gautham R. Shenoy
2026-03-12 20:58 ` Mario Limonciello
2026-03-11 14:01 ` [PATCH v2 9/9] Documentation/amd-pstate: Add documentation for amd_pstate_floor_{freq,count} Gautham R. Shenoy
8 siblings, 1 reply; 18+ messages in thread
From: Gautham R. Shenoy @ 2026-03-11 14:01 UTC (permalink / raw)
To: Mario Limonciello, Rafael J . Wysocki, Viresh Kumar,
K Prateek Nayak
Cc: linux-kernel, linux-pm, Gautham R. Shenoy, Jonathan Corbet,
Shuah Khan
Add the missing amd_pstate_hw_prefcore and amd_pstate_prefcore_ranking
filenames in the sysfs listing example leading to the descriptions of
these parameters.
Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
---
Documentation/admin-guide/pm/amd-pstate.rst | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/Documentation/admin-guide/pm/amd-pstate.rst b/Documentation/admin-guide/pm/amd-pstate.rst
index e1771f2225d5f..f566fea6613e6 100644
--- a/Documentation/admin-guide/pm/amd-pstate.rst
+++ b/Documentation/admin-guide/pm/amd-pstate.rst
@@ -239,8 +239,10 @@ control its functionality at the system level. They are located in the
root@hr-test1:/home/ray# ls /sys/devices/system/cpu/cpufreq/policy0/*amd*
/sys/devices/system/cpu/cpufreq/policy0/amd_pstate_highest_perf
+ /sys/devices/system/cpu/cpufreq/policy0/amd_pstate_hw_prefcore
/sys/devices/system/cpu/cpufreq/policy0/amd_pstate_lowest_nonlinear_freq
/sys/devices/system/cpu/cpufreq/policy0/amd_pstate_max_freq
+ /sys/devices/system/cpu/cpufreq/policy0/amd_pstate_prefcore_ranking
``amd_pstate_highest_perf / amd_pstate_max_freq``
@@ -264,14 +266,17 @@ This attribute is read-only.
``amd_pstate_hw_prefcore``
-Whether the platform supports the preferred core feature and it has been
-enabled. This attribute is read-only.
+Whether the platform supports the preferred core feature and it has
+been enabled. This attribute is read-only. This file is only visible
+on platforms which support the preferred core feature.
``amd_pstate_prefcore_ranking``
-The performance ranking of the core. This number doesn't have any unit, but
-larger numbers are preferred at the time of reading. This can change at
-runtime based on platform conditions. This attribute is read-only.
+The performance ranking of the core. This number doesn't have any
+unit, but larger numbers are preferred at the time of reading. This
+can change at runtime based on platform conditions. This attribute is
+read-only. This file is only visible on platforms which support the
+preferred core feature.
``energy_performance_available_preferences``
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v2 9/9] Documentation/amd-pstate: Add documentation for amd_pstate_floor_{freq,count}
2026-03-11 14:01 [PATCH v2 0/9] amd-pstate: Introduce AMD CPPC Performance Priority Gautham R. Shenoy
` (7 preceding siblings ...)
2026-03-11 14:01 ` [PATCH v2 8/9] Documentation/amd-pstate: List prefcore related sysfs files Gautham R. Shenoy
@ 2026-03-11 14:01 ` Gautham R. Shenoy
2026-03-12 20:59 ` Mario Limonciello (AMD) (kernel.org)
8 siblings, 1 reply; 18+ messages in thread
From: Gautham R. Shenoy @ 2026-03-11 14:01 UTC (permalink / raw)
To: Mario Limonciello, Rafael J . Wysocki, Viresh Kumar,
K Prateek Nayak
Cc: linux-kernel, linux-pm, Gautham R. Shenoy, Jonathan Corbet,
Shuah Khan
Add documentation for the sysfs files
/sys/devices/system/cpu/cpufreq/policy*/amd_pstate_floor_freq
and
/sys/devices/system/cpu/cpufreq/policy*/amd_pstate_floor_count.
Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
---
Documentation/admin-guide/pm/amd-pstate.rst | 32 +++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/Documentation/admin-guide/pm/amd-pstate.rst b/Documentation/admin-guide/pm/amd-pstate.rst
index f566fea6613e6..5fd2a36f8a4b8 100644
--- a/Documentation/admin-guide/pm/amd-pstate.rst
+++ b/Documentation/admin-guide/pm/amd-pstate.rst
@@ -242,6 +242,8 @@ control its functionality at the system level. They are located in the
/sys/devices/system/cpu/cpufreq/policy0/amd_pstate_hw_prefcore
/sys/devices/system/cpu/cpufreq/policy0/amd_pstate_lowest_nonlinear_freq
/sys/devices/system/cpu/cpufreq/policy0/amd_pstate_max_freq
+ /sys/devices/system/cpu/cpufreq/policy0/amd_pstate_floor_freq
+ /sys/devices/system/cpu/cpufreq/policy0/amd_pstate_floor_count
/sys/devices/system/cpu/cpufreq/policy0/amd_pstate_prefcore_ranking
@@ -278,6 +280,36 @@ can change at runtime based on platform conditions. This attribute is
read-only. This file is only visible on platforms which support the
preferred core feature.
+``amd_pstate_floor_freq``
+
+The floor frequency associated with each CPU. Userspace can write any
+value between ``cpuinfo_min_freq`` and ``scaling_max_freq`` into this
+file. When the system is under power or thermal constraints, the
+platform firmware will attempt to throttle the CPU frequency to the
+value specified in ``amd_pstate_floor_freq`` before throttling it
+further. This allows userspace to specify different floor frequencies
+to different CPUs. For optimal results, threads of the same core
+should have the same floor frequency value. This file is only visible
+on platforms that support the CPPC Performance Priority feature.
+
+
+``amd_pstate_floor_count``
+
+The number of distinct Floor Performance levels supported by the
+platform. For example, if this value is 2, then the number of unique
+values obtained from the command ``cat
+/sys/devices/system/cpu/cpufreq/policy*/amd_pstate_floor_freq |
+sort -n | uniq`` should be at most this number for the behavior
+described in ``amd_pstate_floor_freq`` to take effect. A zero value
+implies that the platform supports unlimited floor performance levels.
+This file is only visible on platforms that support the CPPC
+Performance Priority feature.
+
+**Note**: When ``amd_pstate_floor_count`` is non-zero, the frequency to
+which the CPU is throttled under power or thermal constraints is
+undefined when the number of unique values of ``amd_pstate_floor_freq``
+across all CPUs in the system exceeds ``amd_pstate_floor_count``.
+
``energy_performance_available_preferences``
A list of all the supported EPP preferences that could be used for
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH v2 3/9] amd-pstate: Make certain freq_attrs conditionally visible
2026-03-11 14:01 ` [PATCH v2 3/9] amd-pstate: Make certain freq_attrs conditionally visible Gautham R. Shenoy
@ 2026-03-12 6:49 ` Gautham R. Shenoy
2026-03-12 20:46 ` Mario Limonciello (AMD) (kernel.org)
1 sibling, 0 replies; 18+ messages in thread
From: Gautham R. Shenoy @ 2026-03-12 6:49 UTC (permalink / raw)
To: Mario Limonciello, Rafael J . Wysocki, Viresh Kumar,
K Prateek Nayak
Cc: linux-kernel, linux-pm, Chris Mason
Hello,
Claude Opus 4.6 along with Chris Mason's Linux Prompts to which I
added an amd-pstate.md found the following issue with his patch.
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 24cdeffbcd40..fb5d7bb320c1 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
[ ... ]
> static void amd_pstate_driver_cleanup(void)
> {
> if (amd_pstate_prefcore)
> sched_clear_itmt_support();
>
> cppc_state = AMD_PSTATE_DISABLE;
> + kfree(current_pstate_driver->attr);
> current_pstate_driver = NULL;
> }
After the kfree, the .attr field in the static driver struct
(amd_pstate_driver or amd_pstate_epp_driver) still holds the freed
pointer. Should current_pstate_driver->attr be set to NULL before
current_pstate_driver is set to NULL?
Without that, on a mode switch via
amd_pstate_change_driver_mode()->amd_pstate_unregister_driver()
->amd_pstate_driver_cleanup(), the .attr pointer in the old static
driver struct becomes dangling. When
amd_pstate_register_driver()->amd_pstate_set_driver() later re-assigns
current_pstate_driver to that same struct, .attr still holds the stale
pointer. If get_freq_attrs() then fails (kcalloc returns NULL), the
error path calls amd_pstate_driver_cleanup() again, which kfrees the
already-freed .attr -- a double-free.
[ ... ]
> + attr = get_freq_attrs();
> + if (IS_ERR(attr)) {
> + ret = (int) PTR_ERR(attr);
> + pr_err("Couldn't compute freq_attrs for current mode %s [%d]\n",
> + amd_pstate_get_mode_string(cppc_state), ret);
> + amd_pstate_driver_cleanup();
> ^^^^
This is where the double-free would be triggered. At this point
current_pstate_driver->attr was never updated with the new allocation
(it failed), so it still holds whatever the static struct had -- which
is the dangling pointer from a previous amd_pstate_driver_cleanup()
call during a prior mode switch.
I will send a v3 to incorporate this fix.
> + return ret;
> + }
> +
> + current_pstate_driver->attr = attr;
FWIW, the amd-pstate.md for review-prompts/linux is as follows:
x8-------------x8---------------------x8-----------------x8
# AMD Pstate / CPPC Subsystem Delta
Load when patch touches: `drivers/cpufreq/amd-pstate*.c`, `amd_pstate_`, `cppc_` (in cpufreq context).
Generic patterns (memory leaks on error path, NULL checks, uninitialized variables) are covered by
CS-001, patterns/null.md, and false-positive-guide. Apply those; this file adds amd-pstate-specific checks.
## AMD Pstate Patterns [APST]
### APST-001: cppc_req_cached sync on fast_switch path
**Risk**: Stale cached state, wrong EPP/perf on subsequent reads
**Details**: `msr_update_perf()` writes to MSR_AMD_CPPC_REQ but does not update
`cpudata->cppc_req_cached` when the update happens from the fast path (fast_switch).
The cached value is used elsewhere; desync causes incorrect behavior.
- **Check**: Any MSR_AMD_CPPC_REQ write path must update `cppc_req_cached` consistently
- **Fixes context**: Introduced by "Always write EPP value when updating perf"; fast path was missed
### APST-002: Online vs present CPUs for cpc_desc_ptr
**Risk**: NULL deref, crash when accessing offline CPU CPC data
**Details**: `cpc_desc_ptr` (per-CPU) is initialized only for **online** CPUs via
`acpi_soft_cpu_online()` -> `__acpi_processor_start()` -> `acpi_cppc_processor_probe()`.
Code that iterates over **present** CPUs and calls into `cppc_`* (e.g. `cppc_set_auto_sel()` ->
`cppc_set_reg_val()`) can touch uninitialized CPC data for offline CPUs.
- **Check**: Restrict `cppc_set_auto_sel()` and similar CPC ops to online CPUs only
- **Fixes context**: Guided mode control; `amd_pstate_change_mode_without_dvr_change()` iterated present CPUs
### APST-003: EPP 0 after hibernate (S4)
**Risk**: Wrong EPP on resume, performance/power regression
**Details**: During S4 hibernate, CPUs are offlined. When offlined, EPP was reset to 0.
On resume, all CPUs except boot CPU end up with EPP 0 programmed instead of policy value.
- **Check**: When offlining CPUs, do not reset EPP to 0; preserve or reset to policy values so onlining restores correctly
- **Fixes context**: "Requested CPU Min frequency" BIOS option changed offlining behavior
### APST-004: EPP 0 after resume (S3)
**Risk**: Wrong EPP on resume, performance/power regression
**Details**: During suspend, the cached CPPC request was invalidated/destroyed with the
expectation it would be restored on resume. Removing the separate EPP cache and later
explicitly setting EPP to 0 during suspend broke resume.
- **Check**: Preserve or re-apply EPP/CPPC request values during suspend so resume path can restore correctly
- **Fixes context**: "Requested CPU Min frequency" BIOS option; also b7a41156588a (Invalidate cppc_req_cached during suspend)
### APST-005: CPPC.min_perf wrong after governor switch
**Risk**: Performance governor not achieving nominal_perf, throttling incorrectly
**Details**: In active mode with performance governor, CPPC.min_perf must equal nominal_perf.
After "Drop min and max cached frequencies", `amd_pstate_update_min_max_limit()` is
called only when scaling_{min,max}_freq differ from cached values. Governor switch
powersave -> performance does not change scaling limits, so the constraint is never
re-applied and CPPC.min_perf remains at the old powersave value.
- **Check**: Invoke limit update when policy/governor changes, not only when scaling limits change
- **Fixes context**: a9b9b4c2a4cd
### APST-006: ITMT / sched domain init ordering
**Risk**: Wrong asym_prefer_cpu, suboptimal scheduling
**Details**: ITMT support is enabled from `amd_pstate*_cpu_init()`, which runs per CPU.
Sched domains are rebuilt when ITMT is first enabled. Enabling after the first CPU
means other CPUs have not yet initialized their asym priorities; the domain rebuild
captures incomplete data and asym_prefer_cpu is wrong (e.g. always first CPU in group).
- **Check**: Initialize asym priorities for all CPUs first, then enable ITMT (e.g. from `amd_pstate_register_driver()`)
- **Check**: Clear ITMT when driver unregisters; core rankings require update_limits() to be operational
- **Fixes context**: f3a052391822 (Enable amd-pstate preferred core support)
### APST-007: min_limit perf/freq desync for performance governor
**Risk**: Inconsistent min_limit state, wrong scaling behavior
**Details**: With performance governor, min_limit perf and freq are kept in sync. A
special-case path modified only the perf value; the freq value was not updated,
causing perf and freq to diverge.
- **Check**: When updating min_limit perf in performance governor path, update min_limit freq as well
- **Fixes context**: 009d1c29a451 (Move perf values into a union)
### APST-008: freq_to_perf clamping and u8 overflow
**Risk**: Wrong perf values from overflow, wraparound
**Details**: `freq_to_perf()` produces a u8. Values >255 overflow when cast to u8 before
clamping. Also, `clamp_t(u8, ...)` typecasts first then clamps, which does not fix
overflow. Must use a wider type (e.g. u32) for the intermediate value, then clamp,
then cast to u8.
- **Check**: Use intermediate u32 for >255 values; clamp then cast to u8
- **Fixes context**: 620136ced35a / 305621eb6a8b (Modularize perf<->freq conversion)
## Driver Context
### Modes
- **Passive**: Legacy ACPI P-state style
- **Active (EPP)**: Uses MSR_AMD_CPPC_REQ, EPP hint
- **Guided**: Platform-guided; `cppc_set_auto_sel()` involved
### MSR Paths
- **MSR_AMD_CPPC_REQ**: Primary request register; `cppc_req_cached` must stay in sync
- **MSR_AMD_CPPC_REQ2**: Floor perf (newer platforms)
- **MSR_AMD_CPPC_CAP1**: Capabilities, nominal/lowest_perf, etc.
- **Fast path vs slow path**: Both must update `cppc_req_cached` when writing CPPC_REQ
### Per-CPU vs Online
- `cpc_desc_ptr`: Initialized only for **online** CPUs (ACPI CPU hotplug)
- Iterating present CPUs and calling `cppc_`* can access uninitialized data
- Prefer `for_each_online_cpu` or equivalent when touching CPC
### Suspend/Resume
- EPP and CPPC request values must be preserved or explicitly restored
- Offlining during hibernate must not reset EPP to 0; use policy values
- Cached request must be usable for resume restoration
### Governor Interactions
- **Active mode only**: Performance governor CPPC.min_perf = nominal_perf; scaling limits may be ignored. Powersave scaling_min_freq / scaling_max_freq apply.
- **Passive / guided modes**: scaling_min_freq / scaling_max_freq apply regardless of governor.
- Governor switch (in active mode) must re-apply performance constraints; limit updates are not only scaling-limit driven.
## Quick Checks
- Every MSR_AMD_CPPC_REQ write path updates `cppc_req_cached`
- CPC/ACPI ops (e.g. `cppc_set_auto_sel`) restricted to online CPUs
- Suspend/offline paths preserve or reset EPP to policy values, not 0
- Governor switch (especially to performance) triggers limit/constraint refresh
- `freq_to_perf` / `perf_to_freq` use safe clamping (no u8 overflow before clamp)
- Init paths: apply CS-001 error-path validation; amd-pstate has had leaks on init failure
x8-------------x8---------------------x8-----------------x8
--
Thanks and Regards
gautham.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 2/9] amd-pstate: Update cppc_req_cached in fast_switch case
2026-03-11 14:01 ` [PATCH v2 2/9] amd-pstate: Update cppc_req_cached in fast_switch case Gautham R. Shenoy
@ 2026-03-12 20:41 ` Mario Limonciello (AMD) (kernel.org)
0 siblings, 0 replies; 18+ messages in thread
From: Mario Limonciello (AMD) (kernel.org) @ 2026-03-12 20:41 UTC (permalink / raw)
To: Gautham R. Shenoy, Rafael J . Wysocki, Viresh Kumar,
K Prateek Nayak
Cc: linux-kernel, linux-pm
On 3/11/2026 9:01 AM, Gautham R. Shenoy wrote:
> The function msr_update_perf() does not cache the new value that is
> written to MSR_AMD_CPPC_REQ into the variable cpudata->cppc_req_cached
> when the update is happening from the fast path.
>
> Fix that by caching the value everytime the MSR_AMD_CPPC_REQ gets
> updated.
>
> This issue was discovered by Claude Opus 4.6 with the aid of Chris
> Mason's AI review-prompts
> (https://github.com/masoncl/review-prompts/tree/main/kernel).
>
> Assisted-by: Claude:claude-opus-4.6 review-prompts/linux
> Fixes: fff395796917 ("cpufreq/amd-pstate: Always write EPP value when updating perf")
> Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
> ---
> drivers/cpufreq/amd-pstate.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index d57969c72c9dc..24cdeffbcd40e 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -261,7 +261,6 @@ static int msr_update_perf(struct cpufreq_policy *policy, u8 min_perf,
>
> if (fast_switch) {
> wrmsrq(MSR_AMD_CPPC_REQ, value);
> - return 0;
> } else {
> int ret = wrmsrq_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value);
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 3/9] amd-pstate: Make certain freq_attrs conditionally visible
2026-03-11 14:01 ` [PATCH v2 3/9] amd-pstate: Make certain freq_attrs conditionally visible Gautham R. Shenoy
2026-03-12 6:49 ` Gautham R. Shenoy
@ 2026-03-12 20:46 ` Mario Limonciello (AMD) (kernel.org)
1 sibling, 0 replies; 18+ messages in thread
From: Mario Limonciello (AMD) (kernel.org) @ 2026-03-12 20:46 UTC (permalink / raw)
To: Gautham R. Shenoy, Rafael J . Wysocki, Viresh Kumar,
K Prateek Nayak
Cc: linux-kernel, linux-pm
On 3/11/2026 9:01 AM, Gautham R. Shenoy wrote:
> Certain amd_pstate freq_attrs such as amd_pstate_hw_prefcore and
> amd_pstate_prefcore_ranking are enabled even when preferred core is
> not supported on the platform.
>
> Similarly there are common freq_attrs between the amd-pstate and the
> amd-pstate-epp drivers (eg: amd_pstate_max_freq,
> amd_pstate_lowest_non_linear_freq, etc.) but are duplicated in two
> different freq_attr structs.
>
> Unify all the attributes in a single place and associate each of them
> with a visibility function that determines whether the attribute
> should be visible based on the underlying platform support and the
> current amd_pstate mode.
>
> Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
One thing that might make sense as a follow up suggestion though would
be some changes to amd-pstate-ut to validate the right things are always
showing up on the right configuration.
> ---
> drivers/cpufreq/amd-pstate.c | 123 ++++++++++++++++++++++++++---------
> 1 file changed, 92 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 24cdeffbcd40e..fb5d7bb320c15 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -1220,12 +1220,86 @@ static ssize_t show_energy_performance_preference(
> return sysfs_emit(buf, "%s\n", energy_perf_strings[preference]);
> }
>
> +cpufreq_freq_attr_ro(amd_pstate_max_freq);
> +cpufreq_freq_attr_ro(amd_pstate_lowest_nonlinear_freq);
> +
> +cpufreq_freq_attr_ro(amd_pstate_highest_perf);
> +cpufreq_freq_attr_ro(amd_pstate_prefcore_ranking);
> +cpufreq_freq_attr_ro(amd_pstate_hw_prefcore);
> +cpufreq_freq_attr_rw(energy_performance_preference);
> +cpufreq_freq_attr_ro(energy_performance_available_preferences);
> +
> +struct freq_attr_visibility {
> + struct freq_attr *attr;
> + bool (*visibility_fn)(void);
> +};
> +
> +/* For attributes which are always visible */
> +static bool always_visible(void)
> +{
> + return true;
> +}
> +
> +/* Determines whether prefcore related attributes should be visible */
> +static bool prefcore_visibility(void)
> +{
> + return amd_pstate_prefcore;
> +}
> +
> +/* Determines whether energy performance preference should be visible */
> +static bool epp_visibility(void)
> +{
> + return cppc_state == AMD_PSTATE_ACTIVE;
> +}
> +
> +static struct freq_attr_visibility amd_pstate_attr_visibility[] = {
> + {&amd_pstate_max_freq, always_visible},
> + {&amd_pstate_lowest_nonlinear_freq, always_visible},
> + {&amd_pstate_highest_perf, always_visible},
> + {&amd_pstate_prefcore_ranking, prefcore_visibility},
> + {&amd_pstate_hw_prefcore, prefcore_visibility},
> + {&energy_performance_preference, epp_visibility},
> + {&energy_performance_available_preferences, epp_visibility},
> +};
> +
> +static struct freq_attr **get_freq_attrs(void)
> +{
> + bool attr_visible[ARRAY_SIZE(amd_pstate_attr_visibility)];
> + struct freq_attr **attrs;
> + int i, j, count;
> +
> + for (i = 0, count = 0; i < ARRAY_SIZE(amd_pstate_attr_visibility); i++) {
> + struct freq_attr_visibility *v = &amd_pstate_attr_visibility[i];
> +
> + attr_visible[i] = v->visibility_fn();
> + if (attr_visible[i])
> + count++;
> + }
> +
> + /* amd_pstate_{max_freq, lowest_nonlinear_freq, highest_freq} should always be visible */
> + BUG_ON(!count);
> +
> + attrs = kcalloc(count + 1, sizeof(struct freq_attr *), GFP_KERNEL);
> + if (!attrs)
> + return ERR_PTR(-ENOMEM);
> +
> + for (i = 0, j = 0; i < ARRAY_SIZE(amd_pstate_attr_visibility); i++) {
> + if (!attr_visible[i])
> + continue;
> +
> + attrs[j++] = amd_pstate_attr_visibility[i].attr;
> + }
> +
> + return attrs;
> +}
> +
> static void amd_pstate_driver_cleanup(void)
> {
> if (amd_pstate_prefcore)
> sched_clear_itmt_support();
>
> cppc_state = AMD_PSTATE_DISABLE;
> + kfree(current_pstate_driver->attr);
> current_pstate_driver = NULL;
> }
>
> @@ -1250,6 +1324,7 @@ static int amd_pstate_set_driver(int mode_idx)
>
> static int amd_pstate_register_driver(int mode)
> {
> + struct freq_attr **attr = NULL;
> int ret;
>
> ret = amd_pstate_set_driver(mode);
> @@ -1258,6 +1333,22 @@ static int amd_pstate_register_driver(int mode)
>
> cppc_state = mode;
>
> + /*
> + * Note: It is important to compute the attrs _after_
> + * re-initializing the cppc_state. Some attributes become
> + * visible only when cppc_state is AMD_PSTATE_ACTIVE.
> + */
> + attr = get_freq_attrs();
> + if (IS_ERR(attr)) {
> + ret = (int) PTR_ERR(attr);
> + pr_err("Couldn't compute freq_attrs for current mode %s [%d]\n",
> + amd_pstate_get_mode_string(cppc_state), ret);
> + amd_pstate_driver_cleanup();
> + return ret;
> + }
> +
> + current_pstate_driver->attr = attr;
> +
> /* at least one CPU supports CPB */
> current_pstate_driver->boost_enabled = cpu_feature_enabled(X86_FEATURE_CPB);
>
> @@ -1399,37 +1490,9 @@ static ssize_t prefcore_show(struct device *dev,
> return sysfs_emit(buf, "%s\n", str_enabled_disabled(amd_pstate_prefcore));
> }
>
> -cpufreq_freq_attr_ro(amd_pstate_max_freq);
> -cpufreq_freq_attr_ro(amd_pstate_lowest_nonlinear_freq);
> -
> -cpufreq_freq_attr_ro(amd_pstate_highest_perf);
> -cpufreq_freq_attr_ro(amd_pstate_prefcore_ranking);
> -cpufreq_freq_attr_ro(amd_pstate_hw_prefcore);
> -cpufreq_freq_attr_rw(energy_performance_preference);
> -cpufreq_freq_attr_ro(energy_performance_available_preferences);
> static DEVICE_ATTR_RW(status);
> static DEVICE_ATTR_RO(prefcore);
>
> -static struct freq_attr *amd_pstate_attr[] = {
> - &amd_pstate_max_freq,
> - &amd_pstate_lowest_nonlinear_freq,
> - &amd_pstate_highest_perf,
> - &amd_pstate_prefcore_ranking,
> - &amd_pstate_hw_prefcore,
> - NULL,
> -};
> -
> -static struct freq_attr *amd_pstate_epp_attr[] = {
> - &amd_pstate_max_freq,
> - &amd_pstate_lowest_nonlinear_freq,
> - &amd_pstate_highest_perf,
> - &amd_pstate_prefcore_ranking,
> - &amd_pstate_hw_prefcore,
> - &energy_performance_preference,
> - &energy_performance_available_preferences,
> - NULL,
> -};
> -
> static struct attribute *pstate_global_attributes[] = {
> &dev_attr_status.attr,
> &dev_attr_prefcore.attr,
> @@ -1696,7 +1759,6 @@ static struct cpufreq_driver amd_pstate_driver = {
> .set_boost = amd_pstate_set_boost,
> .update_limits = amd_pstate_update_limits,
> .name = "amd-pstate",
> - .attr = amd_pstate_attr,
> };
>
> static struct cpufreq_driver amd_pstate_epp_driver = {
> @@ -1712,7 +1774,6 @@ static struct cpufreq_driver amd_pstate_epp_driver = {
> .update_limits = amd_pstate_update_limits,
> .set_boost = amd_pstate_set_boost,
> .name = "amd-pstate-epp",
> - .attr = amd_pstate_epp_attr,
> };
>
> /*
> @@ -1858,7 +1919,7 @@ static int __init amd_pstate_init(void)
> return ret;
>
> global_attr_free:
> - cpufreq_unregister_driver(current_pstate_driver);
> + amd_pstate_unregister_driver(0);
> return ret;
> }
> device_initcall(amd_pstate_init);
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 5/9] amd-pstate: Add support for CPPC_REQ2 and FLOOR_PERF
2026-03-11 14:01 ` [PATCH v2 5/9] amd-pstate: Add support for CPPC_REQ2 and FLOOR_PERF Gautham R. Shenoy
@ 2026-03-12 20:49 ` Mario Limonciello (AMD) (kernel.org)
0 siblings, 0 replies; 18+ messages in thread
From: Mario Limonciello (AMD) (kernel.org) @ 2026-03-12 20:49 UTC (permalink / raw)
To: Gautham R. Shenoy, Rafael J . Wysocki, Viresh Kumar,
K Prateek Nayak
Cc: linux-kernel, linux-pm
On 3/11/2026 9:01 AM, Gautham R. Shenoy wrote:
> Some future AMD processors have feature named "CPPC Performance
Don't need to include something like timing, it doesn't really age well
in a commit message.
> Priority" which lets userspace specify different floor performance
> levels for different CPUs. The platform firmware takes these different
> floor performance levels into consideration while throttling the CPUs
> under power/thermal constraints. The presence of this feature is
> indicated by bit 16 of the EDX register for CPUID leaf
> 0x80000007. More details can be found in AMD Publication titled "AMD64
> Collaborative Processor Performance Control (CPPC) Performance
> Priority" Revision 1.10.
>
> The number of distinct floor performance levels supported on the
> platform will be advertised through the bits 32:39 of the
> MSR_AMD_CPPC_CAP1. Bits 0:7 of a new MSR MSR_AMD_CPPC_REQ2
> (0xc00102b5) will be used to specify the desired floor performance
> level for that CPU.
>
> Add support for the aforementioned MSR_AMD_CPPC_REQ2, and macros for
> parsing and updating the relevant bits from MSR_AMD_CPPC_CAP1 and
> MSR_AMD_CPPC_REQ2.
>
> On boot if the default value of the MSR_AMD_CPPC_REQ2[7:0] (Floor
> Perf) is lower than CPPC.lowest_perf, and thus invalid, initialize it
> to MSR_AMD_CPPC_CAP1.nominal_perf which is a sane default value.
>
> Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
> ---
> Link to AMD publication describing this feature: https://docs.amd.com/v/u/en-US/69206_1.10_AMD64_CPPC_PUB
I think this can be in the commit message rather as Link: rather than
below cutlist.
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
>
> arch/x86/include/asm/msr-index.h | 5 +++
> drivers/cpufreq/amd-pstate.c | 70 ++++++++++++++++++++++++++++++++
> drivers/cpufreq/amd-pstate.h | 5 +++
> 3 files changed, 80 insertions(+)
>
> diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
> index 6673601246b38..e126c7fb69cf6 100644
> --- a/arch/x86/include/asm/msr-index.h
> +++ b/arch/x86/include/asm/msr-index.h
> @@ -765,12 +765,14 @@
> #define MSR_AMD_CPPC_CAP2 0xc00102b2
> #define MSR_AMD_CPPC_REQ 0xc00102b3
> #define MSR_AMD_CPPC_STATUS 0xc00102b4
> +#define MSR_AMD_CPPC_REQ2 0xc00102b5
>
> /* Masks for use with MSR_AMD_CPPC_CAP1 */
> #define AMD_CPPC_LOWEST_PERF_MASK GENMASK(7, 0)
> #define AMD_CPPC_LOWNONLIN_PERF_MASK GENMASK(15, 8)
> #define AMD_CPPC_NOMINAL_PERF_MASK GENMASK(23, 16)
> #define AMD_CPPC_HIGHEST_PERF_MASK GENMASK(31, 24)
> +#define AMD_CPPC_FLOOR_PERF_CNT_MASK GENMASK_ULL(39, 32)
>
> /* Masks for use with MSR_AMD_CPPC_REQ */
> #define AMD_CPPC_MAX_PERF_MASK GENMASK(7, 0)
> @@ -778,6 +780,9 @@
> #define AMD_CPPC_DES_PERF_MASK GENMASK(23, 16)
> #define AMD_CPPC_EPP_PERF_MASK GENMASK(31, 24)
>
> +/* Masks for use with MSR_AMD_CPPC_REQ2 */
> +#define AMD_CPPC_FLOOR_PERF_MASK GENMASK(7, 0)
> +
> /* AMD Performance Counter Global Status and Control MSRs */
> #define MSR_AMD64_PERF_CNTR_GLOBAL_STATUS 0xc0000300
> #define MSR_AMD64_PERF_CNTR_GLOBAL_CTL 0xc0000301
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index fb5d7bb320c15..3122ad5af6f47 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -329,6 +329,63 @@ static inline int amd_pstate_set_epp(struct cpufreq_policy *policy, u8 epp)
> return static_call(amd_pstate_set_epp)(policy, epp);
> }
>
> +static int amd_pstate_set_floor_perf(struct cpufreq_policy *policy, u8 perf)
> +{
> + struct amd_cpudata *cpudata = policy->driver_data;
> + u64 value, prev;
> + int ret;
> +
> + if (!cpu_feature_enabled(X86_FEATURE_CPPC_PERF_PRIO))
> + return 0;
> +
> + value = prev = READ_ONCE(cpudata->cppc_req2_cached);
> + FIELD_MODIFY(AMD_CPPC_FLOOR_PERF_MASK, &value, perf);
> +
> + if (value == prev)
> + return 0;
> +
> + ret = wrmsrq_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ2, value);
> + if (ret) {
> + pr_err("failed to set CPPC REQ2 value. Error (%d)\n", ret);
> + return ret;
> + }
> +
> + WRITE_ONCE(cpudata->cppc_req2_cached, value);
> +
> + return ret;
> +}
> +
> +static int amd_pstate_init_floor_perf(struct cpufreq_policy *policy)
> +{
> + struct amd_cpudata *cpudata = policy->driver_data;
> + u8 floor_perf;
> + u64 value;
> + int ret;
> +
> + if (!cpu_feature_enabled(X86_FEATURE_CPPC_PERF_PRIO))
> + return 0;
> +
> + ret = rdmsrq_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ2, &value);
> + if (ret) {
> + pr_err("failed to read CPPC REQ2 value. Error (%d)\n", ret);
> + return ret;
> + }
> +
> + WRITE_ONCE(cpudata->cppc_req2_cached, value);
> + floor_perf = FIELD_GET(AMD_CPPC_FLOOR_PERF_MASK,
> + cpudata->cppc_req2_cached);
> +
> + /* Set a sane value for floor_perf if the default value is invalid */
> + if (floor_perf < cpudata->perf.lowest_perf) {
> + floor_perf = cpudata->perf.nominal_perf;
> + ret = amd_pstate_set_floor_perf(policy, floor_perf);
> + if (ret)
> + return ret;
> + }
> +
> + return 0;
> +}
> +
> static int shmem_set_epp(struct cpufreq_policy *policy, u8 epp)
> {
> struct amd_cpudata *cpudata = policy->driver_data;
> @@ -426,6 +483,7 @@ static int msr_init_perf(struct amd_cpudata *cpudata)
> perf.lowest_perf = FIELD_GET(AMD_CPPC_LOWEST_PERF_MASK, cap1);
> WRITE_ONCE(cpudata->perf, perf);
> WRITE_ONCE(cpudata->prefcore_ranking, FIELD_GET(AMD_CPPC_HIGHEST_PERF_MASK, cap1));
> + WRITE_ONCE(cpudata->floor_perf_cnt, FIELD_GET(AMD_CPPC_FLOOR_PERF_CNT_MASK, cap1));
>
> return 0;
> }
> @@ -1036,6 +1094,12 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
> if (cpu_feature_enabled(X86_FEATURE_CPPC))
> policy->fast_switch_possible = true;
>
> + ret = amd_pstate_init_floor_perf(policy);
> + if (ret) {
> + dev_err(dev, "Failed to initialize Floor Perf (%d)\n", ret);
> + goto free_cpudata1;
> + }
> +
> ret = freq_qos_add_request(&policy->constraints, &cpudata->req[0],
> FREQ_QOS_MIN, FREQ_QOS_MIN_DEFAULT_VALUE);
> if (ret < 0) {
> @@ -1597,6 +1661,12 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
> if (ret)
> goto free_cpudata1;
>
> + ret = amd_pstate_init_floor_perf(policy);
> + if (ret) {
> + dev_err(dev, "Failed to initialize Floor Perf (%d)\n", ret);
> + goto free_cpudata1;
> + }
> +
> current_pstate_driver->adjust_perf = NULL;
>
> return 0;
> diff --git a/drivers/cpufreq/amd-pstate.h b/drivers/cpufreq/amd-pstate.h
> index cb45fdca27a6c..0c587ca200199 100644
> --- a/drivers/cpufreq/amd-pstate.h
> +++ b/drivers/cpufreq/amd-pstate.h
> @@ -62,9 +62,12 @@ struct amd_aperf_mperf {
> * @cpu: CPU number
> * @req: constraint request to apply
> * @cppc_req_cached: cached performance request hints
> + * @cppc_req2_cached: cached value of MSR_AMD_CPPC_REQ2
> * @perf: cached performance-related data
> * @prefcore_ranking: the preferred core ranking, the higher value indicates a higher
> * priority.
> + * @floor_perf_cnt: Cached value of the number of distinct floor
> + * performance levels supported
> * @min_limit_freq: Cached value of policy->min (in khz)
> * @max_limit_freq: Cached value of policy->max (in khz)
> * @nominal_freq: the frequency (in khz) that mapped to nominal_perf
> @@ -87,10 +90,12 @@ struct amd_cpudata {
>
> struct freq_qos_request req[2];
> u64 cppc_req_cached;
> + u64 cppc_req2_cached;
>
> union perf_cached perf;
>
> u8 prefcore_ranking;
> + u8 floor_perf_cnt;
> u32 min_limit_freq;
> u32 max_limit_freq;
> u32 nominal_freq;
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 6/9] amd-pstate: Add sysfs support for floor_freq and floor_count
2026-03-11 14:01 ` [PATCH v2 6/9] amd-pstate: Add sysfs support for floor_freq and floor_count Gautham R. Shenoy
@ 2026-03-12 20:57 ` Mario Limonciello (AMD) (kernel.org)
2026-03-12 21:24 ` Mario Limonciello (AMD) (kernel.org)
1 sibling, 0 replies; 18+ messages in thread
From: Mario Limonciello (AMD) (kernel.org) @ 2026-03-12 20:57 UTC (permalink / raw)
To: Gautham R. Shenoy, Rafael J . Wysocki, Viresh Kumar,
K Prateek Nayak
Cc: linux-kernel, linux-pm
On 3/11/2026 9:01 AM, Gautham R. Shenoy wrote:
> When Floor Performance feature is supported by the platform, expose
> two sysfs files:
>
> * amd_pstate_floor_freq to allow userspace to request the floor
> frequency for each CPU.
>
> * amd_pstate_floor_count which advertises the number of distinct
> levels of floor frequencies supported on this platform.
>
> Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
One nit below.
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
> ---
> drivers/cpufreq/amd-pstate.c | 50 ++++++++++++++++++++++++++++++++++++
> drivers/cpufreq/amd-pstate.h | 2 ++
> 2 files changed, 52 insertions(+)
>
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 3122ad5af6f47..54b650f3b4e78 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -383,6 +383,8 @@ static int amd_pstate_init_floor_perf(struct cpufreq_policy *policy)
> return ret;
> }
>
> + cpudata->floor_freq = perf_to_freq(cpudata->perf, cpudata->nominal_freq,
> + floor_perf);
> return 0;
> }
>
> @@ -1284,6 +1286,44 @@ static ssize_t show_energy_performance_preference(
> return sysfs_emit(buf, "%s\n", energy_perf_strings[preference]);
> }
>
> +static ssize_t store_amd_pstate_floor_freq(struct cpufreq_policy *policy,
> + const char *buf, size_t count)
> +{
> + struct amd_cpudata *cpudata = policy->driver_data;
> + union perf_cached perf = READ_ONCE(cpudata->perf);
> + unsigned int freq;
> + u8 floor_perf;
> + int ret;
> +
> + ret = kstrtouint(buf, 0, &freq);
> + if (ret)
> + return ret;
> +
> + floor_perf = freq_to_perf(perf, cpudata->nominal_freq, freq);
> + ret = amd_pstate_set_floor_perf(policy, floor_perf);
> +
> + if (!ret)
> + cpudata->floor_freq = freq;
> +
> + return ret ?: count;
> +}
> +
> +static ssize_t show_amd_pstate_floor_freq(struct cpufreq_policy *policy, char *buf)
> +{
> + struct amd_cpudata *cpudata = policy->driver_data;
> +
> + return sysfs_emit(buf, "%u\n", cpudata->floor_freq);
> +}
> +
> +
> +static ssize_t show_amd_pstate_floor_count(struct cpufreq_policy *policy, char *buf)
> +{
> + struct amd_cpudata *cpudata = policy->driver_data;
> + u8 count = cpudata->floor_perf_cnt;
> +
> + return sysfs_emit(buf, "%u\n", count);
just return cpudata->floor_perf_cnt instead of having a local variable.
> +}
> +
> cpufreq_freq_attr_ro(amd_pstate_max_freq);
> cpufreq_freq_attr_ro(amd_pstate_lowest_nonlinear_freq);
>
> @@ -1292,6 +1332,8 @@ cpufreq_freq_attr_ro(amd_pstate_prefcore_ranking);
> cpufreq_freq_attr_ro(amd_pstate_hw_prefcore);
> cpufreq_freq_attr_rw(energy_performance_preference);
> cpufreq_freq_attr_ro(energy_performance_available_preferences);
> +cpufreq_freq_attr_rw(amd_pstate_floor_freq);
> +cpufreq_freq_attr_ro(amd_pstate_floor_count);
>
> struct freq_attr_visibility {
> struct freq_attr *attr;
> @@ -1316,6 +1358,12 @@ static bool epp_visibility(void)
> return cppc_state == AMD_PSTATE_ACTIVE;
> }
>
> +/* Determines whether amd_pstate_floor_freq related attributes should be visible */
> +static bool floor_freq_visibility(void)
> +{
> + return cpu_feature_enabled(X86_FEATURE_CPPC_PERF_PRIO);
> +}
> +
> static struct freq_attr_visibility amd_pstate_attr_visibility[] = {
> {&amd_pstate_max_freq, always_visible},
> {&amd_pstate_lowest_nonlinear_freq, always_visible},
> @@ -1324,6 +1372,8 @@ static struct freq_attr_visibility amd_pstate_attr_visibility[] = {
> {&amd_pstate_hw_prefcore, prefcore_visibility},
> {&energy_performance_preference, epp_visibility},
> {&energy_performance_available_preferences, epp_visibility},
> + {&amd_pstate_floor_freq, floor_freq_visibility},
> + {&amd_pstate_floor_count, floor_freq_visibility},
> };
>
> static struct freq_attr **get_freq_attrs(void)
> diff --git a/drivers/cpufreq/amd-pstate.h b/drivers/cpufreq/amd-pstate.h
> index 0c587ca200199..ab4caea39f0e8 100644
> --- a/drivers/cpufreq/amd-pstate.h
> +++ b/drivers/cpufreq/amd-pstate.h
> @@ -72,6 +72,7 @@ struct amd_aperf_mperf {
> * @max_limit_freq: Cached value of policy->max (in khz)
> * @nominal_freq: the frequency (in khz) that mapped to nominal_perf
> * @lowest_nonlinear_freq: the frequency (in khz) that mapped to lowest_nonlinear_perf
> + * @floor_freq: Cached value of the user requested floor_freq
> * @cur: Difference of Aperf/Mperf/tsc count between last and current sample
> * @prev: Last Aperf/Mperf/tsc count value read from register
> * @freq: current cpu frequency value (in khz)
> @@ -100,6 +101,7 @@ struct amd_cpudata {
> u32 max_limit_freq;
> u32 nominal_freq;
> u32 lowest_nonlinear_freq;
> + u32 floor_freq;
>
> struct amd_aperf_mperf cur;
> struct amd_aperf_mperf prev;
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 8/9] Documentation/amd-pstate: List prefcore related sysfs files
2026-03-11 14:01 ` [PATCH v2 8/9] Documentation/amd-pstate: List prefcore related sysfs files Gautham R. Shenoy
@ 2026-03-12 20:58 ` Mario Limonciello
0 siblings, 0 replies; 18+ messages in thread
From: Mario Limonciello @ 2026-03-12 20:58 UTC (permalink / raw)
To: Gautham R. Shenoy, Rafael J . Wysocki, Viresh Kumar,
K Prateek Nayak
Cc: linux-kernel, linux-pm, Jonathan Corbet, Shuah Khan
On 3/11/2026 9:01 AM, Gautham R. Shenoy wrote:
> Add the missing amd_pstate_hw_prefcore and amd_pstate_prefcore_ranking
> filenames in the sysfs listing example leading to the descriptions of
> these parameters.
>
> Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
Can you please split this into two patches?
In the first track down and add a Fixes tag for your next spin for the
missing files.
In the second make the change about the visibility.
You can add to both:
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
> ---
> Documentation/admin-guide/pm/amd-pstate.rst | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/admin-guide/pm/amd-pstate.rst b/Documentation/admin-guide/pm/amd-pstate.rst
> index e1771f2225d5f..f566fea6613e6 100644
> --- a/Documentation/admin-guide/pm/amd-pstate.rst
> +++ b/Documentation/admin-guide/pm/amd-pstate.rst
> @@ -239,8 +239,10 @@ control its functionality at the system level. They are located in the
>
> root@hr-test1:/home/ray# ls /sys/devices/system/cpu/cpufreq/policy0/*amd*
> /sys/devices/system/cpu/cpufreq/policy0/amd_pstate_highest_perf
> + /sys/devices/system/cpu/cpufreq/policy0/amd_pstate_hw_prefcore
> /sys/devices/system/cpu/cpufreq/policy0/amd_pstate_lowest_nonlinear_freq
> /sys/devices/system/cpu/cpufreq/policy0/amd_pstate_max_freq
> + /sys/devices/system/cpu/cpufreq/policy0/amd_pstate_prefcore_ranking
>
>
> ``amd_pstate_highest_perf / amd_pstate_max_freq``
> @@ -264,14 +266,17 @@ This attribute is read-only.
>
> ``amd_pstate_hw_prefcore``
>
> -Whether the platform supports the preferred core feature and it has been
> -enabled. This attribute is read-only.
> +Whether the platform supports the preferred core feature and it has
> +been enabled. This attribute is read-only. This file is only visible
> +on platforms which support the preferred core feature.
>
> ``amd_pstate_prefcore_ranking``
>
> -The performance ranking of the core. This number doesn't have any unit, but
> -larger numbers are preferred at the time of reading. This can change at
> -runtime based on platform conditions. This attribute is read-only.
> +The performance ranking of the core. This number doesn't have any
> +unit, but larger numbers are preferred at the time of reading. This
> +can change at runtime based on platform conditions. This attribute is
> +read-only. This file is only visible on platforms which support the
> +preferred core feature.
>
> ``energy_performance_available_preferences``
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 9/9] Documentation/amd-pstate: Add documentation for amd_pstate_floor_{freq,count}
2026-03-11 14:01 ` [PATCH v2 9/9] Documentation/amd-pstate: Add documentation for amd_pstate_floor_{freq,count} Gautham R. Shenoy
@ 2026-03-12 20:59 ` Mario Limonciello (AMD) (kernel.org)
0 siblings, 0 replies; 18+ messages in thread
From: Mario Limonciello (AMD) (kernel.org) @ 2026-03-12 20:59 UTC (permalink / raw)
To: Gautham R. Shenoy, Rafael J . Wysocki, Viresh Kumar,
K Prateek Nayak
Cc: linux-kernel, linux-pm, Jonathan Corbet, Shuah Khan
On 3/11/2026 9:01 AM, Gautham R. Shenoy wrote:
> Add documentation for the sysfs files
> /sys/devices/system/cpu/cpufreq/policy*/amd_pstate_floor_freq
> and
> /sys/devices/system/cpu/cpufreq/policy*/amd_pstate_floor_count.
>
> Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
> ---
> Documentation/admin-guide/pm/amd-pstate.rst | 32 +++++++++++++++++++++
> 1 file changed, 32 insertions(+)
>
> diff --git a/Documentation/admin-guide/pm/amd-pstate.rst b/Documentation/admin-guide/pm/amd-pstate.rst
> index f566fea6613e6..5fd2a36f8a4b8 100644
> --- a/Documentation/admin-guide/pm/amd-pstate.rst
> +++ b/Documentation/admin-guide/pm/amd-pstate.rst
> @@ -242,6 +242,8 @@ control its functionality at the system level. They are located in the
> /sys/devices/system/cpu/cpufreq/policy0/amd_pstate_hw_prefcore
> /sys/devices/system/cpu/cpufreq/policy0/amd_pstate_lowest_nonlinear_freq
> /sys/devices/system/cpu/cpufreq/policy0/amd_pstate_max_freq
> + /sys/devices/system/cpu/cpufreq/policy0/amd_pstate_floor_freq
> + /sys/devices/system/cpu/cpufreq/policy0/amd_pstate_floor_count
> /sys/devices/system/cpu/cpufreq/policy0/amd_pstate_prefcore_ranking
>
>
> @@ -278,6 +280,36 @@ can change at runtime based on platform conditions. This attribute is
> read-only. This file is only visible on platforms which support the
> preferred core feature.
>
> +``amd_pstate_floor_freq``
> +
> +The floor frequency associated with each CPU. Userspace can write any
> +value between ``cpuinfo_min_freq`` and ``scaling_max_freq`` into this
> +file. When the system is under power or thermal constraints, the
> +platform firmware will attempt to throttle the CPU frequency to the
> +value specified in ``amd_pstate_floor_freq`` before throttling it
> +further. This allows userspace to specify different floor frequencies
> +to different CPUs. For optimal results, threads of the same core
> +should have the same floor frequency value. This file is only visible
> +on platforms that support the CPPC Performance Priority feature.
> +
> +
> +``amd_pstate_floor_count``
> +
> +The number of distinct Floor Performance levels supported by the
> +platform. For example, if this value is 2, then the number of unique
> +values obtained from the command ``cat
> +/sys/devices/system/cpu/cpufreq/policy*/amd_pstate_floor_freq |
> +sort -n | uniq`` should be at most this number for the behavior
> +described in ``amd_pstate_floor_freq`` to take effect. A zero value
> +implies that the platform supports unlimited floor performance levels.
> +This file is only visible on platforms that support the CPPC
> +Performance Priority feature.
> +
> +**Note**: When ``amd_pstate_floor_count`` is non-zero, the frequency to
> +which the CPU is throttled under power or thermal constraints is
> +undefined when the number of unique values of ``amd_pstate_floor_freq``
> +across all CPUs in the system exceeds ``amd_pstate_floor_count``.
> +
> ``energy_performance_available_preferences``
>
> A list of all the supported EPP preferences that could be used for
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 6/9] amd-pstate: Add sysfs support for floor_freq and floor_count
2026-03-11 14:01 ` [PATCH v2 6/9] amd-pstate: Add sysfs support for floor_freq and floor_count Gautham R. Shenoy
2026-03-12 20:57 ` Mario Limonciello (AMD) (kernel.org)
@ 2026-03-12 21:24 ` Mario Limonciello (AMD) (kernel.org)
1 sibling, 0 replies; 18+ messages in thread
From: Mario Limonciello (AMD) (kernel.org) @ 2026-03-12 21:24 UTC (permalink / raw)
To: Gautham R. Shenoy, Rafael J . Wysocki, Viresh Kumar,
K Prateek Nayak
Cc: linux-kernel, linux-pm
On 3/11/2026 9:01 AM, Gautham R. Shenoy wrote:
> When Floor Performance feature is supported by the platform, expose
> two sysfs files:
>
> * amd_pstate_floor_freq to allow userspace to request the floor
> frequency for each CPU.
>
> * amd_pstate_floor_count which advertises the number of distinct
> levels of floor frequencies supported on this platform.
>
> Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
One nit below.
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
> ---
> drivers/cpufreq/amd-pstate.c | 50 ++++++++++++++++++++++++++++++++++++
> drivers/cpufreq/amd-pstate.h | 2 ++
> 2 files changed, 52 insertions(+)
>
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 3122ad5af6f47..54b650f3b4e78 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -383,6 +383,8 @@ static int amd_pstate_init_floor_perf(struct cpufreq_policy *policy)
> return ret;
> }
>
> + cpudata->floor_freq = perf_to_freq(cpudata->perf, cpudata->nominal_freq,
> + floor_perf);
> return 0;
> }
>
> @@ -1284,6 +1286,44 @@ static ssize_t show_energy_performance_preference(
> return sysfs_emit(buf, "%s\n", energy_perf_strings[preference]);
> }
>
> +static ssize_t store_amd_pstate_floor_freq(struct cpufreq_policy *policy,
> + const char *buf, size_t count)
> +{
> + struct amd_cpudata *cpudata = policy->driver_data;
> + union perf_cached perf = READ_ONCE(cpudata->perf);
> + unsigned int freq;
> + u8 floor_perf;
> + int ret;
> +
> + ret = kstrtouint(buf, 0, &freq);
> + if (ret)
> + return ret;
> +
> + floor_perf = freq_to_perf(perf, cpudata->nominal_freq, freq);
> + ret = amd_pstate_set_floor_perf(policy, floor_perf);
> +
> + if (!ret)
> + cpudata->floor_freq = freq;
> +
> + return ret ?: count;
> +}
> +
> +static ssize_t show_amd_pstate_floor_freq(struct cpufreq_policy *policy, char *buf)
> +{
> + struct amd_cpudata *cpudata = policy->driver_data;
> +
> + return sysfs_emit(buf, "%u\n", cpudata->floor_freq);
> +}
> +
> +
Extra whitespace here
> +static ssize_t show_amd_pstate_floor_count(struct cpufreq_policy *policy, char *buf)
> +{
> + struct amd_cpudata *cpudata = policy->driver_data;
> + u8 count = cpudata->floor_perf_cnt;
> +
> + return sysfs_emit(buf, "%u\n", count);
> +}
> +
> cpufreq_freq_attr_ro(amd_pstate_max_freq);
> cpufreq_freq_attr_ro(amd_pstate_lowest_nonlinear_freq);
>
> @@ -1292,6 +1332,8 @@ cpufreq_freq_attr_ro(amd_pstate_prefcore_ranking);
> cpufreq_freq_attr_ro(amd_pstate_hw_prefcore);
> cpufreq_freq_attr_rw(energy_performance_preference);
> cpufreq_freq_attr_ro(energy_performance_available_preferences);
> +cpufreq_freq_attr_rw(amd_pstate_floor_freq);
> +cpufreq_freq_attr_ro(amd_pstate_floor_count);
>
> struct freq_attr_visibility {
> struct freq_attr *attr;
> @@ -1316,6 +1358,12 @@ static bool epp_visibility(void)
> return cppc_state == AMD_PSTATE_ACTIVE;
> }
>
> +/* Determines whether amd_pstate_floor_freq related attributes should be visible */
> +static bool floor_freq_visibility(void)
> +{
> + return cpu_feature_enabled(X86_FEATURE_CPPC_PERF_PRIO);
> +}
> +
> static struct freq_attr_visibility amd_pstate_attr_visibility[] = {
> {&amd_pstate_max_freq, always_visible},
> {&amd_pstate_lowest_nonlinear_freq, always_visible},
> @@ -1324,6 +1372,8 @@ static struct freq_attr_visibility amd_pstate_attr_visibility[] = {
> {&amd_pstate_hw_prefcore, prefcore_visibility},
> {&energy_performance_preference, epp_visibility},
> {&energy_performance_available_preferences, epp_visibility},
> + {&amd_pstate_floor_freq, floor_freq_visibility},
> + {&amd_pstate_floor_count, floor_freq_visibility},
> };
>
> static struct freq_attr **get_freq_attrs(void)
> diff --git a/drivers/cpufreq/amd-pstate.h b/drivers/cpufreq/amd-pstate.h
> index 0c587ca200199..ab4caea39f0e8 100644
> --- a/drivers/cpufreq/amd-pstate.h
> +++ b/drivers/cpufreq/amd-pstate.h
> @@ -72,6 +72,7 @@ struct amd_aperf_mperf {
> * @max_limit_freq: Cached value of policy->max (in khz)
> * @nominal_freq: the frequency (in khz) that mapped to nominal_perf
> * @lowest_nonlinear_freq: the frequency (in khz) that mapped to lowest_nonlinear_perf
> + * @floor_freq: Cached value of the user requested floor_freq
> * @cur: Difference of Aperf/Mperf/tsc count between last and current sample
> * @prev: Last Aperf/Mperf/tsc count value read from register
> * @freq: current cpu frequency value (in khz)
> @@ -100,6 +101,7 @@ struct amd_cpudata {
> u32 max_limit_freq;
> u32 nominal_freq;
> u32 lowest_nonlinear_freq;
> + u32 floor_freq;
>
> struct amd_aperf_mperf cur;
> struct amd_aperf_mperf prev;
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2026-03-12 21:24 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-11 14:01 [PATCH v2 0/9] amd-pstate: Introduce AMD CPPC Performance Priority Gautham R. Shenoy
2026-03-11 14:01 ` [PATCH v2 1/9] amd-pstate: Fix memory leak in amd_pstate_epp_cpu_init() Gautham R. Shenoy
2026-03-11 14:01 ` [PATCH v2 2/9] amd-pstate: Update cppc_req_cached in fast_switch case Gautham R. Shenoy
2026-03-12 20:41 ` Mario Limonciello (AMD) (kernel.org)
2026-03-11 14:01 ` [PATCH v2 3/9] amd-pstate: Make certain freq_attrs conditionally visible Gautham R. Shenoy
2026-03-12 6:49 ` Gautham R. Shenoy
2026-03-12 20:46 ` Mario Limonciello (AMD) (kernel.org)
2026-03-11 14:01 ` [PATCH v2 4/9] x86/cpufeatures: Add AMD CPPC Performance Priority feature Gautham R. Shenoy
2026-03-11 14:01 ` [PATCH v2 5/9] amd-pstate: Add support for CPPC_REQ2 and FLOOR_PERF Gautham R. Shenoy
2026-03-12 20:49 ` Mario Limonciello (AMD) (kernel.org)
2026-03-11 14:01 ` [PATCH v2 6/9] amd-pstate: Add sysfs support for floor_freq and floor_count Gautham R. Shenoy
2026-03-12 20:57 ` Mario Limonciello (AMD) (kernel.org)
2026-03-12 21:24 ` Mario Limonciello (AMD) (kernel.org)
2026-03-11 14:01 ` [PATCH v2 7/9] amd-pstate: Introduce a tracepoint trace_amd_pstate_cppc_req2() Gautham R. Shenoy
2026-03-11 14:01 ` [PATCH v2 8/9] Documentation/amd-pstate: List prefcore related sysfs files Gautham R. Shenoy
2026-03-12 20:58 ` Mario Limonciello
2026-03-11 14:01 ` [PATCH v2 9/9] Documentation/amd-pstate: Add documentation for amd_pstate_floor_{freq,count} Gautham R. Shenoy
2026-03-12 20:59 ` Mario Limonciello (AMD) (kernel.org)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox