Message ID | dc7fc753b596a4e262b21d2c2e8eec3570e4a97c.1707016927.git.perry.yuan@amd.com |
---|---|
State | Superseded |
Headers | show |
Series | AMD Pstate Fixes And Enhancements | expand |
Hello. On neděle 4. února 2024 4:26:14 CET Perry Yuan wrote: > Add quirks 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. > > The workaround will match the broken BIOS which lack of CPPC capabilities > nominal_freq and lowest_freq definition in the ACPI table. > > $ cat /sys/devices/system/cpu/cpu0/acpi_cppc/lowest_freq > 0 > $ cat /sys/devices/system/cpu/cpu0/acpi_cppc/nominal_freq > 0 > > Signed-off-by: Perry Yuan <perry.yuan@amd.com> > --- > drivers/cpufreq/amd-pstate.c | 49 ++++++++++++++++++++++++++++++++++-- > include/linux/amd-pstate.h | 6 +++++ > 2 files changed, 53 insertions(+), 2 deletions(-) > > diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c > index 77effc3caf6c..25a6d8a808c4 100644 > --- a/drivers/cpufreq/amd-pstate.c > +++ b/drivers/cpufreq/amd-pstate.c > @@ -67,6 +67,7 @@ static struct cpufreq_driver amd_pstate_epp_driver; > static int cppc_state = AMD_PSTATE_UNDEFINED; > static bool cppc_enabled; > static bool amd_pstate_prefcore = true; > +static struct quirk_entry *quirks; > > /* > * AMD Energy Preference Performance (EPP) > @@ -111,6 +112,33 @@ 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; > + pr_info("hardware type %s found\n", 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_BIOS_VERSION, "5.14"), > + DMI_MATCH(DMI_BIOS_RELEASE, "12/12/2019"); I think this is incorrect, and there should be a comma "," instead of semicolon ";" at the end of the string. Otherwise the build will fail. > + }, > + .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; > @@ -600,13 +628,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) > @@ -635,12 +669,18 @@ 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; > > - return cppc_perf.nominal_freq; > + if (quirks && quirks->nominal_freq) > + nominal_freq = quirks->nominal_freq; > + else > + nominal_freq = cppc_perf.nominal_freq; > + > + return nominal_freq; > } > > static int amd_get_lowest_nonlinear_freq(struct amd_cpudata *cpudata) > @@ -1672,6 +1712,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 d21838835abd..7b2cbb892fd9 100644 > --- a/include/linux/amd-pstate.h > +++ b/include/linux/amd-pstate.h > @@ -124,4 +124,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 */ >
[AMD Official Use Only - General] > -----Original Message----- > From: Oleksandr Natalenko <oleksandr@natalenko.name> > Sent: Sunday, February 4, 2024 10:45 PM > To: rafael.j.wysocki@intel.com; Limonciello, Mario > <Mario.Limonciello@amd.com>; viresh.kumar@linaro.org; Huang, Ray > <Ray.Huang@amd.com>; Shenoy, Gautham Ranjal > <gautham.shenoy@amd.com>; Petkov, Borislav > <Borislav.Petkov@amd.com>; Yuan, Perry <Perry.Yuan@amd.com> > Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Huang, Shimmer > <Shimmer.Huang@amd.com>; Du, Xiaojian <Xiaojian.Du@amd.com>; Meng, > Li (Jassmine) <Li.Meng@amd.com>; linux-pm@vger.kernel.org; linux- > kernel@vger.kernel.org > Subject: Re: [PATCH v3 6/6] cpufreq:amd-pstate: add quirk for the pstate > CPPC capabilities missing > > Hello. > > On neděle 4. února 2024 4:26:14 CET Perry Yuan wrote: > > Add quirks 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. > > > > The workaround will match the broken BIOS which lack of CPPC > > capabilities nominal_freq and lowest_freq definition in the ACPI table. > > > > $ cat /sys/devices/system/cpu/cpu0/acpi_cppc/lowest_freq > > 0 > > $ cat /sys/devices/system/cpu/cpu0/acpi_cppc/nominal_freq > > 0 > > > > Signed-off-by: Perry Yuan <perry.yuan@amd.com> > > --- > > drivers/cpufreq/amd-pstate.c | 49 > ++++++++++++++++++++++++++++++++++-- > > include/linux/amd-pstate.h | 6 +++++ > > 2 files changed, 53 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/cpufreq/amd-pstate.c > > b/drivers/cpufreq/amd-pstate.c index 77effc3caf6c..25a6d8a808c4 100644 > > --- a/drivers/cpufreq/amd-pstate.c > > +++ b/drivers/cpufreq/amd-pstate.c > > @@ -67,6 +67,7 @@ static struct cpufreq_driver amd_pstate_epp_driver; > > static int cppc_state = AMD_PSTATE_UNDEFINED; static bool > > cppc_enabled; static bool amd_pstate_prefcore = true; > > +static struct quirk_entry *quirks; > > > > /* > > * AMD Energy Preference Performance (EPP) @@ -111,6 +112,33 @@ > > 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; > > + pr_info("hardware type %s found\n", 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_BIOS_VERSION, "5.14"), > > + DMI_MATCH(DMI_BIOS_RELEASE, "12/12/2019"); > > I think this is incorrect, and there should be a comma "," instead of > semicolon ";" at the end of the string. Otherwise the build will fail. Good catch, I made a mistake here, I found this after I sent it out, have it fixed in V4. Thanks for the review. 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; > > @@ -600,13 +628,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) @@ -635,12 > > +669,18 @@ 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; > > > > - return cppc_perf.nominal_freq; > > + if (quirks && quirks->nominal_freq) > > + nominal_freq = quirks->nominal_freq; > > + else > > + nominal_freq = cppc_perf.nominal_freq; > > + > > + return nominal_freq; > > } > > > > static int amd_get_lowest_nonlinear_freq(struct amd_cpudata *cpudata) > > @@ -1672,6 +1712,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 d21838835abd..7b2cbb892fd9 100644 > > --- a/include/linux/amd-pstate.h > > +++ b/include/linux/amd-pstate.h > > @@ -124,4 +124,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 */ > > > > > -- > Oleksandr Natalenko (post-factum)
On 2/4/2024 20:29, Yuan, Perry wrote: > [AMD Official Use Only - General] > >> -----Original Message----- >> From: Oleksandr Natalenko <oleksandr@natalenko.name> >> Sent: Sunday, February 4, 2024 10:45 PM >> To: rafael.j.wysocki@intel.com; Limonciello, Mario >> <Mario.Limonciello@amd.com>; viresh.kumar@linaro.org; Huang, Ray >> <Ray.Huang@amd.com>; Shenoy, Gautham Ranjal >> <gautham.shenoy@amd.com>; Petkov, Borislav >> <Borislav.Petkov@amd.com>; Yuan, Perry <Perry.Yuan@amd.com> >> Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Huang, Shimmer >> <Shimmer.Huang@amd.com>; Du, Xiaojian <Xiaojian.Du@amd.com>; Meng, >> Li (Jassmine) <Li.Meng@amd.com>; linux-pm@vger.kernel.org; linux- >> kernel@vger.kernel.org >> Subject: Re: [PATCH v3 6/6] cpufreq:amd-pstate: add quirk for the pstate >> CPPC capabilities missing >> >> Hello. >> >> On neděle 4. února 2024 4:26:14 CET Perry Yuan wrote: >>> Add quirks 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. >>> >>> The workaround will match the broken BIOS which lack of CPPC >>> capabilities nominal_freq and lowest_freq definition in the ACPI table. >>> >>> $ cat /sys/devices/system/cpu/cpu0/acpi_cppc/lowest_freq >>> 0 >>> $ cat /sys/devices/system/cpu/cpu0/acpi_cppc/nominal_freq >>> 0 >>> >>> Signed-off-by: Perry Yuan <perry.yuan@amd.com> >>> --- >>> drivers/cpufreq/amd-pstate.c | 49 >> ++++++++++++++++++++++++++++++++++-- >>> include/linux/amd-pstate.h | 6 +++++ >>> 2 files changed, 53 insertions(+), 2 deletions(-) >>> >>> diff --git a/drivers/cpufreq/amd-pstate.c >>> b/drivers/cpufreq/amd-pstate.c index 77effc3caf6c..25a6d8a808c4 100644 >>> --- a/drivers/cpufreq/amd-pstate.c >>> +++ b/drivers/cpufreq/amd-pstate.c >>> @@ -67,6 +67,7 @@ static struct cpufreq_driver amd_pstate_epp_driver; >>> static int cppc_state = AMD_PSTATE_UNDEFINED; static bool >>> cppc_enabled; static bool amd_pstate_prefcore = true; >>> +static struct quirk_entry *quirks; >>> >>> /* >>> * AMD Energy Preference Performance (EPP) @@ -111,6 +112,33 @@ >>> 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; >>> + pr_info("hardware type %s found\n", 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_BIOS_VERSION, "5.14"), >>> + DMI_MATCH(DMI_BIOS_RELEASE, "12/12/2019"); >> >> I think this is incorrect, and there should be a comma "," instead of >> semicolon ";" at the end of the string. Otherwise the build will fail. > > Good catch, I made a mistake here, I found this after I sent it out, have it fixed in V4. > Thanks for the review. I'm still wondering if this is the right level of narrowness. Does the quirk only apply to a single BIOS vendor? Or any other sysfs attributes that can be generic to all affected systems? Also would it perhaps make sense to rename dmi_matched to dmi_matched_7k62_bios_bug and then in dmi_matched_7k62_bios_bug check the model/family match. In that function you can only set quirks = dmi->driver_data If the right CPU applies then too. > > 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; >>> @@ -600,13 +628,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) @@ -635,12 >>> +669,18 @@ 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; >>> >>> - return cppc_perf.nominal_freq; >>> + if (quirks && quirks->nominal_freq) >>> + nominal_freq = quirks->nominal_freq; >>> + else >>> + nominal_freq = cppc_perf.nominal_freq; >>> + >>> + return nominal_freq; >>> } >>> >>> static int amd_get_lowest_nonlinear_freq(struct amd_cpudata *cpudata) >>> @@ -1672,6 +1712,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 d21838835abd..7b2cbb892fd9 100644 >>> --- a/include/linux/amd-pstate.h >>> +++ b/include/linux/amd-pstate.h >>> @@ -124,4 +124,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 */ >>> >> >> >> -- >> Oleksandr Natalenko (post-factum)
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 77effc3caf6c..25a6d8a808c4 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -67,6 +67,7 @@ static struct cpufreq_driver amd_pstate_epp_driver; static int cppc_state = AMD_PSTATE_UNDEFINED; static bool cppc_enabled; static bool amd_pstate_prefcore = true; +static struct quirk_entry *quirks; /* * AMD Energy Preference Performance (EPP) @@ -111,6 +112,33 @@ 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; + pr_info("hardware type %s found\n", 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_BIOS_VERSION, "5.14"), + DMI_MATCH(DMI_BIOS_RELEASE, "12/12/2019"); + }, + .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; @@ -600,13 +628,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) @@ -635,12 +669,18 @@ 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; - return cppc_perf.nominal_freq; + if (quirks && quirks->nominal_freq) + nominal_freq = quirks->nominal_freq; + else + nominal_freq = cppc_perf.nominal_freq; + + return nominal_freq; } static int amd_get_lowest_nonlinear_freq(struct amd_cpudata *cpudata) @@ -1672,6 +1712,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 d21838835abd..7b2cbb892fd9 100644 --- a/include/linux/amd-pstate.h +++ b/include/linux/amd-pstate.h @@ -124,4 +124,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 */
Add quirks 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. The workaround will match the broken BIOS which lack of CPPC capabilities nominal_freq and lowest_freq definition in the ACPI table. $ cat /sys/devices/system/cpu/cpu0/acpi_cppc/lowest_freq 0 $ cat /sys/devices/system/cpu/cpu0/acpi_cppc/nominal_freq 0 Signed-off-by: Perry Yuan <perry.yuan@amd.com> --- drivers/cpufreq/amd-pstate.c | 49 ++++++++++++++++++++++++++++++++++-- include/linux/amd-pstate.h | 6 +++++ 2 files changed, 53 insertions(+), 2 deletions(-)