Re: [PATCH v2 1/5] cpufreq/amd-pstate: Add dynamic energy performance preference

From: Dhananjay Ugwekar
Date: Wed Mar 12 2025 - 08:16:53 EST


On 3/4/2025 8:53 PM, Mario Limonciello wrote:
> From: Mario Limonciello <mario.limonciello@xxxxxxx>
>
> Dynamic energy performance preference will change the EPP profile
> based on whether the machine is running on AC or DC power.
>
> A notification chain from the power supply core is used to adjust
> EPP values on plug in or plug out events.
>
> For non-server systems:
> * the default EPP for AC mode is `performance`.
> * the default EPP for DC mode is `balance_performance`.
>
> Signed-off-by: Mario Limonciello <mario.limonciello@xxxxxxx>
> ---
> v1->v2:
> * Change defaults to performance (AC) and balance_performance (DC)
> * Default Kconfig to disabled for now
> * Rebase on latest branch
> ---
> Documentation/admin-guide/pm/amd-pstate.rst | 18 ++-
> drivers/cpufreq/Kconfig.x86 | 12 ++
> drivers/cpufreq/amd-pstate.c | 129 ++++++++++++++++++--
> drivers/cpufreq/amd-pstate.h | 5 +-
> 4 files changed, 155 insertions(+), 9 deletions(-)
>
[Snip]
> @@ -1556,6 +1667,10 @@ static int amd_pstate_epp_set_policy(struct cpufreq_policy *policy)
> if (!policy->cpuinfo.max_freq)
> return -ENODEV;
>
> + /* policy can't be changed to performance policy while dynamic epp is enabled */
> + if (policy->policy == CPUFREQ_POLICY_PERFORMANCE && cpudata->dynamic_epp)
> + return -EBUSY;

We might need to tweak this condition, because if we enable "CONFIG_X86_AMD_PSTATE_DYNAMIC_EPP" in config
and boot with "amd_pstate=active" it lands here (cpufreq_online()->amd_pstate_epp_set_policy()) driver init fails
as the default governor is performance.

> +
> cpudata->policy = policy->policy;
>
> ret = amd_pstate_epp_update_limit(policy);
> diff --git a/drivers/cpufreq/amd-pstate.h b/drivers/cpufreq/amd-pstate.h
> index fbe1c08d3f061..6882876f895de 100644
> --- a/drivers/cpufreq/amd-pstate.h
> +++ b/drivers/cpufreq/amd-pstate.h
> @@ -104,7 +104,10 @@ struct amd_cpudata {
> /* EPP feature related attributes*/
> u32 policy;
> bool suspended;
> - u8 epp_default;
> + u8 epp_default_ac;
> + u8 epp_default_dc;
> + bool dynamic_epp;
> + struct notifier_block power_nb;
> };
>
> /*