在 2021/3/30 下午6:13, LeoLiuoc 写道:
Detect the extended topology information of Zhaoxin CPUs if available.
The patch is scheduled to be submitted to the kernel mainline in 2021.
---
v1->v2:
- Fix a code logic issue.
Signed-off-by: LeoLiu-oc <LeoLiu-oc(a)zhaoxin.com>
Reviewed-by: Artie Ding <artie.ding(a)openanolis.org>
---
arch/x86/kernel/cpu/centaur.c | 20 +++++++++++++++++++-
arch/x86/kernel/cpu/zhaoxin.c | 7 ++++++-
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/cpu/centaur.c
b/arch/x86/kernel/cpu/centaur.c
index 8735be464bc1..608b8dfa119f 100644
--- a/arch/x86/kernel/cpu/centaur.c
+++ b/arch/x86/kernel/cpu/centaur.c
@@ -115,6 +115,21 @@ static void early_init_centaur(struct cpuinfo_x86
*c)
set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);
}
+
+ if (c->cpuid_level >= 0x00000001) {
+ u32 eax, ebx, ecx, edx;
+
+ cpuid(0x00000001, &eax, &ebx, &ecx, &edx);
+ /*
+ * If HTT (EDX[28]) is set EBX[16:23] contain the number of
+ * apicids which are reserved per package. Store the resulting
+ * shift value for the package management code.
+ */
+ if (edx & (1U << 28))
+ c->x86_coreid_bits = get_count_order((ebx >> 16) & 0xff);
+ }
+ if (detect_extended_topology_early(c) < 0)
+ detect_ht_early(c);
}
static void centaur_detect_vmx_virtcap(struct cpuinfo_x86 *c)
@@ -158,11 +173,14 @@ static void init_centaur(struct cpuinfo_x86 *c)
clear_cpu_cap(c, 0*32+31);
#endif
early_init_centaur(c);
+ detect_extended_topology(c);
init_intel_cacheinfo(c);
- detect_num_cpu_cores(c);
+ if (!cpu_has(c, X86_FEATURE_XTOPOLOGY)) {
+ detect_num_cpu_cores(c);
#ifdef CONFIG_X86_32
detect_ht(c);
#endif
+ }
if (c->cpuid_level > 9) {
unsigned int eax = cpuid_eax(10);
diff --git a/arch/x86/kernel/cpu/zhaoxin.c
b/arch/x86/kernel/cpu/zhaoxin.c
index 452fd0a6bc61..e4ed34361a1f 100644
--- a/arch/x86/kernel/cpu/zhaoxin.c
+++ b/arch/x86/kernel/cpu/zhaoxin.c
@@ -85,6 +85,8 @@ static void early_init_zhaoxin(struct cpuinfo_x86 *c)
c->x86_coreid_bits = get_count_order((ebx >> 16) & 0xff);
}
+ if (detect_extended_topology_early(c) < 0)
+ detect_ht_early(c);
}
static void zhaoxin_detect_vmx_virtcap(struct cpuinfo_x86 *c)
@@ -115,11 +117,14 @@ static void zhaoxin_detect_vmx_virtcap(struct
cpuinfo_x86 *c)
static void init_zhaoxin(struct cpuinfo_x86 *c)
{
early_init_zhaoxin(c);
+ detect_extended_topology(c);
init_intel_cacheinfo(c);
- detect_num_cpu_cores(c);
+ if (!cpu_has(c, X86_FEATURE_XTOPOLOGY)) {
+ detect_num_cpu_cores(c);
#ifdef CONFIG_X86_32
detect_ht(c);
#endif
+ }
if (c->cpuid_level > 9) {
unsigned int eax = cpuid_eax(10);