2024-01-20 00:19:34

by Mario Limonciello

[permalink] [raw]
Subject: [PATCH] cpufreq/amd-pstate: Fix setting scaling max/min freq values

Scaling min/max freq values were being cached and lagging a setting
each time. Fix the ordering of the clamp call to ensure they work.

Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217931
Cc: [email protected]
Cc: [email protected]
Fixes: febab20caeba ("cpufreq/amd-pstate: Fix scaling_min_freq and scaling_max_freq update")
Signed-off-by: Mario Limonciello <[email protected]>
---
drivers/cpufreq/amd-pstate.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 1f6186475715..1791d37fbc53 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -1232,14 +1232,13 @@ 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);

+ WRITE_ONCE(cpudata->max_limit_perf, max_limit_perf);
+ WRITE_ONCE(cpudata->min_limit_perf, min_limit_perf);
+
max_perf = clamp_t(unsigned long, max_perf, cpudata->min_limit_perf,
cpudata->max_limit_perf);
min_perf = clamp_t(unsigned long, min_perf, cpudata->min_limit_perf,
cpudata->max_limit_perf);
-
- WRITE_ONCE(cpudata->max_limit_perf, max_limit_perf);
- WRITE_ONCE(cpudata->min_limit_perf, min_limit_perf);
-
value = READ_ONCE(cpudata->cppc_req_cached);

if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE)
--
2.34.1



2024-01-22 15:09:01

by Wyes Karny

[permalink] [raw]
Subject: Re: [PATCH] cpufreq/amd-pstate: Fix setting scaling max/min freq values

On Sat, Jan 20, 2024 at 5:49 AM Mario Limonciello
<[email protected]> wrote:
>
> Scaling min/max freq values were being cached and lagging a setting
> each time. Fix the ordering of the clamp call to ensure they work.
>
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217931
> Cc: [email protected]
> Cc: [email protected]
> Fixes: febab20caeba ("cpufreq/amd-pstate: Fix scaling_min_freq and scaling_max_freq update")
> Signed-off-by: Mario Limonciello <[email protected]>

Reviewed-by: Wyes Karny <[email protected]>

> ---
> drivers/cpufreq/amd-pstate.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 1f6186475715..1791d37fbc53 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -1232,14 +1232,13 @@ 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);
>
> + WRITE_ONCE(cpudata->max_limit_perf, max_limit_perf);
> + WRITE_ONCE(cpudata->min_limit_perf, min_limit_perf);
> +
> max_perf = clamp_t(unsigned long, max_perf, cpudata->min_limit_perf,
> cpudata->max_limit_perf);
> min_perf = clamp_t(unsigned long, min_perf, cpudata->min_limit_perf,
> cpudata->max_limit_perf);
> -
> - WRITE_ONCE(cpudata->max_limit_perf, max_limit_perf);
> - WRITE_ONCE(cpudata->min_limit_perf, min_limit_perf);
> -
> value = READ_ONCE(cpudata->cppc_req_cached);
>
> if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE)
> --
> 2.34.1
>


--
Thanks & Regards
Wyes

2024-01-22 20:04:18

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH] cpufreq/amd-pstate: Fix setting scaling max/min freq values

On Mon, Jan 22, 2024 at 3:57 PM Wyes Karny <[email protected]> wrote:
>
> On Sat, Jan 20, 2024 at 5:49 AM Mario Limonciello
> <[email protected]> wrote:
> >
> > Scaling min/max freq values were being cached and lagging a setting
> > each time. Fix the ordering of the clamp call to ensure they work.
> >
> > Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217931
> > Cc: [email protected]
> > Cc: [email protected]
> > Fixes: febab20caeba ("cpufreq/amd-pstate: Fix scaling_min_freq and scaling_max_freq update")
> > Signed-off-by: Mario Limonciello <[email protected]>
>
> Reviewed-by: Wyes Karny <[email protected]>
>
> > ---
> > drivers/cpufreq/amd-pstate.c | 7 +++----
> > 1 file changed, 3 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> > index 1f6186475715..1791d37fbc53 100644
> > --- a/drivers/cpufreq/amd-pstate.c
> > +++ b/drivers/cpufreq/amd-pstate.c
> > @@ -1232,14 +1232,13 @@ 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);
> >
> > + WRITE_ONCE(cpudata->max_limit_perf, max_limit_perf);
> > + WRITE_ONCE(cpudata->min_limit_perf, min_limit_perf);
> > +
> > max_perf = clamp_t(unsigned long, max_perf, cpudata->min_limit_perf,
> > cpudata->max_limit_perf);
> > min_perf = clamp_t(unsigned long, min_perf, cpudata->min_limit_perf,
> > cpudata->max_limit_perf);
> > -
> > - WRITE_ONCE(cpudata->max_limit_perf, max_limit_perf);
> > - WRITE_ONCE(cpudata->min_limit_perf, min_limit_perf);
> > -
> > value = READ_ONCE(cpudata->cppc_req_cached);
> >
> > if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE)
> > --

Applied as 6.8-rc material, thanks!

2024-01-22 23:53:26

by Dan Martins

[permalink] [raw]
Subject: Re: [PATCH] cpufreq/amd-pstate: Fix setting scaling max/min freq values

On Friday, January 19, 2024 6:33:19 A.M. EST Mario Limonciello wrote:
> Scaling min/max freq values were being cached and lagging a setting
> each time. Fix the ordering of the clamp call to ensure they work.
>
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217931
> Cc: [email protected]
> Cc: [email protected]
> Fixes: febab20caeba ("cpufreq/amd-pstate: Fix scaling_min_freq and
> scaling_max_freq update") Signed-off-by: Mario Limonciello
> <[email protected]>
> ---
> drivers/cpufreq/amd-pstate.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 1f6186475715..1791d37fbc53 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -1232,14 +1232,13 @@ 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);
>
> + WRITE_ONCE(cpudata->max_limit_perf, max_limit_perf);
> + WRITE_ONCE(cpudata->min_limit_perf, min_limit_perf);
> +
> max_perf = clamp_t(unsigned long, max_perf, cpudata-
>min_limit_perf,
> cpudata->max_limit_perf);
> min_perf = clamp_t(unsigned long, min_perf, cpudata-
>min_limit_perf,
> cpudata->max_limit_perf);
> -
> - WRITE_ONCE(cpudata->max_limit_perf, max_limit_perf);
> - WRITE_ONCE(cpudata->min_limit_perf, min_limit_perf);
> -
> value = READ_ONCE(cpudata->cppc_req_cached);
>
> if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE)

Tested-by: Dan Martins <[email protected]>