Skip to contentSkip to conversation

Add processor to the ignore PSD override list

RFC PATCH In review Punit Agrawal 4 participants 27 messages Nov 25, 2020 – Dec 17, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Add processor to the ignore PSD override list

Hi,

While looking into Giovanni's patches to enable frequency invariance on AMD systems[0], I noticed an issue with initialising frequency domain information on a recent AMD APU.

Patch 1 refactors the test to ignore firmware provided frequency domain into a separate function.

Patch 2 adds said APU (Family: 0x17, Model: 0x60, Stepping: 0x01) to the list of CPUs for which the PSD override is ignored. I am not quite happy with having to special case a particular CPU but also couldn't find any documentation to help identify the CPUs that don't need the override.

Patch 3 and 4 are somewhat independent and a first step towards improving the situation with regards to the use of raw identifiers for AMD processors throughout the kernel.

All feedback welcome.

Thanks,
Punit

[0] https://lore.kernel.org/linux-acpi/[email protected]/

Punit Agrawal (4):
cpufreq: acpi-cpufreq: Re-factor overriding ACPI PSD
cpufreq: acpi-cpufreq: Add processor to the ignore PSD override list x86/cpu: amd: Define processor families
cpufreq: acpi-cpufreq: Use identifiers for AMD processor family

 arch/x86/include/asm/amd-family.h    | 18 ++++++++++++++++++
 arch/x86/include/asm/cpu_device_id.h |  2 ++
 drivers/cpufreq/acpi-cpufreq.c       | 24 +++++++++++++++++++++---
 3 files changed, 41 insertions(+), 3 deletions(-)
 create mode 100644 arch/x86/include/asm/amd-family.h
Signature · 1 line
2.29.2
#1 lore raw

RFC PATCH 1/4 cpufreq: acpi-cpufreq: Re-factor overriding ACPI PSD

Re-factor the code to override the firmware provided frequency domain information (via PSD) to localise the checks in one function.

No functional change intended.

---
 drivers/cpufreq/acpi-cpufreq.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/cpufreq/acpi-cpufreq.c +15 -2
index 1e4fbb002a31..b1e7df96d428 100644
@@ -191,6 +191,20 @@ static int check_amd_hwpstate_cpu(unsigned int cpuid)
 	return cpu_has(cpu, X86_FEATURE_HW_PSTATE);
 }
 
+static int override_acpi_psd(unsigned int cpu_id)
+{
+	struct cpuinfo_x86 *c = &boot_cpu_data;
+
+	if (c->x86_vendor == X86_VENDOR_AMD) {
+		if (!check_amd_hwpstate_cpu(cpu_id))
+			return false;
+
+		return c->x86 < 0x19;
+	}
+
+	return false;
+}
+
 static unsigned extract_io(struct cpufreq_policy *policy, u32 value)
 {
 	struct acpi_cpufreq_data *data = policy->driver_data;
@@ -691,8 +705,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
 		cpumask_copy(policy->cpus, topology_core_cpumask(cpu));
 	}
 
-	if (check_amd_hwpstate_cpu(cpu) && boot_cpu_data.x86 < 0x19 &&
-	    !acpi_pstate_strict) {
+	if (override_acpi_psd(cpu) && !acpi_pstate_strict) {
 		cpumask_clear(policy->cpus);
 		cpumask_set_cpu(cpu, policy->cpus);
 		cpumask_copy(data->freqdomain_cpus,
Signature · 1 line
2.29.2
#4 lore raw

RFC PATCH 2/4 cpufreq: acpi-cpufreq: Add processor to the ignore PSD override list

In reply to Punit Agrawal

Booting Linux on a Zen2 based processor (family: 0x17, model: 0x60,
stepping: 0x1) shows the following message in the logs -

acpi_cpufreq: overriding BIOS provided _PSD data

Although commit 5368512abe08 ("acpi-cpufreq: Honor _PSD table setting on new AMD CPUs") indicates that the override is not required for Zen3 onwards, it seems that domain information can be trusted even on certain earlier systems. Update the check, to skip the override for Zen2 processors known to work without the override.

---
 drivers/cpufreq/acpi-cpufreq.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/cpufreq/acpi-cpufreq.c +7 -2
index b1e7df96d428..29f1cd93541e 100644
@@ -198,8 +198,13 @@ static int override_acpi_psd(unsigned int cpu_id)
 	if (c->x86_vendor == X86_VENDOR_AMD) {
 		if (!check_amd_hwpstate_cpu(cpu_id))
 			return false;
-
-		return c->x86 < 0x19;
+		/*
+		 * CPU's before Zen3 (except some Zen2) need the
+		 * override.
+		 */
+		return (c->x86 < 0x19) &&
+			!(c->x86 == 0x17 && c->x86_model == 0x60 &&
+			  c->x86_stepping == 0x1);
 	}
 
 	return false;
Signature · 1 line
2.29.2
#17 lore raw

RFC PATCH 3/4 x86/cpu: amd: Define processor families

In reply to Punit Agrawal

So far, the AMD processor identifier (family, models, stepping) are referred to by raw values making it easy to make mistakes. It is also harder to read and maintain. Additionally, these values are also being used in subsystems outside the arch code where not everybody maybe be as familiar with the processor identifiers.

As a first step towards improving the status quo, add macros for the AMD processor families and propagate them through the existing cpu_device_id.h header used for this purpose.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
---
 arch/x86/include/asm/amd-family.h    | 18 ++++++++++++++++++
 arch/x86/include/asm/cpu_device_id.h |  2 ++
 2 files changed, 20 insertions(+)
 create mode 100644 arch/x86/include/asm/amd-family.h
arch/x86/include/asm/amd-family.h new file +18 -0
new file mode 100644
index 000000000000..dff4d13b8e74
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_AMD_FAMILY_H
+#define _ASM_X86_AMD_FAMILY_H
+
+#define AMD_FAM_K5			0x04
+#define AMD_FAM_K6			0x05
+#define AMD_FAM_K7			0x06
+#define AMD_FAM_K8			0x0F
+#define AMD_FAM_K10			0x10
+#define AMD_FAM_K8_K10_HYBRID		0x11
+#define AMD_FAM_LLANO			0x12
+#define AMD_FAM_BOBCAT			0x14
+#define AMD_FAM_BULLDOZER		0x15
+#define AMD_FAM_JAGUAR			0x16
+#define AMD_FAM_ZEN			0x17
+#define AMD_FAM_ZEN3			0x19
+
+#endif /* _ASM_X86_AMD_FAMILY_H */
arch/x86/include/asm/cpu_device_id.h +2 -0
index eb8fcede9e3b..bbb48ba4c7ff 100644
@@ -12,6 +12,8 @@
 #include <linux/mod_devicetable.h>
 /* Get the INTEL_FAM* model defines */
 #include <asm/intel-family.h>
+/* Get the AMD model defines */
+#include <asm/amd-family.h>
 /* And the X86_VENDOR_* ones */
 #include <asm/processor.h>
 
Signature · 1 line
2.29.2
#21 lore raw

RFC PATCH 4/4 cpufreq: acpi-cpufreq: Use identifiers for AMD processor family

In reply to Punit Agrawal

Replace the raw values for AMD processor family with recently introduced identifier macros to improve code readability and maintainability.

---
 drivers/cpufreq/acpi-cpufreq.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/cpufreq/acpi-cpufreq.c +3 -3
index 29f1cd93541e..d8b8300ae9e0 100644
@@ -202,8 +202,8 @@ static int override_acpi_psd(unsigned int cpu_id)
 		 * CPU's before Zen3 (except some Zen2) need the
 		 * override.
 		 */
-		return (c->x86 < 0x19) &&
-			!(c->x86 == 0x17 && c->x86_model == 0x60 &&
+		return (c->x86 < AMD_FAM_ZEN3) &&
+			!(c->x86 == AMD_FAM_ZEN && c->x86_model == 0x60 &&
 			  c->x86_stepping == 0x1);
 	}
 
@@ -735,7 +735,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
 	switch (perf->control_register.space_id) {
 	case ACPI_ADR_SPACE_SYSTEM_IO:
 		if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
-		    boot_cpu_data.x86 == 0xf) {
+		    boot_cpu_data.x86 == AMD_FAM_K8) {
 			pr_debug("AMD K8 systems must use native drivers.\n");
 			result = -ENODEV;
 			goto err_unreg;
Signature · 1 line
2.29.2
maintainer
#18 lore raw

Re: [RFC PATCH 3/4] x86/cpu: amd: Define processor families

In reply to Punit Agrawal
Quoted 27 lines · Punit Agrawal

So far, the AMD processor identifier (family, models, stepping) are referred to by raw values making it easy to make mistakes. It is also harder to read and maintain. Additionally, these values are also being used in subsystems outside the arch code where not everybody maybe be as familiar with the processor identifiers.

As a first step towards improving the status quo, add macros for the AMD processor families and propagate them through the existing cpu_device_id.h header used for this purpose.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
---
 arch/x86/include/asm/amd-family.h    | 18 ++++++++++++++++++
 arch/x86/include/asm/cpu_device_id.h |  2 ++
 2 files changed, 20 insertions(+)
 create mode 100644 arch/x86/include/asm/amd-family.h
arch/x86/include/asm/amd-family.h new file +0 -0
new file mode 100644
index 000000000000..dff4d13b8e74

arch/x86/include/asm/amd-family.h line 9

Quoted 9 lines
arch/x86/include/asm/amd-family.h new file +9 -0
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_AMD_FAMILY_H
+#define _ASM_X86_AMD_FAMILY_H
+
+#define AMD_FAM_K5			0x04
+#define AMD_FAM_K6			0x05
+#define AMD_FAM_K7			0x06
+#define AMD_FAM_K8			0x0F
+#define AMD_FAM_K10			0x10

Fam 0x10 is Greyhound and a lot more core names. I'd let the AMD folks on Cc say what they wanna call it but I don't think K10 was used anywhere except outside of AMD. :)

arch/x86/include/asm/amd-family.h line 10

Quoted 1 line
arch/x86/include/asm/amd-family.h new file +1 -0
+#define AMD_FAM_K8_K10_HYBRID		0x11

That was called Griffin so AMD_FAM_GRIFFIN I guess. If not used anywhere in the tree, no need to add the define. Same holds true for the rest of the defines - add them only when they're used.

arch/x86/include/asm/amd-family.h line 15

Quoted 5 lines
arch/x86/include/asm/amd-family.h new file +5 -0
+#define AMD_FAM_LLANO			0x12
+#define AMD_FAM_BOBCAT			0x14
+#define AMD_FAM_BULLDOZER		0x15
+#define AMD_FAM_JAGUAR			0x16
+#define AMD_FAM_ZEN			0x17

ZEN2 is also 0x17 but different models so this is where the family matching scheme doesn't work - you'd need the models too.

0x18 is HYGON

Quoted 19 lines
arch/x86/include/asm/amd-family.h new file +3 -0
+#define AMD_FAM_ZEN3			0x19
+
+#endif /* _ASM_X86_AMD_FAMILY_H */
arch/x86/include/asm/cpu_device_id.h +2 -0
index eb8fcede9e3b..bbb48ba4c7ff 100644
@@ -12,6 +12,8 @@
 #include <linux/mod_devicetable.h>
 /* Get the INTEL_FAM* model defines */
 #include <asm/intel-family.h>
+/* Get the AMD model defines */
+#include <asm/amd-family.h>
 /* And the X86_VENDOR_* ones */
 #include <asm/processor.h>
 
Signature · 1 line
2.29.2
Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#22 lore raw

Re: [RFC PATCH 4/4] cpufreq: acpi-cpufreq: Use identifiers for AMD processor family

In reply to Punit Agrawal
Quoted 14 lines · Punit Agrawal

Replace the raw values for AMD processor family with recently introduced identifier macros to improve code readability and maintainability.

---
 drivers/cpufreq/acpi-cpufreq.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/cpufreq/acpi-cpufreq.c +0 -0
index 29f1cd93541e..d8b8300ae9e0 100644

drivers/cpufreq/acpi-cpufreq.c static int override_acpi_psd(unsigned int cpu_id) · line 206

Quoted 7 lines
drivers/cpufreq/acpi-cpufreq.c +2 -2
@@ -202,8 +202,8 @@ static int override_acpi_psd(unsigned int cpu_id)
 		 * CPU's before Zen3 (except some Zen2) need the
 		 * override.
 		 */
-		return (c->x86 < 0x19) &&
-			!(c->x86 == 0x17 && c->x86_model == 0x60 &&
+		return (c->x86 < AMD_FAM_ZEN3) &&
+			!(c->x86 == AMD_FAM_ZEN && c->x86_model == 0x60 &&

This is what I mean - that's Zen2 as the comment above says so having

		c->x86 == AMD_FAM_ZEN

is not enough. And you have a comment above it stating which CPUs are matched here so I'm not sure those family defines make it any better...

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#19 lore raw

Re: [RFC PATCH 3/4] x86/cpu: amd: Define processor families

In reply to Borislav Petkov

Hi Boris,

Quoted 33 lines · Borislav Petkov
Quoted 32 lines · Punit Agrawal

So far, the AMD processor identifier (family, models, stepping) are referred to by raw values making it easy to make mistakes. It is also harder to read and maintain. Additionally, these values are also being used in subsystems outside the arch code where not everybody maybe be as familiar with the processor identifiers.

As a first step towards improving the status quo, add macros for the AMD processor families and propagate them through the existing cpu_device_id.h header used for this purpose.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
---
 arch/x86/include/asm/amd-family.h    | 18 ++++++++++++++++++
 arch/x86/include/asm/cpu_device_id.h |  2 ++
 2 files changed, 20 insertions(+)
 create mode 100644 arch/x86/include/asm/amd-family.h
arch/x86/include/asm/amd-family.h new file +5 -0
new file mode 100644
index 000000000000..dff4d13b8e74
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_AMD_FAMILY_H
+#define _ASM_X86_AMD_FAMILY_H
+
+#define AMD_FAM_K5			0x04
Quoted 8 lines

arch/x86/include/asm/amd-family.h line 9

Quoted 4 lines
arch/x86/include/asm/amd-family.h new file +4 -0
+#define AMD_FAM_K6			0x05
+#define AMD_FAM_K7			0x06
+#define AMD_FAM_K8			0x0F
+#define AMD_FAM_K10			0x10

Fam 0x10 is Greyhound and a lot more core names. I'd let the AMD folks on Cc say what they wanna call it but I don't think K10 was used anywhere except outside of AMD. :)

Didn't realize the core was internal only. There are a couple of instances where the family does shows up arch/x86/kernel/cpu/amd.c so atleast some of the patches did make it upstream.

Quoted 4 lines

arch/x86/include/asm/amd-family.h line 10

Quoted 1 line
arch/x86/include/asm/amd-family.h new file +1 -0
+#define AMD_FAM_K8_K10_HYBRID		0x11

That was called Griffin so AMD_FAM_GRIFFIN I guess. If not used anywhere in the tree, no need to add the define.

I haven't looked to deeply but there's one instance in arch/x86/kernel/cpu/amd.c - though I wonder if that could be re-written to rely on a hardware / firmware interface instead.

Quoted 2 lines

Same holds true for the rest of the defines - add them only when they're used.

Makes sense - I will follow your suggestion in the next version.

Quoted 8 lines

arch/x86/include/asm/amd-family.h line 15

Quoted 5 lines
arch/x86/include/asm/amd-family.h new file +5 -0
+#define AMD_FAM_LLANO			0x12
+#define AMD_FAM_BOBCAT			0x14
+#define AMD_FAM_BULLDOZER		0x15
+#define AMD_FAM_JAGUAR			0x16
+#define AMD_FAM_ZEN			0x17

ZEN2 is also 0x17 but different models so this is where the family matching scheme doesn't work - you'd need the models too.

Yes, I wasn't sure the best way to handle this so went with the earlier generation name. I think for such cases, something that looks at the cpuinfo_x86 structure and decides the family / generation is probably the way to go.

Quoted 1 line

0x18 is HYGON

I missed this one. I'll add it to the list.

Thanks for the review and your comments. I'll wait a bit to see if there's any further feedback.

Cheers,
Punit

[...]

#23 lore raw

Re: [RFC PATCH 4/4] cpufreq: acpi-cpufreq: Use identifiers for AMD processor family

In reply to Borislav Petkov
Quoted 25 lines · Borislav Petkov
Quoted 14 lines · Punit Agrawal

Replace the raw values for AMD processor family with recently introduced identifier macros to improve code readability and maintainability.

---
 drivers/cpufreq/acpi-cpufreq.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/cpufreq/acpi-cpufreq.c +0 -0
index 29f1cd93541e..d8b8300ae9e0 100644

drivers/cpufreq/acpi-cpufreq.c static int override_acpi_psd(unsigned int cpu_id) · line 206

Quoted 7 lines
drivers/cpufreq/acpi-cpufreq.c +2 -2
@@ -202,8 +202,8 @@ static int override_acpi_psd(unsigned int cpu_id)
 		 * CPU's before Zen3 (except some Zen2) need the
 		 * override.
 		 */
-		return (c->x86 < 0x19) &&
-			!(c->x86 == 0x17 && c->x86_model == 0x60 &&
+		return (c->x86 < AMD_FAM_ZEN3) &&
+			!(c->x86 == AMD_FAM_ZEN && c->x86_model == 0x60 &&

This is what I mean - that's Zen2 as the comment above says so having

Quoted 4 lines
		c->x86 == AMD_FAM_ZEN

is not enough. And you have a comment above it stating which CPUs are matched here so I'm not sure those family defines make it any better...

Hmm.. for this series, it probably doesn't add much value - especially with the comment and macro mismatch.

The last two patches were posted to check if there's wider interest in the changes. If the macro conversion is useful, I can split the patches from this series into a separate set with more sites being updated. I'll wait to see if there's any further feedback.

Thanks,
Punit

maintainer
#20 lore raw

Re: [RFC PATCH 3/4] x86/cpu: amd: Define processor families

In reply to Punit Agrawal
Quoted 1 line · Punit Agrawal

Didn't realize the core was internal only.

F10h is not internal only - all I'm saying is that "K10" wasn't use inside AMD AFAIR.

Quoted 1 line

Makes sense - I will follow your suggestion in the next version.

Well, I don't think it is worth the churn, TBH.

I'd prefer comments over the f/m/s checks which explain what is matched much better than defines for family numbers which are inadequate when one needs to match the model too, for one.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#24 lore raw
In reply to Punit Agrawal

Hi Rafael,

Quoted 6 lines · Punit Agrawal

Hi,

While looking into Giovanni's patches to enable frequency invariance on AMD systems[0], I noticed an issue with initialising frequency domain information on a recent AMD APU.

Quoted 8 lines

Patch 1 refactors the test to ignore firmware provided frequency domain into a separate function.

Patch 2 adds said APU (Family: 0x17, Model: 0x60, Stepping: 0x01) to the list of CPUs for which the PSD override is ignored. I am not quite happy with having to special case a particular CPU but also couldn't find any documentation to help identify the CPUs that don't need the override.

Are you be OK to pick the first two patches if there are no issues?

Thanks,
Punit

Quoted 22 lines

Patch 3 and 4 are somewhat independent and a first step towards improving the situation with regards to the use of raw identifiers for AMD processors throughout the kernel.

All feedback welcome.

Thanks,
Punit

[0] https://lore.kernel.org/linux-acpi/[email protected]/

Punit Agrawal (4):
cpufreq: acpi-cpufreq: Re-factor overriding ACPI PSD
cpufreq: acpi-cpufreq: Add processor to the ignore PSD override list x86/cpu: amd: Define processor families
cpufreq: acpi-cpufreq: Use identifiers for AMD processor family

 arch/x86/include/asm/amd-family.h    | 18 ++++++++++++++++++
 arch/x86/include/asm/cpu_device_id.h |  2 ++
 drivers/cpufreq/acpi-cpufreq.c       | 24 +++++++++++++++++++++---
 3 files changed, 41 insertions(+), 3 deletions(-)
 create mode 100644 arch/x86/include/asm/amd-family.h
#25 lore raw
Quoted 14 lines · Punit Agrawal

Hi Rafael,

Quoted 9 lines · Punit Agrawal

Hi,

While looking into Giovanni's patches to enable frequency invariance on AMD systems[0], I noticed an issue with initialising frequency domain information on a recent AMD APU.

Patch 1 refactors the test to ignore firmware provided frequency domain into a separate function.

Quoted 7 lines
Quoted 5 lines

Patch 2 adds said APU (Family: 0x17, Model: 0x60, Stepping: 0x01) to the list of CPUs for which the PSD override is ignored. I am not quite happy with having to special case a particular CPU but also couldn't find any documentation to help identify the CPUs that don't need the override.

Are you be OK to pick the first two patches if there are no issues?

Please send them as non-RFC and change the name of override_acpi_psd() to indicate that it is AMD-specific.

Thanks!

#2 lore raw

Re: [RFC PATCH 1/4] cpufreq: acpi-cpufreq: Re-factor overriding ACPI PSD

In reply to Punit Agrawal
Quoted 16 lines · Punit Agrawal

Re-factor the code to override the firmware provided frequency domain information (via PSD) to localise the checks in one function.

No functional change intended.

---
 drivers/cpufreq/acpi-cpufreq.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/cpufreq/acpi-cpufreq.c +0 -0
index 1e4fbb002a31..b1e7df96d428 100644

drivers/cpufreq/acpi-cpufreq.c static int check_amd_hwpstate_cpu(unsigned int cpuid) · line 194

Quoted 4 lines
drivers/cpufreq/acpi-cpufreq.c +1 -0
@@ -191,6 +191,20 @@ static int check_amd_hwpstate_cpu(unsigned int cpuid)
 	return cpu_has(cpu, X86_FEATURE_HW_PSTATE);
 }
 
+static int override_acpi_psd(unsigned int cpu_id)
         ^^^^^

int is fine, but it might be better to use bool. Otherwise I don't see any issues with this patch.

Quoted 27 lines
drivers/cpufreq/acpi-cpufreq.c +14 -2
+{
+	struct cpuinfo_x86 *c = &boot_cpu_data;
+
+	if (c->x86_vendor == X86_VENDOR_AMD) {
+		if (!check_amd_hwpstate_cpu(cpu_id))
+			return false;
+
+		return c->x86 < 0x19;
+	}
+
+	return false;
+}
+
 static unsigned extract_io(struct cpufreq_policy *policy, u32 value)
 {
 	struct acpi_cpufreq_data *data = policy->driver_data;
@@ -691,8 +705,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
 		cpumask_copy(policy->cpus, topology_core_cpumask(cpu));
 	}
 
-	if (check_amd_hwpstate_cpu(cpu) && boot_cpu_data.x86 < 0x19 &&
-	    !acpi_pstate_strict) {
+	if (override_acpi_psd(cpu) && !acpi_pstate_strict) {
 		cpumask_clear(policy->cpus);
 		cpumask_set_cpu(cpu, policy->cpus);
 		cpumask_copy(data->freqdomain_cpus,
#5 lore raw

Re: [RFC PATCH 2/4] cpufreq: acpi-cpufreq: Add processor to the ignore PSD override list

In reply to Punit Agrawal
Quoted 8 lines · Punit Agrawal

Booting Linux on a Zen2 based processor (family: 0x17, model: 0x60,
stepping: 0x1) shows the following message in the logs -

acpi_cpufreq: overriding BIOS provided _PSD data

Although commit 5368512abe08 ("acpi-cpufreq: Honor _PSD table setting on new AMD CPUs") indicates that the override is not required for Zen3 onwards, it seems that domain information can be trusted even on

Given that the original quirk acd316248205 ("acpi-cpufreq: Add quirk to disable _PSD usage on all AMD CPUs") was submitted 8 years ago, it is not a surprise that some system firmware before family 19h might been fixed. Unfortunately, like what Punit said, I didn't find any documentation on the list of existing, fixed CPUs.

In my commit 5368512abe ("acpi-cpufreq: Honor _PSD table setting on new AMD CPUs"), family 19h was picked because 1) we know BIOS will fix this problem for this specific generation of CPUs, and 2) without this commit, it _might_ cause issues on certain CPUs.

In summary, this patch is fine if Punit already verified it. My only concern is the list can potentially increase over the time, and we will keep coming back to fix override_acpi_psd() function.

Quoted 30 lines

certain earlier systems. Update the check, to skip the override for Zen2 processors known to work without the override.

---
 drivers/cpufreq/acpi-cpufreq.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/cpufreq/acpi-cpufreq.c +7 -2
index b1e7df96d428..29f1cd93541e 100644
@@ -198,8 +198,13 @@ static int override_acpi_psd(unsigned int cpu_id)
 	if (c->x86_vendor == X86_VENDOR_AMD) {
 		if (!check_amd_hwpstate_cpu(cpu_id))
 			return false;
-
-		return c->x86 < 0x19;
+		/*
+		 * CPU's before Zen3 (except some Zen2) need the
+		 * override.
+		 */
+		return (c->x86 < 0x19) &&
+			!(c->x86 == 0x17 && c->x86_model == 0x60 &&
+			  c->x86_stepping == 0x1);
 	}
 
 	return false;
maintainer
#6 lore raw

Re: [RFC PATCH 2/4] cpufreq: acpi-cpufreq: Add processor to the ignore PSD override list

Quoted 3 lines · Wei Huang

In summary, this patch is fine if Punit already verified it. My only concern is the list can potentially increase over the time, and we will keep coming back to fix override_acpi_psd() function.

Can the detection be done by looking at those _PSD things instead of comparing f/m/s?

And, alternatively, what is this fixing?

So what if some zen2 boxes have correct _PSD objects? Why do they need to ignore the override?

Hmmm?

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#7 lore raw

Re: [RFC PATCH 2/4] cpufreq: acpi-cpufreq: Add processor to the ignore PSD override list

Quoted 7 lines · Borislav Petkov
Quoted 3 lines · Wei Huang

In summary, this patch is fine if Punit already verified it. My only concern is the list can potentially increase over the time, and we will keep coming back to fix override_acpi_psd() function.

Can the detection be done by looking at those _PSD things instead of comparing f/m/s?

Not I am aware of. I don't know the correlation between _PSD configuration and CPU's f/m/s.

Quoted 5 lines

And, alternatively, what is this fixing?

So what if some zen2 boxes have correct _PSD objects? Why do they need to ignore the override?

I think we shouldn't override zen2 if _PSD is correct. In my opinion, there are two approaches:

* Keep override_acpi_psd()
Let us keep the original quirk and override_acpi_psd() function. Over the time, people may want to add new CPUs to override_acpi_psd(). The maintainer may declare that only CPUs >= family 17h will be fixed, to avoid exploding the check-list.

* Remove the quirk completely
We can completely remove commit acd316248205 ("acpi-cpufreq: Add quirk to disable _PSD usage on all AMD CPUs")? I am not sure what "AMD desktop boards" was referring to in the original commit message of acd316248205. Maybe such machines aren't in use anymore.

Quoted 3 lines

Hmmm?

maintainer
#8 lore raw

Re: [RFC PATCH 2/4] cpufreq: acpi-cpufreq: Add processor to the ignore PSD override list

Quoted 9 lines · Wei Huang

I think we shouldn't override zen2 if _PSD is correct. In my opinion, there are two approaches:

* Keep override_acpi_psd()
Let us keep the original quirk and override_acpi_psd() function. Over the time, people may want to add new CPUs to override_acpi_psd(). The maintainer may declare that only CPUs >= family 17h will be fixed, to avoid exploding the check-list.

Quoted 5 lines

* Remove the quirk completely
We can completely remove commit acd316248205 ("acpi-cpufreq: Add quirk to disable _PSD usage on all AMD CPUs")? I am not sure what "AMD desktop boards" was referring to in the original commit message of acd316248205. Maybe such machines aren't in use anymore.

* Third option: do not do anything. Why?

- Let sleeping dogs lie and leave the workaround acd316248205 for old machines.

- Make a clear cut that the override is not needed from Zen3 on, i.e., your patch

5368512abe08 ("acpi-cpufreq: Honor _PSD table setting on new AMD CPUs")

Punit's commit message reads "...indicates that the override is not required for Zen3 onwards, it seems that domain information can be trusted even on certain earlier systems."

That's not nearly a justification in my book to do this on anything < Zen3.

This way you have a clear cut, you don't need to deal with adding any more models to override_acpi_psd() and all is good.

Unless there's a better reason to skip the override on machines < Zen3 but I haven't heard any so far...

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#9 lore raw

Re: [RFC PATCH 2/4] cpufreq: acpi-cpufreq: Add processor to the ignore PSD override list

Quoted 10 lines · Borislav Petkov
Quoted 9 lines · Wei Huang

I think we shouldn't override zen2 if _PSD is correct. In my opinion, there are two approaches:

* Keep override_acpi_psd()
Let us keep the original quirk and override_acpi_psd() function. Over the time, people may want to add new CPUs to override_acpi_psd(). The maintainer may declare that only CPUs >= family 17h will be fixed, to avoid exploding the check-list.

Quoted 7 lines
Quoted 5 lines

* Remove the quirk completely
We can completely remove commit acd316248205 ("acpi-cpufreq: Add quirk to disable _PSD usage on all AMD CPUs")? I am not sure what "AMD desktop boards" was referring to in the original commit message of acd316248205. Maybe such machines aren't in use anymore.

* Third option: do not do anything. Why?

I am fine with this option, unless Punit can prove me that I am wrong, (i.e. some Zen2 is broken because of acd316248205).

Quoted 24 lines

- Let sleeping dogs lie and leave the workaround acd316248205 for old machines.

- Make a clear cut that the override is not needed from Zen3 on, i.e., your patch

5368512abe08 ("acpi-cpufreq: Honor _PSD table setting on new AMD CPUs")

Punit's commit message reads "...indicates that the override is not required for Zen3 onwards, it seems that domain information can be trusted even on certain earlier systems."

That's not nearly a justification in my book to do this on anything < Zen3.

This way you have a clear cut, you don't need to deal with adding any more models to override_acpi_psd() and all is good.

Unless there's a better reason to skip the override on machines < Zen3 but I haven't heard any so far...

Thx.

#10 lore raw

Re: [RFC PATCH 2/4] cpufreq: acpi-cpufreq: Add processor to the ignore PSD override list

In reply to Borislav Petkov
Quoted 16 lines · Borislav Petkov
Quoted 9 lines · Wei Huang

I think we shouldn't override zen2 if _PSD is correct. In my opinion, there are two approaches:

* Keep override_acpi_psd()
Let us keep the original quirk and override_acpi_psd() function. Over the time, people may want to add new CPUs to override_acpi_psd(). The maintainer may declare that only CPUs >= family 17h will be fixed, to avoid exploding the check-list.

Quoted 5 lines

* Remove the quirk completely
We can completely remove commit acd316248205 ("acpi-cpufreq: Add quirk to disable _PSD usage on all AMD CPUs")? I am not sure what "AMD desktop boards" was referring to in the original commit message of acd316248205. Maybe such machines aren't in use anymore.

Quoted 4 lines

* Third option: do not do anything. Why?

- Let sleeping dogs lie and leave the workaround acd316248205 for old machines.

According to the commit log, acd316248205 seems to be only targeted at powernow-K8 -

"in order to use the hardware to its full potential and keep the original powernow-k8 behavior, lets override the _PSD table setting on AMD hardware."

It's unfortunate that it has continued to apply to all systems since. An alternate to this and 5368512abe08 would be to restrict the original workaround to the system mentioned in the commit log.

Quoted 10 lines

- Make a clear cut that the override is not needed from Zen3 on, i.e., your patch

5368512abe08 ("acpi-cpufreq: Honor _PSD table setting on new AMD CPUs")

Punit's commit message reads "...indicates that the override is not required for Zen3 onwards, it seems that domain information can be trusted even on certain earlier systems."

Quoted 5 lines

That's not nearly a justification in my book to do this on anything < Zen3.

This way you have a clear cut, you don't need to deal with adding any more models to override_acpi_psd() and all is good.

PSD (P-State Dependency) object is used to express the coupling of processors that share the same frequency domain. Ignoring the hardware topology information will cause both power management and scheduling to make sub-optimal choices.

Wasn't this the motivation for taking it into account for Zen3 based systems in 5368512abe08? Or the powernow-k8 in the original workaround (though there it required ignoring firmware)? The exact same argument applies here to the Zen2 system I have running in a thermally constrained environment.

In an ideal case, I was hoping AMD folks would come back with confirmation of how far back the override can be dropped and the workaround condition could be relaxed further. But if that is not available, the only way we have is to include systems that have been verified to not need the override and somebody that cares to send the patch.

#26 lore raw
In reply to Rafael J. Wysocki

Hi Rafael,

Quoted 21 lines · Rafael J. Wysocki
Quoted 20 lines · Punit Agrawal

Hi Rafael,

Quoted 14 lines · Punit Agrawal

Hi,

While looking into Giovanni's patches to enable frequency invariance on AMD systems[0], I noticed an issue with initialising frequency domain information on a recent AMD APU.

Patch 1 refactors the test to ignore firmware provided frequency domain into a separate function.

Patch 2 adds said APU (Family: 0x17, Model: 0x60, Stepping: 0x01) to the list of CPUs for which the PSD override is ignored. I am not quite happy with having to special case a particular CPU but also couldn't find any documentation to help identify the CPUs that don't need the override.

Quoted 4 lines
Quoted 1 line

Are you be OK to pick the first two patches if there are no issues?

Please send them as non-RFC and change the name of override_acpi_psd() to indicate that it is AMD-specific.

Ack - I will incorporate your comments in the next version (once the ongoing discussion finishes).

Thanks.

#3 lore raw

Re: [RFC PATCH 1/4] cpufreq: acpi-cpufreq: Re-factor overriding ACPI PSD

In reply to Wei Huang

Hi Wei,

Quoted 20 lines · Wei Huang
Quoted 19 lines · Punit Agrawal

Re-factor the code to override the firmware provided frequency domain information (via PSD) to localise the checks in one function.

No functional change intended.

---
 drivers/cpufreq/acpi-cpufreq.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/cpufreq/acpi-cpufreq.c +0 -0
index 1e4fbb002a31..b1e7df96d428 100644
@@ -191,6 +191,20 @@ static int check_amd_hwpstate_cpu(unsigned int cpuid)
 	return cpu_has(cpu, X86_FEATURE_HW_PSTATE);
 }
 
Quoted 4 lines

drivers/cpufreq/acpi-cpufreq.c static int check_amd_hwpstate_cpu(unsigned int cpuid) · line 194

Quoted 1 line
drivers/cpufreq/acpi-cpufreq.c +1 -0
+static int override_acpi_psd(unsigned int cpu_id)
         ^^^^^

int is fine, but it might be better to use bool. Otherwise I don't see any issues with this patch.

Makes sense - I will switch to a boolean in the next update.

Thanks for taking a look.

Punit

Quoted 28 lines
Quoted 28 lines
drivers/cpufreq/acpi-cpufreq.c +14 -2
+{
+	struct cpuinfo_x86 *c = &boot_cpu_data;
+
+	if (c->x86_vendor == X86_VENDOR_AMD) {
+		if (!check_amd_hwpstate_cpu(cpu_id))
+			return false;
+
+		return c->x86 < 0x19;
+	}
+
+	return false;
+}
+
 static unsigned extract_io(struct cpufreq_policy *policy, u32 value)
 {
 	struct acpi_cpufreq_data *data = policy->driver_data;
@@ -691,8 +705,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
 		cpumask_copy(policy->cpus, topology_core_cpumask(cpu));
 	}
 
-	if (check_amd_hwpstate_cpu(cpu) && boot_cpu_data.x86 < 0x19 &&
-	    !acpi_pstate_strict) {
+	if (override_acpi_psd(cpu) && !acpi_pstate_strict) {
 		cpumask_clear(policy->cpus);
 		cpumask_set_cpu(cpu, policy->cpus);
 		cpumask_copy(data->freqdomain_cpus,
maintainer
#11 lore raw

Re: [RFC PATCH 2/4] cpufreq: acpi-cpufreq: Add processor to the ignore PSD override list

In reply to Punit Agrawal
Quoted 2 lines · Punit Agrawal

According to the commit log, acd316248205 seems to be only targeted at powernow-K8 -

No, it is not targeted at powernow-k8 - acpi-cpufreq.c is what is used on AMD hw. He means to make acpi-cpufreq's behavior consistent with powernow-k8.

Quoted 2 lines

But if that is not available, the only way we have is to include systems that have been verified to not need the override

You have verified exactly *one* system - yours. Or are you sure that *all* family 0x17, model 0x60, stepping 0x1 machines don't need the override?

Also, you still haven't explained what you're trying to fix here.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#12 lore raw

Re: [RFC PATCH 2/4] cpufreq: acpi-cpufreq: Add processor to the ignore PSD override list

Quoted 7 lines · Borislav Petkov
Quoted 2 lines · Punit Agrawal

According to the commit log, acd316248205 seems to be only targeted at powernow-K8 -

No, it is not targeted at powernow-k8 - acpi-cpufreq.c is what is used on AMD hw. He means to make acpi-cpufreq's behavior consistent with powernow-k8.

So "powernow-k8" is not a cpu but a cpufreq driver. That doesn't change the fact that the patch causes all AMD systems using acpi-cpufreq to ignore processor frequency groupings and treat each processor to be an in independent frequency domain from cpufreq's point of view.

Quoted 6 lines
Quoted 2 lines

But if that is not available, the only way we have is to include systems that have been verified to not need the override

You have verified exactly *one* system - yours. Or are you sure that *all* family 0x17, model 0x60, stepping 0x1 machines don't need the override?

Unfortunately, I only have access to one system with that F/M/S.

Since posting the non-RFC patches, I was able to inspect the ACPI tables for more CPUs -

Family: 0x17h, Model: 0x71h (Ryzen 3950X)
Family: 0x17h, Model: 0x18h (Ryzen 3500u)

To me it suggests, that there are likely more systems from the family that show the characteristic described below.

Quoted 1 line

Also, you still haven't explained what you're trying to fix here.

All the CPUs here are multi-threaded with 2 threads per core. The _PSD for the system describes the cores as having a coupling that consist of a frequency domain per core that contains both the threads. The firmware description makes sense and seems to accurately describe the hardware topology.

In all these systems, the override causes this topology information to be ignored - treating each core to be a separate domain. The proposed patch removes the override so that _PSD is taken into account.

maintainer
#13 lore raw

Re: [RFC PATCH 2/4] cpufreq: acpi-cpufreq: Add processor to the ignore PSD override list

Quoted 2 lines · Punit Agrawal

To me it suggests, that there are likely more systems from the family that show the characteristic described below.

Until we find a *single* system with a broken BIOS which has those objects kaputt and then this heuristic would need an exception.

VS the clear statement from AMD that from zen3 onwards, all BIOS will be tested. I hope they boot Linux at least before they ship.

Quoted 3 lines

In all these systems, the override causes this topology information to be ignored - treating each core to be a separate domain. The proposed patch removes the override so that _PSD is taken into account.

You're still not answering my question: what does the coupling of the SMT threads bring on those systems? Power savings? Perf improvement? Anything palpable or measurable?

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#14 lore raw

Re: [RFC PATCH 2/4] cpufreq: acpi-cpufreq: Add processor to the ignore PSD override list

Quoted 9 lines · Borislav Petkov
Quoted 2 lines · Punit Agrawal

To me it suggests, that there are likely more systems from the family that show the characteristic described below.

Until we find a *single* system with a broken BIOS which has those objects kaputt and then this heuristic would need an exception.

VS the clear statement from AMD that from zen3 onwards, all BIOS will be tested. I hope they boot Linux at least before they ship.

IIUC, this suggests that Linux booting on anything prior to Zen3 is down to pure luck - I hope that wasn't the case.

Quoted 7 lines
Quoted 3 lines

In all these systems, the override causes this topology information to be ignored - treating each core to be a separate domain. The proposed patch removes the override so that _PSD is taken into account.

You're still not answering my question: what does the coupling of the SMT threads bring on those systems? Power savings? Perf improvement? Anything palpable or measurable?

At the moment acpi thermals is bust on this and other affected AMD system I have access to. That'll need fixing before any sensible measurements can be run.

Tbh, I didn't quite expect the patch to the PSD exclusion list to be so controversial - especially when a similar change for zen3 had recently been merged. If you're really not keen on the change, I will carry it locally for the time being and revisit once the other issues have been resolved.

maintainer
#15 lore raw

Re: [RFC PATCH 2/4] cpufreq: acpi-cpufreq: Add processor to the ignore PSD override list

Quoted 2 lines · Punit Agrawal

IIUC, this suggests that Linux booting on anything prior to Zen3 is down to pure luck - I hope that wasn't the case.

WTF does this have to do with linux booting?!

Quoted 3 lines

At the moment acpi thermals is bust on this and other affected AMD system I have access to. That'll need fixing before any sensible measurements can be run.

Nope, still not answering my questions.

Quoted 2 lines

Tbh, I didn't quite expect the patch to the PSD exclusion list to be so controversial

It won't be if you explain properly what your patch is fixing. That is, if it fixes anything.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#16 lore raw

Re: [RFC PATCH 2/4] cpufreq: acpi-cpufreq: Add processor to the ignore PSD override list

Quoted 5 lines · Borislav Petkov
Quoted 2 lines · Punit Agrawal

IIUC, this suggests that Linux booting on anything prior to Zen3 is down to pure luck - I hope that wasn't the case.

WTF does this have to do with linux booting?!

I guess I misunderstood the comment from your previous mail. Pasting back for context (emphasis mine) -

VS the clear statement from AMD that from zen3 onwards, all BIOS will be tested. *I hope they boot Linux at least before they ship.*

Quoted 11 lines
Quoted 3 lines

At the moment acpi thermals is bust on this and other affected AMD system I have access to. That'll need fixing before any sensible measurements can be run.

Nope, still not answering my questions.

Quoted 2 lines

Tbh, I didn't quite expect the patch to the PSD exclusion list to be so controversial

It won't be if you explain properly what your patch is fixing. That is, if it fixes anything.

I stared at the driver code (and the ACPI tables for the platform) to see if I could provide a better explanation.

That's when I realised that as the platform advertises hardware frequency co-ordination, even without the override it still skips setting the policy cpus -

    /*
     * Will let policy->cpus know about dependency only when software
     * coordination is required.
     */
    if (policy->shared_type == CPUFREQ_SHARED_TYPE_ALL ||
        policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) {
            cpumask_copy(policy->cpus, perf->shared_cpu_map);
    }

This ends up treating each CPU as an independent frequency domain anyways. So even ignoring the override for the CPU, doesn't change anything other than dropping the message from boot log -

overriding BIOS provided _PSD data

As such, there's no point in merging the patch as it is.

Apologies for the noise. I should've checked more thoroughly before sending the patches.

[ Aside: If Zen3 is using hardware co-ordination it'll probably face the issue described above as well. ]