public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Gautham R. Shenoy" <gautham.shenoy@amd.com>
To: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>
Cc: mario.limonciello@amd.com, perry.yuan@amd.com, rafael@kernel.org,
	viresh.kumar@linaro.org, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/5] cpufreq/amd-pstate: Refactor amd_pstate_epp_reenable() and amd_pstate_epp_offline()
Date: Fri, 6 Dec 2024 10:31:00 +0530	[thread overview]
Message-ID: <Z1KFDDFl3L7bHS9k@BLRRASHENOY1.amd.com> (raw)
In-Reply-To: <20241204144842.164178-4-Dhananjay.Ugwekar@amd.com>

On Wed, Dec 04, 2024 at 02:48:40PM +0000, Dhananjay Ugwekar wrote:
> Replace similar code chunks with amd_pstate_update_perf() and
> amd_pstate_set_epp() function calls.
> 
> Signed-off-by: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>
> ---
>  drivers/cpufreq/amd-pstate.c | 36 +++++++-----------------------------
>  1 file changed, 7 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index a1b2393cef22..a38be7727c9d 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -1630,25 +1630,17 @@ static int amd_pstate_epp_set_policy(struct cpufreq_policy *policy)
>  
>  static void amd_pstate_epp_reenable(struct amd_cpudata *cpudata)
>  {
> -	struct cppc_perf_ctrls perf_ctrls;
> -	u64 value, max_perf;
> +	u64 max_perf;
>  	int ret;
>  
>  	ret = amd_pstate_cppc_enable(true);
>  	if (ret)
>  		pr_err("failed to enable amd pstate during resume, return %d\n", ret);
>  
> -	value = READ_ONCE(cpudata->cppc_req_cached);
>  	max_perf = READ_ONCE(cpudata->highest_perf);
>  
> -	if (cpu_feature_enabled(X86_FEATURE_CPPC)) {
> -		wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value);
> -	} else {
> -		perf_ctrls.max_perf = max_perf;
> -		cppc_set_perf(cpudata->cpu, &perf_ctrls);
> -		perf_ctrls.energy_perf = AMD_CPPC_ENERGY_PERF_PREF(cpudata->epp_cached);
> -		cppc_set_epp_perf(cpudata->cpu, &perf_ctrls, 1);
> -	}
> +	amd_pstate_update_perf(cpudata, 0, 0, max_perf, false);
> +	amd_pstate_set_epp(cpudata, cpudata->epp_cached);

This will cause two MSR writes on MSR based systems.

But then, we don't expect the amd_pstate_epp_reenable() and
amd_pstate_epp_offline() to be called often. Hence it should be ok.

Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>

--
Thanks and Regards
gautham.




>  }
>  
>  static int amd_pstate_epp_cpu_online(struct cpufreq_policy *policy)
> @@ -1668,7 +1660,6 @@ static int amd_pstate_epp_cpu_online(struct cpufreq_policy *policy)
>  static void amd_pstate_epp_offline(struct cpufreq_policy *policy)
>  {
>  	struct amd_cpudata *cpudata = policy->driver_data;
> -	struct cppc_perf_ctrls perf_ctrls;
>  	int min_perf;
>  	u64 value;
>  
> @@ -1676,23 +1667,10 @@ static void amd_pstate_epp_offline(struct cpufreq_policy *policy)
>  	value = READ_ONCE(cpudata->cppc_req_cached);
>  
>  	mutex_lock(&amd_pstate_limits_lock);
> -	if (cpu_feature_enabled(X86_FEATURE_CPPC)) {
> -		cpudata->epp_policy = CPUFREQ_POLICY_UNKNOWN;
> -
> -		/* Set max perf same as min perf */
> -		value &= ~AMD_CPPC_MAX_PERF(~0L);
> -		value |= AMD_CPPC_MAX_PERF(min_perf);
> -		value &= ~AMD_CPPC_MIN_PERF(~0L);
> -		value |= AMD_CPPC_MIN_PERF(min_perf);
> -		wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value);
> -	} else {
> -		perf_ctrls.desired_perf = 0;
> -		perf_ctrls.min_perf = min_perf;
> -		perf_ctrls.max_perf = min_perf;
> -		cppc_set_perf(cpudata->cpu, &perf_ctrls);
> -		perf_ctrls.energy_perf = AMD_CPPC_ENERGY_PERF_PREF(HWP_EPP_BALANCE_POWERSAVE);
> -		cppc_set_epp_perf(cpudata->cpu, &perf_ctrls, 1);
> -	}
> +
> +	amd_pstate_update_perf(cpudata, min_perf, 0, min_perf, false);
> +	amd_pstate_set_epp(cpudata, AMD_CPPC_EPP_BALANCE_POWERSAVE);
> +
>  	mutex_unlock(&amd_pstate_limits_lock);
>  }
>  
> -- 
> 2.34.1
> 

  parent reply	other threads:[~2024-12-06  5:01 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-04 14:48 [PATCH 0/5] cpufreq/amd-pstate: Reuse and refactor code Dhananjay Ugwekar
2024-12-04 14:48 ` [PATCH 1/5] cpufreq/amd-pstate: Convert the amd_pstate_get/set_epp() to static calls Dhananjay Ugwekar
2024-12-06  4:43   ` Gautham R. Shenoy
2024-12-04 14:48 ` [PATCH 2/5] cpufreq/amd-pstate: Move the invocation of amd_pstate_update_perf() Dhananjay Ugwekar
2024-12-06  4:45   ` Gautham R. Shenoy
2024-12-04 14:48 ` [PATCH 3/5] cpufreq/amd-pstate: Refactor amd_pstate_epp_reenable() and amd_pstate_epp_offline() Dhananjay Ugwekar
2024-12-04 22:55   ` kernel test robot
2024-12-06  5:01   ` Gautham R. Shenoy [this message]
2024-12-04 14:48 ` [PATCH 4/5] cpufreq/amd-pstate: Remove the cppc_state check in offline/online functions Dhananjay Ugwekar
2024-12-04 14:48 ` [PATCH 5/5] cpufreq/amd-pstate: Merge amd_pstate_epp_cpu_offline() and amd_pstate_epp_offline() Dhananjay Ugwekar
2024-12-04 17:07 ` [PATCH 0/5] cpufreq/amd-pstate: Reuse and refactor code Mario Limonciello
2024-12-05  4:29   ` Dhananjay Ugwekar
2024-12-05  4:50     ` 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=Z1KFDDFl3L7bHS9k@BLRRASHENOY1.amd.com \
    --to=gautham.shenoy@amd.com \
    --cc=Dhananjay.Ugwekar@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=perry.yuan@amd.com \
    --cc=rafael@kernel.org \
    --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