public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Gautham R. Shenoy" <gautham.shenoy@amd.com>
To: Mario Limonciello <mario.limonciello@amd.com>
Cc: Perry Yuan <perry.yuan@amd.com>,
	linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
	Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>
Subject: Re: [PATCH 02/15] cpufreq/amd-pstate: convert mutex use to guard()
Date: Fri, 6 Dec 2024 11:45:50 +0530	[thread overview]
Message-ID: <Z1KWljiXpshduCSe@BLRRASHENOY1.amd.com> (raw)
In-Reply-To: <20241205222847.7889-3-mario.limonciello@amd.com>

On Thu, Dec 05, 2024 at 04:28:34PM -0600, Mario Limonciello wrote:
> Using scoped guard declaration will unlock mutexes automatically.
> 
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>


Looks good to me.

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

--
Thanks and Regards
gautham.
> ---
>  drivers/cpufreq/amd-pstate.c | 32 ++++++++++++--------------------
>  1 file changed, 12 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 4d1da49d345ec..7eb013585df51 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -752,12 +752,12 @@ static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state)
>  		pr_err("Boost mode is not supported by this processor or SBIOS\n");
>  		return -EOPNOTSUPP;
>  	}
> -	mutex_lock(&amd_pstate_driver_lock);
> +	guard(mutex)(&amd_pstate_driver_lock);
> +
>  	ret = amd_pstate_cpu_boost_update(policy, state);
>  	WRITE_ONCE(cpudata->boost_state, !ret ? state : false);
>  	policy->boost_enabled = !ret ? state : false;
>  	refresh_frequency_limits(policy);
> -	mutex_unlock(&amd_pstate_driver_lock);
>  
>  	return ret;
>  }
> @@ -848,7 +848,8 @@ static void amd_pstate_update_limits(unsigned int cpu)
>  	if (!amd_pstate_prefcore)
>  		return;
>  
> -	mutex_lock(&amd_pstate_driver_lock);
> +	guard(mutex)(&amd_pstate_driver_lock);
> +
>  	ret = amd_get_highest_perf(cpu, &cur_high);
>  	if (ret)
>  		goto free_cpufreq_put;
> @@ -868,7 +869,6 @@ static void amd_pstate_update_limits(unsigned int cpu)
>  	if (!highest_perf_changed)
>  		cpufreq_update_policy(cpu);
>  
> -	mutex_unlock(&amd_pstate_driver_lock);
>  }
>  
>  /*
> @@ -1201,11 +1201,11 @@ static ssize_t store_energy_performance_preference(
>  	if (ret < 0)
>  		return -EINVAL;
>  
> -	mutex_lock(&amd_pstate_limits_lock);
> +	guard(mutex)(&amd_pstate_limits_lock);
> +
>  	ret = amd_pstate_set_energy_pref_index(cpudata, ret);
> -	mutex_unlock(&amd_pstate_limits_lock);
>  
> -	return ret ?: count;
> +	return ret ? ret : count;
>  }
>  
>  static ssize_t show_energy_performance_preference(
> @@ -1369,13 +1369,10 @@ EXPORT_SYMBOL_GPL(amd_pstate_update_status);
>  static ssize_t status_show(struct device *dev,
>  			   struct device_attribute *attr, char *buf)
>  {
> -	ssize_t ret;
>  
> -	mutex_lock(&amd_pstate_driver_lock);
> -	ret = amd_pstate_show_status(buf);
> -	mutex_unlock(&amd_pstate_driver_lock);
> +	guard(mutex)(&amd_pstate_driver_lock);
>  
> -	return ret;
> +	return amd_pstate_show_status(buf);
>  }
>  
>  static ssize_t status_store(struct device *a, struct device_attribute *b,
> @@ -1384,9 +1381,8 @@ static ssize_t status_store(struct device *a, struct device_attribute *b,
>  	char *p = memchr(buf, '\n', count);
>  	int ret;
>  
> -	mutex_lock(&amd_pstate_driver_lock);
> +	guard(mutex)(&amd_pstate_driver_lock);
>  	ret = amd_pstate_update_status(buf, p ? p - buf : count);
> -	mutex_unlock(&amd_pstate_driver_lock);
>  
>  	return ret < 0 ? ret : count;
>  }
> @@ -1687,7 +1683,7 @@ static int amd_pstate_epp_cpu_offline(struct cpufreq_policy *policy)
>  
>  	min_perf = READ_ONCE(cpudata->lowest_perf);
>  
> -	mutex_lock(&amd_pstate_limits_lock);
> +	guard(mutex)(&amd_pstate_limits_lock);
>  
>  	if (trace_amd_pstate_epp_perf_enabled()) {
>  		trace_amd_pstate_epp_perf(cpudata->cpu, cpudata->highest_perf,
> @@ -1698,8 +1694,6 @@ static int amd_pstate_epp_cpu_offline(struct cpufreq_policy *policy)
>  	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);
> -
>  	return 0;
>  }
>  
> @@ -1728,13 +1722,11 @@ static int amd_pstate_epp_resume(struct cpufreq_policy *policy)
>  	struct amd_cpudata *cpudata = policy->driver_data;
>  
>  	if (cpudata->suspended) {
> -		mutex_lock(&amd_pstate_limits_lock);
> +		guard(mutex)(&amd_pstate_limits_lock);
>  
>  		/* enable amd pstate from suspend state*/
>  		amd_pstate_epp_reenable(cpudata);
>  
> -		mutex_unlock(&amd_pstate_limits_lock);
> -
>  		cpudata->suspended = false;
>  	}
>  
> -- 
> 2.43.0
> 

  reply	other threads:[~2024-12-06  6:16 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-05 22:28 [PATCH 00/15] amd-pstate 6.14 cleanups and improvements Mario Limonciello
2024-12-05 22:28 ` [PATCH 01/15] cpufreq/amd-pstate: Add trace event for EPP perf updates Mario Limonciello
2024-12-06  5:05   ` Yuan, Perry
2024-12-06  5:44   ` Gautham R. Shenoy
2024-12-05 22:28 ` [PATCH 02/15] cpufreq/amd-pstate: convert mutex use to guard() Mario Limonciello
2024-12-06  6:15   ` Gautham R. Shenoy [this message]
2024-12-05 22:28 ` [PATCH 03/15] cpufreq/amd-pstate: Drop cached epp_policy variable Mario Limonciello
2024-12-06  6:16   ` Gautham R. Shenoy
2024-12-05 22:28 ` [PATCH 04/15] cpufreq/amd-pstate: Use FIELD_PREP and FIELD_GET macros Mario Limonciello
2024-12-06  6:21   ` Gautham R. Shenoy
2024-12-05 22:28 ` [PATCH 05/15] cpufreq/amd-pstate: Store the boost numerator as highest perf again Mario Limonciello
2024-12-06  6:25   ` Gautham R. Shenoy
2024-12-05 22:28 ` [PATCH 06/15] cpufreq/amd-pstate: Use boost numerator for upper bound of frequencies Mario Limonciello
2024-12-06  6:27   ` Gautham R. Shenoy
2024-12-05 22:28 ` [PATCH 07/15] cpufreq/amd-pstate: Only update the cached value in msr_set_epp() on success Mario Limonciello
2024-12-06  6:32   ` Gautham R. Shenoy
2024-12-05 22:28 ` [PATCH 08/15] cpufreq/amd-pstate: store all values in cpudata struct in khz Mario Limonciello
2024-12-06  6:43   ` Gautham R. Shenoy
2024-12-05 22:28 ` [PATCH 09/15] cpufreq/amd-pstate: Change amd_pstate_update_perf() to return an int Mario Limonciello
2024-12-06  6:43   ` Gautham R. Shenoy
2024-12-05 22:28 ` [PATCH 10/15] cpufreq/amd-pstate: Move limit updating code Mario Limonciello
2024-12-06  3:10   ` kernel test robot
2024-12-06 15:19   ` Gautham R. Shenoy
2024-12-05 22:28 ` [PATCH 11/15] cpufreq/amd-pstate: Cache EPP value and use that everywhere Mario Limonciello
2024-12-06 16:14   ` Gautham R. Shenoy
2024-12-06 16:16     ` Mario Limonciello
2024-12-05 22:28 ` [PATCH 12/15] cpufreq/amd-pstate: Always write EPP value when updating perf Mario Limonciello
2024-12-05 22:28 ` [PATCH 13/15] cpufreq/amd-pstate: Check if CPPC request has changed before writing to the MSR or shared memory Mario Limonciello
2024-12-05 22:28 ` [PATCH 14/15] cpufreq/amd-pstate: Drop ret variable from amd_pstate_set_energy_pref_index() Mario Limonciello
2024-12-05 22:28 ` [PATCH 15/15] cpufreq/amd-pstate: Set different default EPP policy for Epyc and Ryzen 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=Z1KWljiXpshduCSe@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 \
    /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