2024-01-31 09:09:08

by Yuan, Perry

[permalink] [raw]
Subject: [PATCH 6/6] cpufreq:amd-pstate: add quirk for the pstate CPPC capabilities missing

Add quirk table to get CPPC capabilities issue fixed by providing
correct perf or frequency values while driver loading.

If CPPC capabilities are not defined in the ACPI tables or wrongly
defined by platform firmware, it needs to use quick to get those
issues fixed with correct workaround values to make pstate driver
can be loaded even though there are CPPC capabilities errors.

Signed-off-by: Perry Yuan <[email protected]>
---
drivers/cpufreq/amd-pstate.c | 51 +++++++++++++++++++++++++++++++-----
include/linux/amd-pstate.h | 6 +++++
2 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index eea2e192d748..cbc415af0f08 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -64,6 +64,7 @@ static struct cpufreq_driver amd_pstate_driver;
static struct cpufreq_driver amd_pstate_epp_driver;
static int cppc_state = AMD_PSTATE_UNDEFINED;
static bool cppc_enabled;
+static struct quirk_entry *quirks;

/**
* struct global_params - Global parameters, mostly tunable via sysfs.
@@ -121,6 +122,32 @@ static unsigned int epp_values[] = {

typedef int (*cppc_mode_transition_fn)(int);

+static struct quirk_entry quirk_amd_7k62 = {
+ .nominal_freq = 2600,
+ .lowest_freq = 550,
+};
+
+static int __init dmi_matched(const struct dmi_system_id *dmi)
+{
+ quirks = dmi->driver_data;
+
+ return 1;
+}
+
+static const struct dmi_system_id amd_pstate_quirks_table[] __initconst = {
+ {
+ .callback = dmi_matched,
+ .ident = "AMD EPYC 7K62",
+ .matches = {
+ DMI_MATCH(DMI_PRODUCT_VERSION, "C1"),
+ DMI_MATCH(DMI_PRODUCT_SERIAL, "FX19911000028"),
+ },
+ .driver_data = &quirk_amd_7k62,
+ },
+ {}
+};
+MODULE_DEVICE_TABLE(dmi, amd_pstate_quirks_table);
+
static inline int get_mode_idx_from_str(const char *str, size_t size)
{
int i;
@@ -581,13 +608,19 @@ static void amd_pstate_adjust_perf(unsigned int cpu,
static int amd_get_min_freq(struct amd_cpudata *cpudata)
{
struct cppc_perf_caps cppc_perf;
+ u32 lowest_freq;

int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf);
if (ret)
return ret;

+ if (quirks && quirks->lowest_freq)
+ lowest_freq = quirks->lowest_freq;
+ else
+ lowest_freq = cppc_perf.lowest_freq;
+
/* Switch to khz */
- return cppc_perf.lowest_freq * 1000;
+ return lowest_freq * 1000;
}

static int amd_get_max_freq(struct amd_cpudata *cpudata)
@@ -619,13 +652,14 @@ static int amd_get_max_freq(struct amd_cpudata *cpudata)

static int amd_get_nominal_freq(struct amd_cpudata *cpudata)
{
- struct cppc_perf_caps cppc_perf;
+ u32 nominal_freq;

- int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf);
- if (ret)
- return ret;
+ if (quirks && quirks->nominal_freq)
+ nominal_freq = quirks->nominal_freq;
+ else
+ nominal_freq = READ_ONCE(cpudata->nominal_freq);

- return cppc_perf.nominal_freq;
+ return nominal_freq;
}

static int amd_get_lowest_nonlinear_freq(struct amd_cpudata *cpudata)
@@ -1623,6 +1657,11 @@ static int __init amd_pstate_init(void)
if (cpufreq_get_current_driver())
return -EEXIST;

+ quirks = NULL;
+
+ /* check if this machine need CPPC quirks */
+ dmi_check_system(amd_pstate_quirks_table);
+
switch (cppc_state) {
case AMD_PSTATE_UNDEFINED:
/* Disable on the following configs by default:
diff --git a/include/linux/amd-pstate.h b/include/linux/amd-pstate.h
index 446394f84606..ea80f961607d 100644
--- a/include/linux/amd-pstate.h
+++ b/include/linux/amd-pstate.h
@@ -110,4 +110,10 @@ static const char * const amd_pstate_mode_string[] = {
[AMD_PSTATE_GUIDED] = "guided",
NULL,
};
+
+struct quirk_entry {
+ u32 nominal_freq;
+ u32 lowest_freq;
+};
+
#endif /* _LINUX_AMD_PSTATE_H */
--
2.34.1



2024-01-31 21:59:49

by Mario Limonciello

[permalink] [raw]
Subject: Re: [PATCH 6/6] cpufreq:amd-pstate: add quirk for the pstate CPPC capabilities missing

On 1/31/2024 02:50, Perry Yuan wrote:
> Add quirk table to get CPPC capabilities issue fixed by providing
> correct perf or frequency values while driver loading.
>
> If CPPC capabilities are not defined in the ACPI tables or wrongly
> defined by platform firmware, it needs to use quick to get those

s/quick/quirk/

> issues fixed with correct workaround values to make pstate driver

to allow the pstate driver

> can be loaded even though there are CPPC capabilities errors.
>
> Signed-off-by: Perry Yuan <[email protected]>
> ---
> drivers/cpufreq/amd-pstate.c | 51 +++++++++++++++++++++++++++++++-----
> include/linux/amd-pstate.h | 6 +++++
> 2 files changed, 51 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index eea2e192d748..cbc415af0f08 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -64,6 +64,7 @@ static struct cpufreq_driver amd_pstate_driver;
> static struct cpufreq_driver amd_pstate_epp_driver;
> static int cppc_state = AMD_PSTATE_UNDEFINED;
> static bool cppc_enabled;
> +static struct quirk_entry *quirks;
>
> /**
> * struct global_params - Global parameters, mostly tunable via sysfs.
> @@ -121,6 +122,32 @@ static unsigned int epp_values[] = {
>
> typedef int (*cppc_mode_transition_fn)(int);
>
> +static struct quirk_entry quirk_amd_7k62 = {
> + .nominal_freq = 2600,
> + .lowest_freq = 550,
> +};
> +
> +static int __init dmi_matched(const struct dmi_system_id *dmi)
> +{
> + quirks = dmi->driver_data; > +

Under the presumption that the quirk list will grow as more buggy older
machines are identified, maybe it's worth having a dyndbg or info
statement here to indicate that it's using quirked values for dmi->ident.

> + return 1;
> +}
> +
> +static const struct dmi_system_id amd_pstate_quirks_table[] __initconst = {
> + {
> + .callback = dmi_matched,
> + .ident = "AMD EPYC 7K62",
> + .matches = {
> + DMI_MATCH(DMI_PRODUCT_VERSION, "C1"),
> + DMI_MATCH(DMI_PRODUCT_SERIAL, "FX19911000028"),

This is way too specific isn't it? It would only load on that single
system I would expect. But I think you want to have an entry that
matches the DMI_PRODUCT_NAME or DMI_FAMILY_NAME instead most likely.

> + },
> + .driver_data = &quirk_amd_7k62,
> + },
> + {}
> +};
> +MODULE_DEVICE_TABLE(dmi, amd_pstate_quirks_table);
> +
> static inline int get_mode_idx_from_str(const char *str, size_t size)
> {
> int i;
> @@ -581,13 +608,19 @@ static void amd_pstate_adjust_perf(unsigned int cpu,
> static int amd_get_min_freq(struct amd_cpudata *cpudata)
> {
> struct cppc_perf_caps cppc_perf;
> + u32 lowest_freq;
>
> int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf);
> if (ret)
> return ret;
>
> + if (quirks && quirks->lowest_freq)
> + lowest_freq = quirks->lowest_freq;
> + else
> + lowest_freq = cppc_perf.lowest_freq;
> +
> /* Switch to khz */
> - return cppc_perf.lowest_freq * 1000;
> + return lowest_freq * 1000;
> }
>
> static int amd_get_max_freq(struct amd_cpudata *cpudata)
> @@ -619,13 +652,14 @@ static int amd_get_max_freq(struct amd_cpudata *cpudata)
>
> static int amd_get_nominal_freq(struct amd_cpudata *cpudata)
> {
> - struct cppc_perf_caps cppc_perf;
> + u32 nominal_freq;
>
> - int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf);
> - if (ret)
> - return ret;

I think this hunk should be earlier in your series. Conceptually it
seems to match what patch 3 does to me.

> + if (quirks && quirks->nominal_freq)
> + nominal_freq = quirks->nominal_freq;
> + else
> + nominal_freq = READ_ONCE(cpudata->nominal_freq);
>
> - return cppc_perf.nominal_freq;
> + return nominal_freq;
> }
>
> static int amd_get_lowest_nonlinear_freq(struct amd_cpudata *cpudata)
> @@ -1623,6 +1657,11 @@ static int __init amd_pstate_init(void)
> if (cpufreq_get_current_driver())
> return -EEXIST;
>
> + quirks = NULL;
> +
> + /* check if this machine need CPPC quirks */
> + dmi_check_system(amd_pstate_quirks_table);
> +
> switch (cppc_state) {
> case AMD_PSTATE_UNDEFINED:
> /* Disable on the following configs by default:
> diff --git a/include/linux/amd-pstate.h b/include/linux/amd-pstate.h
> index 446394f84606..ea80f961607d 100644
> --- a/include/linux/amd-pstate.h
> +++ b/include/linux/amd-pstate.h
> @@ -110,4 +110,10 @@ static const char * const amd_pstate_mode_string[] = {
> [AMD_PSTATE_GUIDED] = "guided",
> NULL,
> };
> +
> +struct quirk_entry {
> + u32 nominal_freq;
> + u32 lowest_freq;
> +};
> +
> #endif /* _LINUX_AMD_PSTATE_H */


2024-02-02 09:11:24

by Yuan, Perry

[permalink] [raw]
Subject: RE: [PATCH 6/6] cpufreq:amd-pstate: add quirk for the pstate CPPC capabilities missing

[AMD Official Use Only - General]

Hi Mario,

> -----Original Message-----
> From: Limonciello, Mario <[email protected]>
> Sent: Thursday, February 1, 2024 6:00 AM
> To: Yuan, Perry <[email protected]>; [email protected];
> [email protected]; Huang, Ray <[email protected]>; Shenoy,
> Gautham Ranjal <[email protected]>; Petkov, Borislav
> <[email protected]>
> Cc: Deucher, Alexander <[email protected]>; Huang, Shimmer
> <[email protected]>; Du, Xiaojian <[email protected]>; Meng,
> Li (Jassmine) <[email protected]>; [email protected]; linux-
> [email protected]
> Subject: Re: [PATCH 6/6] cpufreq:amd-pstate: add quirk for the pstate CPPC
> capabilities missing
>
> On 1/31/2024 02:50, Perry Yuan wrote:
> > Add quirk table to get CPPC capabilities issue fixed by providing
> > correct perf or frequency values while driver loading.
> >
> > If CPPC capabilities are not defined in the ACPI tables or wrongly
> > defined by platform firmware, it needs to use quick to get those
>
> s/quick/quirk/
>
> > issues fixed with correct workaround values to make pstate driver
>
> to allow the pstate driver
>
> > can be loaded even though there are CPPC capabilities errors.
> >
> > Signed-off-by: Perry Yuan <[email protected]>
> > ---
> > drivers/cpufreq/amd-pstate.c | 51
> +++++++++++++++++++++++++++++++-----
> > include/linux/amd-pstate.h | 6 +++++
> > 2 files changed, 51 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/cpufreq/amd-pstate.c
> > b/drivers/cpufreq/amd-pstate.c index eea2e192d748..cbc415af0f08
> 100644
> > --- a/drivers/cpufreq/amd-pstate.c
> > +++ b/drivers/cpufreq/amd-pstate.c
> > @@ -64,6 +64,7 @@ static struct cpufreq_driver amd_pstate_driver;
> > static struct cpufreq_driver amd_pstate_epp_driver;
> > static int cppc_state = AMD_PSTATE_UNDEFINED;
> > static bool cppc_enabled;
> > +static struct quirk_entry *quirks;
> >
> > /**
> > * struct global_params - Global parameters, mostly tunable via sysfs.
> > @@ -121,6 +122,32 @@ static unsigned int epp_values[] = {
> >
> > typedef int (*cppc_mode_transition_fn)(int);
> >
> > +static struct quirk_entry quirk_amd_7k62 = {
> > + .nominal_freq = 2600,
> > + .lowest_freq = 550,
> > +};
> > +
> > +static int __init dmi_matched(const struct dmi_system_id *dmi) {
> > + quirks = dmi->driver_data; > +
>
> Under the presumption that the quirk list will grow as more buggy older
> machines are identified, maybe it's worth having a dyndbg or info statement
> here to indicate that it's using quirked values for dmi->ident.

Added a debug line in V2.

>
> > + return 1;
> > +}
> > +
> > +static const struct dmi_system_id amd_pstate_quirks_table[] __initconst = {
> > + {
> > + .callback = dmi_matched,
> > + .ident = "AMD EPYC 7K62",
> > + .matches = {
> > + DMI_MATCH(DMI_PRODUCT_VERSION, "C1"),
> > + DMI_MATCH(DMI_PRODUCT_SERIAL,
> "FX19911000028"),
>
> This is way too specific isn't it? It would only load on that single system I
> would expect. But I think you want to have an entry that matches the
> DMI_PRODUCT_NAME or DMI_FAMILY_NAME instead most likely.

Yes, nominally we use DMI_PRODUCT_NAME or DMI_FAMILY_NAME,
Current quirk for 7K62 is special added for a AMD customer I did not get permission to exposure the product information.
It is used by a specific system which has broken BIOS, there are lots of server nodes that cannot upgrade BIOS.
So we match the system with version and serial number for the special fix.

If users have other products for quirks fix, we still can use DMI_PRODUCT_NAME or DMI_FAMILY_NAME in the next matches.

Perry.

>
> > + },
> > + .driver_data = &quirk_amd_7k62,
> > + },
> > + {}
> > +};
> > +MODULE_DEVICE_TABLE(dmi, amd_pstate_quirks_table);
> > +
> > static inline int get_mode_idx_from_str(const char *str, size_t size)
> > {
> > int i;
> > @@ -581,13 +608,19 @@ static void amd_pstate_adjust_perf(unsigned int
> cpu,
> > static int amd_get_min_freq(struct amd_cpudata *cpudata)
> > {
> > struct cppc_perf_caps cppc_perf;
> > + u32 lowest_freq;
> >
> > int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf);
> > if (ret)
> > return ret;
> >
> > + if (quirks && quirks->lowest_freq)
> > + lowest_freq = quirks->lowest_freq;
> > + else
> > + lowest_freq = cppc_perf.lowest_freq;
> > +
> > /* Switch to khz */
> > - return cppc_perf.lowest_freq * 1000;
> > + return lowest_freq * 1000;
> > }
> >
> > static int amd_get_max_freq(struct amd_cpudata *cpudata) @@ -619,13
> > +652,14 @@ static int amd_get_max_freq(struct amd_cpudata *cpudata)
> >
> > static int amd_get_nominal_freq(struct amd_cpudata *cpudata)
> > {
> > - struct cppc_perf_caps cppc_perf;
> > + u32 nominal_freq;
> >
> > - int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf);
> > - if (ret)
> > - return ret;
>
> I think this hunk should be earlier in your series. Conceptually it seems to
> match what patch 3 does to me.

It is a mistake that remove the code here.
I have fixed it in the V2 and tested the patches work as expected.


>
> > + if (quirks && quirks->nominal_freq)
> > + nominal_freq = quirks->nominal_freq;
> > + else
> > + nominal_freq = READ_ONCE(cpudata->nominal_freq);
> >
> > - return cppc_perf.nominal_freq;
> > + return nominal_freq;
> > }
> >
> > static int amd_get_lowest_nonlinear_freq(struct amd_cpudata
> > *cpudata) @@ -1623,6 +1657,11 @@ static int __init amd_pstate_init(void)
> > if (cpufreq_get_current_driver())
> > return -EEXIST;
> >
> > + quirks = NULL;
> > +
> > + /* check if this machine need CPPC quirks */
> > + dmi_check_system(amd_pstate_quirks_table);
> > +
> > switch (cppc_state) {
> > case AMD_PSTATE_UNDEFINED:
> > /* Disable on the following configs by default:
> > diff --git a/include/linux/amd-pstate.h b/include/linux/amd-pstate.h
> > index 446394f84606..ea80f961607d 100644
> > --- a/include/linux/amd-pstate.h
> > +++ b/include/linux/amd-pstate.h
> > @@ -110,4 +110,10 @@ static const char * const
> amd_pstate_mode_string[] = {
> > [AMD_PSTATE_GUIDED] = "guided",
> > NULL,
> > };
> > +
> > +struct quirk_entry {
> > + u32 nominal_freq;
> > + u32 lowest_freq;
> > +};
> > +
> > #endif /* _LINUX_AMD_PSTATE_H */