All of lore.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 1/5] cpufreq/amd-pstate: Convert the amd_pstate_get/set_epp() to static calls
Date: Fri, 6 Dec 2024 10:13:31 +0530	[thread overview]
Message-ID: <Z1KA82G2rajkCHLx@BLRRASHENOY1.amd.com> (raw)
In-Reply-To: <20241204144842.164178-2-Dhananjay.Ugwekar@amd.com>

Hello Dhananjay,

On Wed, Dec 04, 2024 at 02:48:38PM +0000, Dhananjay Ugwekar wrote:
> MSR and shared memory based systems have different mechanisms to get and
> set the epp value. Split those mechanisms into different functions and
> assign them appropriately to the static calls at boot time. This eliminates
> the need for the "if(cpu_feature_enabled(X86_FEATURE_CPPC))" checks at
> runtime.
> 
> Also, propagate the error code from rdmsrl_on_cpu() and cppc_get_epp_perf()
> to *_get_epp()'s caller, instead of returning -EIO unconditionally.
> 
> Signed-off-by: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>

Thanks for taking this up.
This patch looks good to me.

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

--
Thanks and Regards
gautham.

> ---
>  drivers/cpufreq/amd-pstate.c | 92 +++++++++++++++++++++++-------------
>  1 file changed, 60 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index d7630bab2516..d391e8cafeca 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -180,26 +180,40 @@ static inline int get_mode_idx_from_str(const char *str, size_t size)
>  static DEFINE_MUTEX(amd_pstate_limits_lock);
>  static DEFINE_MUTEX(amd_pstate_driver_lock);
>  
> -static s16 amd_pstate_get_epp(struct amd_cpudata *cpudata, u64 cppc_req_cached)
> +static s16 msr_get_epp(struct amd_cpudata *cpudata, u64 cppc_req_cached)
>  {
>  	u64 epp;
>  	int ret;
>  
> -	if (cpu_feature_enabled(X86_FEATURE_CPPC)) {
> -		if (!cppc_req_cached) {
> -			epp = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ,
> -					&cppc_req_cached);
> -			if (epp)
> -				return epp;
> -		}
> -		epp = (cppc_req_cached >> 24) & 0xFF;
> -	} else {
> -		ret = cppc_get_epp_perf(cpudata->cpu, &epp);
> +	if (!cppc_req_cached) {
> +		ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, &cppc_req_cached);
>  		if (ret < 0) {
>  			pr_debug("Could not retrieve energy perf value (%d)\n", ret);
> -			return -EIO;
> +			return ret;
>  		}
>  	}
> +	epp = (cppc_req_cached >> 24) & 0xFF;
> +
> +	return (s16)epp;
> +}
> +
> +DEFINE_STATIC_CALL(amd_pstate_get_epp, msr_get_epp);
> +
> +static inline s16 amd_pstate_get_epp(struct amd_cpudata *cpudata, u64 cppc_req_cached)
> +{
> +	return static_call(amd_pstate_get_epp)(cpudata, cppc_req_cached);
> +}
> +
> +static s16 shmem_get_epp(struct amd_cpudata *cpudata, u64 dummy)
> +{
> +	u64 epp;
> +	int ret;
> +
> +	ret = cppc_get_epp_perf(cpudata->cpu, &epp);
> +	if (ret < 0) {
> +		pr_debug("Could not retrieve energy perf value (%d)\n", ret);
> +		return ret;
> +	}
>  
>  	return (s16)(epp & 0xff);
>  }
> @@ -253,33 +267,45 @@ static inline void amd_pstate_update_perf(struct amd_cpudata *cpudata,
>  					    max_perf, fast_switch);
>  }
>  
> -static int amd_pstate_set_epp(struct amd_cpudata *cpudata, u32 epp)
> +static int msr_set_epp(struct amd_cpudata *cpudata, u32 epp)
>  {
>  	int ret;
> -	struct cppc_perf_ctrls perf_ctrls;
> -
> -	if (cpu_feature_enabled(X86_FEATURE_CPPC)) {
> -		u64 value = READ_ONCE(cpudata->cppc_req_cached);
>  
> -		value &= ~GENMASK_ULL(31, 24);
> -		value |= (u64)epp << 24;
> -		WRITE_ONCE(cpudata->cppc_req_cached, value);
> +	u64 value = READ_ONCE(cpudata->cppc_req_cached);
>  
> -		ret = wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value);
> -		if (!ret)
> -			cpudata->epp_cached = epp;
> -	} else {
> -		amd_pstate_update_perf(cpudata, cpudata->min_limit_perf, 0U,
> -					     cpudata->max_limit_perf, false);
> +	value &= ~GENMASK_ULL(31, 24);
> +	value |= (u64)epp << 24;
> +	WRITE_ONCE(cpudata->cppc_req_cached, value);
>  
> -		perf_ctrls.energy_perf = epp;
> -		ret = cppc_set_epp_perf(cpudata->cpu, &perf_ctrls, 1);
> -		if (ret) {
> -			pr_debug("failed to set energy perf value (%d)\n", ret);
> -			return ret;
> -		}
> +	ret = wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value);
> +	if (!ret)
>  		cpudata->epp_cached = epp;
> +
> +	return ret;
> +}
> +
> +DEFINE_STATIC_CALL(amd_pstate_set_epp, msr_set_epp);
> +
> +static inline int amd_pstate_set_epp(struct amd_cpudata *cpudata, u32 epp)
> +{
> +	return static_call(amd_pstate_set_epp)(cpudata, epp);
> +}
> +
> +static int shmem_set_epp(struct amd_cpudata *cpudata, u32 epp)
> +{
> +	int ret;
> +	struct cppc_perf_ctrls perf_ctrls;
> +
> +	amd_pstate_update_perf(cpudata, cpudata->min_limit_perf, 0U,
> +				     cpudata->max_limit_perf, false);
> +
> +	perf_ctrls.energy_perf = epp;
> +	ret = cppc_set_epp_perf(cpudata->cpu, &perf_ctrls, 1);
> +	if (ret) {
> +		pr_debug("failed to set energy perf value (%d)\n", ret);
> +		return ret;
>  	}
> +	cpudata->epp_cached = epp;
>  
>  	return ret;
>  }
> @@ -1867,6 +1893,8 @@ static int __init amd_pstate_init(void)
>  		static_call_update(amd_pstate_cppc_enable, shmem_cppc_enable);
>  		static_call_update(amd_pstate_init_perf, shmem_init_perf);
>  		static_call_update(amd_pstate_update_perf, shmem_update_perf);
> +		static_call_update(amd_pstate_get_epp, shmem_get_epp);
> +		static_call_update(amd_pstate_set_epp, shmem_set_epp);
>  	}
>  
>  	ret = amd_pstate_register_driver(cppc_state);
> -- 
> 2.34.1
> 

  reply	other threads:[~2024-12-06  4:43 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 [this message]
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
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=Z1KA82G2rajkCHLx@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.