2022-08-14 17:10:19

by Yuan, Perry

[permalink] [raw]
Subject: [PATCH v5 0/7] AMD Pstate Enhancement And Issue Fixs

This patchsets adds support for precision boost hardware control
for AMD processors.

Meanwhile the patchset fixs lowest perf query and desired perf scope issues.
Update transition delay and latency default value to meet SMU firmware requirement.
and do some code cleanups,
It also exports cpufreq cpu release and acquire for coming amd-pstate epp mode driver

The patch series are tested on the AMD mobile and EYPC server systems

v4->v5:
- drop the amd precision boost mode control patch
- combine acpi_cpc_valid() changes into single patch
- pick up Reviewed-by flags by Huang Ray

v3->v4:
- check cached bit for core performance boost from hardware configuration
register
- pick up the Acked-by flags from Viresh and Sudeep

v2->v3:
- drop cpufreq cpu release and acquire export patch
- remove the clamp_t in the amd_pstate_adjust_perf()

v1->v2:
- add two new patches to remove the acpi_disabled check
- fix some typos in the commit info
- move the clamp_t() into amd_pstate_update() function
- rebased to 5.19-rc5

Perry Yuan (7):
cpufreq: amd-pstate: cleanup the unused and duplicated headers
declaration
cpufreq: amd-pstate: simplify cpudata pointer assignment
cpufreq: amd-pstate: fix white-space
cpufreq: amd_pstate: fix wrong lowest perf fetch
cpufreq: amd_pstate: map desired perf into pstate scope for powersave
governor
cpufreq: amd-pstate: update pstate frequency transition delay time
cpufreq: amd-pstate: add ACPI disabled check in acpi_cpc_valid()

drivers/acpi/cppc_acpi.c | 3 +++
drivers/base/arch_topology.c | 2 +-
drivers/cpufreq/amd-pstate.c | 32 ++++++++++----------------------
drivers/cpufreq/cppc_cpufreq.c | 2 +-
4 files changed, 15 insertions(+), 24 deletions(-)

--
2.34.1


2022-08-14 17:11:03

by Yuan, Perry

[permalink] [raw]
Subject: [PATCH v5 2/7] cpufreq: amd-pstate: simplify cpudata pointer assignment

move the cpudata assignment to cpudata declaration which
will simplify the functions.

No functional change intended.

Reviewed-by: Huang Rui <[email protected]>
Acked-by: Viresh Kumar <[email protected]>
Signed-off-by: Perry Yuan <[email protected]>
---
drivers/cpufreq/amd-pstate.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 19a078e232dd..b31bb5e6cefc 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -550,9 +550,7 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)

static int amd_pstate_cpu_exit(struct cpufreq_policy *policy)
{
- struct amd_cpudata *cpudata;
-
- cpudata = policy->driver_data;
+ struct amd_cpudata *cpudata = policy->driver_data;

freq_qos_remove_request(&cpudata->req[1]);
freq_qos_remove_request(&cpudata->req[0]);
@@ -594,9 +592,7 @@ static ssize_t show_amd_pstate_max_freq(struct cpufreq_policy *policy,
char *buf)
{
int max_freq;
- struct amd_cpudata *cpudata;
-
- cpudata = policy->driver_data;
+ struct amd_cpudata *cpudata = policy->driver_data;

max_freq = amd_get_max_freq(cpudata);
if (max_freq < 0)
@@ -609,9 +605,7 @@ static ssize_t show_amd_pstate_lowest_nonlinear_freq(struct cpufreq_policy *poli
char *buf)
{
int freq;
- struct amd_cpudata *cpudata;
-
- cpudata = policy->driver_data;
+ struct amd_cpudata *cpudata = policy->driver_data;

freq = amd_get_lowest_nonlinear_freq(cpudata);
if (freq < 0)
--
2.34.1

2022-08-14 17:11:55

by Yuan, Perry

[permalink] [raw]
Subject: [PATCH v5 3/7] cpufreq: amd-pstate: fix white-space

Remove the white space and correct mixed-up indentation

Acked-by: Viresh Kumar <[email protected]>
Signed-off-by: Perry Yuan <[email protected]>
---
drivers/cpufreq/amd-pstate.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index b31bb5e6cefc..5cdef6638681 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -115,7 +115,7 @@ struct amd_cpudata {
struct amd_aperf_mperf cur;
struct amd_aperf_mperf prev;

- u64 freq;
+ u64 freq;
bool boost_supported;
};

@@ -651,7 +651,7 @@ static struct cpufreq_driver amd_pstate_driver = {
.resume = amd_pstate_cpu_resume,
.set_boost = amd_pstate_set_boost,
.name = "amd-pstate",
- .attr = amd_pstate_attr,
+ .attr = amd_pstate_attr,
};

static int __init amd_pstate_init(void)
--
2.34.1

2022-08-14 17:12:35

by Yuan, Perry

[permalink] [raw]
Subject: [PATCH v5 1/7] cpufreq: amd-pstate: cleanup the unused and duplicated headers declaration

Cleanup the headers declaration which are not used
actually and some duplicated declaration which is declarated in some
other headers already, it will help to simplify the header part.

Reviewed-by: Huang Rui <[email protected]>
Acked-by: Viresh Kumar <[email protected]>
Signed-off-by: Perry Yuan <[email protected]>
---
drivers/cpufreq/amd-pstate.c | 5 -----
1 file changed, 5 deletions(-)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 9ac75c1cde9c..19a078e232dd 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -31,19 +31,14 @@
#include <linux/compiler.h>
#include <linux/dmi.h>
#include <linux/slab.h>
-#include <linux/acpi.h>
#include <linux/io.h>
#include <linux/delay.h>
#include <linux/uaccess.h>
#include <linux/static_call.h>

-#include <acpi/processor.h>
#include <acpi/cppc_acpi.h>

#include <asm/msr.h>
-#include <asm/processor.h>
-#include <asm/cpufeature.h>
-#include <asm/cpu_device_id.h>
#include "amd-pstate-trace.h"

#define AMD_PSTATE_TRANSITION_LATENCY 0x20000
--
2.34.1

2022-08-14 17:16:06

by Yuan, Perry

[permalink] [raw]
Subject: [PATCH v5 5/7] cpufreq: amd_pstate: map desired perf into pstate scope for powersave governor

The patch will fix the invalid desired perf value for powersave
governor. This issue is found when testing on one AMD EPYC system, the
actual des_perf is smaller than the min_perf value, that is invalid
value. because the min_perf is the lowest_perf system can support in
idle state.

Reviewed-by: Huang Rui <[email protected]>
Signed-off-by: Perry Yuan <[email protected]>
---
drivers/cpufreq/amd-pstate.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 183cdd4ba00e..e40177d14310 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -264,6 +264,7 @@ static void amd_pstate_update(struct amd_cpudata *cpudata, u32 min_perf,
u64 prev = READ_ONCE(cpudata->cppc_req_cached);
u64 value = prev;

+ des_perf = clamp_t(unsigned long, des_perf, min_perf, max_perf);
value &= ~AMD_CPPC_MIN_PERF(~0L);
value |= AMD_CPPC_MIN_PERF(min_perf);

@@ -352,8 +353,6 @@ static void amd_pstate_adjust_perf(unsigned int cpu,
if (max_perf < min_perf)
max_perf = min_perf;

- des_perf = clamp_t(unsigned long, des_perf, min_perf, max_perf);
-
amd_pstate_update(cpudata, min_perf, des_perf, max_perf, true);
}

--
2.34.1

2022-08-14 17:24:28

by Yuan, Perry

[permalink] [raw]
Subject: [PATCH v5 4/7] cpufreq: amd_pstate: fix wrong lowest perf fetch

Fix the wrong lowest perf value reading which is used for new
des_perf calculation by governor requested, the incorrect min_perf will
get incorrect des_perf to be set , that will cause the system frequency
changing unexpectedly.

Reviewed-by: Huang Rui <[email protected]>
Acked-by: Viresh Kumar <[email protected]>
Signed-off-by: Perry Yuan <[email protected]>
Signed-off-by: Su Jinzhou <[email protected]>
---
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 5cdef6638681..183cdd4ba00e 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -307,7 +307,7 @@ static int amd_pstate_target(struct cpufreq_policy *policy,
return -ENODEV;

cap_perf = READ_ONCE(cpudata->highest_perf);
- min_perf = READ_ONCE(cpudata->lowest_nonlinear_perf);
+ min_perf = READ_ONCE(cpudata->lowest_perf);
max_perf = cap_perf;

freqs.old = policy->cur;
--
2.34.1

2022-08-14 17:33:06

by Yuan, Perry

[permalink] [raw]
Subject: [PATCH v5 6/7] cpufreq: amd-pstate: update pstate frequency transition delay time

Change the default transition latency to be 20ms that is more
reasonable transition delay for AMD processors in non-EPP driver mode.

Update transition delay time to 1ms, in the AMD CPU autonomous mode and
non-autonomous mode, CPPC firmware will decide frequency at 1ms timescale
based on the workload utilization.

Acked-by: Viresh Kumar <[email protected]>
Signed-off-by: Perry Yuan <[email protected]>
---
drivers/cpufreq/amd-pstate.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index e40177d14310..9cb051d61422 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -41,8 +41,8 @@
#include <asm/msr.h>
#include "amd-pstate-trace.h"

-#define AMD_PSTATE_TRANSITION_LATENCY 0x20000
-#define AMD_PSTATE_TRANSITION_DELAY 500
+#define AMD_PSTATE_TRANSITION_LATENCY 20000
+#define AMD_PSTATE_TRANSITION_DELAY 1000

/*
* TODO: We need more time to fine tune processors with shared memory solution
--
2.34.1

2022-08-15 15:32:59

by Punit Agrawal

[permalink] [raw]
Subject: Re: [PATCH v5 4/7] cpufreq: amd_pstate: fix wrong lowest perf fetch

Hi Perry,

Perry Yuan <[email protected]> writes:

> Fix the wrong lowest perf value reading which is used for new
> des_perf calculation by governor requested, the incorrect min_perf will
> get incorrect des_perf to be set , that will cause the system frequency
> changing unexpectedly.
>
> Reviewed-by: Huang Rui <[email protected]>
> Acked-by: Viresh Kumar <[email protected]>
> Signed-off-by: Perry Yuan <[email protected]>
> Signed-off-by: Su Jinzhou <[email protected]>
> ---
> 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 5cdef6638681..183cdd4ba00e 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -307,7 +307,7 @@ static int amd_pstate_target(struct cpufreq_policy *policy,
> return -ENODEV;
>
> cap_perf = READ_ONCE(cpudata->highest_perf);
> - min_perf = READ_ONCE(cpudata->lowest_nonlinear_perf);
> + min_perf = READ_ONCE(cpudata->lowest_perf);
> max_perf = cap_perf;
>
> freqs.old = policy->cur;

This looks to be a pretty big change (lowest nonlinear vs lowest). Does
the patch need to be backported to older kernels?

2022-08-15 15:33:08

by Punit Agrawal

[permalink] [raw]
Subject: Re: [PATCH v5 1/7] cpufreq: amd-pstate: cleanup the unused and duplicated headers declaration

Hi Perry,

Perry Yuan <[email protected]> writes:

> Cleanup the headers declaration which are not used
> actually and some duplicated declaration which is declarated in some
> other headers already, it will help to simplify the header part.

We usually don't get rid of indirectly included headers as long as
definitions from header are used in the code. This avoids problems if
for some reason the included header gets dropped - it'll leave the code
in an uncompilable state.

More below.

>
> Reviewed-by: Huang Rui <[email protected]>
> Acked-by: Viresh Kumar <[email protected]>
> Signed-off-by: Perry Yuan <[email protected]>
> ---
> drivers/cpufreq/amd-pstate.c | 5 -----
> 1 file changed, 5 deletions(-)
>
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 9ac75c1cde9c..19a078e232dd 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -31,19 +31,14 @@
> #include <linux/compiler.h>
> #include <linux/dmi.h>
> #include <linux/slab.h>
> -#include <linux/acpi.h>
> #include <linux/io.h>
> #include <linux/delay.h>
> #include <linux/uaccess.h>
> #include <linux/static_call.h>
>
> -#include <acpi/processor.h>
> #include <acpi/cppc_acpi.h>
>
> #include <asm/msr.h>
> -#include <asm/processor.h>

On a quick scan, I noticed that "boot_cpu_data" and "boot_cpu_has()" in
the module init function are defined in "asm/processor.h" that is being
removed here. It may compile for now but makes the code more fragile as
explained above.

Please ensure that only the header files that have no definitions used
in this file (amd-pstate.c) are dropped.

> -#include <asm/cpufeature.h>
> -#include <asm/cpu_device_id.h>
> #include "amd-pstate-trace.h"
>
> #define AMD_PSTATE_TRANSITION_LATENCY 0x20000

2022-08-15 15:46:09

by Punit Agrawal

[permalink] [raw]
Subject: Re: [PATCH v5 6/7] cpufreq: amd-pstate: update pstate frequency transition delay time

Perry Yuan <[email protected]> writes:

> Change the default transition latency to be 20ms that is more
> reasonable transition delay for AMD processors in non-EPP driver mode.
>
> Update transition delay time to 1ms, in the AMD CPU autonomous mode and
> non-autonomous mode, CPPC firmware will decide frequency at 1ms timescale
> based on the workload utilization.
>
> Acked-by: Viresh Kumar <[email protected]>
> Signed-off-by: Perry Yuan <[email protected]>
> ---
> drivers/cpufreq/amd-pstate.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index e40177d14310..9cb051d61422 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -41,8 +41,8 @@
> #include <asm/msr.h>
> #include "amd-pstate-trace.h"
>
> -#define AMD_PSTATE_TRANSITION_LATENCY 0x20000
> -#define AMD_PSTATE_TRANSITION_DELAY 500
> +#define AMD_PSTATE_TRANSITION_LATENCY 20000
> +#define AMD_PSTATE_TRANSITION_DELAY 1000

How were these values derived? If from documentation, it'll be good to
add a link to the relevant documentation. And if they were derived from
testing, please mention this in the commit log (along with some details
of the tests used to determine the value).

>
> /*
> * TODO: We need more time to fine tune processors with shared memory solution

2022-08-16 09:21:41

by Yuan, Perry

[permalink] [raw]
Subject: RE: [PATCH v5 6/7] cpufreq: amd-pstate: update pstate frequency transition delay time

[AMD Official Use Only - General]

Hi Punit

> -----Original Message-----
> From: Punit Agrawal <[email protected]>
> Sent: Monday, August 15, 2022 11:06 PM
> To: Yuan, Perry <[email protected]>
> Cc: [email protected]; Huang, Ray <[email protected]>;
> [email protected]; Sharma, Deepak <[email protected]>;
> Limonciello, Mario <[email protected]>; Fontenot, Nathan
> <[email protected]>; Deucher, Alexander
> <[email protected]>; Su, Jinzhou (Joe) <[email protected]>;
> Huang, Shimmer <[email protected]>; Du, Xiaojian
> <[email protected]>; Meng, Li (Jassmine) <[email protected]>; linux-
> [email protected]; [email protected]
> Subject: Re: [PATCH v5 6/7] cpufreq: amd-pstate: update pstate frequency
> transition delay time
>
> [CAUTION: External Email]
>
> Perry Yuan <[email protected]> writes:
>
> > Change the default transition latency to be 20ms that is more
> > reasonable transition delay for AMD processors in non-EPP driver mode.
> >
> > Update transition delay time to 1ms, in the AMD CPU autonomous mode
> > and non-autonomous mode, CPPC firmware will decide frequency at 1ms
> > timescale based on the workload utilization.
> >
> > Acked-by: Viresh Kumar <[email protected]>
> > Signed-off-by: Perry Yuan <[email protected]>
> > ---
> > drivers/cpufreq/amd-pstate.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/cpufreq/amd-pstate.c
> > b/drivers/cpufreq/amd-pstate.c index e40177d14310..9cb051d61422 100644
> > --- a/drivers/cpufreq/amd-pstate.c
> > +++ b/drivers/cpufreq/amd-pstate.c
> > @@ -41,8 +41,8 @@
> > #include <asm/msr.h>
> > #include "amd-pstate-trace.h"
> >
> > -#define AMD_PSTATE_TRANSITION_LATENCY 0x20000
> > -#define AMD_PSTATE_TRANSITION_DELAY 500
> > +#define AMD_PSTATE_TRANSITION_LATENCY 20000
> > +#define AMD_PSTATE_TRANSITION_DELAY 1000
>
> How were these values derived? If from documentation, it'll be good to add a
> link to the relevant documentation. And if they were derived from testing,
> please mention this in the commit log (along with some details of the tests used
> to determine the value).

The values are calculated from the CPU PM firmware and hardware design.
There are some latency and delay values defined in the PM firmware, I have no documents about the detail for now.

Perry.
>
> >
> > /*
> > * TODO: We need more time to fine tune processors with shared memory
> > solution

2022-08-16 16:55:21

by Punit Agrawal

[permalink] [raw]
Subject: Re: [PATCH v5 6/7] cpufreq: amd-pstate: update pstate frequency transition delay time

Hi Perry,

"Yuan, Perry" <[email protected]> writes:

> [AMD Official Use Only - General]
>
> Hi Punit
>
>> -----Original Message-----
>> From: Punit Agrawal <[email protected]>
>> Sent: Monday, August 15, 2022 11:06 PM
>> To: Yuan, Perry <[email protected]>
>> Cc: [email protected]; Huang, Ray <[email protected]>;
>> [email protected]; Sharma, Deepak <[email protected]>;
>> Limonciello, Mario <[email protected]>; Fontenot, Nathan
>> <[email protected]>; Deucher, Alexander
>> <[email protected]>; Su, Jinzhou (Joe) <[email protected]>;
>> Huang, Shimmer <[email protected]>; Du, Xiaojian
>> <[email protected]>; Meng, Li (Jassmine) <[email protected]>; linux-
>> [email protected]; [email protected]
>> Subject: Re: [PATCH v5 6/7] cpufreq: amd-pstate: update pstate frequency
>> transition delay time
>>
>> [CAUTION: External Email]
>>
>> Perry Yuan <[email protected]> writes:
>>
>> > Change the default transition latency to be 20ms that is more
>> > reasonable transition delay for AMD processors in non-EPP driver mode.
>> >
>> > Update transition delay time to 1ms, in the AMD CPU autonomous mode
>> > and non-autonomous mode, CPPC firmware will decide frequency at 1ms
>> > timescale based on the workload utilization.
>> >
>> > Acked-by: Viresh Kumar <[email protected]>
>> > Signed-off-by: Perry Yuan <[email protected]>
>> > ---
>> > drivers/cpufreq/amd-pstate.c | 4 ++--
>> > 1 file changed, 2 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/drivers/cpufreq/amd-pstate.c
>> > b/drivers/cpufreq/amd-pstate.c index e40177d14310..9cb051d61422 100644
>> > --- a/drivers/cpufreq/amd-pstate.c
>> > +++ b/drivers/cpufreq/amd-pstate.c
>> > @@ -41,8 +41,8 @@
>> > #include <asm/msr.h>
>> > #include "amd-pstate-trace.h"
>> >
>> > -#define AMD_PSTATE_TRANSITION_LATENCY 0x20000
>> > -#define AMD_PSTATE_TRANSITION_DELAY 500
>> > +#define AMD_PSTATE_TRANSITION_LATENCY 20000
>> > +#define AMD_PSTATE_TRANSITION_DELAY 1000
>>
>> How were these values derived? If from documentation, it'll be good to add a
>> link to the relevant documentation. And if they were derived from testing,
>> please mention this in the commit log (along with some details of the tests used
>> to determine the value).
>
> The values are calculated from the CPU PM firmware and hardware design.
> There are some latency and delay values defined in the PM firmware, I have no documents about the detail for now.

In that case, please mention that the values are calculated from
firmware / hardware design in the commit log (and include a reference to
the firmware sources if available).

Thanks!

[...]

2022-08-31 09:48:09

by Yuan, Perry

[permalink] [raw]
Subject: RE: [PATCH v5 4/7] cpufreq: amd_pstate: fix wrong lowest perf fetch

[AMD Official Use Only - General]

Hi Agrawal,

> -----Original Message-----
> From: Punit Agrawal <[email protected]>
> Sent: Monday, August 15, 2022 11:05 PM
> To: Yuan, Perry <[email protected]>
> Cc: [email protected]; Huang, Ray <[email protected]>;
> [email protected]; Sharma, Deepak <[email protected]>;
> Limonciello, Mario <[email protected]>; Fontenot, Nathan
> <[email protected]>; Deucher, Alexander
> <[email protected]>; Su, Jinzhou (Joe) <[email protected]>;
> Huang, Shimmer <[email protected]>; Du, Xiaojian
> <[email protected]>; Meng, Li (Jassmine) <[email protected]>; linux-
> [email protected]; [email protected]
> Subject: Re: [PATCH v5 4/7] cpufreq: amd_pstate: fix wrong lowest perf fetch
>
> [CAUTION: External Email]
>
> Hi Perry,
>
> Perry Yuan <[email protected]> writes:
>
> > Fix the wrong lowest perf value reading which is used for new des_perf
> > calculation by governor requested, the incorrect min_perf will get
> > incorrect des_perf to be set , that will cause the system frequency
> > changing unexpectedly.
> >
> > Reviewed-by: Huang Rui <[email protected]>
> > Acked-by: Viresh Kumar <[email protected]>
> > Signed-off-by: Perry Yuan <[email protected]>
> > Signed-off-by: Su Jinzhou <[email protected]>
> > ---
> > 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 5cdef6638681..183cdd4ba00e 100644
> > --- a/drivers/cpufreq/amd-pstate.c
> > +++ b/drivers/cpufreq/amd-pstate.c
> > @@ -307,7 +307,7 @@ static int amd_pstate_target(struct cpufreq_policy
> *policy,
> > return -ENODEV;
> >
> > cap_perf = READ_ONCE(cpudata->highest_perf);
> > - min_perf = READ_ONCE(cpudata->lowest_nonlinear_perf);
> > + min_perf = READ_ONCE(cpudata->lowest_perf);
> > max_perf = cap_perf;
> >
> > freqs.old = policy->cur;
>
> This looks to be a pretty big change (lowest nonlinear vs lowest). Does the patch
> need to be backported to older kernels?

The patch fixes the min perf initial value, the correct min perf is lowest_perf which is captured through MSR_AMD_CPPC_CAP1 register or the cppc_get_perf_caps().
Yes, the patch will need to be backported to other kernel branch as issue fix.
Sorry to response late.

Perry.

2022-08-31 19:13:15

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v5 3/7] cpufreq: amd-pstate: fix white-space

On Sun, Aug 14, 2022 at 6:49 PM Perry Yuan <[email protected]> wrote:
>
> Remove the white space and correct mixed-up indentation
>
> Acked-by: Viresh Kumar <[email protected]>
> Signed-off-by: Perry Yuan <[email protected]>
> ---
> drivers/cpufreq/amd-pstate.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index b31bb5e6cefc..5cdef6638681 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -115,7 +115,7 @@ struct amd_cpudata {
> struct amd_aperf_mperf cur;
> struct amd_aperf_mperf prev;
>
> - u64 freq;
> + u64 freq;
> bool boost_supported;
> };
>
> @@ -651,7 +651,7 @@ static struct cpufreq_driver amd_pstate_driver = {
> .resume = amd_pstate_cpu_resume,
> .set_boost = amd_pstate_set_boost,
> .name = "amd-pstate",
> - .attr = amd_pstate_attr,
> + .attr = amd_pstate_attr,
> };
>
> static int __init amd_pstate_init(void)
> --

Applied as 6.1 material along with patches [3-6/7].

The [7/7] was applied earlier and there was a change request for patch [1/7].

2022-09-01 05:49:53

by Yuan, Perry

[permalink] [raw]
Subject: RE: [PATCH v5 1/7] cpufreq: amd-pstate: cleanup the unused and duplicated headers declaration

[AMD Official Use Only - General]

Hi Punit,

> -----Original Message-----
> From: Punit Agrawal <[email protected]>
> Sent: Monday, August 15, 2022 11:05 PM
> To: Yuan, Perry <[email protected]>
> Cc: [email protected]; Huang, Ray <[email protected]>;
> [email protected]; Sharma, Deepak <[email protected]>;
> Limonciello, Mario <[email protected]>; Fontenot, Nathan
> <[email protected]>; Deucher, Alexander
> <[email protected]>; Su, Jinzhou (Joe) <[email protected]>;
> Huang, Shimmer <[email protected]>; Du, Xiaojian
> <[email protected]>; Meng, Li (Jassmine) <[email protected]>; linux-
> [email protected]; [email protected]
> Subject: Re: [PATCH v5 1/7] cpufreq: amd-pstate: cleanup the unused and
> duplicated headers declaration
>
> [CAUTION: External Email]
>
> Hi Perry,
>
> Perry Yuan <[email protected]> writes:
>
> > Cleanup the headers declaration which are not used actually and some
> > duplicated declaration which is declarated in some other headers
> > already, it will help to simplify the header part.
>
> We usually don't get rid of indirectly included headers as long as definitions from
> header are used in the code. This avoids problems if for some reason the
> included header gets dropped - it'll leave the code in an uncompilable state.
>
> More below.
>
> >
> > Reviewed-by: Huang Rui <[email protected]>
> > Acked-by: Viresh Kumar <[email protected]>
> > Signed-off-by: Perry Yuan <[email protected]>
> > ---
> > drivers/cpufreq/amd-pstate.c | 5 -----
> > 1 file changed, 5 deletions(-)
> >
> > diff --git a/drivers/cpufreq/amd-pstate.c
> > b/drivers/cpufreq/amd-pstate.c index 9ac75c1cde9c..19a078e232dd 100644
> > --- a/drivers/cpufreq/amd-pstate.c
> > +++ b/drivers/cpufreq/amd-pstate.c
> > @@ -31,19 +31,14 @@
> > #include <linux/compiler.h>
> > #include <linux/dmi.h>
> > #include <linux/slab.h>
> > -#include <linux/acpi.h>
> > #include <linux/io.h>
> > #include <linux/delay.h>
> > #include <linux/uaccess.h>
> > #include <linux/static_call.h>
> >
> > -#include <acpi/processor.h>
> > #include <acpi/cppc_acpi.h>
> >
> > #include <asm/msr.h>
> > -#include <asm/processor.h>
>
> On a quick scan, I noticed that "boot_cpu_data" and "boot_cpu_has()" in the
> module init function are defined in "asm/processor.h" that is being removed
> here. It may compile for now but makes the code more fragile as explained
> above.
>
> Please ensure that only the header files that have no definitions used in this file
> (amd-pstate.c) are dropped.

Here is the part of the headers we are working on.

==============================================
#include <linux/static_call.h>

#include <acpi/cppc_acpi.h>

#include <asm/msr.h>
#include "amd-pstate-trace.h"

============================================

I have tested the latest Linux-pm/bleeding-edge branch to verify the changes working.
As I know the "asm/processor.h" is included by the "acpi/cppc_acpi.h" subpath

#include <acpi/cppc_acpi.h>
#include <linux/acpi.h>
#include <acpi/acpi.h>
#include <asm/acpi.h>
#include <asm/processor.h>

To make it comfortable for us, I will send V6 for this patch (1/7)

Perry.

>
> > -#include <asm/cpufeature.h>
> > -#include <asm/cpu_device_id.h>
> > #include "amd-pstate-trace.h"
> >
> > #define AMD_PSTATE_TRANSITION_LATENCY 0x20000

2022-09-01 16:43:38

by Punit Agrawal

[permalink] [raw]
Subject: Re: [PATCH v5 4/7] cpufreq: amd_pstate: fix wrong lowest perf fetch

"Yuan, Perry" <[email protected]> writes:

[...]

>> Perry Yuan <[email protected]> writes:
>>
>> > Fix the wrong lowest perf value reading which is used for new des_perf
>> > calculation by governor requested, the incorrect min_perf will get
>> > incorrect des_perf to be set , that will cause the system frequency
>> > changing unexpectedly.
>> >
>> > Reviewed-by: Huang Rui <[email protected]>
>> > Acked-by: Viresh Kumar <[email protected]>
>> > Signed-off-by: Perry Yuan <[email protected]>
>> > Signed-off-by: Su Jinzhou <[email protected]>
>> > ---
>> > 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 5cdef6638681..183cdd4ba00e 100644
>> > --- a/drivers/cpufreq/amd-pstate.c
>> > +++ b/drivers/cpufreq/amd-pstate.c
>> > @@ -307,7 +307,7 @@ static int amd_pstate_target(struct cpufreq_policy
>> *policy,
>> > return -ENODEV;
>> >
>> > cap_perf = READ_ONCE(cpudata->highest_perf);
>> > - min_perf = READ_ONCE(cpudata->lowest_nonlinear_perf);
>> > + min_perf = READ_ONCE(cpudata->lowest_perf);
>> > max_perf = cap_perf;
>> >
>> > freqs.old = policy->cur;
>>
>> This looks to be a pretty big change (lowest nonlinear vs lowest). Does the patch
>> need to be backported to older kernels?
>
> The patch fixes the min perf initial value, the correct min perf is lowest_perf which is captured through MSR_AMD_CPPC_CAP1 register or the cppc_get_perf_caps().
> Yes, the patch will need to be backported to other kernel branch as issue fix.

Great, thanks for confirming!

[...]