From: Mario Limonciello <superm1@kernel.org>
To: K Prateek Nayak <kprateek.nayak@amd.com>,
Huang Rui <ray.huang@amd.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>,
Kalpana Shetty <kalpana.shetty@amd.com>
Cc: Mario Limonciello <superm1@kernel.org>,
Perry Yuan <perry.yuan@amd.com>,
linux-pm@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 9/9] cpufreq/amd-pstate-ut: Add unit test for CPPC Performance Priority
Date: Fri, 24 Jul 2026 14:04:14 -0500 [thread overview]
Message-ID: <409ce8fd-e2b9-4b0f-94d8-1d473e0d269c@kernel.org> (raw)
In-Reply-To: <20260723201228.22584-10-kprateek.nayak@amd.com>
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@amd.com>
> Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com>
> ---
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
> 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;
>
next prev parent reply other threads:[~2026-07-24 19:04 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 20:12 [PATCH v2 0/9] cpufreq/amd-pstate: BIOS min perf fixes and Dynamic EPP rework K Prateek Nayak
2026-07-23 20:12 ` [PATCH v2 1/9] cpufreq/amd-pstate: Set min_limit_freq based on bios_min_perf K Prateek Nayak
2026-07-23 20:12 ` [PATCH v2 2/9] cpufreq/amd-pstate: Remove the defensive check for bios_min_perf K Prateek Nayak
2026-07-23 21:17 ` Mario Limonciello
2026-07-23 20:12 ` [PATCH v2 3/9] cpufreq/amd-pstate: Extract platform profile to EPP conversion into a helper K Prateek Nayak
2026-07-23 20:12 ` [PATCH v2 4/9] cpufreq/amd-pstate: Add dynamic EPP as an "energy_performance_preference" mode K Prateek Nayak
2026-07-24 18:55 ` Mario Limonciello
2026-07-23 20:12 ` [PATCH v2 5/9] cpufreq/amd-pstate: Remove "amd_dynamic_epp" cmdline and "dynamic_epp" sysfs K Prateek Nayak
2026-07-24 18:55 ` Mario Limonciello
2026-07-23 20:12 ` [PATCH v2 6/9] Documentation/amd-pstate: Update dynamic_epp documentation with new behavior K Prateek Nayak
2026-07-24 18:57 ` Mario Limonciello
2026-07-23 20:12 ` [PATCH v2 7/9] cpufreq/amd-pstate: Reduce the scope of exported symbols K Prateek Nayak
2026-07-23 20:12 ` [PATCH v2 8/9] cpufreq/amd-pstate-ut: Add unit test for "dynamic" EPP mode K Prateek Nayak
2026-07-24 19:04 ` Mario Limonciello
2026-07-23 20:12 ` [PATCH v2 9/9] cpufreq/amd-pstate-ut: Add unit test for CPPC Performance Priority K Prateek Nayak
2026-07-24 19:04 ` Mario Limonciello [this message]
2026-07-24 19:07 ` [PATCH v2 0/9] cpufreq/amd-pstate: BIOS min perf fixes and Dynamic EPP rework Mario Limonciello
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=409ce8fd-e2b9-4b0f-94d8-1d473e0d269c@kernel.org \
--to=superm1@kernel.org \
--cc=kalpana.shetty@amd.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=perry.yuan@amd.com \
--cc=rafael@kernel.org \
--cc=ray.huang@amd.com \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox