Re: [PATCH v2 9/9] cpufreq/amd-pstate-ut: Add unit test for CPPC Performance Priority

From: Mario Limonciello

Date: Fri Jul 24 2026 - 15:10:26 EST




On 7/23/26 15:12, K Prateek Nayak wrote:
Add a unit test for CPPC Performance Priority that modifies the floor
perf and confirms if the modification was successful similar to the
energy_performance_preference unit test.

On platforms that do not support X86_FEATURE_CPPC_PERF_PRIO, the test
returns -EOPNOTSUPP and amd_pstate_ut_check_floor_freq is marked as
"skipped".

Suggested-by: Kalpana Shetty <kalpana.shetty@xxxxxxx>
Signed-off-by: K Prateek Nayak <kprateek.nayak@xxxxxxx>
---
Reviewed-by: Mario Limonciello (AMD) <superm1@xxxxxxxxxx>
changelog rfc v1..v2:

o New patch.
---
drivers/cpufreq/amd-pstate-ut.c | 83 ++++++++++++++++++++++++++++++++-
drivers/cpufreq/amd-pstate.c | 7 +--
drivers/cpufreq/amd-pstate.h | 2 +
3 files changed, 87 insertions(+), 5 deletions(-)

diff --git a/drivers/cpufreq/amd-pstate-ut.c b/drivers/cpufreq/amd-pstate-ut.c
index d1f730e3502b..6a17941380c2 100644
--- a/drivers/cpufreq/amd-pstate-ut.c
+++ b/drivers/cpufreq/amd-pstate-ut.c
@@ -59,6 +59,7 @@ static int amd_pstate_ut_check_freq(u32 index);
static int amd_pstate_ut_epp(u32 index);
static int amd_pstate_ut_check_driver(u32 index);
static int amd_pstate_ut_check_freq_attrs(u32 index);
+static int amd_pstate_ut_check_floor_freq(u32 index);
static struct amd_pstate_ut_struct amd_pstate_ut_cases[] = {
{"amd_pstate_ut_acpi_cpc_valid", amd_pstate_ut_acpi_cpc_valid },
@@ -68,6 +69,7 @@ static struct amd_pstate_ut_struct amd_pstate_ut_cases[] = {
{"amd_pstate_ut_epp", amd_pstate_ut_epp },
{"amd_pstate_ut_check_driver", amd_pstate_ut_check_driver },
{"amd_pstate_ut_check_freq_attrs", amd_pstate_ut_check_freq_attrs },
+ {"amd_pstate_ut_check_floor_freq", amd_pstate_ut_check_floor_freq },
};
static bool test_in_list(const char *list, const char *name)
@@ -560,6 +562,77 @@ static int amd_pstate_ut_check_freq_attrs(u32 index)
return ret;
}
+static int amd_pstate_ut_check_floor_freq(u32 index)
+{
+ struct cpufreq_policy *policy __free(put_cpufreq_policy) = NULL;
+ char *buf __free(cleanup_page) = NULL;
+ unsigned int orig_floor_freq;
+ unsigned int floor_freq;
+ int ret, cpu = 0;
+
+ if (!cpu_feature_enabled(X86_FEATURE_CPPC_PERF_PRIO))
+ return -EOPNOTSUPP;
+
+ policy = cpufreq_cpu_get(cpu);
+ if (!policy || !policy->driver_data)
+ return -ENODEV;
+
+ buf = (char *)__get_free_page(GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+
+ guard(rwsem_write)(&policy->rwsem);
+
+ /* Retrieve original floor frequency */
+ memset(buf, 0, PAGE_SIZE);
+ ret = show_amd_pstate_floor_freq(policy, buf);
+ if (ret < 0)
+ return ret;
+
+ ret = kstrtou32(buf, 0, &orig_floor_freq);
+ if (ret)
+ return ret;
+
+ memset(buf, 0, PAGE_SIZE);
+ snprintf(buf, PAGE_SIZE, "%u", policy->cpuinfo.min_freq);
+
+ /* Set floor frequency to cpuinfo.min_freq */
+ ret = store_amd_pstate_floor_freq(policy, buf, strlen(buf));
+ if (ret < 0) {
+ pr_err("Failed to set floor frequency to %s\n", buf);
+ return ret;
+ }
+
+ memset(buf, 0, PAGE_SIZE);
+ ret = show_amd_pstate_floor_freq(policy, buf);
+ if (ret < 0)
+ return ret;
+
+ strreplace(buf, '\n', '\0');
+ ret = kstrtou32(buf, 0, &floor_freq);
+ if (ret)
+ return ret;
+
+ /* Confirm sysfs reflects the change correctly. */
+ if (floor_freq != policy->cpuinfo.min_freq) {
+ pr_err("Floor frequency value mismatch: %u != %u\n",
+ floor_freq, policy->cpuinfo.min_freq);
+ return -EINVAL;
+ }
+
+ memset(buf, 0, PAGE_SIZE);
+ snprintf(buf, PAGE_SIZE, "%u", orig_floor_freq);
+
+ /* Restore the original value. */
+ ret = store_amd_pstate_floor_freq(policy, buf, strlen(buf));
+ if (ret < 0) {
+ pr_err("Failed to restore floor frequency to %s\n", buf);
+ return ret;
+ }
+
+ return 0;
+}
+
static int __init amd_pstate_ut_init(void)
{
u32 i = 0, arr_size = ARRAY_SIZE(amd_pstate_ut_cases);
@@ -578,10 +651,16 @@ static int __init amd_pstate_ut_init(void)
ret = amd_pstate_ut_cases[i].func(i);
- if (ret)
+ if (ret) {
+ /* Platform does not support the feature being tested. */
+ if (ret == -EOPNOTSUPP) {
+ pr_err("%-4d %-20s\t skipped!\n", i+1, amd_pstate_ut_cases[i].name);
+ continue;
+ }
pr_err("%-4d %-20s\t fail: %d!\n", i+1, amd_pstate_ut_cases[i].name, ret);
- else
+ } else {
pr_info("%-4d %-20s\t success!\n", i+1, amd_pstate_ut_cases[i].name);
+ }
}
return 0;
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index b875e92103e1..a42899722a21 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -1502,8 +1502,7 @@ ssize_t show_energy_performance_preference(struct cpufreq_policy *policy, char *
}
EXPORT_SYMBOL_FOR_PSTATE_UT(show_energy_performance_preference);
-static ssize_t store_amd_pstate_floor_freq(struct cpufreq_policy *policy,
- const char *buf, size_t count)
+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);
@@ -1526,13 +1525,15 @@ static ssize_t store_amd_pstate_floor_freq(struct cpufreq_policy *policy,
return ret ?: count;
}
+EXPORT_SYMBOL_FOR_PSTATE_UT(store_amd_pstate_floor_freq);
-static ssize_t show_amd_pstate_floor_freq(struct cpufreq_policy *policy, char *buf)
+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);
}
+EXPORT_SYMBOL_FOR_PSTATE_UT(show_amd_pstate_floor_freq);
static ssize_t show_amd_pstate_floor_count(struct cpufreq_policy *policy, char *buf)
{
diff --git a/drivers/cpufreq/amd-pstate.h b/drivers/cpufreq/amd-pstate.h
index edd697a5e29f..f8e2f6ba1534 100644
--- a/drivers/cpufreq/amd-pstate.h
+++ b/drivers/cpufreq/amd-pstate.h
@@ -160,6 +160,8 @@ ssize_t store_energy_performance_preference(struct cpufreq_policy *policy,
const char *buf, size_t count);
ssize_t show_energy_performance_preference(struct cpufreq_policy *policy, char *buf);
void amd_pstate_clear_dynamic_epp(struct cpufreq_policy *policy);
+ssize_t store_amd_pstate_floor_freq(struct cpufreq_policy *policy, const char *buf, size_t count);
+ssize_t show_amd_pstate_floor_freq(struct cpufreq_policy *policy, char *buf);
struct freq_attr;