Skip to content

Commit 22d6366

Browse files
committed
x86/cpu: Use common topology code for Intel
Intel CPUs use either topology leaf 0xb/0x1f evaluation or the legacy SMP/HT evaluation based on CPUID leaf 0x1/0x4. Move it over to the consolidated topology code and remove the random topology hacks which are sprinkled into the Intel and the common code. No functional change intended. Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Juergen Gross <[email protected]> Tested-by: Sohil Mehta <[email protected]> Tested-by: Michael Kelley <[email protected]> Tested-by: Zhang Rui <[email protected]> Tested-by: Wang Wendy <[email protected]> Tested-by: K Prateek Nayak <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 3d41009 commit 22d6366

File tree

5 files changed

+4
-117
lines changed

5 files changed

+4
-117
lines changed

arch/x86/kernel/cpu/common.c

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -793,19 +793,6 @@ static void get_model_name(struct cpuinfo_x86 *c)
793793
*(s + 1) = '\0';
794794
}
795795

796-
void detect_num_cpu_cores(struct cpuinfo_x86 *c)
797-
{
798-
unsigned int eax, ebx, ecx, edx;
799-
800-
c->x86_max_cores = 1;
801-
if (!IS_ENABLED(CONFIG_SMP) || c->cpuid_level < 4)
802-
return;
803-
804-
cpuid_count(4, 0, &eax, &ebx, &ecx, &edx);
805-
if (eax & 0x1f)
806-
c->x86_max_cores = (eax >> 26) + 1;
807-
}
808-
809796
void cpu_detect_cache_sizes(struct cpuinfo_x86 *c)
810797
{
811798
unsigned int n, dummy, ebx, ecx, edx, l2size;
@@ -867,54 +854,6 @@ static void cpu_detect_tlb(struct cpuinfo_x86 *c)
867854
tlb_lld_4m[ENTRIES], tlb_lld_1g[ENTRIES]);
868855
}
869856

870-
int detect_ht_early(struct cpuinfo_x86 *c)
871-
{
872-
#ifdef CONFIG_SMP
873-
u32 eax, ebx, ecx, edx;
874-
875-
if (!cpu_has(c, X86_FEATURE_HT))
876-
return -1;
877-
878-
if (cpu_has(c, X86_FEATURE_CMP_LEGACY))
879-
return -1;
880-
881-
if (cpu_has(c, X86_FEATURE_XTOPOLOGY))
882-
return -1;
883-
884-
cpuid(1, &eax, &ebx, &ecx, &edx);
885-
886-
smp_num_siblings = (ebx & 0xff0000) >> 16;
887-
if (smp_num_siblings == 1)
888-
pr_info_once("CPU0: Hyper-Threading is disabled\n");
889-
#endif
890-
return 0;
891-
}
892-
893-
void detect_ht(struct cpuinfo_x86 *c)
894-
{
895-
#ifdef CONFIG_SMP
896-
int index_msb, core_bits;
897-
898-
if (topo_is_converted(c))
899-
return;
900-
901-
if (detect_ht_early(c) < 0)
902-
return;
903-
904-
index_msb = get_count_order(smp_num_siblings);
905-
c->topo.pkg_id = apic->phys_pkg_id(c->topo.initial_apicid, index_msb);
906-
907-
smp_num_siblings = smp_num_siblings / c->x86_max_cores;
908-
909-
index_msb = get_count_order(smp_num_siblings);
910-
911-
core_bits = get_count_order(c->x86_max_cores);
912-
913-
c->topo.core_id = apic->phys_pkg_id(c->topo.initial_apicid, index_msb) &
914-
((1 << core_bits) - 1);
915-
#endif
916-
}
917-
918857
static void get_cpu_vendor(struct cpuinfo_x86 *c)
919858
{
920859
char *v = c->x86_vendor_id;
@@ -1899,10 +1838,6 @@ static void identify_cpu(struct cpuinfo_x86 *c)
18991838
c->x86, c->x86_model);
19001839
}
19011840

1902-
#ifdef CONFIG_X86_64
1903-
detect_ht(c);
1904-
#endif
1905-
19061841
x86_init_rdrand(c);
19071842
setup_pku(c);
19081843
setup_cet(c);

arch/x86/kernel/cpu/cpu.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,7 @@ extern void init_intel_cacheinfo(struct cpuinfo_x86 *c);
7676
extern void init_amd_cacheinfo(struct cpuinfo_x86 *c);
7777
extern void init_hygon_cacheinfo(struct cpuinfo_x86 *c);
7878

79-
extern void detect_num_cpu_cores(struct cpuinfo_x86 *c);
80-
extern int detect_extended_topology_early(struct cpuinfo_x86 *c);
8179
extern int detect_extended_topology(struct cpuinfo_x86 *c);
82-
extern int detect_ht_early(struct cpuinfo_x86 *c);
83-
extern void detect_ht(struct cpuinfo_x86 *c);
8480
extern void check_null_seg_clears_base(struct cpuinfo_x86 *c);
8581

8682
void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c);

arch/x86/kernel/cpu/intel.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,6 @@ static void early_init_intel(struct cpuinfo_x86 *c)
315315
}
316316

317317
check_memory_type_self_snoop_errata(c);
318-
319-
/*
320-
* Get the number of SMT siblings early from the extended topology
321-
* leaf, if available. Otherwise try the legacy SMT detection.
322-
*/
323-
if (detect_extended_topology_early(c) < 0)
324-
detect_ht_early(c);
325318
}
326319

327320
static void bsp_init_intel(struct cpuinfo_x86 *c)
@@ -603,24 +596,6 @@ static void init_intel(struct cpuinfo_x86 *c)
603596

604597
intel_workarounds(c);
605598

606-
/*
607-
* Detect the extended topology information if available. This
608-
* will reinitialise the initial_apicid which will be used
609-
* in init_intel_cacheinfo()
610-
*/
611-
detect_extended_topology(c);
612-
613-
if (!cpu_has(c, X86_FEATURE_XTOPOLOGY)) {
614-
/*
615-
* let's use the legacy cpuid vector 0x1 and 0x4 for topology
616-
* detection.
617-
*/
618-
detect_num_cpu_cores(c);
619-
#ifdef CONFIG_X86_32
620-
detect_ht(c);
621-
#endif
622-
}
623-
624599
init_intel_cacheinfo(c);
625600

626601
if (c->cpuid_level > 9) {

arch/x86/kernel/cpu/topology.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,6 @@ static int detect_extended_topology_leaf(struct cpuinfo_x86 *c)
5959
}
6060
#endif
6161

62-
int detect_extended_topology_early(struct cpuinfo_x86 *c)
63-
{
64-
#ifdef CONFIG_SMP
65-
unsigned int eax, ebx, ecx, edx;
66-
int leaf;
67-
68-
leaf = detect_extended_topology_leaf(c);
69-
if (leaf < 0)
70-
return -1;
71-
72-
set_cpu_cap(c, X86_FEATURE_XTOPOLOGY);
73-
74-
cpuid_count(leaf, SMT_LEVEL, &eax, &ebx, &ecx, &edx);
75-
/*
76-
* initial apic id, which also represents 32-bit extended x2apic id.
77-
*/
78-
c->topo.initial_apicid = edx;
79-
smp_num_siblings = max_t(int, smp_num_siblings, LEVEL_MAX_SIBLINGS(ebx));
80-
#endif
81-
return 0;
82-
}
83-
8462
/*
8563
* Check for extended topology enumeration cpuid leaf, and if it
8664
* exists, use it for populating initial_apicid and cpu topology

arch/x86/kernel/cpu/topology_common.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ bool topo_is_converted(struct cpuinfo_x86 *c)
7171
/* Temporary until everything is converted over. */
7272
switch (boot_cpu_data.x86_vendor) {
7373
case X86_VENDOR_AMD:
74-
case X86_VENDOR_INTEL:
7574
case X86_VENDOR_HYGON:
7675
return false;
7776
default:
@@ -136,6 +135,10 @@ static void parse_topology(struct topo_scan *tscan, bool early)
136135
case X86_VENDOR_ZHAOXIN:
137136
parse_legacy(tscan);
138137
break;
138+
case X86_VENDOR_INTEL:
139+
if (!IS_ENABLED(CONFIG_CPU_SUP_INTEL) || !cpu_parse_topology_ext(tscan))
140+
parse_legacy(tscan);
141+
break;
139142
}
140143
}
141144

0 commit comments

Comments
 (0)