mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
To: "Mario Limonciello (AMD)" <superm1@kernel.org>,
	"Gautham R . Shenoy" <gautham.shenoy@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>,
	zhongqiu.han@oss.qualcomm.com
Subject: Re: [PATCH v2] cpufreq/amd-pstate: Cache the max frequency in cpudata
Date: Tue, 24 Mar 2026 11:54:53 +0800	[thread overview]
Message-ID: <3722f045-666b-4802-952c-359be6221809@oss.qualcomm.com> (raw)
In-Reply-To: <20260323043253.722730-1-superm1@kernel.org>

On 3/23/2026 12:32 PM, Mario Limonciello (AMD) wrote:
> The value of maximum frequency is fixed and never changes. Doing
> calculations every time based off of perf is unnecessary.
> 
> Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
> ---
> v2:
>   * Remove unused variable
> ---
>   drivers/cpufreq/amd-pstate.c | 27 +++++++++------------------
>   drivers/cpufreq/amd-pstate.h |  1 +
>   2 files changed, 10 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 5aa9fcd80cf51..9f80f8b23a43f 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -757,15 +757,13 @@ static void amd_pstate_adjust_perf(unsigned int cpu,
>   static int amd_pstate_cpu_boost_update(struct cpufreq_policy *policy, bool on)
>   {
>   	struct amd_cpudata *cpudata = policy->driver_data;
> -	union perf_cached perf = READ_ONCE(cpudata->perf);
> -	u32 nominal_freq, max_freq;
> +	u32 nominal_freq;
>   	int ret = 0;
>   
>   	nominal_freq = READ_ONCE(cpudata->nominal_freq);
> -	max_freq = perf_to_freq(perf, cpudata->nominal_freq, perf.highest_perf);
>   
>   	if (on)
> -		policy->cpuinfo.max_freq = max_freq;
> +		policy->cpuinfo.max_freq = cpudata->max_freq;
>   	else if (policy->cpuinfo.max_freq > nominal_freq)
>   		policy->cpuinfo.max_freq = nominal_freq;
>   
> @@ -952,13 +950,15 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata)
>   
>   	WRITE_ONCE(cpudata->nominal_freq, nominal_freq);
>   
> +	/* max_freq is calculated according to (nominal_freq * highest_perf)/nominal_perf */
>   	max_freq = perf_to_freq(perf, nominal_freq, perf.highest_perf);
> +	WRITE_ONCE(cpudata->max_freq, max_freq);
> +
>   	lowest_nonlinear_freq = perf_to_freq(perf, nominal_freq, perf.lowest_nonlinear_perf);
>   	WRITE_ONCE(cpudata->lowest_nonlinear_freq, lowest_nonlinear_freq);
>   
>   	/**
>   	 * Below values need to be initialized correctly, otherwise driver will fail to load
> -	 * max_freq is calculated according to (nominal_freq * highest_perf)/nominal_perf
>   	 * lowest_nonlinear_freq is a value between [min_freq, nominal_freq]
>   	 * Check _CPC in ACPI table objects if any values are incorrect
>   	 */
> @@ -1021,9 +1021,7 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
>   	policy->cpuinfo.min_freq = policy->min = perf_to_freq(perf,
>   							      cpudata->nominal_freq,
>   							      perf.lowest_perf);
> -	policy->cpuinfo.max_freq = policy->max = perf_to_freq(perf,
> -							      cpudata->nominal_freq,
> -							      perf.highest_perf);
> +	policy->cpuinfo.max_freq = policy->max = cpudata->max_freq;
>   
>   	ret = amd_pstate_cppc_enable(policy);
>   	if (ret)
> @@ -1090,14 +1088,9 @@ static void amd_pstate_cpu_exit(struct cpufreq_policy *policy)
>   static ssize_t show_amd_pstate_max_freq(struct cpufreq_policy *policy,
>   					char *buf)
>   {
> -	struct amd_cpudata *cpudata;
> -	union perf_cached perf;
> -
> -	cpudata = policy->driver_data;
> -	perf = READ_ONCE(cpudata->perf);
> +	struct amd_cpudata *cpudata = policy->driver_data;
>   
> -	return sysfs_emit(buf, "%u\n",
> -			  perf_to_freq(perf, cpudata->nominal_freq, perf.highest_perf));
> +	return sysfs_emit(buf, "%u\n", cpudata->max_freq);
>   }
>   
>   static ssize_t show_amd_pstate_lowest_nonlinear_freq(struct cpufreq_policy *policy,
> @@ -1503,9 +1496,7 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
>   	policy->cpuinfo.min_freq = policy->min = perf_to_freq(perf,
>   							      cpudata->nominal_freq,
>   							      perf.lowest_perf);
> -	policy->cpuinfo.max_freq = policy->max = perf_to_freq(perf,
> -							      cpudata->nominal_freq,
> -							      perf.highest_perf);
> +	policy->cpuinfo.max_freq = policy->max = cpudata->max_freq;
>   	policy->driver_data = cpudata;
>   
>   	ret = amd_pstate_cppc_enable(policy);
> diff --git a/drivers/cpufreq/amd-pstate.h b/drivers/cpufreq/amd-pstate.h
> index cb45fdca27a6c..485ee023d79c5 100644
> --- a/drivers/cpufreq/amd-pstate.h
> +++ b/drivers/cpufreq/amd-pstate.h
> @@ -94,6 +94,7 @@ struct amd_cpudata {
>   	u32	min_limit_freq;
>   	u32	max_limit_freq;
>   	u32	nominal_freq;
> +	u32	max_freq;

Hi Mario,

A minor finding: the new u32 max_freq field is missing a kdoc entry in
struct amd_cpudata.


>   	u32	lowest_nonlinear_freq;
>   
>   	struct amd_aperf_mperf cur;


-- 
Thx and BRs,
Zhongqiu Han

      reply	other threads:[~2026-03-24  3:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-23  4:32 Mario Limonciello (AMD)
2026-03-24  3:54 ` Zhongqiu Han [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=3722f045-666b-4802-952c-359be6221809@oss.qualcomm.com \
    --to=zhongqiu.han@oss.qualcomm.com \
    --cc=gautham.shenoy@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=perry.yuan@amd.com \
    --cc=superm1@kernel.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

all inboxes | Powered by JetHome®