public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cpufreq: amd-pstate: adjust min/max limit perf
@ 2024-02-27  7:39 Meng Li
  2024-02-27 15:36 ` Mario Limonciello
  0 siblings, 1 reply; 3+ messages in thread
From: Meng Li @ 2024-02-27  7:39 UTC (permalink / raw)
  To: Rafael J . Wysocki, Huang Rui
  Cc: linux-pm, linux-kernel, x86, linux-acpi, Shuah Khan,
	linux-kselftest, Nathan Fontenot, Deepak Sharma, Alex Deucher,
	Mario Limonciello, Shimmer Huang, Perry Yuan, Xiaojian Du,
	Viresh Kumar, Borislav Petkov, Meng Li

The min/max limit perf values calculated based on frequency
may exceed the reasonable range of perf(highest perf, lowest perf).

Signed-off-by: Meng Li <li.meng@amd.com>
---
 drivers/cpufreq/amd-pstate.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index aa5e57e27d2b..2015c9fcc3c9 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -484,12 +484,19 @@ static int amd_pstate_verify(struct cpufreq_policy_data *policy)
 
 static int amd_pstate_update_min_max_limit(struct cpufreq_policy *policy)
 {
-	u32 max_limit_perf, min_limit_perf;
+	u32 max_limit_perf, min_limit_perf, lowest_perf;
 	struct amd_cpudata *cpudata = policy->driver_data;
 
 	max_limit_perf = div_u64(policy->max * cpudata->highest_perf, cpudata->max_freq);
 	min_limit_perf = div_u64(policy->min * cpudata->highest_perf, cpudata->max_freq);
 
+	lowest_perf = READ_ONCE(cpudata->lowest_perf);
+	if (min_limit_perf < lowest_perf)
+		min_limit_perf = lowest_perf;
+
+	if (max_limit_perf < min_limit_perf)
+		max_limit_perf = min_limit_perf;
+
 	WRITE_ONCE(cpudata->max_limit_perf, max_limit_perf);
 	WRITE_ONCE(cpudata->min_limit_perf, min_limit_perf);
 	WRITE_ONCE(cpudata->max_limit_freq, policy->max);
@@ -1387,6 +1394,12 @@ static void amd_pstate_epp_update_limit(struct cpufreq_policy *policy)
 	max_limit_perf = div_u64(policy->max * cpudata->highest_perf, cpudata->max_freq);
 	min_limit_perf = div_u64(policy->min * cpudata->highest_perf, cpudata->max_freq);
 
+	if (min_limit_perf < min_perf)
+		min_limit_perf = min_perf;
+
+	if (max_limit_perf < min_limit_perf)
+		max_limit_perf = min_limit_perf;
+
 	WRITE_ONCE(cpudata->max_limit_perf, max_limit_perf);
 	WRITE_ONCE(cpudata->min_limit_perf, min_limit_perf);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] cpufreq: amd-pstate: adjust min/max limit perf
  2024-02-27  7:39 [PATCH] cpufreq: amd-pstate: adjust min/max limit perf Meng Li
@ 2024-02-27 15:36 ` Mario Limonciello
  2024-02-29 19:13   ` Rafael J. Wysocki
  0 siblings, 1 reply; 3+ messages in thread
From: Mario Limonciello @ 2024-02-27 15:36 UTC (permalink / raw)
  To: Meng Li, Rafael J . Wysocki, Huang Rui
  Cc: linux-pm, linux-kernel, x86, linux-acpi, Shuah Khan,
	linux-kselftest, Nathan Fontenot, Deepak Sharma, Alex Deucher,
	Shimmer Huang, Perry Yuan, Xiaojian Du, Viresh Kumar,
	Borislav Petkov

On 2/27/2024 01:39, Meng Li wrote:
> The min/max limit perf values calculated based on frequency
> may exceed the reasonable range of perf(highest perf, lowest perf).
> 
> Signed-off-by: Meng Li <li.meng@amd.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
>   drivers/cpufreq/amd-pstate.c | 15 ++++++++++++++-
>   1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index aa5e57e27d2b..2015c9fcc3c9 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -484,12 +484,19 @@ static int amd_pstate_verify(struct cpufreq_policy_data *policy)
>   
>   static int amd_pstate_update_min_max_limit(struct cpufreq_policy *policy)
>   {
> -	u32 max_limit_perf, min_limit_perf;
> +	u32 max_limit_perf, min_limit_perf, lowest_perf;
>   	struct amd_cpudata *cpudata = policy->driver_data;
>   
>   	max_limit_perf = div_u64(policy->max * cpudata->highest_perf, cpudata->max_freq);
>   	min_limit_perf = div_u64(policy->min * cpudata->highest_perf, cpudata->max_freq);
>   
> +	lowest_perf = READ_ONCE(cpudata->lowest_perf);
> +	if (min_limit_perf < lowest_perf)
> +		min_limit_perf = lowest_perf;
> +
> +	if (max_limit_perf < min_limit_perf)
> +		max_limit_perf = min_limit_perf;
> +
>   	WRITE_ONCE(cpudata->max_limit_perf, max_limit_perf);
>   	WRITE_ONCE(cpudata->min_limit_perf, min_limit_perf);
>   	WRITE_ONCE(cpudata->max_limit_freq, policy->max);
> @@ -1387,6 +1394,12 @@ static void amd_pstate_epp_update_limit(struct cpufreq_policy *policy)
>   	max_limit_perf = div_u64(policy->max * cpudata->highest_perf, cpudata->max_freq);
>   	min_limit_perf = div_u64(policy->min * cpudata->highest_perf, cpudata->max_freq);
>   
> +	if (min_limit_perf < min_perf)
> +		min_limit_perf = min_perf;
> +
> +	if (max_limit_perf < min_limit_perf)
> +		max_limit_perf = min_limit_perf;
> +
>   	WRITE_ONCE(cpudata->max_limit_perf, max_limit_perf);
>   	WRITE_ONCE(cpudata->min_limit_perf, min_limit_perf);
>   


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] cpufreq: amd-pstate: adjust min/max limit perf
  2024-02-27 15:36 ` Mario Limonciello
@ 2024-02-29 19:13   ` Rafael J. Wysocki
  0 siblings, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2024-02-29 19:13 UTC (permalink / raw)
  To: Mario Limonciello, Meng Li
  Cc: Rafael J . Wysocki, Huang Rui, linux-pm, linux-kernel, x86,
	linux-acpi, Shuah Khan, linux-kselftest, Nathan Fontenot,
	Deepak Sharma, Alex Deucher, Shimmer Huang, Perry Yuan,
	Xiaojian Du, Viresh Kumar, Borislav Petkov

On Tue, Feb 27, 2024 at 4:36 PM Mario Limonciello
<mario.limonciello@amd.com> wrote:
>
> On 2/27/2024 01:39, Meng Li wrote:
> > The min/max limit perf values calculated based on frequency
> > may exceed the reasonable range of perf(highest perf, lowest perf).
> >
> > Signed-off-by: Meng Li <li.meng@amd.com>
> Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>

Applied as 6.9 material, thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-29 19:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-27  7:39 [PATCH] cpufreq: amd-pstate: adjust min/max limit perf Meng Li
2024-02-27 15:36 ` Mario Limonciello
2024-02-29 19:13   ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox