Skip to contentSkip to conversation

x86/cpu: Enable SD_ASYM_PACKING for PKG domain on systems with AMD preferred cores

PATCH In review Mario Limonciello 3 participants 6 messages Dec 3, 2024 x86

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86/cpu: Enable SD_ASYM_PACKING for PKG domain on systems with AMD preferred cores

For the scheduler to use and prefer AMD preferred core rankings set SD_ASYM_PACKING for x86_die_flags().

---
v2:
* Fix c23 compatibility issue reported by LKP

---
 arch/x86/kernel/smpboot.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/x86/kernel/smpboot.c +11 -0
index b5a8f0891135b..6a38cf3feb1a9 100644
@@ -62,6 +62,8 @@
 #include <linux/mc146818rtc.h>
 #include <linux/acpi.h>
 
+#include <acpi/cppc_acpi.h>
+
 #include <asm/acpi.h>
 #include <asm/cacheinfo.h>
 #include <asm/desc.h>
@@ -501,6 +503,15 @@ static int x86_die_flags(void)
 	    cpu_feature_enabled(X86_FEATURE_AMD_HETEROGENEOUS_CORES))
 		return x86_sched_itmt_flags();
 
+	if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD ||
+	    boot_cpu_data.x86_vendor == X86_VENDOR_HYGON) {
+		bool prefcore = false;
+
+		amd_detect_prefcore(&prefcore);
+		if (prefcore)
+			return x86_sched_itmt_flags();
+	}
+
 	return 0;
 }
 

base-commit: 40384c840ea1944d7c5a392e8975ed088ecf0b37

Signature · 1 line
2.43.0
Tested-by on v2 1/1
#1 lore raw

This does fix the preferred core behavior now and it works now as it should.
Tested with a 9950X on several games, and the scheduler now picks the correct cores, which results into a heavy performance improvement, due not migrating through the second ccd.

Thanks!

Quoted 44 lines · Mario Limonciello

For the scheduler to use and prefer AMD preferred core rankings set SD_ASYM_PACKING for x86_die_flags().

---
v2:
* Fix c23 compatibility issue reported by LKP

---
  arch/x86/kernel/smpboot.c | 11 +++++++++++
  1 file changed, 11 insertions(+)
arch/x86/kernel/smpboot.c +11 -0
index b5a8f0891135b..6a38cf3feb1a9 100644
@@ -62,6 +62,8 @@
  #include <linux/mc146818rtc.h>
  #include <linux/acpi.h>
 
+#include <acpi/cppc_acpi.h>
+
  #include <asm/acpi.h>
  #include <asm/cacheinfo.h>
  #include <asm/desc.h>
@@ -501,6 +503,15 @@ static int x86_die_flags(void)
  	    cpu_feature_enabled(X86_FEATURE_AMD_HETEROGENEOUS_CORES))
  		return x86_sched_itmt_flags();
 
+	if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD ||
+	    boot_cpu_data.x86_vendor == X86_VENDOR_HYGON) {
+		bool prefcore = false;
+
+		amd_detect_prefcore(&prefcore);
+		if (prefcore)
+			return x86_sched_itmt_flags();
+	}
+
  	return 0;
  }
 

base-commit: 40384c840ea1944d7c5a392e8975ed088ecf0b37 -- 2.43.0

maintainer
#2 lore raw
In reply to Mario Limonciello
Quoted 25 lines · Mario Limonciello

For the scheduler to use and prefer AMD preferred core rankings set SD_ASYM_PACKING for x86_die_flags().

---
v2:
* Fix c23 compatibility issue reported by LKP

---
 arch/x86/kernel/smpboot.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/x86/kernel/smpboot.c +2 -0
index b5a8f0891135b..6a38cf3feb1a9 100644
@@ -62,6 +62,8 @@
 #include <linux/mc146818rtc.h>
 #include <linux/acpi.h>
 
+#include <acpi/cppc_acpi.h>
+
 #include <asm/acpi.h>
 #include <asm/cacheinfo.h>
 #include <asm/desc.h>

arch/x86/kernel/smpboot.c static int x86_die_flags(void) · line 507

Quoted 5 lines
arch/x86/kernel/smpboot.c +2 -0
@@ -501,6 +503,15 @@ static int x86_die_flags(void)
 	    cpu_feature_enabled(X86_FEATURE_AMD_HETEROGENEOUS_CORES))
 		return x86_sched_itmt_flags();
 
+	if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD ||
+	    boot_cpu_data.x86_vendor == X86_VENDOR_HYGON) {

You're going to call this on *every* AMD and on Hygon?

So that whole effort with X86_FEATURE_s was for nothing?

What's up?

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#3 lore raw
Quoted 29 lines · Borislav Petkov
Quoted 28 lines · Mario Limonciello

For the scheduler to use and prefer AMD preferred core rankings set SD_ASYM_PACKING for x86_die_flags().

---
v2:
* Fix c23 compatibility issue reported by LKP

---
  arch/x86/kernel/smpboot.c | 11 +++++++++++
  1 file changed, 11 insertions(+)
arch/x86/kernel/smpboot.c +2 -0
index b5a8f0891135b..6a38cf3feb1a9 100644
@@ -62,6 +62,8 @@
  #include <linux/mc146818rtc.h>
  #include <linux/acpi.h>
 
+#include <acpi/cppc_acpi.h>
+
  #include <asm/acpi.h>
  #include <asm/cacheinfo.h>
  #include <asm/desc.h>
@@ -501,6 +503,15 @@ static int x86_die_flags(void)
  	    cpu_feature_enabled(X86_FEATURE_AMD_HETEROGENEOUS_CORES))
  		return x86_sched_itmt_flags();
 
Quoted 9 lines

arch/x86/kernel/smpboot.c static int x86_die_flags(void) · line 507

Quoted 2 lines
arch/x86/kernel/smpboot.c +2 -0
+	if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD ||
+	    boot_cpu_data.x86_vendor == X86_VENDOR_HYGON) {

You're going to call this on *every* AMD and on Hygon?

So that whole effort with X86_FEATURE_s was for nothing?

What's up?

Preferred core classifications are available on "non-heterogenous" designs for a few generations. There isn't an indication they're supported which is why amd_detect_prefcore() was made.

That's already called during the boot either way because that is used
to identify the boost numerator. The boolean value it finds is cached, and the next call will use the cached value. So I don't expect this change affects boot speed.

maintainer
#4 lore raw
Quoted 3 lines · Mario Limonciello

Preferred core classifications are available on "non-heterogenous" designs for a few generations. There isn't an indication they're supported which is why amd_detect_prefcore() was made.

Not surprised.

Quoted 4 lines

That's already called during the boot either way because that is used to identify the boost numerator. The boolean value it finds is cached, and the next call will use the cached value. So I don't expect this change affects boot speed.

So with this addition, amd_detect_prefcore() would get called *three* times where you need to call it exactly and only once. And all it gives you a one bit of information which states that the system has preferred cores.

So why don't you define a synthetic X86_FEATURE:

X86_FEATURE_AMD_PREFERRED_CORES

run this code *once* and *early* enough so that every user can have the result ready, if you have preferred cores, do

setup_force_cpu_cap(X86_FEATURE_AMD_PREFERRED_CORES)

(it needs to run before alternatives) and then in each user, you do

	if (cpu_feature_enabled(X86_FEATURE_AMD_PREFERRED_CORES))
		/* do things */

instead of what you have now?

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#5 lore raw
Quoted 25 lines · Borislav Petkov
Quoted 3 lines · Mario Limonciello

Preferred core classifications are available on "non-heterogenous" designs for a few generations. There isn't an indication they're supported which is why amd_detect_prefcore() was made.

Not surprised.

Quoted 4 lines

That's already called during the boot either way because that is used to identify the boost numerator. The boolean value it finds is cached, and the next call will use the cached value. So I don't expect this change affects boot speed.

So with this addition, amd_detect_prefcore() would get called *three* times where you need to call it exactly and only once. And all it gives you a one bit of information which states that the system has preferred cores.

So why don't you define a synthetic X86_FEATURE:

X86_FEATURE_AMD_PREFERRED_CORES

run this code *once* and *early* enough so that every user can have the result ready, if you have preferred cores, do

setup_force_cpu_cap(X86_FEATURE_AMD_PREFERRED_CORES)

Quoted 9 lines

(it needs to run before alternatives) and then in each user, you do

	if (cpu_feature_enabled(X86_FEATURE_AMD_PREFERRED_CORES))
		/* do things */

instead of what you have now?

Thx.

Sure, that sounds reasonable, I'll try to find the most appropriate call site for it.