mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Mario Limonciello <mario.limonciello@amd.com>
Cc: Perry Yuan <perry.yuan@amd.com>,
	"open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
	<linux-kernel@vger.kernel.org>,
	"open list:CPU FREQUENCY SCALING FRAMEWORK"
	<linux-pm@vger.kernel.org>
Subject: Re: [PATCH] cpufreq: amd-pstate: Preserve names for aliased EPP values
Date: Wed, 14 Oct 2026 14:33:45 +0530	[thread overview]
Message-ID: <e2a7a5c9-0886-4130-894b-dda93854e36b@amd.com> (raw)
In-Reply-To: <20261012205559.3421297-1-mario.limonciello@amd.com>

Hello Mario,

On 10/13/2026 2:25 AM, Mario Limonciello wrote:
> Zen6 low-power cores use the same numeric EPP value for the
> balance_performance, balance_power, and power preferences. The show
> callback currently scans the numeric values and returns the first matching
> name, so writing balance_power or power reads back as
> balance_performance.
> 
> Cache the index of the last successfully written static named preference.
> Return that name while the cached numeric EPP still agrees, retaining the
> numeric lookup as a fallback for boot, firmware, default, and dynamic
> states.
> 
> Make the unit test require exact string round-tripping again.
> 
> Fixes: 52763c00945a ("cpufreq: amd-pstate: Update Zen6 client EPP tuning values")
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>

Feel free to include:

Reviewed-by: K Prateek Nayak <kprateek.nayak@amd.com>
Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>

One small nit. below:


> @@ -1548,6 +1551,14 @@ ssize_t show_energy_performance_preference(struct cpufreq_policy *policy, char *
>  	if (!cpudata->dynamic_epp && cpudata->raw_epp)
>  		return sysfs_emit(buf, "%u\n", epp);
>  
> +	/* Several named preferences may share the same numeric EPP value. */
> +	if (!cpudata->dynamic_epp &&
> +	    cpudata->epp_index >= EPP_INDEX_PERFORMANCE &&
> +	    cpudata->epp_index <= EPP_INDEX_POWERSAVE &&
> +	    epp == values[cpudata->epp_index])

That checks seems overly defensive. And I have a hunch ...

> +		return sysfs_emit(buf, "%s\n",
> +				  energy_perf_strings[cpudata->epp_index]);
> +
>  	/*
>  	 * Map the cached EPP value back to a named preference. Skip the
>  	 * "default" slot (index 0) so an EPP of 0 reports as "performance".
> @@ -1980,6 +1991,7 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
>  
>  	cpudata->cpu = policy->cpu;
>  	cpudata->cpu_type = cpu_data(policy->cpu).topo.cpu_type;
> +	cpudata->epp_index = EPP_INDEX_MAX;

... it is mostly to handle this case. Can we instead initialize it to
the correct index and say if epp_index != EPP_INDEX_MAX, use the
index to derive string always?

Something like below squashed into your patch:

  (Tested with amd-pstate-ut on top of your patch)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 8eebba922219..1f64726348bc 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -1504,7 +1504,7 @@ ssize_t store_energy_performance_preference(struct cpufreq_policy *policy,
 			if (ret)
 				return ret;
 
-			return count;
+			goto success;
 		}
 
 		if (ret) {
@@ -1533,6 +1533,7 @@ ssize_t store_energy_performance_preference(struct cpufreq_policy *policy,
 		return ret;
 
 	cpudata->raw_epp = raw_epp;
+success:
 	cpudata->epp_index = epp_index;
 
 	return count;
@@ -1552,10 +1553,7 @@ ssize_t show_energy_performance_preference(struct cpufreq_policy *policy, char *
 		return sysfs_emit(buf, "%u\n", epp);
 
 	/* Several named preferences may share the same numeric EPP value. */
-	if (!cpudata->dynamic_epp &&
-	    cpudata->epp_index >= EPP_INDEX_PERFORMANCE &&
-	    cpudata->epp_index <= EPP_INDEX_POWERSAVE &&
-	    epp == values[cpudata->epp_index])
+	if (cpudata->epp_index != EPP_INDEX_MAX)
 		return sysfs_emit(buf, "%s\n",
 				  energy_perf_strings[cpudata->epp_index]);
 
@@ -1980,7 +1978,6 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
 
 	cpudata->cpu = policy->cpu;
 	cpudata->cpu_type = cpu_data(policy->cpu).topo.cpu_type;
-	cpudata->epp_index = EPP_INDEX_MAX;
 
 	ret = amd_pstate_init_perf(cpudata);
 	if (ret)
@@ -2030,6 +2027,7 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
 		policy->policy = CPUFREQ_POLICY_PERFORMANCE;
 		cpudata->epp_default_ac = cpudata->epp_default_dc = default_epp;
 		cpudata->current_profile = PLATFORM_PROFILE_PERFORMANCE;
+		cpudata->epp_index = EPP_INDEX_PERFORMANCE;
 	} else {
 		u8 *values = amd_pstate_cpu_epp_values(cpudata->cpu_type);
 
@@ -2037,6 +2035,7 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
 		cpudata->epp_default_ac = values[EPP_INDEX_PERFORMANCE];
 		cpudata->epp_default_dc = values[EPP_INDEX_BALANCE_PERFORMANCE];
 		cpudata->current_profile = PLATFORM_PROFILE_BALANCED;
+		cpudata->epp_index = EPP_INDEX_BALANCE_PERFORMANCE;
 	}
 
 	ret = amd_pstate_set_epp(policy, cpudata->epp_default_dc);
-- 
Thanks and Regards,
Prateek


      reply	other threads:[~2026-10-14  9:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 20:55 Mario Limonciello
2026-10-14  9:03 ` K Prateek Nayak [this message]

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=e2a7a5c9-0886-4130-894b-dda93854e36b@amd.com \
    --to=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=perry.yuan@amd.com \
    /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

all inboxes | Powered by JetHome®