diff mbox series

cpufreq: amd-pstate: Fix the inconsistency in max frequency units

Message ID 20240527051128.110091-1-Dhananjay.Ugwekar@amd.com
State Accepted
Commit e4731baaf29438508197d3a8a6d4f5a8c51663f8
Headers show
Series cpufreq: amd-pstate: Fix the inconsistency in max frequency units | expand

Commit Message

Dhananjay Ugwekar May 27, 2024, 5:11 a.m. UTC
The nominal frequency in cpudata is maintained in MHz whereas all other
frequencies are in KHz. This means we have to convert nominal frequency
value to KHz before we do any interaction with other frequency values.

In amd_pstate_set_boost(), this conversion from MHz to KHz is missed,
fix that.

Tested on a AMD Zen4 EPYC server

Before:
$ cat /sys/devices/system/cpu/cpufreq/policy*/scaling_max_freq | uniq
2151
$ cat /sys/devices/system/cpu/cpufreq/policy*/cpuinfo_min_freq | uniq
400000
$ cat /sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq | uniq
2151
409422

After:
$ cat /sys/devices/system/cpu/cpufreq/policy*/scaling_max_freq | uniq
2151000
$ cat /sys/devices/system/cpu/cpufreq/policy*/cpuinfo_min_freq | uniq
400000
$ cat /sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq | uniq
2151000
1799527

Fixes: ec437d71db77 ("cpufreq: amd-pstate: Introduce a new AMD P-State driver to support future processors")
Signed-off-by: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>
---
 drivers/cpufreq/amd-pstate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Mario Limonciello May 27, 2024, 2:40 p.m. UTC | #1
On 5/27/2024 00:11, Dhananjay Ugwekar wrote:
> The nominal frequency in cpudata is maintained in MHz whereas all other
> frequencies are in KHz. This means we have to convert nominal frequency
> value to KHz before we do any interaction with other frequency values.
> 
> In amd_pstate_set_boost(), this conversion from MHz to KHz is missed,
> fix that.
> 
> Tested on a AMD Zen4 EPYC server
> 
> Before:
> $ cat /sys/devices/system/cpu/cpufreq/policy*/scaling_max_freq | uniq
> 2151
> $ cat /sys/devices/system/cpu/cpufreq/policy*/cpuinfo_min_freq | uniq
> 400000
> $ cat /sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq | uniq
> 2151
> 409422
> 
> After:
> $ cat /sys/devices/system/cpu/cpufreq/policy*/scaling_max_freq | uniq
> 2151000
> $ cat /sys/devices/system/cpu/cpufreq/policy*/cpuinfo_min_freq | uniq
> 400000
> $ cat /sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq | uniq
> 2151000
> 1799527
> 

Cc: stable@vger.kernel.org

> Fixes: ec437d71db77 ("cpufreq: amd-pstate: Introduce a new AMD P-State driver to support future processors")
> Signed-off-by: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>

Acked-by: Mario Limonciello <mario.limonciello@amd.com>

> ---
>   drivers/cpufreq/amd-pstate.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 1b7e82a0ad2e..cde3b91b4422 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -669,7 +669,7 @@ static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state)
>   	if (state)
>   		policy->cpuinfo.max_freq = cpudata->max_freq;
>   	else
> -		policy->cpuinfo.max_freq = cpudata->nominal_freq;
> +		policy->cpuinfo.max_freq = cpudata->nominal_freq * 1000;
>   
>   	policy->max = policy->cpuinfo.max_freq;
>
Gautham R.Shenoy May 27, 2024, 3:45 p.m. UTC | #2
On Mon, May 27, 2024 at 09:40:21AM -0500, Mario Limonciello wrote:
> On 5/27/2024 00:11, Dhananjay Ugwekar wrote:
> > The nominal frequency in cpudata is maintained in MHz whereas all other
> > frequencies are in KHz. This means we have to convert nominal frequency
> > value to KHz before we do any interaction with other frequency values.
> > 
> > In amd_pstate_set_boost(), this conversion from MHz to KHz is missed,
> > fix that.
> > 
> > Tested on a AMD Zen4 EPYC server
> > 
> > Before:
> > $ cat /sys/devices/system/cpu/cpufreq/policy*/scaling_max_freq | uniq
> > 2151
> > $ cat /sys/devices/system/cpu/cpufreq/policy*/cpuinfo_min_freq | uniq
> > 400000
> > $ cat /sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq | uniq
> > 2151
> > 409422
> > 
> > After:
> > $ cat /sys/devices/system/cpu/cpufreq/policy*/scaling_max_freq | uniq
> > 2151000
> > $ cat /sys/devices/system/cpu/cpufreq/policy*/cpuinfo_min_freq | uniq
> > 400000
> > $ cat /sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq | uniq
> > 2151000
> > 1799527
> > 
> 
> Cc: stable@vger.kernel.org
> 
> > Fixes: ec437d71db77 ("cpufreq: amd-pstate: Introduce a new AMD P-State driver to support future processors")
> > Signed-off-by: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>
> 
> Acked-by: Mario Limonciello <mario.limonciello@amd.com>

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

> 
> > ---
> >   drivers/cpufreq/amd-pstate.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> > index 1b7e82a0ad2e..cde3b91b4422 100644
> > --- a/drivers/cpufreq/amd-pstate.c
> > +++ b/drivers/cpufreq/amd-pstate.c
> > @@ -669,7 +669,7 @@ static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state)
> >   	if (state)
> >   		policy->cpuinfo.max_freq = cpudata->max_freq;
> >   	else
> > -		policy->cpuinfo.max_freq = cpudata->nominal_freq;
> > +		policy->cpuinfo.max_freq = cpudata->nominal_freq * 1000;
> >   	policy->max = policy->cpuinfo.max_freq;
>
Peter Jung May 28, 2024, 5:25 p.m. UTC | #3
> > > Fixes: ec437d71db77 ("cpufreq: amd-pstate: Introduce a new AMD 
P-State driver to support future processors")
 > > > Signed-off-by: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>
 > >
 > > Acked-by: Mario Limonciello <mario.limonciello@amd.com>
 >
 > Acked-by: Gautham R. Shenoy <gautham.shenoy@amd.com>


Tested-by: Peter Jung <ptr1337@cachyos.org>

Fixes also an introduced regression in amd-pstate=passive reporting 
wrong frequency values.

Also, see[1]

[1]https://github.com/CachyOS/linux-cachyos/issues/253#issuecomment-2135659124
Rafael J. Wysocki May 28, 2024, 8:05 p.m. UTC | #4
On Mon, May 27, 2024 at 4:40 PM Mario Limonciello
<mario.limonciello@amd.com> wrote:
>
> On 5/27/2024 00:11, Dhananjay Ugwekar wrote:
> > The nominal frequency in cpudata is maintained in MHz whereas all other
> > frequencies are in KHz. This means we have to convert nominal frequency
> > value to KHz before we do any interaction with other frequency values.
> >
> > In amd_pstate_set_boost(), this conversion from MHz to KHz is missed,
> > fix that.
> >
> > Tested on a AMD Zen4 EPYC server
> >
> > Before:
> > $ cat /sys/devices/system/cpu/cpufreq/policy*/scaling_max_freq | uniq
> > 2151
> > $ cat /sys/devices/system/cpu/cpufreq/policy*/cpuinfo_min_freq | uniq
> > 400000
> > $ cat /sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq | uniq
> > 2151
> > 409422
> >
> > After:
> > $ cat /sys/devices/system/cpu/cpufreq/policy*/scaling_max_freq | uniq
> > 2151000
> > $ cat /sys/devices/system/cpu/cpufreq/policy*/cpuinfo_min_freq | uniq
> > 400000
> > $ cat /sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq | uniq
> > 2151000
> > 1799527
> >
>
> Cc: stable@vger.kernel.org
>
> > Fixes: ec437d71db77 ("cpufreq: amd-pstate: Introduce a new AMD P-State driver to support future processors")
> > Signed-off-by: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>
>
> Acked-by: Mario Limonciello <mario.limonciello@amd.com>

Applied as 6.10-rc material, thanks!

> > ---
> >   drivers/cpufreq/amd-pstate.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> > index 1b7e82a0ad2e..cde3b91b4422 100644
> > --- a/drivers/cpufreq/amd-pstate.c
> > +++ b/drivers/cpufreq/amd-pstate.c
> > @@ -669,7 +669,7 @@ static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state)
> >       if (state)
> >               policy->cpuinfo.max_freq = cpudata->max_freq;
> >       else
> > -             policy->cpuinfo.max_freq = cpudata->nominal_freq;
> > +             policy->cpuinfo.max_freq = cpudata->nominal_freq * 1000;
> >
> >       policy->max = policy->cpuinfo.max_freq;
> >
>
diff mbox series

Patch

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 1b7e82a0ad2e..cde3b91b4422 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -669,7 +669,7 @@  static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state)
 	if (state)
 		policy->cpuinfo.max_freq = cpudata->max_freq;
 	else
-		policy->cpuinfo.max_freq = cpudata->nominal_freq;
+		policy->cpuinfo.max_freq = cpudata->nominal_freq * 1000;
 
 	policy->max = policy->cpuinfo.max_freq;