x86/cpu: Rework the topology evaluation
Subsystems (24)
v4 cover x86/cpu: Rework the topology evaluation
Hi!
This is the follow up to V3:
https://lore.kernel.org/lkml/[email protected]
which addresses the review feedback.
TLDR:
This reworks the way how topology information is evaluated via CPUID in preparation for a larger topology management overhaul to address shortcomings of the current code vs. hybrid systems and systems which make use of the extended topology domains in leaf 0x1f. Aside of that it's an overdue spring cleaning to get rid of accumulated layers of duct tape and haywire.
What changed vs. V3:
- Added the Hygon fix from Pu Wen and adjusted the new code accordingly
- Fixed the off by one in the AMD parser for real - Michael
- Reworked the unknown domain type handling in the 0xb/01f parser - Rui
- Made core ID package relative - Rui
- Folded the missing u32 conversions - Qiuxu
- Folded the fake_topology() fixup from the full topology series
- Small cleanups and enhancements
- Picked up Tested-by tags
The series is based on the the APIC cleanup series in tip:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/apic
and also available on top of that from git:
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git topo-cpuid-v4
Thanks,
tglx
--- arch/x86/kernel/cpu/topology.c | 168 ------------------- b/Documentation/arch/x86/topology.rst | 12 - b/arch/x86/events/amd/core.c | 2 b/arch/x86/events/amd/uncore.c | 2 b/arch/x86/events/intel/uncore.c | 2 b/arch/x86/hyperv/hv_vtl.c | 2 b/arch/x86/include/asm/apic.h | 38 +--- b/arch/x86/include/asm/cacheinfo.h | 3 b/arch/x86/include/asm/cpuid.h | 36 ++++ b/arch/x86/include/asm/mpspec.h | 2 b/arch/x86/include/asm/processor.h | 60 ++++-- b/arch/x86/include/asm/smp.h | 4 b/arch/x86/include/asm/topology.h | 51 +++++ b/arch/x86/include/asm/x86_init.h | 2 b/arch/x86/kernel/acpi/boot.c | 4 b/arch/x86/kernel/amd_nb.c | 8 b/arch/x86/kernel/apic/apic.c | 29 ++- b/arch/x86/kernel/apic/apic_common.c | 4 b/arch/x86/kernel/apic/apic_flat_64.c | 13 - b/arch/x86/kernel/apic/apic_noop.c | 9 - b/arch/x86/kernel/apic/apic_numachip.c | 21 -- b/arch/x86/kernel/apic/bigsmp_32.c | 10 - b/arch/x86/kernel/apic/ipi.c | 5 b/arch/x86/kernel/apic/local.h | 6 b/arch/x86/kernel/apic/probe_32.c | 10 - b/arch/x86/kernel/apic/x2apic_cluster.c | 1 b/arch/x86/kernel/apic/x2apic_phys.c | 10 - b/arch/x86/kernel/apic/x2apic_uv_x.c | 67 +------ b/arch/x86/kernel/cpu/Makefile | 5 b/arch/x86/kernel/cpu/amd.c | 156 ------------------ b/arch/x86/kernel/cpu/cacheinfo.c | 51 ++--- b/arch/x86/kernel/cpu/centaur.c | 4 b/arch/x86/kernel/cpu/common.c | 111 +----------- b/arch/x86/kernel/cpu/cpu.h | 14 + b/arch/x86/kernel/cpu/debugfs.c | 97 +++++++++++ b/arch/x86/kernel/cpu/hygon.c | 135 --------------- b/arch/x86/kernel/cpu/intel.c | 38 ---- b/arch/x86/kernel/cpu/mce/amd.c | 4 b/arch/x86/kernel/cpu/mce/apei.c | 4 b/arch/x86/kernel/cpu/mce/core.c | 4 b/arch/x86/kernel/cpu/mce/inject.c | 7 b/arch/x86/kernel/cpu/proc.c | 8 b/arch/x86/kernel/cpu/topology.h | 56 ++++++ b/arch/x86/kernel/cpu/topology_amd.c | 182 +++++++++++++++++++++ b/arch/x86/kernel/cpu/topology_common.c | 241 ++++++++++++++++++++++++++++ b/arch/x86/kernel/cpu/topology_ext.c | 132 +++++++++++++++ b/arch/x86/kernel/cpu/zhaoxin.c | 18 -- b/arch/x86/kernel/kvm.c | 6 b/arch/x86/kernel/sev.c | 2 b/arch/x86/kernel/smpboot.c | 97 ++++++----- b/arch/x86/kernel/vsmp_64.c | 13 - b/arch/x86/mm/amdtopology.c | 35 +--- b/arch/x86/mm/numa.c | 4 b/arch/x86/xen/apic.c | 14 - b/arch/x86/xen/smp_pv.c | 3 b/drivers/edac/amd64_edac.c | 4 b/drivers/edac/mce_amd.c | 4 b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 2 b/drivers/hwmon/fam15h_power.c | 7 b/drivers/scsi/lpfc/lpfc_init.c | 8 b/drivers/virt/acrn/hsm.c | 2 b/kernel/cpu.c | 16 + 62 files changed, 1095 insertions(+), 970 deletions(-)
PATCH v4 1/41 x86/cpu/hygon: Fix the CPU topology evaluation for real
From: Pu Wen <[email protected]>
Hygon updated processors have CPUID leaf 0xB correctly populated and don't need the fixed package ID shift workaround. The fixup is also incorrect when running in a guest.
--- arch/x86/kernel/cpu/hygon.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/hygon.c +6 -2
@@ -87,8 +87,12 @@ static void hygon_get_topology(struct cpif (!err) c->x86_coreid_bits =get_count_order (c->x86_max_cores); -/* Socket ID is ApicId[6] for these processors. */ - c->phys_proc_id = c->apicid >>APICID_SOCKET_ID_BIT ; +/* +* Socket ID is ApicId[6] for the processors with model <= 0x3 +* when running on host. +*/ +if (!boot_cpu_has (X86_FEATURE_HYPERVISOR ) && c->x86_model <=0x3 ) + c->phys_proc_id = c->apicid >>APICID_SOCKET_ID_BIT ;cacheinfo_hygon_init_llc_id (c, cpu); }else if (cpu_has (c,X86_FEATURE_NODEID_MSR )) {
PATCH v4 2/41 cpu/SMT: Make SMT control more robust against enumeration failures
In reply to Thomas GleixnerThe SMT control mechanism got added as speculation attack vector mitigation. The implemented logic relies on the primary thread mask to be set up properly.
This turns out to be an issue with XEN/PV guests because their CPU hotplug mechanics do not enumerate APICs and therefore the mask is never correctly populated.
This went unnoticed so far because by chance XEN/PV ends up with smp_num_siblings == 2. So smt_hotplug_control stays at its default value CPU_SMT_ENABLED and the primary thread mask is never evaluated in the context of CPU hotplug.
This stopped "working" with the upcoming overhaul of the topology evaluation which legitimately provides a fake topology for XEN/PV. That sets smp_num_siblings to 1, which causes the core CPU hot-plug core to refuse to bring up the APs.
This happens because smt_hotplug_control is set to CPU_SMT_NOT_SUPPORTED which causes cpu_smt_allowed() to evaluate the unpopulated primary thread mask with the conclusion that all non-boot CPUs are not valid to be plugged.
Make cpu_smt_allowed() more robust and take CPU_SMT_NOT_SUPPORTED and CPU_SMT_NOT_IMPLEMENTED into account. Rename it to cpu_bootable() while at it as that makes it more clear what the function is about.
The primary mask issue on x86 XEN/PV needs to be addressed separately as there are users outside of the CPU hotplug code too.
---
V2: Rename cpu_smt_allowed() - Borislav
--- kernel/cpu.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
kernel/cpu.c +11 -5
@@ -625,11 +625,17 @@ static int __init smt_cmdline_disable(ch }early_param ("nosmt" , smt_cmdline_disable); -static inline bool cpu_smt_allowed (unsigned int cpu) +static inline bool cpu_bootable (unsigned int cpu) {if (cpu_smt_control ==CPU_SMT_ENABLED )return true; +if (cpu_smt_control ==CPU_SMT_NOT_SUPPORTED ) +return true; + +if (cpu_smt_control ==CPU_SMT_NOT_IMPLEMENTED ) +return true; +if (topology_is_primary_thread (cpu))return true;
@@ -660,7 +666,7 @@ static inline const struct cpumask *cpuh return cpu_primary_thread_mask; }#else -static inline bool cpu_smt_allowed (unsigned int cpu) {return true; } +static inline bool cpu_bootable (unsigned int cpu) {return true; }static inline bool cpuhp_smt_aware (void ) {return false; }static inline const struct cpumask *cpuhp_get_primary_thread_mask (void ) {
@@ -768,10 +774,10 @@ static int bringup_wait_for_ap_online(un* SMT soft disabling on X86 requires to bring the CPU out of the * BIOS 'wait for SIPI' state in order to set the CR4.MCE bit. The * CPU marked itself as booted_once in notify_cpu_starting() so the -* cpu_smt_allowed() check will now return false if this is not the +* cpu_bootable() check will now return false if this is not the * primary sibling. */ -if (!cpu_smt_allowed (cpu)) +if (!cpu_bootable (cpu))return -ECANCELED ;return 0 ; }
@@ -1699,7 +1705,7 @@ static int cpu_up(unsigned int cpu, enum err = -EBUSY ; goto out; } -if (!cpu_smt_allowed (cpu)) { +if (!cpu_bootable (cpu)) { err = -EPERM ; goto out; }
Re: [patch V4 02/41] cpu/SMT: Make SMT control more robust against enumeration failures
kernel/cpu.c static int __init smt_cmdline_disable(ch · line 634
Quoted 8 lines · Thomas Gleixner
kernel/cpu.c +3
-1-static inline bool cpu_smt_allowed (unsigned int cpu) +static inline bool cpu_bootable (unsigned int cpu) {if (cpu_smt_control ==CPU_SMT_ENABLED )return true; +if (cpu_smt_control ==CPU_SMT_NOT_SUPPORTED ) +return true;
I found this new pair of if()'s rather counterintuitive to read.
The first one reads like:
"If SMT is not supported, the CPU is always bootable"
but "supported" could easily mean CONFIG_SMP==n (which is actually covered in the next case). Would this be better named:
CPU_SMT_NOT_ENUMERATED
or
CPU_SMT_NOT_DETECTED
?
/* Every CPU is bootable on non-SMT systems: */ if (cpu_smt_control == CPU_SMT_NOT_DETECTED) return true;
For the next one:
kernel/cpu.c static int __init smt_cmdline_disable(ch · line 637
Quoted 2 lines
kernel/cpu.c +2
-0+if (cpu_smt_control ==CPU_SMT_NOT_IMPLEMENTED ) +return true;
This reads a bit like "SMT is not implemented" rather than "SMT controls are not implemented". Maybe a comment would help:
/* All CPUs are bootable if controls are not implemented: */
Re: [patch V4 02/41] cpu/SMT: Make SMT control more robust against enumeration failures
Quoted 16 lines · Dave Hansen
kernel/cpu.c static int __init smt_cmdline_disable(ch · line 634
Quoted 8 lines · Thomas Gleixner
kernel/cpu.c +3
-1-static inline bool cpu_smt_allowed (unsigned int cpu) +static inline bool cpu_bootable (unsigned int cpu) {if (cpu_smt_control ==CPU_SMT_ENABLED )return true; +if (cpu_smt_control ==CPU_SMT_NOT_SUPPORTED ) +return true;I found this new pair of if()'s rather counterintuitive to read.
The first one reads like:
"If SMT is not supported, the CPU is always bootable"
Quoted 8 lines
but "supported" could easily mean
CONFIG_SMP==n(which is actually covered in the next case). Would this be better named:
CPU_SMT_NOT_ENUMERATED
or
CPU_SMT_NOT_DETECTED?
Yes, no, maybe. I rather keep them as is because the strings which are exposed via sysfs cannot be changed and are matching.
Quoted 6 lines
/* Every CPU is bootable on non-SMT systems: */ if (cpu_smt_control == CPU_SMT_NOT_DETECTED) return true;For the next one:
Quoted 7 lines
kernel/cpu.c static int __init smt_cmdline_disable(ch · line 637
Quoted 2 lines
kernel/cpu.c +2
-0+if (cpu_smt_control ==CPU_SMT_NOT_IMPLEMENTED ) +return true;This reads a bit like "SMT is not implemented" rather than "SMT controls are not implemented". Maybe a comment would help:
/* All CPUs are bootable if controls are not implemented: */
Sure.
[tip: x86/core] cpu/SMT: Make SMT control more robust against enumeration failures
In reply to Thomas GleixnerThe following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: d91bdd96b55cc3ce98d883a60f133713821b80a6 Gitweb: https://git.kernel.org/tip/d91bdd96b55cc3ce98d883a60f133713821b80a6 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:27 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:17 +02:00
cpu/SMT: Make SMT control more robust against enumeration failures
The SMT control mechanism got added as speculation attack vector mitigation. The implemented logic relies on the primary thread mask to be set up properly.
This turns out to be an issue with XEN/PV guests because their CPU hotplug mechanics do not enumerate APICs and therefore the mask is never correctly populated.
This went unnoticed so far because by chance XEN/PV ends up with smp_num_siblings == 2. So smt_hotplug_control stays at its default value CPU_SMT_ENABLED and the primary thread mask is never evaluated in the context of CPU hotplug.
This stopped "working" with the upcoming overhaul of the topology evaluation which legitimately provides a fake topology for XEN/PV. That sets smp_num_siblings to 1, which causes the core CPU hot-plug core to refuse to bring up the APs.
This happens because smt_hotplug_control is set to CPU_SMT_NOT_SUPPORTED which causes cpu_smt_allowed() to evaluate the unpopulated primary thread mask with the conclusion that all non-boot CPUs are not valid to be plugged.
Make cpu_smt_allowed() more robust and take CPU_SMT_NOT_SUPPORTED and CPU_SMT_NOT_IMPLEMENTED into account. Rename it to cpu_bootable() while at it as that makes it more clear what the function is about.
The primary mask issue on x86 XEN/PV needs to be addressed separately as there are users outside of the CPU hotplug code too.
--- kernel/cpu.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
kernel/cpu.c +13 -5
@@ -659,11 +659,19 @@ static inline bool cpu_smt_thread_allowed(unsigned int cpu)#endif } -static inline bool cpu_smt_allowed (unsigned int cpu) +static inline bool cpu_bootable (unsigned int cpu) {if (cpu_smt_control ==CPU_SMT_ENABLED &&cpu_smt_thread_allowed (cpu))return true; +/* All CPUs are bootable if controls are not configured */ +if (cpu_smt_control ==CPU_SMT_NOT_IMPLEMENTED ) +return true; + +/* All CPUs are bootable if CPU is not SMT capable */ +if (cpu_smt_control ==CPU_SMT_NOT_SUPPORTED ) +return true; +if (topology_is_primary_thread (cpu))return true;
@@ -685,7 +693,7 @@ bool cpu_smt_possible(void)EXPORT_SYMBOL_GPL (cpu_smt_possible);#else -static inline bool cpu_smt_allowed (unsigned int cpu) {return true; } +static inline bool cpu_bootable (unsigned int cpu) {return true; }#endif static inline enum cpuhp_state
@@ -788,10 +796,10 @@ static int bringup_wait_for_ap_online(unsigned int cpu)* SMT soft disabling on X86 requires to bring the CPU out of the * BIOS 'wait for SIPI' state in order to set the CR4.MCE bit. The * CPU marked itself as booted_once in notify_cpu_starting() so the -* cpu_smt_allowed() check will now return false if this is not the +* cpu_bootable() check will now return false if this is not the * primary sibling. */ -if (!cpu_smt_allowed (cpu)) +if (!cpu_bootable (cpu))return -ECANCELED ;return 0 ; }
@@ -1741,7 +1749,7 @@ static int cpu_up(unsigned int cpu, enum cpuhp_state target) err = -EBUSY ; goto out; } -if (!cpu_smt_allowed (cpu)) { +if (!cpu_bootable (cpu)) { err = -EPERM ; goto out; }
PATCH v4 3/41 x86/apic: Fake primary thread mask for XEN/PV
In reply to Thomas GleixnerThe SMT control mechanism got added as speculation attack vector mitigation. The implemented logic relies on the primary thread mask to be set up properly.
This turns out to be an issue with XEN/PV guests because their CPU hotplug mechanics do not enumerate APICs and therefore the mask is never correctly populated.
This went unnoticed so far because by chance XEN/PV ends up with smp_num_siblings == 2. So cpu_smt_control stays at its default value CPU_SMT_ENABLED and the primary thread mask is never evaluated in the context of CPU hotplug.
This stopped "working" with the upcoming overhaul of the topology evaluation which legitimately provides a fake topology for XEN/PV. That sets smp_num_siblings to 1, which causes the core CPU hot-plug core to refuse to bring up the APs.
This happens because cpu_smt_control is set to CPU_SMT_NOT_SUPPORTED which causes cpu_bootable() to evaluate the unpopulated primary thread mask with the conclusion that all non-boot CPUs are not valid to be plugged.
The core code has already been made more robust against this kind of fail, but the primary thread mask really wants to be populated to avoid other issues all over the place.
Just fake the mask by pretending that all XEN/PV vCPUs are primary threads, which is consistent because all of XEN/PVs topology is fake or non-existent.
---
V2: Fixup changelog - Borislav
--- arch/x86/kernel/apic/apic.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/x86/kernel/apic/apic.c +11 -0
@@ -36,6 +36,8 @@#include <linux/smp.h> #include <linux/mm.h> +#include <xen/xen.h> +#include <asm/trace/irq_vectors.h> #include <asm/irq_remapping.h> #include <asm/pc-conf-reg.h>
@@ -2344,6 +2346,15 @@ static int __init smp_init_primary_threa {unsigned int cpu; +/* +* XEN/PV provides either none or useless topology information. +* Pretend that all vCPUs are primary threads. +*/ +if (xen_pv_domain ()) { +cpumask_copy (&__cpu_primary_thread_mask, cpu_possible_mask); +return 0 ; + } +for (cpu =0 ; cpu < nr_logical_cpuids; cpu++)cpu_mark_primary_thread (cpu, cpuid_to_apicid[cpu]);return 0 ;
[tip: x86/core] x86/apic: Fake primary thread mask for XEN/PV
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 965e05ff8af98c44f9937366715c512000373164 Gitweb: https://git.kernel.org/tip/965e05ff8af98c44f9937366715c512000373164 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:28 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:17 +02:00
x86/apic: Fake primary thread mask for XEN/PV
The SMT control mechanism got added as speculation attack vector mitigation. The implemented logic relies on the primary thread mask to be set up properly.
This turns out to be an issue with XEN/PV guests because their CPU hotplug mechanics do not enumerate APICs and therefore the mask is never correctly populated.
This went unnoticed so far because by chance XEN/PV ends up with smp_num_siblings == 2. So cpu_smt_control stays at its default value CPU_SMT_ENABLED and the primary thread mask is never evaluated in the context of CPU hotplug.
This stopped "working" with the upcoming overhaul of the topology evaluation which legitimately provides a fake topology for XEN/PV. That sets smp_num_siblings to 1, which causes the core CPU hot-plug core to refuse to bring up the APs.
This happens because cpu_smt_control is set to CPU_SMT_NOT_SUPPORTED which causes cpu_bootable() to evaluate the unpopulated primary thread mask with the conclusion that all non-boot CPUs are not valid to be plugged.
The core code has already been made more robust against this kind of fail, but the primary thread mask really wants to be populated to avoid other issues all over the place.
Just fake the mask by pretending that all XEN/PV vCPUs are primary threads, which is consistent because all of XEN/PVs topology is fake or non-existent.
--- arch/x86/kernel/apic/apic.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/x86/kernel/apic/apic.c +11 -0
@@ -36,6 +36,8 @@#include <linux/smp.h> #include <linux/mm.h> +#include <xen/xen.h> +#include <asm/trace/irq_vectors.h> #include <asm/irq_remapping.h> #include <asm/pc-conf-reg.h>
@@ -2344,6 +2346,15 @@ static int __init smp_init_primary_thread_mask(void) {unsigned int cpu; +/* +* XEN/PV provides either none or useless topology information. +* Pretend that all vCPUs are primary threads. +*/ +if (xen_pv_domain ()) { +cpumask_copy (&__cpu_primary_thread_mask, cpu_possible_mask); +return 0 ; + } +for (cpu =0 ; cpu < nr_logical_cpuids; cpu++)cpu_mark_primary_thread (cpu, cpuid_to_apicid[cpu]);return 0 ;
PATCH v4 4/41 x86/cpu: Encapsulate topology information in cpuinfo_x86
In reply to Thomas GleixnerThe topology related information is randomly scattered across cpuinfo_x86.
Create a new structure cpuinfo_topo and move in a first step initial_apicid and apicid into it.
Aside of being better readable this is in preparation for replacing the horribly fragile CPU topology evaluation code further down the road.
Consolidate APIC ID fields to u32 as that represents the hardware type.
No functional change.
--- arch/x86/include/asm/processor.h | 14 +++++++++----- arch/x86/kernel/cpu/amd.c | 10 +++++----- arch/x86/kernel/cpu/cacheinfo.c | 20 ++++++++++---------- arch/x86/kernel/cpu/common.c | 18 +++++++++--------- arch/x86/kernel/cpu/hygon.c | 12 ++++++------ arch/x86/kernel/cpu/mce/apei.c | 2 +- arch/x86/kernel/cpu/mce/core.c | 2 +- arch/x86/kernel/cpu/proc.c | 4 ++-- arch/x86/kernel/cpu/topology.c | 12 ++++++------ arch/x86/xen/apic.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 2 +- drivers/virt/acrn/hsm.c | 2 +- 12 files changed, 52 insertions(+), 48 deletions(-)
arch/x86/include/asm/processor.h +9 -5
@@ -74,11 +74,16 @@ extern u16 __read_mostly tlb_lld_4m[NR_Iextern u16 __read_mostly tlb_lld_1g[NR_INFO ];/* -* CPU type and hardware bug flags. Kept separately for each CPU. -* Members of this structure are referenced in head_32.S, so think twice -* before touching them. [mj] +* CPU type and hardware bug flags. Kept separately for each CPU. */ +struct cpuinfo_topology { +// Real APIC ID read from the local APIC +u32 apicid; +// The initial APIC ID provided by CPUID +u32 initial_apicid; +}; +struct cpuinfo_x86 {__u8 x86;/* CPU family */ __u8 x86_vendor;/* CPU vendor */
@@ -111,6 +116,7 @@ struct cpuinfo_x86 { };char x86_vendor_id[16 ];char x86_model_id[64 ]; +struct cpuinfo_topology topo;/* in KB - valid for CPUS which support this call: */ unsigned int x86_cache_size;int x86_cache_alignment;/* In bytes */
@@ -124,8 +130,6 @@ struct cpuinfo_x86 {u64 ppin;/* cpuid returned max cores value: */ u16 x86_max_cores; -u16 apicid; -u16 initial_apicid;u16 x86_clflush_size;/* number of cores as seen by the OS: */ u16 booted_cores;
arch/x86/kernel/cpu/amd.c +5 -5
@@ -454,9 +454,9 @@ static void amd_detect_cmp(struct cpuinf bits = c->x86_coreid_bits;/* Low order bits define the core id (index of core in socket) */ - c->cpu_core_id = c->initial_apicid & ((1 << bits)-1 ); + c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1 );/* Convert the initial APIC ID into the socket ID */ - c->phys_proc_id = c->initial_apicid >> bits; + c->phys_proc_id = c->topo.initial_apicid >> bits;/* use socket ID also for last level cache */ per_cpu (cpu_llc_id, cpu) = c->cpu_die_id = c->phys_proc_id; }
@@ -472,7 +472,7 @@ static void srat_detect_node(struct cpui#ifdef CONFIG_NUMA int cpu =smp_processor_id ();int node; -unsigned apicid = c->apicid; +unsigned apicid = c->topo.apicid; node =numa_cpu_node (cpu);if (node ==NUMA_NO_NODE )
@@ -506,7 +506,7 @@ static void srat_detect_node(struct cpui* through CPU mapping may alter the outcome, directly * access __apicid_to_node[]. */ -int ht_nodeid = c->initial_apicid; +int ht_nodeid = c->topo.initial_apicid;if (__apicid_to_node[ht_nodeid] !=NUMA_NO_NODE ) node = __apicid_to_node[ht_nodeid];
@@ -1042,7 +1042,7 @@ static void init_amd(struct cpuinfo_x86set_cpu_cap (c,X86_FEATURE_FSRS );/* get apicid instead of initial apic id from cpuid */ - c->apicid =read_apic_id (); + c->topo.apicid =read_apic_id ();/* K6s reports MCEs but don't actually have all the MSRs */ if (c->x86 <6 )
arch/x86/kernel/cpu/cacheinfo.c +10 -10
@@ -678,7 +678,7 @@ void cacheinfo_amd_init_llc_id(struct cp* LLC is at the core complex level. * Core complex ID is ApicId[3] for these processors. */ -per_cpu (cpu_llc_id, cpu) = c->apicid >>3 ; +per_cpu (cpu_llc_id, cpu) = c->topo.apicid >>3 ; }else {/* * LLC ID is calculated from the number of threads sharing the
@@ -694,7 +694,7 @@ void cacheinfo_amd_init_llc_id(struct cpif (num_sharing_cache) {int bits =get_count_order (num_sharing_cache); -per_cpu (cpu_llc_id, cpu) = c->apicid >> bits; +per_cpu (cpu_llc_id, cpu) = c->topo.apicid >> bits; } } }
@@ -712,7 +712,7 @@ void cacheinfo_hygon_init_llc_id(struct* LLC is at the core complex level. * Core complex ID is ApicId[3] for these processors. */ -per_cpu (cpu_llc_id, cpu) = c->apicid >>3 ; +per_cpu (cpu_llc_id, cpu) = c->topo.apicid >>3 ; }void init_amd_cacheinfo (struct cpuinfo_x86 *c)
@@ -776,13 +776,13 @@ void init_intel_cacheinfo(struct cpuinfo new_l2 = this_leaf.size/1024 ; num_threads_sharing =1 + this_leaf.eax.split.num_threads_sharing; index_msb =get_count_order (num_threads_sharing); - l2_id = c->apicid & ~((1 << index_msb) -1 ); + l2_id = c->topo.apicid & ~((1 << index_msb) -1 );break ;case 3 : new_l3 = this_leaf.size/1024 ; num_threads_sharing =1 + this_leaf.eax.split.num_threads_sharing; index_msb =get_count_order (num_threads_sharing); - l3_id = c->apicid & ~((1 << index_msb) -1 ); + l3_id = c->topo.apicid & ~((1 << index_msb) -1 );break ;default :break ;
@@ -915,7 +915,7 @@ static int __cache_amd_cpumap_setup(unsiunsigned int apicid, nshared, first, last; nshared = base->eax.split.num_threads_sharing +1 ; - apicid =cpu_data (cpu).apicid; + apicid =cpu_data (cpu).topo.apicid; first = apicid - (apicid % nshared); last = first + nshared -1 ;
@@ -924,14 +924,14 @@ static int __cache_amd_cpumap_setup(unsiif (!this_cpu_ci->info_list)continue ; - apicid =cpu_data (i).apicid; + apicid =cpu_data (i).topo.apicid;if ((apicid < first) || (apicid > last))continue ; this_leaf = this_cpu_ci->info_list + index;for_each_online_cpu (sibling) { - apicid =cpu_data (sibling).apicid; + apicid =cpu_data (sibling).topo.apicid;if ((apicid < first) || (apicid > last))continue ; cpumask_set_cpu(sibling,
@@ -969,7 +969,7 @@ static void __cache_cpumap_setup(unsigne index_msb =get_count_order (num_threads_sharing);for_each_online_cpu (i) -if (cpu_data (i).apicid >> index_msb == c->apicid >> index_msb) { +if (cpu_data (i).topo.apicid >> index_msb == c->topo.apicid >> index_msb) {struct cpu_cacheinfo *sib_cpu_ci =get_cpu_cacheinfo (i);if (i == cpu || !sib_cpu_ci->info_list)
@@ -1024,7 +1024,7 @@ static void get_cache_id(int cpu, struct num_threads_sharing =1 + id4_regs->eax.split.num_threads_sharing; index_msb =get_count_order (num_threads_sharing); - id4_regs->id = c->apicid >> index_msb; + id4_regs->id = c->topo.apicid >> index_msb; }int populate_cache_leaves (unsigned int cpu)
arch/x86/kernel/cpu/common.c +9 -9
@@ -899,7 +899,7 @@ void detect_ht(struct cpuinfo_x86 *c)return ; index_msb =get_count_order (smp_num_siblings); - c->phys_proc_id = apic->phys_pkg_id (c->initial_apicid, index_msb); + c->phys_proc_id = apic->phys_pkg_id (c->topo.initial_apicid, index_msb); smp_num_siblings = smp_num_siblings / c->x86_max_cores;
@@ -907,7 +907,7 @@ void detect_ht(struct cpuinfo_x86 *c) core_bits =get_count_order (c->x86_max_cores); - c->cpu_core_id = apic->phys_pkg_id (c->initial_apicid, index_msb) & + c->cpu_core_id = apic->phys_pkg_id (c->topo.initial_apicid, index_msb) & ((1 << core_bits) -1 );#endif }
@@ -1721,15 +1721,15 @@ static void generic_identify(struct cpuiget_cpu_address_sizes (c);if (c->cpuid_level >=0x00000001 ) { - c->initial_apicid = (cpuid_ebx (1 ) >>24 ) &0xFF ; + c->topo.initial_apicid = (cpuid_ebx (1 ) >>24 ) &0xFF ;#ifdef CONFIG_X86_32 # ifdef CONFIG_SMP - c->apicid = apic->phys_pkg_id (c->initial_apicid,0 ); + c->topo.apicid = apic->phys_pkg_id (c->topo.initial_apicid,0 );# else - c->apicid = c->initial_apicid; + c->topo.apicid = c->topo.initial_apicid;# endif #endif - c->phys_proc_id = c->initial_apicid; + c->phys_proc_id = c->topo.initial_apicid; }get_model_name (c);/* Default name */
@@ -1763,9 +1763,9 @@ static void validate_apic_and_package_id apicid = apic->cpu_present_to_apicid (cpu); -if (apicid != c->apicid) { +if (apicid != c->topo.apicid) {pr_err (FW_BUG "CPU%u: APIC id mismatch. Firmware: %x APIC: %x\n" , - cpu, apicid, c->initial_apicid); + cpu, apicid, c->topo.initial_apicid); }BUG_ON (topology_update_package_map (c->phys_proc_id, cpu));BUG_ON (topology_update_die_map (c->cpu_die_id, cpu));
@@ -1815,7 +1815,7 @@ static void identify_cpu(struct cpuinfo_apply_forced_caps (c);#ifdef CONFIG_X86_64 - c->apicid = apic->phys_pkg_id (c->initial_apicid,0 ); + c->topo.apicid = apic->phys_pkg_id (c->topo.initial_apicid,0 );#endif /*
arch/x86/kernel/cpu/hygon.c +6 -6
@@ -92,7 +92,7 @@ static void hygon_get_topology(struct cp* when running on host. */ if (!boot_cpu_has (X86_FEATURE_HYPERVISOR ) && c->x86_model <=0x3 ) - c->phys_proc_id = c->apicid >>APICID_SOCKET_ID_BIT ; + c->phys_proc_id = c->topo.apicid >>APICID_SOCKET_ID_BIT ;cacheinfo_hygon_init_llc_id (c, cpu); }else if (cpu_has (c,X86_FEATURE_NODEID_MSR )) {
@@ -120,9 +120,9 @@ static void hygon_detect_cmp(struct cpui bits = c->x86_coreid_bits;/* Low order bits define the core id (index of core in socket) */ - c->cpu_core_id = c->initial_apicid & ((1 << bits)-1 ); + c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1 );/* Convert the initial APIC ID into the socket ID */ - c->phys_proc_id = c->initial_apicid >> bits; + c->phys_proc_id = c->topo.initial_apicid >> bits;/* use socket ID also for last level cache */ per_cpu (cpu_llc_id, cpu) = c->cpu_die_id = c->phys_proc_id; }
@@ -132,7 +132,7 @@ static void srat_detect_node(struct cpui#ifdef CONFIG_NUMA int cpu =smp_processor_id ();int node; -unsigned int apicid = c->apicid; +unsigned int apicid = c->topo.apicid; node =numa_cpu_node (cpu);if (node ==NUMA_NO_NODE )
@@ -165,7 +165,7 @@ static void srat_detect_node(struct cpui* through CPU mapping may alter the outcome, directly * access __apicid_to_node[]. */ -int ht_nodeid = c->initial_apicid; +int ht_nodeid = c->topo.initial_apicid;if (__apicid_to_node[ht_nodeid] !=NUMA_NO_NODE ) node = __apicid_to_node[ht_nodeid];
@@ -305,7 +305,7 @@ static void init_hygon(struct cpuinfo_x8set_cpu_cap (c,X86_FEATURE_REP_GOOD );/* get apicid instead of initial apic id from cpuid */ - c->apicid =read_apic_id (); + c->topo.apicid =read_apic_id ();/* * XXX someone from Hygon needs to confirm this DTRT
arch/x86/kernel/cpu/mce/apei.c +1 -1
@@ -103,7 +103,7 @@ int apei_smca_report_x86_error(struct cp m.socketid =-1 ;for_each_possible_cpu (cpu) { -if (cpu_data (cpu).initial_apicid == lapic_id) { +if (cpu_data (cpu).topo.initial_apicid == lapic_id) { m.extcpu = cpu; m.socketid =cpu_data (m.extcpu).phys_proc_id;break ;
arch/x86/kernel/cpu/mce/core.c +1 -1
@@ -124,7 +124,7 @@ void mce_setup(struct mce *m) m->cpuvendor = boot_cpu_data.x86_vendor; m->cpuid =cpuid_eax (1 ); m->socketid =cpu_data (m->extcpu).phys_proc_id; - m->apicid =cpu_data (m->extcpu).initial_apicid; + m->apicid =cpu_data (m->extcpu).topo.initial_apicid; m->mcgcap =__rdmsr (MSR_IA32_MCG_CAP ); m->ppin =cpu_data (m->extcpu).ppin; m->microcode = boot_cpu_data.microcode;
arch/x86/kernel/cpu/proc.c +2 -2
@@ -23,8 +23,8 @@ static void show_cpuinfo_core(struct seq cpumask_weight(topology_core_cpumask(cpu)));seq_printf (m,"core id\t\t: %d\n" , c->cpu_core_id);seq_printf (m,"cpu cores\t: %d\n" , c->booted_cores); -seq_printf (m,"apicid\t\t: %d\n" , c->apicid); -seq_printf (m,"initial apicid\t: %d\n" , c->initial_apicid); +seq_printf (m,"apicid\t\t: %d\n" , c->topo.apicid); +seq_printf (m,"initial apicid\t: %d\n" , c->topo.initial_apicid);#endif }
arch/x86/kernel/cpu/topology.c +6 -6
@@ -78,7 +78,7 @@ int detect_extended_topology_early(struc/* * initial apic id, which also represents 32-bit extended x2apic id. */ - c->initial_apicid = edx; + c->topo.initial_apicid = edx; smp_num_siblings =max_t (int, smp_num_siblings,LEVEL_MAX_SIBLINGS (ebx));#endif return 0 ;
@@ -108,7 +108,7 @@ int detect_extended_topology(struct cpui* Populate HT related information from sub-leaf level 0. */ cpuid_count (leaf,SMT_LEVEL , &eax, &ebx, &ecx, &edx); - c->initial_apicid = edx; + c->topo.initial_apicid = edx; core_level_siblings =LEVEL_MAX_SIBLINGS (ebx); smp_num_siblings =max_t (int, smp_num_siblings,LEVEL_MAX_SIBLINGS (ebx)); core_plus_mask_width = ht_mask_width =BITS_SHIFT_NEXT_LEVEL (eax);
@@ -146,20 +146,20 @@ int detect_extended_topology(struct cpui die_select_mask = (~(-1 << die_plus_mask_width)) >> core_plus_mask_width; - c->cpu_core_id = apic->phys_pkg_id (c->initial_apicid, + c->cpu_core_id = apic->phys_pkg_id (c->topo.initial_apicid, ht_mask_width) & core_select_mask;if (die_level_present) { - c->cpu_die_id = apic->phys_pkg_id (c->initial_apicid, + c->cpu_die_id = apic->phys_pkg_id (c->topo.initial_apicid, core_plus_mask_width) & die_select_mask; } - c->phys_proc_id = apic->phys_pkg_id (c->initial_apicid, + c->phys_proc_id = apic->phys_pkg_id (c->topo.initial_apicid, pkg_mask_width);/* * Reinit the apicid, now that we have extended initial_apicid. */ - c->apicid = apic->phys_pkg_id (c->initial_apicid,0 ); + c->topo.apicid = apic->phys_pkg_id (c->topo.initial_apicid,0 ); c->x86_max_cores = (core_level_siblings / smp_num_siblings); __max_die_per_package = (die_level_siblings / core_level_siblings);
arch/x86/xen/apic.c +1 -1
@@ -118,7 +118,7 @@ static int xen_phys_pkg_id(int initial_astatic int xen_cpu_present_to_apicid (int cpu) {if (cpu_present (cpu)) -return cpu_data (cpu).apicid; +return cpu_data (cpu).topo.apicid;else return BAD_APICID ; }
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1 -1
@@ -2255,7 +2255,7 @@ static int kfd_cpumask_to_apic_id(constif (first_cpu_of_numa_node >= nr_cpu_ids)return -1 ;#ifdef CONFIG_X86_64 -return cpu_data (first_cpu_of_numa_node).apicid; +return cpu_data (first_cpu_of_numa_node).topo.apicid;#else return first_cpu_of_numa_node;#endif
drivers/virt/acrn/hsm.c +1 -1
@@ -447,7 +447,7 @@ static ssize_t remove_cpu_store(struct dif (cpu_online (cpu))remove_cpu (cpu); - lapicid =cpu_data (cpu).apicid; + lapicid =cpu_data (cpu).topo.apicid;dev_dbg (dev,"Try to remove cpu %lld with lapicid %lld\n" , cpu, lapicid); ret =hcall_sos_remove_cpu (lapicid);if (ret <0 ) {
[tip: x86/core] x86/cpu: Encapsulate topology information in cpuinfo_x86
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: b9655e702dc5d856e5e05ae414b71708ca98b30c Gitweb: https://git.kernel.org/tip/b9655e702dc5d856e5e05ae414b71708ca98b30c Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:29 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:17 +02:00
x86/cpu: Encapsulate topology information in cpuinfo_x86
The topology related information is randomly scattered across cpuinfo_x86.
Create a new structure cpuinfo_topo and move in a first step initial_apicid and apicid into it.
Aside of being better readable this is in preparation for replacing the horribly fragile CPU topology evaluation code further down the road.
Consolidate APIC ID fields to u32 as that represents the hardware type.
No functional change.
--- arch/x86/include/asm/processor.h | 14 +++++++++----- arch/x86/kernel/cpu/amd.c | 10 +++++----- arch/x86/kernel/cpu/cacheinfo.c | 20 ++++++++++---------- arch/x86/kernel/cpu/common.c | 18 +++++++++--------- arch/x86/kernel/cpu/hygon.c | 12 ++++++------ arch/x86/kernel/cpu/mce/apei.c | 2 +- arch/x86/kernel/cpu/mce/core.c | 2 +- arch/x86/kernel/cpu/proc.c | 4 ++-- arch/x86/kernel/cpu/topology.c | 12 ++++++------ arch/x86/xen/apic.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 2 +- drivers/virt/acrn/hsm.c | 2 +- 12 files changed, 52 insertions(+), 48 deletions(-)
arch/x86/include/asm/processor.h +9 -5
@@ -75,11 +75,16 @@ extern u16 __read_mostly tlb_lld_4m[NR_INFO];extern u16 __read_mostly tlb_lld_1g[NR_INFO ];/* -* CPU type and hardware bug flags. Kept separately for each CPU. -* Members of this structure are referenced in head_32.S, so think twice -* before touching them. [mj] +* CPU type and hardware bug flags. Kept separately for each CPU. */ +struct cpuinfo_topology { +// Real APIC ID read from the local APIC +u32 apicid; +// The initial APIC ID provided by CPUID +u32 initial_apicid; +}; +struct cpuinfo_x86 {__u8 x86;/* CPU family */ __u8 x86_vendor;/* CPU vendor */
@@ -112,6 +117,7 @@ struct cpuinfo_x86 { };char x86_vendor_id[16 ];char x86_model_id[64 ]; +struct cpuinfo_topology topo;/* in KB - valid for CPUS which support this call: */ unsigned int x86_cache_size;int x86_cache_alignment;/* In bytes */
@@ -125,8 +131,6 @@ struct cpuinfo_x86 {u64 ppin;/* cpuid returned max cores value: */ u16 x86_max_cores; -u16 apicid; -u16 initial_apicid;u16 x86_clflush_size;/* number of cores as seen by the OS: */ u16 booted_cores;
arch/x86/kernel/cpu/amd.c +5 -5
@@ -459,9 +459,9 @@ static void amd_detect_cmp(struct cpuinfo_x86 *c) bits = c->x86_coreid_bits;/* Low order bits define the core id (index of core in socket) */ - c->cpu_core_id = c->initial_apicid & ((1 << bits)-1 ); + c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1 );/* Convert the initial APIC ID into the socket ID */ - c->phys_proc_id = c->initial_apicid >> bits; + c->phys_proc_id = c->topo.initial_apicid >> bits;/* use socket ID also for last level cache */ per_cpu (cpu_llc_id, cpu) = c->cpu_die_id = c->phys_proc_id; }
@@ -477,7 +477,7 @@ static void srat_detect_node(struct cpuinfo_x86 *c)#ifdef CONFIG_NUMA int cpu =smp_processor_id ();int node; -unsigned apicid = c->apicid; +unsigned apicid = c->topo.apicid; node =numa_cpu_node (cpu);if (node ==NUMA_NO_NODE )
@@ -511,7 +511,7 @@ static void srat_detect_node(struct cpuinfo_x86 *c)* through CPU mapping may alter the outcome, directly * access __apicid_to_node[]. */ -int ht_nodeid = c->initial_apicid; +int ht_nodeid = c->topo.initial_apicid;if (__apicid_to_node[ht_nodeid] !=NUMA_NO_NODE ) node = __apicid_to_node[ht_nodeid];
@@ -1047,7 +1047,7 @@ static void init_amd(struct cpuinfo_x86 *c)set_cpu_cap (c,X86_FEATURE_FSRS );/* get apicid instead of initial apic id from cpuid */ - c->apicid =read_apic_id (); + c->topo.apicid =read_apic_id ();/* K6s reports MCEs but don't actually have all the MSRs */ if (c->x86 <6 )
arch/x86/kernel/cpu/cacheinfo.c +10 -10
@@ -678,7 +678,7 @@ void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu)* LLC is at the core complex level. * Core complex ID is ApicId[3] for these processors. */ -per_cpu (cpu_llc_id, cpu) = c->apicid >>3 ; +per_cpu (cpu_llc_id, cpu) = c->topo.apicid >>3 ; }else {/* * LLC ID is calculated from the number of threads sharing the
@@ -694,7 +694,7 @@ void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu)if (num_sharing_cache) {int bits =get_count_order (num_sharing_cache); -per_cpu (cpu_llc_id, cpu) = c->apicid >> bits; +per_cpu (cpu_llc_id, cpu) = c->topo.apicid >> bits; } } }
@@ -712,7 +712,7 @@ void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c, int cpu)* LLC is at the core complex level. * Core complex ID is ApicId[3] for these processors. */ -per_cpu (cpu_llc_id, cpu) = c->apicid >>3 ; +per_cpu (cpu_llc_id, cpu) = c->topo.apicid >>3 ; }void init_amd_cacheinfo (struct cpuinfo_x86 *c)
@@ -776,13 +776,13 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) new_l2 = this_leaf.size/1024 ; num_threads_sharing =1 + this_leaf.eax.split.num_threads_sharing; index_msb =get_count_order (num_threads_sharing); - l2_id = c->apicid & ~((1 << index_msb) -1 ); + l2_id = c->topo.apicid & ~((1 << index_msb) -1 );break ;case 3 : new_l3 = this_leaf.size/1024 ; num_threads_sharing =1 + this_leaf.eax.split.num_threads_sharing; index_msb =get_count_order (num_threads_sharing); - l3_id = c->apicid & ~((1 << index_msb) -1 ); + l3_id = c->topo.apicid & ~((1 << index_msb) -1 );break ;default :break ;
@@ -915,7 +915,7 @@ static int __cache_amd_cpumap_setup(unsigned int cpu, int index,unsigned int apicid, nshared, first, last; nshared = base->eax.split.num_threads_sharing +1 ; - apicid =cpu_data (cpu).apicid; + apicid =cpu_data (cpu).topo.apicid; first = apicid - (apicid % nshared); last = first + nshared -1 ;
@@ -924,14 +924,14 @@ static int __cache_amd_cpumap_setup(unsigned int cpu, int index,if (!this_cpu_ci->info_list)continue ; - apicid =cpu_data (i).apicid; + apicid =cpu_data (i).topo.apicid;if ((apicid < first) || (apicid > last))continue ; this_leaf = this_cpu_ci->info_list + index;for_each_online_cpu (sibling) { - apicid =cpu_data (sibling).apicid; + apicid =cpu_data (sibling).topo.apicid;if ((apicid < first) || (apicid > last))continue ; cpumask_set_cpu(sibling,
@@ -969,7 +969,7 @@ static void __cache_cpumap_setup(unsigned int cpu, int index, index_msb =get_count_order (num_threads_sharing);for_each_online_cpu (i) -if (cpu_data (i).apicid >> index_msb == c->apicid >> index_msb) { +if (cpu_data (i).topo.apicid >> index_msb == c->topo.apicid >> index_msb) {struct cpu_cacheinfo *sib_cpu_ci =get_cpu_cacheinfo (i);if (i == cpu || !sib_cpu_ci->info_list)
@@ -1024,7 +1024,7 @@ static void get_cache_id(int cpu, struct _cpuid4_info_regs *id4_regs) num_threads_sharing =1 + id4_regs->eax.split.num_threads_sharing; index_msb =get_count_order (num_threads_sharing); - id4_regs->id = c->apicid >> index_msb; + id4_regs->id = c->topo.apicid >> index_msb; }int populate_cache_leaves (unsigned int cpu)
arch/x86/kernel/cpu/common.c +9 -9
@@ -914,7 +914,7 @@ void detect_ht(struct cpuinfo_x86 *c)return ; index_msb =get_count_order (smp_num_siblings); - c->phys_proc_id = apic->phys_pkg_id (c->initial_apicid, index_msb); + c->phys_proc_id = apic->phys_pkg_id (c->topo.initial_apicid, index_msb); smp_num_siblings = smp_num_siblings / c->x86_max_cores;
@@ -922,7 +922,7 @@ void detect_ht(struct cpuinfo_x86 *c) core_bits =get_count_order (c->x86_max_cores); - c->cpu_core_id = apic->phys_pkg_id (c->initial_apicid, index_msb) & + c->cpu_core_id = apic->phys_pkg_id (c->topo.initial_apicid, index_msb) & ((1 << core_bits) -1 );#endif }
@@ -1761,15 +1761,15 @@ static void generic_identify(struct cpuinfo_x86 *c)get_cpu_address_sizes (c);if (c->cpuid_level >=0x00000001 ) { - c->initial_apicid = (cpuid_ebx (1 ) >>24 ) &0xFF ; + c->topo.initial_apicid = (cpuid_ebx (1 ) >>24 ) &0xFF ;#ifdef CONFIG_X86_32 # ifdef CONFIG_SMP - c->apicid = apic->phys_pkg_id (c->initial_apicid,0 ); + c->topo.apicid = apic->phys_pkg_id (c->topo.initial_apicid,0 );# else - c->apicid = c->initial_apicid; + c->topo.apicid = c->topo.initial_apicid;# endif #endif - c->phys_proc_id = c->initial_apicid; + c->phys_proc_id = c->topo.initial_apicid; }get_model_name (c);/* Default name */
@@ -1803,9 +1803,9 @@ static void validate_apic_and_package_id(struct cpuinfo_x86 *c) apicid = apic->cpu_present_to_apicid (cpu); -if (apicid != c->apicid) { +if (apicid != c->topo.apicid) {pr_err (FW_BUG "CPU%u: APIC id mismatch. Firmware: %x APIC: %x\n" , - cpu, apicid, c->initial_apicid); + cpu, apicid, c->topo.initial_apicid); }BUG_ON (topology_update_package_map (c->phys_proc_id, cpu));BUG_ON (topology_update_die_map (c->cpu_die_id, cpu));
@@ -1855,7 +1855,7 @@ static void identify_cpu(struct cpuinfo_x86 *c)apply_forced_caps (c);#ifdef CONFIG_X86_64 - c->apicid = apic->phys_pkg_id (c->initial_apicid,0 ); + c->topo.apicid = apic->phys_pkg_id (c->topo.initial_apicid,0 );#endif /*
arch/x86/kernel/cpu/hygon.c +6 -6
@@ -92,7 +92,7 @@ static void hygon_get_topology(struct cpuinfo_x86 *c)* when running on host. */ if (!boot_cpu_has (X86_FEATURE_HYPERVISOR ) && c->x86_model <=0x3 ) - c->phys_proc_id = c->apicid >>APICID_SOCKET_ID_BIT ; + c->phys_proc_id = c->topo.apicid >>APICID_SOCKET_ID_BIT ;cacheinfo_hygon_init_llc_id (c, cpu); }else if (cpu_has (c,X86_FEATURE_NODEID_MSR )) {
@@ -120,9 +120,9 @@ static void hygon_detect_cmp(struct cpuinfo_x86 *c) bits = c->x86_coreid_bits;/* Low order bits define the core id (index of core in socket) */ - c->cpu_core_id = c->initial_apicid & ((1 << bits)-1 ); + c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1 );/* Convert the initial APIC ID into the socket ID */ - c->phys_proc_id = c->initial_apicid >> bits; + c->phys_proc_id = c->topo.initial_apicid >> bits;/* use socket ID also for last level cache */ per_cpu (cpu_llc_id, cpu) = c->cpu_die_id = c->phys_proc_id; }
@@ -132,7 +132,7 @@ static void srat_detect_node(struct cpuinfo_x86 *c)#ifdef CONFIG_NUMA int cpu =smp_processor_id ();int node; -unsigned int apicid = c->apicid; +unsigned int apicid = c->topo.apicid; node =numa_cpu_node (cpu);if (node ==NUMA_NO_NODE )
@@ -165,7 +165,7 @@ static void srat_detect_node(struct cpuinfo_x86 *c)* through CPU mapping may alter the outcome, directly * access __apicid_to_node[]. */ -int ht_nodeid = c->initial_apicid; +int ht_nodeid = c->topo.initial_apicid;if (__apicid_to_node[ht_nodeid] !=NUMA_NO_NODE ) node = __apicid_to_node[ht_nodeid];
@@ -305,7 +305,7 @@ static void init_hygon(struct cpuinfo_x86 *c)set_cpu_cap (c,X86_FEATURE_REP_GOOD );/* get apicid instead of initial apic id from cpuid */ - c->apicid =read_apic_id (); + c->topo.apicid =read_apic_id ();/* * XXX someone from Hygon needs to confirm this DTRT
arch/x86/kernel/cpu/mce/apei.c +1 -1
@@ -103,7 +103,7 @@ int apei_smca_report_x86_error(struct cper_ia_proc_ctx *ctx_info, u64 lapic_id) m.socketid =-1 ;for_each_possible_cpu (cpu) { -if (cpu_data (cpu).initial_apicid == lapic_id) { +if (cpu_data (cpu).topo.initial_apicid == lapic_id) { m.extcpu = cpu; m.socketid =cpu_data (m.extcpu).phys_proc_id;break ;
arch/x86/kernel/cpu/mce/core.c +1 -1
@@ -124,7 +124,7 @@ void mce_setup(struct mce *m) m->cpuvendor = boot_cpu_data.x86_vendor; m->cpuid =cpuid_eax (1 ); m->socketid =cpu_data (m->extcpu).phys_proc_id; - m->apicid =cpu_data (m->extcpu).initial_apicid; + m->apicid =cpu_data (m->extcpu).topo.initial_apicid; m->mcgcap =__rdmsr (MSR_IA32_MCG_CAP ); m->ppin =cpu_data (m->extcpu).ppin; m->microcode = boot_cpu_data.microcode;
arch/x86/kernel/cpu/proc.c +2 -2
@@ -25,8 +25,8 @@ static void show_cpuinfo_core(struct seq_file *m, struct cpuinfo_x86 *c, cpumask_weight(topology_core_cpumask(cpu)));seq_printf (m,"core id\t\t: %d\n" , c->cpu_core_id);seq_printf (m,"cpu cores\t: %d\n" , c->booted_cores); -seq_printf (m,"apicid\t\t: %d\n" , c->apicid); -seq_printf (m,"initial apicid\t: %d\n" , c->initial_apicid); +seq_printf (m,"apicid\t\t: %d\n" , c->topo.apicid); +seq_printf (m,"initial apicid\t: %d\n" , c->topo.initial_apicid);#endif }
arch/x86/kernel/cpu/topology.c +6 -6
@@ -78,7 +78,7 @@ int detect_extended_topology_early(struct cpuinfo_x86 *c)/* * initial apic id, which also represents 32-bit extended x2apic id. */ - c->initial_apicid = edx; + c->topo.initial_apicid = edx; smp_num_siblings =max_t (int, smp_num_siblings,LEVEL_MAX_SIBLINGS (ebx));#endif return 0 ;
@@ -108,7 +108,7 @@ int detect_extended_topology(struct cpuinfo_x86 *c)* Populate HT related information from sub-leaf level 0. */ cpuid_count (leaf,SMT_LEVEL , &eax, &ebx, &ecx, &edx); - c->initial_apicid = edx; + c->topo.initial_apicid = edx; core_level_siblings =LEVEL_MAX_SIBLINGS (ebx); smp_num_siblings =max_t (int, smp_num_siblings,LEVEL_MAX_SIBLINGS (ebx)); core_plus_mask_width = ht_mask_width =BITS_SHIFT_NEXT_LEVEL (eax);
@@ -146,20 +146,20 @@ int detect_extended_topology(struct cpuinfo_x86 *c) die_select_mask = (~(-1 << die_plus_mask_width)) >> core_plus_mask_width; - c->cpu_core_id = apic->phys_pkg_id (c->initial_apicid, + c->cpu_core_id = apic->phys_pkg_id (c->topo.initial_apicid, ht_mask_width) & core_select_mask;if (die_level_present) { - c->cpu_die_id = apic->phys_pkg_id (c->initial_apicid, + c->cpu_die_id = apic->phys_pkg_id (c->topo.initial_apicid, core_plus_mask_width) & die_select_mask; } - c->phys_proc_id = apic->phys_pkg_id (c->initial_apicid, + c->phys_proc_id = apic->phys_pkg_id (c->topo.initial_apicid, pkg_mask_width);/* * Reinit the apicid, now that we have extended initial_apicid. */ - c->apicid = apic->phys_pkg_id (c->initial_apicid,0 ); + c->topo.apicid = apic->phys_pkg_id (c->topo.initial_apicid,0 ); c->x86_max_cores = (core_level_siblings / smp_num_siblings); __max_die_per_package = (die_level_siblings / core_level_siblings);
arch/x86/xen/apic.c +1 -1
@@ -118,7 +118,7 @@ static int xen_phys_pkg_id(int initial_apic_id, int index_msb)static int xen_cpu_present_to_apicid (int cpu) {if (cpu_present (cpu)) -return cpu_data (cpu).apicid; +return cpu_data (cpu).topo.apicid;else return BAD_APICID ; }
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1 -1
@@ -2209,7 +2209,7 @@ static int kfd_cpumask_to_apic_id(const struct cpumask *cpumask)if (first_cpu_of_numa_node >= nr_cpu_ids)return -1 ;#ifdef CONFIG_X86_64 -return cpu_data (first_cpu_of_numa_node).apicid; +return cpu_data (first_cpu_of_numa_node).topo.apicid;#else return first_cpu_of_numa_node;#endif
drivers/virt/acrn/hsm.c +1 -1
@@ -447,7 +447,7 @@ static ssize_t remove_cpu_store(struct device *dev,if (cpu_online (cpu))remove_cpu (cpu); - lapicid =cpu_data (cpu).apicid; + lapicid =cpu_data (cpu).topo.apicid;dev_dbg (dev,"Try to remove cpu %lld with lapicid %lld\n" , cpu, lapicid); ret =hcall_sos_remove_cpu (lapicid);if (ret <0 ) {
PATCH v4 5/41 x86/cpu: Move phys_proc_id into topology info
In reply to Thomas GleixnerRename it to pkg_id which is the terminology used in the kernel.
No functional change.
--- Documentation/arch/x86/topology.rst | 2 +- arch/x86/include/asm/processor.h | 5 +++-- arch/x86/include/asm/topology.h | 2 +- arch/x86/include/asm/x86_init.h | 2 +- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/cpu/amd.c | 4 ++-- arch/x86/kernel/cpu/cacheinfo.c | 4 ++-- arch/x86/kernel/cpu/common.c | 6 +++--- arch/x86/kernel/cpu/hygon.c | 6 +++--- arch/x86/kernel/cpu/mce/apei.c | 2 +- arch/x86/kernel/cpu/mce/core.c | 2 +- arch/x86/kernel/cpu/proc.c | 2 +- arch/x86/kernel/cpu/topology.c | 3 +-- arch/x86/kernel/smpboot.c | 16 ++++++++-------- drivers/scsi/lpfc/lpfc_init.c | 6 +----- 15 files changed, 30 insertions(+), 34 deletions(-)
Documentation/arch/x86/topology.rst +1 -1
@@ -59,7 +59,7 @@ AMD nomenclature for package is 'Node'. The physical ID of the die. This information is retrieved via CPUID. - - cpuinfo_x86.phys_proc_id: + - cpuinfo_x86.topo.pkg_id: The physical ID of the package. This information is retrieved via CPUID and deduced from the APIC IDs of the cores in the package.
arch/x86/include/asm/processor.h +3 -2
@@ -82,6 +82,9 @@ struct cpuinfo_topology {u32 apicid;// The initial APIC ID provided by CPUID u32 initial_apicid; + +// Physical package ID +u32 pkg_id; };struct cpuinfo_x86 {
@@ -133,8 +136,6 @@ struct cpuinfo_x86 {u16 x86_clflush_size;/* number of cores as seen by the OS: */ u16 booted_cores; -/* Physical processor id: */ -u16 phys_proc_id;/* Logical processor id: */ u16 logical_proc_id;/* Core id: */
arch/x86/include/asm/topology.h +1 -1
@@ -106,7 +106,7 @@ extern const struct cpumask *cpu_coregroextern const struct cpumask *cpu_clustergroup_mask (int cpu);#define topology_logical_package_id (cpu) (cpu_data(cpu).logical_proc_id) -#define topology_physical_package_id (cpu) (cpu_data(cpu).phys_proc_id) +#define topology_physical_package_id (cpu) (cpu_data(cpu).topo.pkg_id)#define topology_logical_die_id (cpu) (cpu_data(cpu).logical_die_id)#define topology_die_id (cpu) (cpu_data(cpu).cpu_die_id)#define topology_core_id (cpu) (cpu_data(cpu).cpu_core_id)
arch/x86/include/asm/x86_init.h +1 -1
@@ -177,7 +177,7 @@ struct x86_init_ops {* struct x86_cpuinit_ops - platform specific cpu hotplug setups * @setup_percpu_clockev: set up the per cpu clock event device * @early_percpu_clock_init: early init of the per cpu clock event device -* @fixup_cpu_id: fixup function for cpuinfo_x86::phys_proc_id +* @fixup_cpu_id: fixup function for cpuinfo_x86::topo.pkg_id * @parallel_bringup: Parallel bringup control */ struct x86_cpuinit_ops {
arch/x86/kernel/apic/apic_numachip.c +1 -1
@@ -169,7 +169,7 @@ static void fixup_cpu_id(struct cpuinfo_ nodes = ((val >>3 ) &7 ) +1 ; } - c->phys_proc_id = node / nodes; + c->topo.pkg_id = node / nodes; }static int __init numachip_system_init (void )
arch/x86/kernel/cpu/amd.c +2 -2
@@ -456,9 +456,9 @@ static void amd_detect_cmp(struct cpuinf/* Low order bits define the core id (index of core in socket) */ c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1 );/* Convert the initial APIC ID into the socket ID */ - c->phys_proc_id = c->topo.initial_apicid >> bits; + c->topo.pkg_id = c->topo.initial_apicid >> bits;/* use socket ID also for last level cache */ -per_cpu (cpu_llc_id, cpu) = c->cpu_die_id = c->phys_proc_id; +per_cpu (cpu_llc_id, cpu) = c->cpu_die_id = c->topo.pkg_id; }u32 amd_get_nodes_per_socket (void )
arch/x86/kernel/cpu/cacheinfo.c +2 -2
@@ -875,10 +875,10 @@ void init_intel_cacheinfo(struct cpuinfo* turns means that the only possibility is SMT (as indicated in * cpuid1). Since cpuid2 doesn't specify shared caches, and we know * that SMT shares all caches, we can unconditionally set cpu_llc_id to -* c->phys_proc_id. +* c->topo.pkg_id. */ if (per_cpu (cpu_llc_id, cpu) ==BAD_APICID ) -per_cpu (cpu_llc_id, cpu) = c->phys_proc_id; +per_cpu (cpu_llc_id, cpu) = c->topo.pkg_id;#endif c->x86_cache_size = l3 ? l3 : (l2 ? l2 : (l1i+l1d));
arch/x86/kernel/cpu/common.c +3 -3
@@ -899,7 +899,7 @@ void detect_ht(struct cpuinfo_x86 *c)return ; index_msb =get_count_order (smp_num_siblings); - c->phys_proc_id = apic->phys_pkg_id (c->topo.initial_apicid, index_msb); + c->topo.pkg_id = apic->phys_pkg_id (c->topo.initial_apicid, index_msb); smp_num_siblings = smp_num_siblings / c->x86_max_cores;
@@ -1729,7 +1729,7 @@ static void generic_identify(struct cpui c->topo.apicid = c->topo.initial_apicid;# endif #endif - c->phys_proc_id = c->topo.initial_apicid; + c->topo.pkg_id = c->topo.initial_apicid; }get_model_name (c);/* Default name */
@@ -1767,7 +1767,7 @@ static void validate_apic_and_package_idpr_err (FW_BUG "CPU%u: APIC id mismatch. Firmware: %x APIC: %x\n" , cpu, apicid, c->topo.initial_apicid); } -BUG_ON (topology_update_package_map (c->phys_proc_id, cpu)); +BUG_ON (topology_update_package_map (c->topo.pkg_id, cpu));BUG_ON (topology_update_die_map (c->cpu_die_id, cpu));#else c->logical_proc_id =0 ;
arch/x86/kernel/cpu/hygon.c +3 -3
@@ -92,7 +92,7 @@ static void hygon_get_topology(struct cp* when running on host. */ if (!boot_cpu_has (X86_FEATURE_HYPERVISOR ) && c->x86_model <=0x3 ) - c->phys_proc_id = c->topo.apicid >>APICID_SOCKET_ID_BIT ; + c->topo.pkg_id = c->topo.apicid >>APICID_SOCKET_ID_BIT ;cacheinfo_hygon_init_llc_id (c, cpu); }else if (cpu_has (c,X86_FEATURE_NODEID_MSR )) {
@@ -122,9 +122,9 @@ static void hygon_detect_cmp(struct cpui/* Low order bits define the core id (index of core in socket) */ c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1 );/* Convert the initial APIC ID into the socket ID */ - c->phys_proc_id = c->topo.initial_apicid >> bits; + c->topo.pkg_id = c->topo.initial_apicid >> bits;/* use socket ID also for last level cache */ -per_cpu (cpu_llc_id, cpu) = c->cpu_die_id = c->phys_proc_id; +per_cpu (cpu_llc_id, cpu) = c->cpu_die_id = c->topo.pkg_id; }static void srat_detect_node (struct cpuinfo_x86 *c)
arch/x86/kernel/cpu/mce/apei.c +1 -1
@@ -105,7 +105,7 @@ int apei_smca_report_x86_error(struct cpfor_each_possible_cpu (cpu) {if (cpu_data (cpu).topo.initial_apicid == lapic_id) { m.extcpu = cpu; - m.socketid =cpu_data (m.extcpu).phys_proc_id; + m.socketid =cpu_data (m.extcpu).topo.pkg_id;break ; } }
arch/x86/kernel/cpu/mce/core.c +1 -1
@@ -123,7 +123,7 @@ void mce_setup(struct mce *m) m->time =__ktime_get_real_seconds (); m->cpuvendor = boot_cpu_data.x86_vendor; m->cpuid =cpuid_eax (1 ); - m->socketid =cpu_data (m->extcpu).phys_proc_id; + m->socketid =cpu_data (m->extcpu).topo.pkg_id; m->apicid =cpu_data (m->extcpu).topo.initial_apicid; m->mcgcap =__rdmsr (MSR_IA32_MCG_CAP ); m->ppin =cpu_data (m->extcpu).ppin;
arch/x86/kernel/cpu/proc.c +1 -1
@@ -18,7 +18,7 @@ static void show_cpuinfo_core(struct seq unsigned int cpu) {#ifdef CONFIG_SMP -seq_printf (m,"physical id\t: %d\n" , c->phys_proc_id); +seq_printf (m,"physical id\t: %d\n" , c->topo.pkg_id);seq_printf (m,"siblings\t: %d\n" ,cpumask_weight (topology_core_cpumask (cpu)));seq_printf (m,"core id\t\t: %d\n" , c->cpu_core_id);
arch/x86/kernel/cpu/topology.c +1 -2
@@ -154,8 +154,7 @@ int detect_extended_topology(struct cpui core_plus_mask_width) & die_select_mask; } - c->phys_proc_id = apic->phys_pkg_id (c->topo.initial_apicid, - pkg_mask_width); + c->topo.pkg_id = apic->phys_pkg_id (c->topo.initial_apicid, pkg_mask_width);/* * Reinit the apicid, now that we have extended initial_apicid. */
arch/x86/kernel/smpboot.c +8 -8
@@ -347,7 +347,7 @@ int topology_phys_to_logical_pkg(unsignefor_each_possible_cpu (cpu) {struct cpuinfo_x86 *c = &cpu_data (cpu); -if (c->initialized && c->phys_proc_id == phys_pkg) +if (c->initialized && c->topo.pkg_id == phys_pkg)return c->logical_proc_id; }return -1 ;
@@ -363,13 +363,13 @@ EXPORT_SYMBOL(topology_phys_to_logical_p*/ static int topology_phys_to_logical_die (unsigned int die_id,unsigned int cur_cpu) { -int cpu, proc_id =cpu_data (cur_cpu).phys_proc_id; +int cpu, proc_id =cpu_data (cur_cpu).topo.pkg_id;for_each_possible_cpu (cpu) {struct cpuinfo_x86 *c = &cpu_data (cpu);if (c->initialized && c->cpu_die_id == die_id && - c->phys_proc_id == proc_id) + c->topo.pkg_id == proc_id)return c->logical_die_id; }return -1 ;
@@ -429,7 +429,7 @@ void __init smp_store_boot_cpu_info(void *c = boot_cpu_data; c->cpu_index = id; -topology_update_package_map (c->phys_proc_id, id); +topology_update_package_map (c->topo.pkg_id, id);topology_update_die_map (c->cpu_die_id, id); c->initialized = true; }
@@ -484,7 +484,7 @@ static bool match_smt(struct cpuinfo_x86if (boot_cpu_has (X86_FEATURE_TOPOEXT )) {int cpu1 = c->cpu_index, cpu2 = o->cpu_index; -if (c->phys_proc_id == o->phys_proc_id && +if (c->topo.pkg_id == o->topo.pkg_id && c->cpu_die_id == o->cpu_die_id &&per_cpu (cpu_llc_id, cpu1) ==per_cpu (cpu_llc_id, cpu2)) {if (c->cpu_core_id == o->cpu_core_id)
@@ -496,7 +496,7 @@ static bool match_smt(struct cpuinfo_x86return topology_sane (c, o,"smt" ); } - }else if (c->phys_proc_id == o->phys_proc_id && + }else if (c->topo.pkg_id == o->topo.pkg_id && c->cpu_die_id == o->cpu_die_id && c->cpu_core_id == o->cpu_core_id) {return topology_sane (c, o,"smt" );
@@ -507,7 +507,7 @@ static bool match_smt(struct cpuinfo_x86static bool match_die (struct cpuinfo_x86 *c,struct cpuinfo_x86 *o) { -if (c->phys_proc_id == o->phys_proc_id && +if (c->topo.pkg_id == o->topo.pkg_id && c->cpu_die_id == o->cpu_die_id)return true;return false;
@@ -535,7 +535,7 @@ static bool match_l2c(struct cpuinfo_x86*/ static bool match_pkg (struct cpuinfo_x86 *c,struct cpuinfo_x86 *o) { -if (c->phys_proc_id == o->phys_proc_id) +if (c->topo.pkg_id == o->topo.pkg_id)return true;return false; }
drivers/scsi/lpfc/lpfc_init.c +1 -5
@@ -12428,9 +12428,6 @@ lpfc_cpu_affinity_check(struct lpfc_hbaint max_core_id, min_core_id;struct lpfc_vector_map_info *cpup;struct lpfc_vector_map_info *new_cpup; -#ifdef CONFIG_X86 -struct cpuinfo_x86 *cpuinfo; -#endif #ifdef CONFIG_SCSI_LPFC_DEBUG_FS struct lpfc_hdwq_stat *c_stat;#endif
@@ -12444,8 +12441,7 @@ lpfc_cpu_affinity_check(struct lpfc_hbafor_each_present_cpu (cpu) { cpup = &phba->sli4_hba.cpu_map[cpu];#ifdef CONFIG_X86 - cpuinfo = &cpu_data (cpu); - cpup->phys_id = cpuinfo->phys_proc_id; + cpup->phys_id =topology_physical_package_id (cpu); cpup->core_id = cpuinfo->cpu_core_id;if (lpfc_find_hyper (phba, cpu, cpup->phys_id, cpup->core_id)) cpup->flag |=LPFC_CPU_MAP_HYPER ;
[tip: x86/core] x86/cpu: Move phys_proc_id into topology info
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 02fb601d27a7abf60d52b21bdf5b100a8d63da3f Gitweb: https://git.kernel.org/tip/02fb601d27a7abf60d52b21bdf5b100a8d63da3f Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:30 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:17 +02:00
x86/cpu: Move phys_proc_id into topology info
Rename it to pkg_id which is the terminology used in the kernel.
No functional change.
--- Documentation/arch/x86/topology.rst | 2 +- arch/x86/include/asm/processor.h | 5 +++-- arch/x86/include/asm/topology.h | 2 +- arch/x86/include/asm/x86_init.h | 2 +- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/cpu/amd.c | 4 ++-- arch/x86/kernel/cpu/cacheinfo.c | 4 ++-- arch/x86/kernel/cpu/common.c | 6 +++--- arch/x86/kernel/cpu/hygon.c | 6 +++--- arch/x86/kernel/cpu/mce/apei.c | 2 +- arch/x86/kernel/cpu/mce/core.c | 2 +- arch/x86/kernel/cpu/proc.c | 2 +- arch/x86/kernel/cpu/topology.c | 3 +-- arch/x86/kernel/smpboot.c | 16 ++++++++-------- drivers/scsi/lpfc/lpfc_init.c | 6 +----- 15 files changed, 30 insertions(+), 34 deletions(-)
Documentation/arch/x86/topology.rst +1 -1
@@ -59,7 +59,7 @@ Package-related topology information in the kernel: The physical ID of the die. This information is retrieved via CPUID. - - cpuinfo_x86.phys_proc_id: + - cpuinfo_x86.topo.pkg_id: The physical ID of the package. This information is retrieved via CPUID and deduced from the APIC IDs of the cores in the package.
arch/x86/include/asm/processor.h +3 -2
@@ -83,6 +83,9 @@ struct cpuinfo_topology {u32 apicid;// The initial APIC ID provided by CPUID u32 initial_apicid; + +// Physical package ID +u32 pkg_id; };struct cpuinfo_x86 {
@@ -134,8 +137,6 @@ struct cpuinfo_x86 {u16 x86_clflush_size;/* number of cores as seen by the OS: */ u16 booted_cores; -/* Physical processor id: */ -u16 phys_proc_id;/* Logical processor id: */ u16 logical_proc_id;/* Core id: */
arch/x86/include/asm/topology.h +1 -1
@@ -106,7 +106,7 @@ extern const struct cpumask *cpu_coregroup_mask(int cpu);extern const struct cpumask *cpu_clustergroup_mask (int cpu);#define topology_logical_package_id (cpu) (cpu_data(cpu).logical_proc_id) -#define topology_physical_package_id (cpu) (cpu_data(cpu).phys_proc_id) +#define topology_physical_package_id (cpu) (cpu_data(cpu).topo.pkg_id)#define topology_logical_die_id (cpu) (cpu_data(cpu).logical_die_id)#define topology_die_id (cpu) (cpu_data(cpu).cpu_die_id)#define topology_core_id (cpu) (cpu_data(cpu).cpu_core_id)
arch/x86/include/asm/x86_init.h +1 -1
@@ -177,7 +177,7 @@ struct x86_init_ops {* struct x86_cpuinit_ops - platform specific cpu hotplug setups * @setup_percpu_clockev: set up the per cpu clock event device * @early_percpu_clock_init: early init of the per cpu clock event device -* @fixup_cpu_id: fixup function for cpuinfo_x86::phys_proc_id +* @fixup_cpu_id: fixup function for cpuinfo_x86::topo.pkg_id * @parallel_bringup: Parallel bringup control */ struct x86_cpuinit_ops {
arch/x86/kernel/apic/apic_numachip.c +1 -1
@@ -169,7 +169,7 @@ static void fixup_cpu_id(struct cpuinfo_x86 *c, int node) nodes = ((val >>3 ) &7 ) +1 ; } - c->phys_proc_id = node / nodes; + c->topo.pkg_id = node / nodes; }static int __init numachip_system_init (void )
arch/x86/kernel/cpu/amd.c +2 -2
@@ -461,9 +461,9 @@ static void amd_detect_cmp(struct cpuinfo_x86 *c)/* Low order bits define the core id (index of core in socket) */ c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1 );/* Convert the initial APIC ID into the socket ID */ - c->phys_proc_id = c->topo.initial_apicid >> bits; + c->topo.pkg_id = c->topo.initial_apicid >> bits;/* use socket ID also for last level cache */ -per_cpu (cpu_llc_id, cpu) = c->cpu_die_id = c->phys_proc_id; +per_cpu (cpu_llc_id, cpu) = c->cpu_die_id = c->topo.pkg_id; }u32 amd_get_nodes_per_socket (void )
arch/x86/kernel/cpu/cacheinfo.c +2 -2
@@ -875,10 +875,10 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c)* turns means that the only possibility is SMT (as indicated in * cpuid1). Since cpuid2 doesn't specify shared caches, and we know * that SMT shares all caches, we can unconditionally set cpu_llc_id to -* c->phys_proc_id. +* c->topo.pkg_id. */ if (per_cpu (cpu_llc_id, cpu) ==BAD_APICID ) -per_cpu (cpu_llc_id, cpu) = c->phys_proc_id; +per_cpu (cpu_llc_id, cpu) = c->topo.pkg_id;#endif c->x86_cache_size = l3 ? l3 : (l2 ? l2 : (l1i+l1d));
arch/x86/kernel/cpu/common.c +3 -3
@@ -914,7 +914,7 @@ void detect_ht(struct cpuinfo_x86 *c)return ; index_msb =get_count_order (smp_num_siblings); - c->phys_proc_id = apic->phys_pkg_id (c->topo.initial_apicid, index_msb); + c->topo.pkg_id = apic->phys_pkg_id (c->topo.initial_apicid, index_msb); smp_num_siblings = smp_num_siblings / c->x86_max_cores;
@@ -1769,7 +1769,7 @@ static void generic_identify(struct cpuinfo_x86 *c) c->topo.apicid = c->topo.initial_apicid;# endif #endif - c->phys_proc_id = c->topo.initial_apicid; + c->topo.pkg_id = c->topo.initial_apicid; }get_model_name (c);/* Default name */
@@ -1807,7 +1807,7 @@ static void validate_apic_and_package_id(struct cpuinfo_x86 *c)pr_err (FW_BUG "CPU%u: APIC id mismatch. Firmware: %x APIC: %x\n" , cpu, apicid, c->topo.initial_apicid); } -BUG_ON (topology_update_package_map (c->phys_proc_id, cpu)); +BUG_ON (topology_update_package_map (c->topo.pkg_id, cpu));BUG_ON (topology_update_die_map (c->cpu_die_id, cpu));#else c->logical_proc_id =0 ;
arch/x86/kernel/cpu/hygon.c +3 -3
@@ -92,7 +92,7 @@ static void hygon_get_topology(struct cpuinfo_x86 *c)* when running on host. */ if (!boot_cpu_has (X86_FEATURE_HYPERVISOR ) && c->x86_model <=0x3 ) - c->phys_proc_id = c->topo.apicid >>APICID_SOCKET_ID_BIT ; + c->topo.pkg_id = c->topo.apicid >>APICID_SOCKET_ID_BIT ;cacheinfo_hygon_init_llc_id (c, cpu); }else if (cpu_has (c,X86_FEATURE_NODEID_MSR )) {
@@ -122,9 +122,9 @@ static void hygon_detect_cmp(struct cpuinfo_x86 *c)/* Low order bits define the core id (index of core in socket) */ c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1 );/* Convert the initial APIC ID into the socket ID */ - c->phys_proc_id = c->topo.initial_apicid >> bits; + c->topo.pkg_id = c->topo.initial_apicid >> bits;/* use socket ID also for last level cache */ -per_cpu (cpu_llc_id, cpu) = c->cpu_die_id = c->phys_proc_id; +per_cpu (cpu_llc_id, cpu) = c->cpu_die_id = c->topo.pkg_id; }static void srat_detect_node (struct cpuinfo_x86 *c)
arch/x86/kernel/cpu/mce/apei.c +1 -1
@@ -105,7 +105,7 @@ int apei_smca_report_x86_error(struct cper_ia_proc_ctx *ctx_info, u64 lapic_id)for_each_possible_cpu (cpu) {if (cpu_data (cpu).topo.initial_apicid == lapic_id) { m.extcpu = cpu; - m.socketid =cpu_data (m.extcpu).phys_proc_id; + m.socketid =cpu_data (m.extcpu).topo.pkg_id;break ; } }
arch/x86/kernel/cpu/mce/core.c +1 -1
@@ -123,7 +123,7 @@ void mce_setup(struct mce *m) m->time =__ktime_get_real_seconds (); m->cpuvendor = boot_cpu_data.x86_vendor; m->cpuid =cpuid_eax (1 ); - m->socketid =cpu_data (m->extcpu).phys_proc_id; + m->socketid =cpu_data (m->extcpu).topo.pkg_id; m->apicid =cpu_data (m->extcpu).topo.initial_apicid; m->mcgcap =__rdmsr (MSR_IA32_MCG_CAP ); m->ppin =cpu_data (m->extcpu).ppin;
arch/x86/kernel/cpu/proc.c +1 -1
@@ -20,7 +20,7 @@ static void show_cpuinfo_core(struct seq_file *m, struct cpuinfo_x86 *c, unsigned int cpu) {#ifdef CONFIG_SMP -seq_printf (m,"physical id\t: %d\n" , c->phys_proc_id); +seq_printf (m,"physical id\t: %d\n" , c->topo.pkg_id);seq_printf (m,"siblings\t: %d\n" ,cpumask_weight (topology_core_cpumask (cpu)));seq_printf (m,"core id\t\t: %d\n" , c->cpu_core_id);
arch/x86/kernel/cpu/topology.c +1 -2
@@ -154,8 +154,7 @@ int detect_extended_topology(struct cpuinfo_x86 *c) core_plus_mask_width) & die_select_mask; } - c->phys_proc_id = apic->phys_pkg_id (c->topo.initial_apicid, - pkg_mask_width); + c->topo.pkg_id = apic->phys_pkg_id (c->topo.initial_apicid, pkg_mask_width);/* * Reinit the apicid, now that we have extended initial_apicid. */
arch/x86/kernel/smpboot.c +8 -8
@@ -339,7 +339,7 @@ int topology_phys_to_logical_pkg(unsigned int phys_pkg)for_each_possible_cpu (cpu) {struct cpuinfo_x86 *c = &cpu_data (cpu); -if (c->initialized && c->phys_proc_id == phys_pkg) +if (c->initialized && c->topo.pkg_id == phys_pkg)return c->logical_proc_id; }return -1 ;
@@ -355,13 +355,13 @@ EXPORT_SYMBOL(topology_phys_to_logical_pkg);*/ static int topology_phys_to_logical_die (unsigned int die_id,unsigned int cur_cpu) { -int cpu, proc_id =cpu_data (cur_cpu).phys_proc_id; +int cpu, proc_id =cpu_data (cur_cpu).topo.pkg_id;for_each_possible_cpu (cpu) {struct cpuinfo_x86 *c = &cpu_data (cpu);if (c->initialized && c->cpu_die_id == die_id && - c->phys_proc_id == proc_id) + c->topo.pkg_id == proc_id)return c->logical_die_id; }return -1 ;
@@ -421,7 +421,7 @@ static void __init smp_store_boot_cpu_info(void) *c = boot_cpu_data; c->cpu_index = id; -topology_update_package_map (c->phys_proc_id, id); +topology_update_package_map (c->topo.pkg_id, id);topology_update_die_map (c->cpu_die_id, id); c->initialized = true; }
@@ -476,7 +476,7 @@ static bool match_smt(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)if (boot_cpu_has (X86_FEATURE_TOPOEXT )) {int cpu1 = c->cpu_index, cpu2 = o->cpu_index; -if (c->phys_proc_id == o->phys_proc_id && +if (c->topo.pkg_id == o->topo.pkg_id && c->cpu_die_id == o->cpu_die_id &&per_cpu (cpu_llc_id, cpu1) ==per_cpu (cpu_llc_id, cpu2)) {if (c->cpu_core_id == o->cpu_core_id)
@@ -488,7 +488,7 @@ static bool match_smt(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)return topology_sane (c, o,"smt" ); } - }else if (c->phys_proc_id == o->phys_proc_id && + }else if (c->topo.pkg_id == o->topo.pkg_id && c->cpu_die_id == o->cpu_die_id && c->cpu_core_id == o->cpu_core_id) {return topology_sane (c, o,"smt" );
@@ -499,7 +499,7 @@ static bool match_smt(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)static bool match_die (struct cpuinfo_x86 *c,struct cpuinfo_x86 *o) { -if (c->phys_proc_id == o->phys_proc_id && +if (c->topo.pkg_id == o->topo.pkg_id && c->cpu_die_id == o->cpu_die_id)return true;return false;
@@ -527,7 +527,7 @@ static bool match_l2c(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)*/ static bool match_pkg (struct cpuinfo_x86 *c,struct cpuinfo_x86 *o) { -if (c->phys_proc_id == o->phys_proc_id) +if (c->topo.pkg_id == o->topo.pkg_id)return true;return false; }
drivers/scsi/lpfc/lpfc_init.c +1 -5
@@ -12442,9 +12442,6 @@ lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)int max_core_id, min_core_id;struct lpfc_vector_map_info *cpup;struct lpfc_vector_map_info *new_cpup; -#ifdef CONFIG_X86 -struct cpuinfo_x86 *cpuinfo; -#endif #ifdef CONFIG_SCSI_LPFC_DEBUG_FS struct lpfc_hdwq_stat *c_stat;#endif
@@ -12458,8 +12455,7 @@ lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)for_each_present_cpu (cpu) { cpup = &phba->sli4_hba.cpu_map[cpu];#ifdef CONFIG_X86 - cpuinfo = &cpu_data (cpu); - cpup->phys_id = cpuinfo->phys_proc_id; + cpup->phys_id =topology_physical_package_id (cpu); cpup->core_id = cpuinfo->cpu_core_id;if (lpfc_find_hyper (phba, cpu, cpup->phys_id, cpup->core_id)) cpup->flag |=LPFC_CPU_MAP_HYPER ;
PATCH v4 6/41 x86/cpu: Move cpu_die_id into topology info
In reply to Thomas GleixnerMove the next member.
No functional change.
--- Documentation/arch/x86/topology.rst | 4 ++-- arch/x86/include/asm/processor.h | 4 +++- arch/x86/include/asm/topology.h | 2 +- arch/x86/kernel/cpu/amd.c | 8 ++++---- arch/x86/kernel/cpu/cacheinfo.c | 2 +- arch/x86/kernel/cpu/common.c | 2 +- arch/x86/kernel/cpu/hygon.c | 8 ++++---- arch/x86/kernel/cpu/topology.c | 2 +- arch/x86/kernel/smpboot.c | 10 +++++----- 9 files changed, 22 insertions(+), 20 deletions(-)
Documentation/arch/x86/topology.rst +2 -2
@@ -55,7 +55,7 @@ AMD nomenclature for package is 'Node'. The number of dies in a package. This information is retrieved via CPUID. - - cpuinfo_x86.cpu_die_id: + - cpuinfo_x86.topo.die_id: The physical ID of the die. This information is retrieved via CPUID.
@@ -65,7 +65,7 @@ AMD nomenclature for package is 'Node'. and deduced from the APIC IDs of the cores in the package. Modern systems use this value for the socket. There may be multiple - packages within a socket. This value may differ from cpu_die_id. + packages within a socket. This value may differ from topo.die_id. - cpuinfo_x86.logical_proc_id:
arch/x86/include/asm/processor.h +3 -1
@@ -85,6 +85,9 @@ struct cpuinfo_topology {// Physical package ID u32 pkg_id; + +// Physical die ID on AMD, Relative on Intel +u32 die_id; };struct cpuinfo_x86 {
@@ -140,7 +143,6 @@ struct cpuinfo_x86 {u16 logical_proc_id;/* Core id: */ u16 cpu_core_id; -u16 cpu_die_id;u16 logical_die_id;/* Index into per_cpu list: */ u16 cpu_index;
arch/x86/include/asm/topology.h +1 -1
@@ -108,7 +108,7 @@ extern const struct cpumask *cpu_cluster#define topology_logical_package_id (cpu) (cpu_data(cpu).logical_proc_id)#define topology_physical_package_id (cpu) (cpu_data(cpu).topo.pkg_id)#define topology_logical_die_id (cpu) (cpu_data(cpu).logical_die_id) -#define topology_die_id (cpu) (cpu_data(cpu).cpu_die_id) +#define topology_die_id (cpu) (cpu_data(cpu).topo.die_id)#define topology_core_id (cpu) (cpu_data(cpu).cpu_core_id)#define topology_ppin (cpu) (cpu_data(cpu).ppin)
arch/x86/kernel/cpu/amd.c +4 -4
@@ -405,7 +405,7 @@ static void amd_get_topology(struct cpuicpuid (0x8000001e , &eax, &ebx, &ecx, &edx); - c->cpu_die_id = ecx &0xff ; + c->topo.die_id = ecx &0xff ;if (c->x86 ==0x15 ) c->cu_id = ebx &0xff ;
@@ -431,9 +431,9 @@ static void amd_get_topology(struct cpuiu64 value;rdmsrl (MSR_FAM10H_NODE_ID , value); - c->cpu_die_id = value &7 ; + c->topo.die_id = value &7 ; -per_cpu (cpu_llc_id, cpu) = c->cpu_die_id; +per_cpu (cpu_llc_id, cpu) = c->topo.die_id; }else return ;
@@ -458,7 +458,7 @@ static void amd_detect_cmp(struct cpuinf/* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits;/* use socket ID also for last level cache */ -per_cpu (cpu_llc_id, cpu) = c->cpu_die_id = c->topo.pkg_id; +per_cpu (cpu_llc_id, cpu) = c->topo.die_id = c->topo.pkg_id; }u32 amd_get_nodes_per_socket (void )
arch/x86/kernel/cpu/cacheinfo.c +1 -1
@@ -672,7 +672,7 @@ void cacheinfo_amd_init_llc_id(struct cpif (c->x86 <0x17 ) {/* LLC is at the node level. */ -per_cpu (cpu_llc_id, cpu) = c->cpu_die_id; +per_cpu (cpu_llc_id, cpu) = c->topo.die_id; }else if (c->x86 ==0x17 && c->x86_model <=0x1F ) {/* * LLC is at the core complex level.
arch/x86/kernel/cpu/common.c +1 -1
@@ -1768,7 +1768,7 @@ static void validate_apic_and_package_id cpu, apicid, c->topo.initial_apicid); }BUG_ON (topology_update_package_map (c->topo.pkg_id, cpu)); -BUG_ON (topology_update_die_map (c->cpu_die_id, cpu)); +BUG_ON (topology_update_die_map (c->topo.die_id, cpu));#else c->logical_proc_id =0 ;#endif
arch/x86/kernel/cpu/hygon.c +4 -4
@@ -72,7 +72,7 @@ static void hygon_get_topology(struct cpcpuid (0x8000001e , &eax, &ebx, &ecx, &edx); - c->cpu_die_id = ecx &0xff ; + c->topo.die_id = ecx &0xff ; c->cpu_core_id = ebx &0xff ;
@@ -95,9 +95,9 @@ static void hygon_get_topology(struct cpu64 value;rdmsrl (MSR_FAM10H_NODE_ID , value); - c->cpu_die_id = value &7 ; + c->topo.die_id = value &7 ; -per_cpu (cpu_llc_id, cpu) = c->cpu_die_id; +per_cpu (cpu_llc_id, cpu) = c->topo.die_id; }else return ;
@@ -120,7 +120,7 @@ static void hygon_detect_cmp(struct cpui/* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits;/* use socket ID also for last level cache */ -per_cpu (cpu_llc_id, cpu) = c->cpu_die_id = c->topo.pkg_id; +per_cpu (cpu_llc_id, cpu) = c->topo.die_id = c->topo.pkg_id; }static void srat_detect_node (struct cpuinfo_x86 *c)
arch/x86/kernel/cpu/topology.c +1 -1
@@ -150,7 +150,7 @@ int detect_extended_topology(struct cpui ht_mask_width) & core_select_mask;if (die_level_present) { - c->cpu_die_id = apic->phys_pkg_id (c->topo.initial_apicid, + c->topo.die_id = apic->phys_pkg_id (c->topo.initial_apicid, core_plus_mask_width) & die_select_mask; }
arch/x86/kernel/smpboot.c +5 -5
@@ -368,7 +368,7 @@ static int topology_phys_to_logical_die(for_each_possible_cpu (cpu) {struct cpuinfo_x86 *c = &cpu_data (cpu); -if (c->initialized && c->cpu_die_id == die_id && +if (c->initialized && c->topo.die_id == die_id && c->topo.pkg_id == proc_id)return c->logical_die_id; }
@@ -430,7 +430,7 @@ void __init smp_store_boot_cpu_info(void *c = boot_cpu_data; c->cpu_index = id;topology_update_package_map (c->topo.pkg_id, id); -topology_update_die_map (c->cpu_die_id, id); +topology_update_die_map (c->topo.die_id, id); c->initialized = true; }
@@ -485,7 +485,7 @@ static bool match_smt(struct cpuinfo_x86int cpu1 = c->cpu_index, cpu2 = o->cpu_index;if (c->topo.pkg_id == o->topo.pkg_id && - c->cpu_die_id == o->cpu_die_id && + c->topo.die_id == o->topo.die_id &&per_cpu (cpu_llc_id, cpu1) ==per_cpu (cpu_llc_id, cpu2)) {if (c->cpu_core_id == o->cpu_core_id)return topology_sane (c, o,"smt" );
@@ -497,7 +497,7 @@ static bool match_smt(struct cpuinfo_x86 } }else if (c->topo.pkg_id == o->topo.pkg_id && - c->cpu_die_id == o->cpu_die_id && + c->topo.die_id == o->topo.die_id && c->cpu_core_id == o->cpu_core_id) {return topology_sane (c, o,"smt" ); }
@@ -508,7 +508,7 @@ static bool match_smt(struct cpuinfo_x86static bool match_die (struct cpuinfo_x86 *c,struct cpuinfo_x86 *o) {if (c->topo.pkg_id == o->topo.pkg_id && - c->cpu_die_id == o->cpu_die_id) + c->topo.die_id == o->topo.die_id)return true;return false; }
[tip: x86/core] x86/cpu: Move cpu_die_id into topology info
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 8a169ed40fcf6e0e7a2d900c7ab4408649488f40 Gitweb: https://git.kernel.org/tip/8a169ed40fcf6e0e7a2d900c7ab4408649488f40 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:31 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:17 +02:00
x86/cpu: Move cpu_die_id into topology info
Move the next member.
No functional change.
--- Documentation/arch/x86/topology.rst | 4 ++-- arch/x86/include/asm/processor.h | 4 +++- arch/x86/include/asm/topology.h | 2 +- arch/x86/kernel/cpu/amd.c | 8 ++++---- arch/x86/kernel/cpu/cacheinfo.c | 2 +- arch/x86/kernel/cpu/common.c | 2 +- arch/x86/kernel/cpu/hygon.c | 8 ++++---- arch/x86/kernel/cpu/topology.c | 2 +- arch/x86/kernel/smpboot.c | 10 +++++----- 9 files changed, 22 insertions(+), 20 deletions(-)
Documentation/arch/x86/topology.rst +2 -2
@@ -55,7 +55,7 @@ Package-related topology information in the kernel: The number of dies in a package. This information is retrieved via CPUID. - - cpuinfo_x86.cpu_die_id: + - cpuinfo_x86.topo.die_id: The physical ID of the die. This information is retrieved via CPUID.
@@ -65,7 +65,7 @@ Package-related topology information in the kernel: and deduced from the APIC IDs of the cores in the package. Modern systems use this value for the socket. There may be multiple - packages within a socket. This value may differ from cpu_die_id. + packages within a socket. This value may differ from topo.die_id. - cpuinfo_x86.logical_proc_id:
arch/x86/include/asm/processor.h +3 -1
@@ -86,6 +86,9 @@ struct cpuinfo_topology {// Physical package ID u32 pkg_id; + +// Physical die ID on AMD, Relative on Intel +u32 die_id; };struct cpuinfo_x86 {
@@ -141,7 +144,6 @@ struct cpuinfo_x86 {u16 logical_proc_id;/* Core id: */ u16 cpu_core_id; -u16 cpu_die_id;u16 logical_die_id;/* Index into per_cpu list: */ u16 cpu_index;
arch/x86/include/asm/topology.h +1 -1
@@ -108,7 +108,7 @@ extern const struct cpumask *cpu_clustergroup_mask(int cpu);#define topology_logical_package_id (cpu) (cpu_data(cpu).logical_proc_id)#define topology_physical_package_id (cpu) (cpu_data(cpu).topo.pkg_id)#define topology_logical_die_id (cpu) (cpu_data(cpu).logical_die_id) -#define topology_die_id (cpu) (cpu_data(cpu).cpu_die_id) +#define topology_die_id (cpu) (cpu_data(cpu).topo.die_id)#define topology_core_id (cpu) (cpu_data(cpu).cpu_core_id)#define topology_ppin (cpu) (cpu_data(cpu).ppin)
arch/x86/kernel/cpu/amd.c +4 -4
@@ -410,7 +410,7 @@ static void amd_get_topology(struct cpuinfo_x86 *c)cpuid (0x8000001e , &eax, &ebx, &ecx, &edx); - c->cpu_die_id = ecx &0xff ; + c->topo.die_id = ecx &0xff ;if (c->x86 ==0x15 ) c->cu_id = ebx &0xff ;
@@ -436,9 +436,9 @@ static void amd_get_topology(struct cpuinfo_x86 *c)u64 value;rdmsrl (MSR_FAM10H_NODE_ID , value); - c->cpu_die_id = value &7 ; + c->topo.die_id = value &7 ; -per_cpu (cpu_llc_id, cpu) = c->cpu_die_id; +per_cpu (cpu_llc_id, cpu) = c->topo.die_id; }else return ;
@@ -463,7 +463,7 @@ static void amd_detect_cmp(struct cpuinfo_x86 *c)/* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits;/* use socket ID also for last level cache */ -per_cpu (cpu_llc_id, cpu) = c->cpu_die_id = c->topo.pkg_id; +per_cpu (cpu_llc_id, cpu) = c->topo.die_id = c->topo.pkg_id; }u32 amd_get_nodes_per_socket (void )
arch/x86/kernel/cpu/cacheinfo.c +1 -1
@@ -672,7 +672,7 @@ void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu)if (c->x86 <0x17 ) {/* LLC is at the node level. */ -per_cpu (cpu_llc_id, cpu) = c->cpu_die_id; +per_cpu (cpu_llc_id, cpu) = c->topo.die_id; }else if (c->x86 ==0x17 && c->x86_model <=0x1F ) {/* * LLC is at the core complex level.
arch/x86/kernel/cpu/common.c +1 -1
@@ -1808,7 +1808,7 @@ static void validate_apic_and_package_id(struct cpuinfo_x86 *c) cpu, apicid, c->topo.initial_apicid); }BUG_ON (topology_update_package_map (c->topo.pkg_id, cpu)); -BUG_ON (topology_update_die_map (c->cpu_die_id, cpu)); +BUG_ON (topology_update_die_map (c->topo.die_id, cpu));#else c->logical_proc_id =0 ;#endif
arch/x86/kernel/cpu/hygon.c +4 -4
@@ -72,7 +72,7 @@ static void hygon_get_topology(struct cpuinfo_x86 *c)cpuid (0x8000001e , &eax, &ebx, &ecx, &edx); - c->cpu_die_id = ecx &0xff ; + c->topo.die_id = ecx &0xff ; c->cpu_core_id = ebx &0xff ;
@@ -99,9 +99,9 @@ static void hygon_get_topology(struct cpuinfo_x86 *c)u64 value;rdmsrl (MSR_FAM10H_NODE_ID , value); - c->cpu_die_id = value &7 ; + c->topo.die_id = value &7 ; -per_cpu (cpu_llc_id, cpu) = c->cpu_die_id; +per_cpu (cpu_llc_id, cpu) = c->topo.die_id; }else return ;
@@ -124,7 +124,7 @@ static void hygon_detect_cmp(struct cpuinfo_x86 *c)/* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits;/* use socket ID also for last level cache */ -per_cpu (cpu_llc_id, cpu) = c->cpu_die_id = c->topo.pkg_id; +per_cpu (cpu_llc_id, cpu) = c->topo.die_id = c->topo.pkg_id; }static void srat_detect_node (struct cpuinfo_x86 *c)
arch/x86/kernel/cpu/topology.c +1 -1
@@ -150,7 +150,7 @@ int detect_extended_topology(struct cpuinfo_x86 *c) ht_mask_width) & core_select_mask;if (die_level_present) { - c->cpu_die_id = apic->phys_pkg_id (c->topo.initial_apicid, + c->topo.die_id = apic->phys_pkg_id (c->topo.initial_apicid, core_plus_mask_width) & die_select_mask; }
arch/x86/kernel/smpboot.c +5 -5
@@ -360,7 +360,7 @@ static int topology_phys_to_logical_die(unsigned int die_id, unsigned int cur_cpfor_each_possible_cpu (cpu) {struct cpuinfo_x86 *c = &cpu_data (cpu); -if (c->initialized && c->cpu_die_id == die_id && +if (c->initialized && c->topo.die_id == die_id && c->topo.pkg_id == proc_id)return c->logical_die_id; }
@@ -422,7 +422,7 @@ static void __init smp_store_boot_cpu_info(void) *c = boot_cpu_data; c->cpu_index = id;topology_update_package_map (c->topo.pkg_id, id); -topology_update_die_map (c->cpu_die_id, id); +topology_update_die_map (c->topo.die_id, id); c->initialized = true; }
@@ -477,7 +477,7 @@ static bool match_smt(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)int cpu1 = c->cpu_index, cpu2 = o->cpu_index;if (c->topo.pkg_id == o->topo.pkg_id && - c->cpu_die_id == o->cpu_die_id && + c->topo.die_id == o->topo.die_id &&per_cpu (cpu_llc_id, cpu1) ==per_cpu (cpu_llc_id, cpu2)) {if (c->cpu_core_id == o->cpu_core_id)return topology_sane (c, o,"smt" );
@@ -489,7 +489,7 @@ static bool match_smt(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o) } }else if (c->topo.pkg_id == o->topo.pkg_id && - c->cpu_die_id == o->cpu_die_id && + c->topo.die_id == o->topo.die_id && c->cpu_core_id == o->cpu_core_id) {return topology_sane (c, o,"smt" ); }
@@ -500,7 +500,7 @@ static bool match_smt(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)static bool match_die (struct cpuinfo_x86 *c,struct cpuinfo_x86 *o) {if (c->topo.pkg_id == o->topo.pkg_id && - c->cpu_die_id == o->cpu_die_id) + c->topo.die_id == o->topo.die_id)return true;return false; }
PATCH v4 7/41 scsi: lpfc: Use topology_core_id()
In reply to Thomas GleixnerUse the provided topology helper.
--- drivers/scsi/lpfc/lpfc_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/lpfc/lpfc_init.c +1 -1
@@ -12442,7 +12442,7 @@ lpfc_cpu_affinity_check(struct lpfc_hba cpup = &phba->sli4_hba.cpu_map[cpu];#ifdef CONFIG_X86 cpup->phys_id =topology_physical_package_id (cpu); - cpup->core_id = cpuinfo->cpu_core_id; + cpup->core_id =topology_core_id (cpu);if (lpfc_find_hyper (phba, cpu, cpup->phys_id, cpup->core_id)) cpup->flag |=LPFC_CPU_MAP_HYPER ;#else
[tip: x86/core] scsi: lpfc: Use topology_core_id()
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 09253672b5d9f911b96651400a02ad6666b7ae2c Gitweb: https://git.kernel.org/tip/09253672b5d9f911b96651400a02ad6666b7ae2c Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:32 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:17 +02:00
scsi: lpfc: Use topology_core_id()
Use the provided topology helper.
--- drivers/scsi/lpfc/lpfc_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/lpfc/lpfc_init.c +1 -1
@@ -12456,7 +12456,7 @@ lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors) cpup = &phba->sli4_hba.cpu_map[cpu];#ifdef CONFIG_X86 cpup->phys_id =topology_physical_package_id (cpu); - cpup->core_id = cpuinfo->cpu_core_id; + cpup->core_id =topology_core_id (cpu);if (lpfc_find_hyper (phba, cpu, cpup->phys_id, cpup->core_id)) cpup->flag |=LPFC_CPU_MAP_HYPER ;#else
PATCH v4 8/41 hwmon: (fam15h_power) Use topology_core_id()
In reply to Thomas GleixnerUse the provided topology helper function instead of fiddling in cpu_data.
--- drivers/hwmon/fam15h_power.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/hwmon/fam15h_power.c +3 -4
@@ -17,6 +17,7 @@#include <linux/cpumask.h> #include <linux/time.h> #include <linux/sched.h> +#include <linux/topology.h> #include <asm/processor.h> #include <asm/msr.h>
@@ -134,15 +135,13 @@ static DEVICE_ATTR_RO(power1_crit);static void do_read_registers_on_cu (void *_data) {struct fam15h_power_data *data = _data; -int cpu, cu; - - cpu =smp_processor_id (); +int cu;/* * With the new x86 topology modelling, cpu core id actually * is compute unit id. */ - cu =cpu_data (cpu).cpu_core_id; + cu =topology_core_id (smp_processor_id ());rdmsrl_safe (MSR_F15H_CU_PWR_ACCUMULATOR , &data->cu_acc_power[cu]);rdmsrl_safe (MSR_F15H_PTSC , &data->cpu_sw_pwr_ptsc[cu]);
[tip: x86/core] hwmon: (fam15h_power) Use topology_core_id()
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 94f0b3978ea87c180b7e989e54faedd0a097f7ea Gitweb: https://git.kernel.org/tip/94f0b3978ea87c180b7e989e54faedd0a097f7ea Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:33 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:17 +02:00
hwmon: (fam15h_power) Use topology_core_id()
Use the provided topology helper function instead of fiddling in cpu_data.
--- drivers/hwmon/fam15h_power.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/hwmon/fam15h_power.c +3 -4
@@ -17,6 +17,7 @@#include <linux/cpumask.h> #include <linux/time.h> #include <linux/sched.h> +#include <linux/topology.h> #include <asm/processor.h> #include <asm/msr.h>
@@ -134,15 +135,13 @@ static DEVICE_ATTR_RO(power1_crit);static void do_read_registers_on_cu (void *_data) {struct fam15h_power_data *data = _data; -int cpu, cu; - - cpu =smp_processor_id (); +int cu;/* * With the new x86 topology modelling, cpu core id actually * is compute unit id. */ - cu =cpu_data (cpu).cpu_core_id; + cu =topology_core_id (smp_processor_id ());rdmsrl_safe (MSR_F15H_CU_PWR_ACCUMULATOR , &data->cu_acc_power[cu]);rdmsrl_safe (MSR_F15H_PTSC , &data->cpu_sw_pwr_ptsc[cu]);
PATCH v4 9/41 x86/cpu: Move cpu_core_id into topology info
In reply to Thomas GleixnerRename it to core_id and stick it to the other ID fields.
No functional change.
--- arch/x86/include/asm/processor.h | 4 +++- arch/x86/include/asm/topology.h | 2 +- arch/x86/kernel/amd_nb.c | 4 ++-- arch/x86/kernel/cpu/amd.c | 8 ++++---- arch/x86/kernel/cpu/common.c | 4 ++-- arch/x86/kernel/cpu/hygon.c | 4 ++-- arch/x86/kernel/cpu/proc.c | 2 +- arch/x86/kernel/cpu/topology.c | 2 +- arch/x86/kernel/smpboot.c | 6 +++--- 9 files changed, 19 insertions(+), 17 deletions(-)
arch/x86/include/asm/processor.h +3 -1
@@ -88,6 +88,9 @@ struct cpuinfo_topology {// Physical die ID on AMD, Relative on Intel u32 die_id; + +// Core ID relative to the package +u32 core_id; };struct cpuinfo_x86 {
@@ -142,7 +145,6 @@ struct cpuinfo_x86 {/* Logical processor id: */ u16 logical_proc_id;/* Core id: */ -u16 cpu_core_id;u16 logical_die_id;/* Index into per_cpu list: */ u16 cpu_index;
arch/x86/include/asm/topology.h +1 -1
@@ -109,7 +109,7 @@ extern const struct cpumask *cpu_cluster#define topology_physical_package_id (cpu) (cpu_data(cpu).topo.pkg_id)#define topology_logical_die_id (cpu) (cpu_data(cpu).logical_die_id)#define topology_die_id (cpu) (cpu_data(cpu).topo.die_id) -#define topology_core_id (cpu) (cpu_data(cpu).cpu_core_id) +#define topology_core_id (cpu) (cpu_data(cpu).topo.core_id)#define topology_ppin (cpu) (cpu_data(cpu).ppin)extern unsigned int __max_die_per_package;
arch/x86/kernel/amd_nb.c +2 -2
@@ -378,7 +378,7 @@ int amd_get_subcaches(int cpu)pci_read_config_dword (link,0x1d4 , &mask); -return (mask >> (4 *cpu_data (cpu).cpu_core_id)) &0xf ; +return (mask >> (4 *cpu_data (cpu).topo.core_id)) &0xf ; }int amd_set_subcaches (int cpu,unsigned long mask)
@@ -404,7 +404,7 @@ int amd_set_subcaches(int cpu, unsignedpci_write_config_dword (nb->misc,0x1b8 , reg & ~0x180000 ); } - cuid =cpu_data (cpu).cpu_core_id; + cuid =cpu_data (cpu).topo.core_id; mask <<=4 * cuid; mask |= (0xf ^ (1 << cuid)) <<26 ;
arch/x86/kernel/cpu/amd.c +4 -4
@@ -373,7 +373,7 @@ static int nearby_node(int apicid)#endif /* -* Fix up cpu_core_id for pre-F17h systems to be in the +* Fix up topo::core_id for pre-F17h systems to be in the * [0 .. cores_per_node - 1] range. Not really needed but * kept so as not to break existing setups. */
@@ -385,7 +385,7 @@ static void legacy_fixup_core_id(structreturn ; cus_per_node = c->x86_max_cores / nodes_per_socket; - c->cpu_core_id %= cus_per_node; + c->topo.core_id %= cus_per_node; }/*
@@ -411,7 +411,7 @@ static void amd_get_topology(struct cpui c->cu_id = ebx &0xff ;if (c->x86 >=0x17 ) { - c->cpu_core_id = ebx &0xff ; + c->topo.core_id = ebx &0xff ;if (smp_num_siblings >1 ) c->x86_max_cores /= smp_num_siblings;
@@ -454,7 +454,7 @@ static void amd_detect_cmp(struct cpuinf bits = c->x86_coreid_bits;/* Low order bits define the core id (index of core in socket) */ - c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1 ); + c->topo.core_id = c->topo.initial_apicid & ((1 << bits)-1 );/* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits;/* use socket ID also for last level cache */
arch/x86/kernel/cpu/common.c +2 -2
@@ -907,8 +907,8 @@ void detect_ht(struct cpuinfo_x86 *c) core_bits =get_count_order (c->x86_max_cores); - c->cpu_core_id = apic->phys_pkg_id (c->topo.initial_apicid, index_msb) & - ((1 << core_bits) -1 ); + c->topo.core_id = apic->phys_pkg_id (c->topo.initial_apicid, index_msb) & + ((1 << core_bits) -1 );#endif }
arch/x86/kernel/cpu/hygon.c +2 -2
@@ -74,7 +74,7 @@ static void hygon_get_topology(struct cp c->topo.die_id = ecx &0xff ; - c->cpu_core_id = ebx &0xff ; + c->topo.core_id = ebx &0xff ;if (smp_num_siblings >1 ) c->x86_max_cores /= smp_num_siblings;
@@ -116,7 +116,7 @@ static void hygon_detect_cmp(struct cpui bits = c->x86_coreid_bits;/* Low order bits define the core id (index of core in socket) */ - c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1 ); + c->topo.core_id = c->topo.initial_apicid & ((1 << bits)-1 );/* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits;/* use socket ID also for last level cache */
arch/x86/kernel/cpu/proc.c +1 -1
@@ -21,7 +21,7 @@ static void show_cpuinfo_core(struct seqseq_printf (m,"physical id\t: %d\n" , c->topo.pkg_id);seq_printf (m,"siblings\t: %d\n" ,cpumask_weight (topology_core_cpumask (cpu))); -seq_printf (m,"core id\t\t: %d\n" , c->cpu_core_id); +seq_printf (m,"core id\t\t: %d\n" , c->topo.core_id);seq_printf (m,"cpu cores\t: %d\n" , c->booted_cores);seq_printf (m,"apicid\t\t: %d\n" , c->topo.apicid);seq_printf (m,"initial apicid\t: %d\n" , c->topo.initial_apicid);
arch/x86/kernel/cpu/topology.c +1 -1
@@ -146,7 +146,7 @@ int detect_extended_topology(struct cpui die_select_mask = (~(-1 << die_plus_mask_width)) >> core_plus_mask_width; - c->cpu_core_id = apic->phys_pkg_id (c->topo.initial_apicid, + c->topo.core_id = apic->phys_pkg_id (c->topo.initial_apicid, ht_mask_width) & core_select_mask;if (die_level_present) {
arch/x86/kernel/smpboot.c +3 -3
@@ -487,7 +487,7 @@ static bool match_smt(struct cpuinfo_x86if (c->topo.pkg_id == o->topo.pkg_id && c->topo.die_id == o->topo.die_id &&per_cpu (cpu_llc_id, cpu1) ==per_cpu (cpu_llc_id, cpu2)) { -if (c->cpu_core_id == o->cpu_core_id) +if (c->topo.core_id == o->topo.core_id)return topology_sane (c, o,"smt" ); if ((c->cu_id != 0xff) &&
@@ -498,7 +498,7 @@ static bool match_smt(struct cpuinfo_x86 }else if (c->topo.pkg_id == o->topo.pkg_id && c->topo.die_id == o->topo.die_id && - c->cpu_core_id == o->cpu_core_id) { + c->topo.core_id == o->topo.core_id) {return topology_sane (c, o,"smt" ); }
@@ -1439,7 +1439,7 @@ static void remove_siblinginfo(int cpu)cpumask_clear (topology_sibling_cpumask (cpu));cpumask_clear (topology_core_cpumask (cpu));cpumask_clear (topology_die_cpumask (cpu)); - c->cpu_core_id =0 ; + c->topo.core_id =0 ; c->booted_cores =0 ;cpumask_clear_cpu (cpu, cpu_sibling_setup_mask);recompute_smt_state ();
[tip: x86/core] x86/cpu: Move cpu_core_id into topology info
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: e95256335d45cc965cd12c423535002974313340 Gitweb: https://git.kernel.org/tip/e95256335d45cc965cd12c423535002974313340 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:34 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:17 +02:00
x86/cpu: Move cpu_core_id into topology info
Rename it to core_id and stick it to the other ID fields.
No functional change.
--- arch/x86/include/asm/processor.h | 4 +++- arch/x86/include/asm/topology.h | 2 +- arch/x86/kernel/amd_nb.c | 4 ++-- arch/x86/kernel/cpu/amd.c | 8 ++++---- arch/x86/kernel/cpu/common.c | 4 ++-- arch/x86/kernel/cpu/hygon.c | 4 ++-- arch/x86/kernel/cpu/proc.c | 2 +- arch/x86/kernel/cpu/topology.c | 2 +- arch/x86/kernel/smpboot.c | 6 +++--- 9 files changed, 19 insertions(+), 17 deletions(-)
arch/x86/include/asm/processor.h +3 -1
@@ -89,6 +89,9 @@ struct cpuinfo_topology {// Physical die ID on AMD, Relative on Intel u32 die_id; + +// Core ID relative to the package +u32 core_id; };struct cpuinfo_x86 {
@@ -143,7 +146,6 @@ struct cpuinfo_x86 {/* Logical processor id: */ u16 logical_proc_id;/* Core id: */ -u16 cpu_core_id;u16 logical_die_id;/* Index into per_cpu list: */ u16 cpu_index;
arch/x86/include/asm/topology.h +1 -1
@@ -109,7 +109,7 @@ extern const struct cpumask *cpu_clustergroup_mask(int cpu);#define topology_physical_package_id (cpu) (cpu_data(cpu).topo.pkg_id)#define topology_logical_die_id (cpu) (cpu_data(cpu).logical_die_id)#define topology_die_id (cpu) (cpu_data(cpu).topo.die_id) -#define topology_core_id (cpu) (cpu_data(cpu).cpu_core_id) +#define topology_core_id (cpu) (cpu_data(cpu).topo.core_id)#define topology_ppin (cpu) (cpu_data(cpu).ppin)extern unsigned int __max_die_per_package;
arch/x86/kernel/amd_nb.c +2 -2
@@ -386,7 +386,7 @@ int amd_get_subcaches(int cpu)pci_read_config_dword (link,0x1d4 , &mask); -return (mask >> (4 *cpu_data (cpu).cpu_core_id)) &0xf ; +return (mask >> (4 *cpu_data (cpu).topo.core_id)) &0xf ; }int amd_set_subcaches (int cpu,unsigned long mask)
@@ -412,7 +412,7 @@ int amd_set_subcaches(int cpu, unsigned long mask)pci_write_config_dword (nb->misc,0x1b8 , reg & ~0x180000 ); } - cuid =cpu_data (cpu).cpu_core_id; + cuid =cpu_data (cpu).topo.core_id; mask <<=4 * cuid; mask |= (0xf ^ (1 << cuid)) <<26 ;
arch/x86/kernel/cpu/amd.c +4 -4
@@ -378,7 +378,7 @@ static int nearby_node(int apicid)#endif /* -* Fix up cpu_core_id for pre-F17h systems to be in the +* Fix up topo::core_id for pre-F17h systems to be in the * [0 .. cores_per_node - 1] range. Not really needed but * kept so as not to break existing setups. */
@@ -390,7 +390,7 @@ static void legacy_fixup_core_id(struct cpuinfo_x86 *c)return ; cus_per_node = c->x86_max_cores / nodes_per_socket; - c->cpu_core_id %= cus_per_node; + c->topo.core_id %= cus_per_node; }/*
@@ -416,7 +416,7 @@ static void amd_get_topology(struct cpuinfo_x86 *c) c->cu_id = ebx &0xff ;if (c->x86 >=0x17 ) { - c->cpu_core_id = ebx &0xff ; + c->topo.core_id = ebx &0xff ;if (smp_num_siblings >1 ) c->x86_max_cores /= smp_num_siblings;
@@ -459,7 +459,7 @@ static void amd_detect_cmp(struct cpuinfo_x86 *c) bits = c->x86_coreid_bits;/* Low order bits define the core id (index of core in socket) */ - c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1 ); + c->topo.core_id = c->topo.initial_apicid & ((1 << bits)-1 );/* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits;/* use socket ID also for last level cache */
arch/x86/kernel/cpu/common.c +2 -2
@@ -922,8 +922,8 @@ void detect_ht(struct cpuinfo_x86 *c) core_bits =get_count_order (c->x86_max_cores); - c->cpu_core_id = apic->phys_pkg_id (c->topo.initial_apicid, index_msb) & - ((1 << core_bits) -1 ); + c->topo.core_id = apic->phys_pkg_id (c->topo.initial_apicid, index_msb) & + ((1 << core_bits) -1 );#endif }
arch/x86/kernel/cpu/hygon.c +2 -2
@@ -74,7 +74,7 @@ static void hygon_get_topology(struct cpuinfo_x86 *c) c->topo.die_id = ecx &0xff ; - c->cpu_core_id = ebx &0xff ; + c->topo.core_id = ebx &0xff ;if (smp_num_siblings >1 ) c->x86_max_cores /= smp_num_siblings;
@@ -120,7 +120,7 @@ static void hygon_detect_cmp(struct cpuinfo_x86 *c) bits = c->x86_coreid_bits;/* Low order bits define the core id (index of core in socket) */ - c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1 ); + c->topo.core_id = c->topo.initial_apicid & ((1 << bits)-1 );/* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits;/* use socket ID also for last level cache */
arch/x86/kernel/cpu/proc.c +1 -1
@@ -23,7 +23,7 @@ static void show_cpuinfo_core(struct seq_file *m, struct cpuinfo_x86 *c,seq_printf (m,"physical id\t: %d\n" , c->topo.pkg_id);seq_printf (m,"siblings\t: %d\n" ,cpumask_weight (topology_core_cpumask (cpu))); -seq_printf (m,"core id\t\t: %d\n" , c->cpu_core_id); +seq_printf (m,"core id\t\t: %d\n" , c->topo.core_id);seq_printf (m,"cpu cores\t: %d\n" , c->booted_cores);seq_printf (m,"apicid\t\t: %d\n" , c->topo.apicid);seq_printf (m,"initial apicid\t: %d\n" , c->topo.initial_apicid);
arch/x86/kernel/cpu/topology.c +1 -1
@@ -146,7 +146,7 @@ int detect_extended_topology(struct cpuinfo_x86 *c) die_select_mask = (~(-1 << die_plus_mask_width)) >> core_plus_mask_width; - c->cpu_core_id = apic->phys_pkg_id (c->topo.initial_apicid, + c->topo.core_id = apic->phys_pkg_id (c->topo.initial_apicid, ht_mask_width) & core_select_mask;if (die_level_present) {
arch/x86/kernel/smpboot.c +3 -3
@@ -479,7 +479,7 @@ static bool match_smt(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)if (c->topo.pkg_id == o->topo.pkg_id && c->topo.die_id == o->topo.die_id &&per_cpu (cpu_llc_id, cpu1) ==per_cpu (cpu_llc_id, cpu2)) { -if (c->cpu_core_id == o->cpu_core_id) +if (c->topo.core_id == o->topo.core_id)return topology_sane (c, o,"smt" ); if ((c->cu_id != 0xff) &&
@@ -490,7 +490,7 @@ static bool match_smt(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o) }else if (c->topo.pkg_id == o->topo.pkg_id && c->topo.die_id == o->topo.die_id && - c->cpu_core_id == o->cpu_core_id) { + c->topo.core_id == o->topo.core_id) {return topology_sane (c, o,"smt" ); }
@@ -1426,7 +1426,7 @@ static void remove_siblinginfo(int cpu)cpumask_clear (topology_sibling_cpumask (cpu));cpumask_clear (topology_core_cpumask (cpu));cpumask_clear (topology_die_cpumask (cpu)); - c->cpu_core_id =0 ; + c->topo.core_id =0 ; c->booted_cores =0 ;cpumask_clear_cpu (cpu, cpu_sibling_setup_mask);recompute_smt_state ();
PATCH v4 10/41 x86/cpu: Move cu_id into topology info
In reply to Thomas GleixnerNo functional change.
--- arch/x86/include/asm/processor.h | 4 +++- arch/x86/kernel/cpu/amd.c | 2 +- arch/x86/kernel/cpu/common.c | 2 +- arch/x86/kernel/smpboot.c | 6 +++--- 4 files changed, 8 insertions(+), 6 deletions(-)
arch/x86/include/asm/processor.h +3 -1
@@ -89,6 +89,9 @@ struct cpuinfo_topology {// Physical die ID on AMD, Relative on Intel u32 die_id; +// Compute unit ID - AMD specific +u32 cu_id; +// Core ID relative to the package u32 core_id; };
@@ -109,7 +112,6 @@ struct cpuinfo_x86 {__u8 x86_phys_bits;/* CPUID returned core id bits: */ __u8 x86_coreid_bits; -__u8 cu_id;/* Max extended CPUID function supported: */ __u32 extended_cpuid_level;/* Maximum supported CPUID level, -1=no CPUID: */
arch/x86/kernel/cpu/amd.c +1 -1
@@ -408,7 +408,7 @@ static void amd_get_topology(struct cpui c->topo.die_id = ecx &0xff ;if (c->x86 ==0x15 ) - c->cu_id = ebx &0xff ; + c->topo.cu_id = ebx &0xff ;if (c->x86 >=0x17 ) { c->topo.core_id = ebx &0xff ;
arch/x86/kernel/cpu/common.c +1 -1
@@ -1789,7 +1789,7 @@ static void identify_cpu(struct cpuinfo_ c->x86_model_id[0 ] ='\0' ;/* Unset */ c->x86_max_cores =1 ; c->x86_coreid_bits =0 ; - c->cu_id =0xff ; + c->topo.cu_id =0xff ;#ifdef CONFIG_X86_64 c->x86_clflush_size =64 ; c->x86_phys_bits =36 ;
arch/x86/kernel/smpboot.c +3 -3
@@ -490,9 +490,9 @@ static bool match_smt(struct cpuinfo_x86if (c->topo.core_id == o->topo.core_id)return topology_sane (c, o,"smt" ); -if ((c->cu_id !=0xff ) && - (o->cu_id !=0xff ) && - (c->cu_id == o->cu_id)) +if ((c->topo.cu_id !=0xff ) && + (o->topo.cu_id !=0xff ) && + (c->topo.cu_id == o->topo.cu_id))return topology_sane (c, o,"smt" ); }
[tip: x86/core] x86/cpu: Move cu_id into topology info
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: e3c0c5d52ad34ab2c97f93ca4a0c2e9ca2fdc06b Gitweb: https://git.kernel.org/tip/e3c0c5d52ad34ab2c97f93ca4a0c2e9ca2fdc06b Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:35 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:18 +02:00
x86/cpu: Move cu_id into topology info
No functional change.
--- arch/x86/include/asm/processor.h | 4 +++- arch/x86/kernel/cpu/amd.c | 2 +- arch/x86/kernel/cpu/common.c | 2 +- arch/x86/kernel/smpboot.c | 6 +++--- 4 files changed, 8 insertions(+), 6 deletions(-)
arch/x86/include/asm/processor.h +3 -1
@@ -90,6 +90,9 @@ struct cpuinfo_topology {// Physical die ID on AMD, Relative on Intel u32 die_id; +// Compute unit ID - AMD specific +u32 cu_id; +// Core ID relative to the package u32 core_id; };
@@ -110,7 +113,6 @@ struct cpuinfo_x86 {__u8 x86_phys_bits;/* CPUID returned core id bits: */ __u8 x86_coreid_bits; -__u8 cu_id;/* Max extended CPUID function supported: */ __u32 extended_cpuid_level;/* Maximum supported CPUID level, -1=no CPUID: */
arch/x86/kernel/cpu/amd.c +1 -1
@@ -413,7 +413,7 @@ static void amd_get_topology(struct cpuinfo_x86 *c) c->topo.die_id = ecx &0xff ;if (c->x86 ==0x15 ) - c->cu_id = ebx &0xff ; + c->topo.cu_id = ebx &0xff ;if (c->x86 >=0x17 ) { c->topo.core_id = ebx &0xff ;
arch/x86/kernel/cpu/common.c +1 -1
@@ -1829,7 +1829,7 @@ static void identify_cpu(struct cpuinfo_x86 *c) c->x86_model_id[0 ] ='\0' ;/* Unset */ c->x86_max_cores =1 ; c->x86_coreid_bits =0 ; - c->cu_id =0xff ; + c->topo.cu_id =0xff ;#ifdef CONFIG_X86_64 c->x86_clflush_size =64 ; c->x86_phys_bits =36 ;
arch/x86/kernel/smpboot.c +3 -3
@@ -482,9 +482,9 @@ static bool match_smt(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)if (c->topo.core_id == o->topo.core_id)return topology_sane (c, o,"smt" ); -if ((c->cu_id !=0xff ) && - (o->cu_id !=0xff ) && - (c->cu_id == o->cu_id)) +if ((c->topo.cu_id !=0xff ) && + (o->topo.cu_id !=0xff ) && + (c->topo.cu_id == o->topo.cu_id))return topology_sane (c, o,"smt" ); }
PATCH v4 11/41 x86/cpu: Remove pointless evaluation of x86_coreid_bits
In reply to Thomas Gleixnercpuinfo_x86::x86_coreid_bits is only used by the AMD numa topology code. No point in evaluating it on non AMD systems.
No functional change.
--- arch/x86/kernel/cpu/intel.c | 13 ------------- arch/x86/kernel/cpu/zhaoxin.c | 14 -------------- 2 files changed, 27 deletions(-)
arch/x86/kernel/cpu/intel.c +0 -13
@@ -488,19 +488,6 @@ static void early_init_intel(struct cpuisetup_clear_cpu_cap (X86_FEATURE_PGE ); } -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 ); - } -check_memory_type_self_snoop_errata (c);/*
arch/x86/kernel/cpu/zhaoxin.c +0 -14
@@ -65,20 +65,6 @@ static void early_init_zhaoxin(struct cpset_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 ); - } - }static void init_zhaoxin (struct cpuinfo_x86 *c)
[tip: x86/core] x86/cpu: Remove pointless evaluation of x86_coreid_bits
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 594957d723a0674ca15bfefb755b3403624b8239 Gitweb: https://git.kernel.org/tip/594957d723a0674ca15bfefb755b3403624b8239 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:36 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:18 +02:00
x86/cpu: Remove pointless evaluation of x86_coreid_bits
cpuinfo_x86::x86_coreid_bits is only used by the AMD numa topology code. No point in evaluating it on non AMD systems.
No functional change.
--- arch/x86/kernel/cpu/intel.c | 13 ------------- arch/x86/kernel/cpu/zhaoxin.c | 14 -------------- 2 files changed, 27 deletions(-)
arch/x86/kernel/cpu/intel.c +0 -13
@@ -314,19 +314,6 @@ static void early_init_intel(struct cpuinfo_x86 *c)setup_clear_cpu_cap (X86_FEATURE_PGE ); } -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 ); - } -check_memory_type_self_snoop_errata (c);/*
arch/x86/kernel/cpu/zhaoxin.c +0 -14
@@ -65,20 +65,6 @@ static void early_init_zhaoxin(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 ); - } - }static void init_zhaoxin (struct cpuinfo_x86 *c)
PATCH v4 12/41 x86/cpu: Move logical package and die IDs into topology info
In reply to Thomas GleixnerYet another topology related data pair. Rename logical_proc_id to logical_pkg_id so it fits the common naming conventions.
No functional change.
--- Documentation/arch/x86/topology.rst | 2 +- arch/x86/events/intel/uncore.c | 2 +- arch/x86/include/asm/processor.h | 8 ++++---- arch/x86/include/asm/topology.h | 4 ++-- arch/x86/kernel/cpu/common.c | 2 +- arch/x86/kernel/smpboot.c | 8 ++++---- 6 files changed, 13 insertions(+), 13 deletions(-)
Documentation/arch/x86/topology.rst +1 -1
@@ -67,7 +67,7 @@ AMD nomenclature for package is 'Node'. Modern systems use this value for the socket. There may be multiple packages within a socket. This value may differ from topo.die_id. - - cpuinfo_x86.logical_proc_id: + - cpuinfo_x86.topo.logical_pkg_id: The logical ID of the package. As we do not trust BIOSes to enumerate the packages in a consistent way, we introduced the concept of logical package
arch/x86/events/intel/uncore.c +1 -1
@@ -74,7 +74,7 @@ int uncore_device_to_die(struct pci_devstruct cpuinfo_x86 *c = &cpu_data (cpu);if (c->initialized &&cpu_to_node (cpu) == node) -return c->logical_die_id; +return c->topo.logical_die_id; }return -1 ;
arch/x86/include/asm/processor.h +4 -4
@@ -94,6 +94,10 @@ struct cpuinfo_topology {// Core ID relative to the package u32 core_id; + +// Logical ID mappings +u32 logical_pkg_id; +u32 logical_die_id; };struct cpuinfo_x86 {
@@ -144,10 +148,6 @@ struct cpuinfo_x86 {u16 x86_clflush_size;/* number of cores as seen by the OS: */ u16 booted_cores; -/* Logical processor id: */ -u16 logical_proc_id; -/* Core id: */ -u16 logical_die_id;/* Index into per_cpu list: */ u16 cpu_index;/* Is SMT active on this core? */
arch/x86/include/asm/topology.h +2 -2
@@ -105,9 +105,9 @@ static inline void setup_node_to_cpumaskextern const struct cpumask *cpu_coregroup_mask (int cpu);extern const struct cpumask *cpu_clustergroup_mask (int cpu); -#define topology_logical_package_id (cpu) (cpu_data(cpu).logical_proc_id) +#define topology_logical_package_id (cpu) (cpu_data(cpu).topo.logical_pkg_id)#define topology_physical_package_id (cpu) (cpu_data(cpu).topo.pkg_id) -#define topology_logical_die_id (cpu) (cpu_data(cpu).logical_die_id) +#define topology_logical_die_id (cpu) (cpu_data(cpu).topo.logical_die_id)#define topology_die_id (cpu) (cpu_data(cpu).topo.die_id)#define topology_core_id (cpu) (cpu_data(cpu).topo.core_id)#define topology_ppin (cpu) (cpu_data(cpu).ppin)
arch/x86/kernel/cpu/common.c +1 -1
@@ -1770,7 +1770,7 @@ static void validate_apic_and_package_idBUG_ON (topology_update_package_map (c->topo.pkg_id, cpu));BUG_ON (topology_update_die_map (c->topo.die_id, cpu));#else - c->logical_proc_id =0 ; + c->topo.logical_pkg_id =0 ;#endif }
arch/x86/kernel/smpboot.c +4 -4
@@ -348,7 +348,7 @@ int topology_phys_to_logical_pkg(unsignestruct cpuinfo_x86 *c = &cpu_data (cpu);if (c->initialized && c->topo.pkg_id == phys_pkg) -return c->logical_proc_id; +return c->topo.logical_pkg_id; }return -1 ; }
@@ -370,7 +370,7 @@ static int topology_phys_to_logical_die(if (c->initialized && c->topo.die_id == die_id && c->topo.pkg_id == proc_id) -return c->logical_die_id; +return c->topo.logical_die_id; }return -1 ; }
@@ -395,7 +395,7 @@ int topology_update_package_map(unsigned cpu, pkg, new); } found: -cpu_data (cpu).logical_proc_id = new; +cpu_data (cpu).topo.logical_pkg_id = new;return 0 ; }/**
@@ -418,7 +418,7 @@ int topology_update_die_map(unsigned int cpu, die, new); } found: -cpu_data (cpu).logical_die_id = new; +cpu_data (cpu).topo.logical_die_id = new;return 0 ; }
[tip: x86/core] x86/cpu: Move logical package and die IDs into topology info
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 22dc9631625352426cd665f4e3f8fe0d793b2bf5 Gitweb: https://git.kernel.org/tip/22dc9631625352426cd665f4e3f8fe0d793b2bf5 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:37 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:18 +02:00
x86/cpu: Move logical package and die IDs into topology info
Yet another topology related data pair. Rename logical_proc_id to logical_pkg_id so it fits the common naming conventions.
No functional change.
--- Documentation/arch/x86/topology.rst | 2 +- arch/x86/events/intel/uncore.c | 2 +- arch/x86/include/asm/processor.h | 8 ++++---- arch/x86/include/asm/topology.h | 4 ++-- arch/x86/kernel/cpu/common.c | 2 +- arch/x86/kernel/smpboot.c | 8 ++++---- 6 files changed, 13 insertions(+), 13 deletions(-)
Documentation/arch/x86/topology.rst +1 -1
@@ -67,7 +67,7 @@ Package-related topology information in the kernel: Modern systems use this value for the socket. There may be multiple packages within a socket. This value may differ from topo.die_id. - - cpuinfo_x86.logical_proc_id: + - cpuinfo_x86.topo.logical_pkg_id: The logical ID of the package. As we do not trust BIOSes to enumerate the packages in a consistent way, we introduced the concept of logical package
arch/x86/events/intel/uncore.c +1 -1
@@ -74,7 +74,7 @@ int uncore_device_to_die(struct pci_dev *dev)struct cpuinfo_x86 *c = &cpu_data (cpu);if (c->initialized &&cpu_to_node (cpu) == node) -return c->logical_die_id; +return c->topo.logical_die_id; }return -1 ;
arch/x86/include/asm/processor.h +4 -4
@@ -95,6 +95,10 @@ struct cpuinfo_topology {// Core ID relative to the package u32 core_id; + +// Logical ID mappings +u32 logical_pkg_id; +u32 logical_die_id; };struct cpuinfo_x86 {
@@ -145,10 +149,6 @@ struct cpuinfo_x86 {u16 x86_clflush_size;/* number of cores as seen by the OS: */ u16 booted_cores; -/* Logical processor id: */ -u16 logical_proc_id; -/* Core id: */ -u16 logical_die_id;/* Index into per_cpu list: */ u16 cpu_index;/* Is SMT active on this core? */
arch/x86/include/asm/topology.h +2 -2
@@ -105,9 +105,9 @@ static inline void setup_node_to_cpumask_map(void) { }extern const struct cpumask *cpu_coregroup_mask (int cpu);extern const struct cpumask *cpu_clustergroup_mask (int cpu); -#define topology_logical_package_id (cpu) (cpu_data(cpu).logical_proc_id) +#define topology_logical_package_id (cpu) (cpu_data(cpu).topo.logical_pkg_id)#define topology_physical_package_id (cpu) (cpu_data(cpu).topo.pkg_id) -#define topology_logical_die_id (cpu) (cpu_data(cpu).logical_die_id) +#define topology_logical_die_id (cpu) (cpu_data(cpu).topo.logical_die_id)#define topology_die_id (cpu) (cpu_data(cpu).topo.die_id)#define topology_core_id (cpu) (cpu_data(cpu).topo.core_id)#define topology_ppin (cpu) (cpu_data(cpu).ppin)
arch/x86/kernel/cpu/common.c +1 -1
@@ -1810,7 +1810,7 @@ static void validate_apic_and_package_id(struct cpuinfo_x86 *c)BUG_ON (topology_update_package_map (c->topo.pkg_id, cpu));BUG_ON (topology_update_die_map (c->topo.die_id, cpu));#else - c->logical_proc_id =0 ; + c->topo.logical_pkg_id =0 ;#endif }
arch/x86/kernel/smpboot.c +4 -4
@@ -340,7 +340,7 @@ int topology_phys_to_logical_pkg(unsigned int phys_pkg)struct cpuinfo_x86 *c = &cpu_data (cpu);if (c->initialized && c->topo.pkg_id == phys_pkg) -return c->logical_proc_id; +return c->topo.logical_pkg_id; }return -1 ; }
@@ -362,7 +362,7 @@ static int topology_phys_to_logical_die(unsigned int die_id, unsigned int cur_cpif (c->initialized && c->topo.die_id == die_id && c->topo.pkg_id == proc_id) -return c->logical_die_id; +return c->topo.logical_die_id; }return -1 ; }
@@ -387,7 +387,7 @@ int topology_update_package_map(unsigned int pkg, unsigned int cpu) cpu, pkg, new); } found: -cpu_data (cpu).logical_proc_id = new; +cpu_data (cpu).topo.logical_pkg_id = new;return 0 ; }/**
@@ -410,7 +410,7 @@ int topology_update_die_map(unsigned int die, unsigned int cpu) cpu, die, new); } found: -cpu_data (cpu).logical_die_id = new; +cpu_data (cpu).topo.logical_die_id = new;return 0 ; }
PATCH v4 13/41 x86/cpu: Move cpu_l[l2]c_id into topology info
In reply to Thomas GleixnerThe topology IDs which identify the LLC and L2 domains clearly belong to the per CPU topology information.
Move them into cpuinfo_x86::cpuinfo_topo and get rid of the extra per CPU data and the related exports.
This also paves the way to do proper topology evaluation during early boot because it removes the only per CPU dependency for that.
No functional change.
--- Documentation/arch/x86/topology.rst | 4 +--- arch/x86/events/amd/uncore.c | 2 +- arch/x86/include/asm/cacheinfo.h | 3 --- arch/x86/include/asm/processor.h | 14 +++++++++++++- arch/x86/include/asm/smp.h | 2 -- arch/x86/include/asm/topology.h | 2 +- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/cpu/amd.c | 12 ++++-------- arch/x86/kernel/cpu/cacheinfo.c | 33 ++++++++++++--------------------- arch/x86/kernel/cpu/common.c | 14 ++------------ arch/x86/kernel/cpu/cpu.h | 3 +++ arch/x86/kernel/cpu/hygon.c | 14 +++++--------- arch/x86/kernel/smpboot.c | 10 +++++----- 13 files changed, 48 insertions(+), 67 deletions(-)
Documentation/arch/x86/topology.rst +1 -3
@@ -79,9 +79,7 @@ AMD nomenclature for package is 'Node'. The maximum possible number of packages in the system. Helpful for per package facilities to preallocate per package information. - - cpu_llc_id: - - A per-CPU variable containing: + - cpuinfo_x86.topo.llc_id: - On Intel, the first APIC ID of the list of CPUs sharing the Last Level Cache
arch/x86/events/amd/uncore.c +1 -1
@@ -537,7 +537,7 @@ static int amd_uncore_cpu_starting(unsigif (amd_uncore_llc) { uncore = *per_cpu_ptr (amd_uncore_llc, cpu); - uncore->id =get_llc_id (cpu); + uncore->id =per_cpu_llc_id (cpu); uncore =amd_uncore_find_online_sibling (uncore, amd_uncore_llc); *per_cpu_ptr (amd_uncore_llc, cpu) = uncore;
arch/x86/include/asm/cacheinfo.h +0 -3
@@ -7,9 +7,6 @@ extern unsigned int memory_caching_contr#define CACHE_MTRR 0x01#define CACHE_PAT 0x02 -void cacheinfo_amd_init_llc_id (struct cpuinfo_x86 *c,int cpu); -void cacheinfo_hygon_init_llc_id (struct cpuinfo_x86 *c,int cpu); -void cache_disable (void );void cache_enable (void );void set_cache_aps_delayed_init (bool val);
arch/x86/include/asm/processor.h +13 -1
@@ -98,6 +98,10 @@ struct cpuinfo_topology {// Logical ID mappings u32 logical_pkg_id;u32 logical_die_id; + +// Cache level topology IDs +u32 llc_id; +u32 l2c_id; };struct cpuinfo_x86 {
@@ -687,7 +691,15 @@ extern int set_tsc_mode(unsigned int valDECLARE_PER_CPU (u64, msr_misc_features_shadow); -extern u16 get_llc_id (unsigned int cpu); +static inline u16 per_cpu_llc_id (unsigned int cpu) +{ +return per_cpu (cpu_info.topo.llc_id, cpu); +} + +static inline u16 per_cpu_l2c_id (unsigned int cpu) +{ +return per_cpu (cpu_info.topo.l2c_id, cpu); +}#ifdef CONFIG_CPU_SUP_AMD extern u32 amd_get_nodes_per_socket (void );
arch/x86/include/asm/smp.h +0 -2
@@ -17,8 +17,6 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_/* cpus sharing the last level cache: */ DECLARE_PER_CPU_READ_MOSTLY (cpumask_var_t, cpu_llc_shared_map);DECLARE_PER_CPU_READ_MOSTLY (cpumask_var_t, cpu_l2c_shared_map); -DECLARE_PER_CPU_READ_MOSTLY (u16, cpu_llc_id); -DECLARE_PER_CPU_READ_MOSTLY (u16, cpu_l2c_id);DECLARE_EARLY_PER_CPU_READ_MOSTLY (u16, x86_cpu_to_apicid);DECLARE_EARLY_PER_CPU_READ_MOSTLY (u32, x86_cpu_to_acpiid);
arch/x86/include/asm/topology.h +1 -1
@@ -115,7 +115,7 @@ extern const struct cpumask *cpu_clusterextern unsigned int __max_die_per_package;#ifdef CONFIG_SMP -#define topology_cluster_id (cpu) (per_cpu(cpu_l2c_id, cpu)) +#define topology_cluster_id (cpu) (cpu_data(cpu).topo.l2c_id)#define topology_die_cpumask (cpu) (per_cpu(cpu_die_map, cpu))#define topology_cluster_cpumask (cpu) (cpu_clustergroup_mask(cpu))#define topology_core_cpumask (cpu) (per_cpu(cpu_core_map, cpu))
arch/x86/kernel/apic/apic_numachip.c +1 -1
@@ -161,7 +161,7 @@ static void fixup_cpu_id(struct cpuinfo_u64 val;u32 nodes =1 ; -this_cpu_write (cpu_llc_id, node); + c->topo.llc_id = node;/* Account for nodes per socket in multi-core-module processors */ if (boot_cpu_has (X86_FEATURE_NODEID_MSR )) {
arch/x86/kernel/cpu/amd.c +4 -8
@@ -396,8 +396,6 @@ static void legacy_fixup_core_id(struct*/ static void amd_get_topology (struct cpuinfo_x86 *c) { -int cpu =smp_processor_id (); -/* get information required for multi-node processors */ if (boot_cpu_has (X86_FEATURE_TOPOEXT )) {int err;
@@ -425,15 +423,14 @@ static void amd_get_topology(struct cpuiif (!err) c->x86_coreid_bits =get_count_order (c->x86_max_cores); -cacheinfo_amd_init_llc_id (c, cpu); +cacheinfo_amd_init_llc_id (c); }else if (cpu_has (c,X86_FEATURE_NODEID_MSR )) {u64 value;rdmsrl (MSR_FAM10H_NODE_ID , value); c->topo.die_id = value &7 ; - -per_cpu (cpu_llc_id, cpu) = c->topo.die_id; + c->topo.llc_id = c->topo.die_id; }else return ;
@@ -450,7 +447,6 @@ static void amd_get_topology(struct cpuistatic void amd_detect_cmp (struct cpuinfo_x86 *c) {unsigned bits; -int cpu =smp_processor_id (); bits = c->x86_coreid_bits;/* Low order bits define the core id (index of core in socket) */
@@ -458,7 +454,7 @@ static void amd_detect_cmp(struct cpuinf/* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits;/* use socket ID also for last level cache */ -per_cpu (cpu_llc_id, cpu) = c->topo.die_id = c->topo.pkg_id; + c->topo.llc_id = c->topo.die_id = c->topo.pkg_id; }u32 amd_get_nodes_per_socket (void )
@@ -476,7 +472,7 @@ static void srat_detect_node(struct cpui node =numa_cpu_node (cpu);if (node ==NUMA_NO_NODE ) - node =get_llc_id (cpu); + node =per_cpu_llc_id (cpu);/* * On multi-fabric platform (e.g. Numascale NumaChip) a
arch/x86/kernel/cpu/cacheinfo.c +12 -21
@@ -661,7 +661,7 @@ static int find_num_cache_leaves(structreturn i; } -void cacheinfo_amd_init_llc_id (struct cpuinfo_x86 *c,int cpu) +void cacheinfo_amd_init_llc_id (struct cpuinfo_x86 *c) {/* * We may have multiple LLCs if L3 caches exist, so check if we
@@ -672,13 +672,13 @@ void cacheinfo_amd_init_llc_id(struct cpif (c->x86 <0x17 ) {/* LLC is at the node level. */ -per_cpu (cpu_llc_id, cpu) = c->topo.die_id; + c->topo.llc_id = c->topo.die_id; }else if (c->x86 ==0x17 && c->x86_model <=0x1F ) {/* * LLC is at the core complex level. * Core complex ID is ApicId[3] for these processors. */ -per_cpu (cpu_llc_id, cpu) = c->topo.apicid >>3 ; + c->topo.llc_id = c->topo.apicid >>3 ; }else {/* * LLC ID is calculated from the number of threads sharing the
@@ -694,12 +694,12 @@ void cacheinfo_amd_init_llc_id(struct cpif (num_sharing_cache) {int bits =get_count_order (num_sharing_cache); -per_cpu (cpu_llc_id, cpu) = c->topo.apicid >> bits; + c->topo.llc_id = c->topo.apicid >> bits; } } } -void cacheinfo_hygon_init_llc_id (struct cpuinfo_x86 *c,int cpu) +void cacheinfo_hygon_init_llc_id (struct cpuinfo_x86 *c) {/* * We may have multiple LLCs if L3 caches exist, so check if we
@@ -712,7 +712,7 @@ void cacheinfo_hygon_init_llc_id(struct* LLC is at the core complex level. * Core complex ID is ApicId[3] for these processors. */ -per_cpu (cpu_llc_id, cpu) = c->topo.apicid >>3 ; + c->topo.llc_id = c->topo.apicid >>3 ; }void init_amd_cacheinfo (struct cpuinfo_x86 *c)
@@ -740,9 +740,6 @@ void init_intel_cacheinfo(struct cpuinfounsigned int new_l1d =0 , new_l1i =0 ;/* Cache sizes from cpuid(4) */ unsigned int new_l2 =0 , new_l3 =0 , i;/* Cache sizes from cpuid(4) */ unsigned int l2_id =0 , l3_id =0 , num_threads_sharing, index_msb; -#ifdef CONFIG_SMP -unsigned int cpu = c->cpu_index; -#endif if (c->cpuid_level >3 ) {static int is_initialized;
@@ -856,30 +853,24 @@ void init_intel_cacheinfo(struct cpuinfoif (new_l2) { l2 = new_l2; -#ifdef CONFIG_SMP -per_cpu (cpu_llc_id, cpu) = l2_id; -per_cpu (cpu_l2c_id, cpu) = l2_id; -#endif + c->topo.llc_id = l2_id; + c->topo.l2c_id = l2_id; }if (new_l3) { l3 = new_l3; -#ifdef CONFIG_SMP -per_cpu (cpu_llc_id, cpu) = l3_id; -#endif + c->topo.llc_id = l3_id; } -#ifdef CONFIG_SMP /* -* If cpu_llc_id is not yet set, this means cpuid_level < 4 which in +* If llc_id is not yet set, this means cpuid_level < 4 which in * turns means that the only possibility is SMT (as indicated in * cpuid1). Since cpuid2 doesn't specify shared caches, and we know * that SMT shares all caches, we can unconditionally set cpu_llc_id to * c->topo.pkg_id. */ -if (per_cpu (cpu_llc_id, cpu) ==BAD_APICID ) -per_cpu (cpu_llc_id, cpu) = c->topo.pkg_id; -#endif +if (c->topo.llc_id ==BAD_APICID ) + c->topo.llc_id = c->topo.pkg_id; c->x86_cache_size = l3 ? l3 : (l2 ? l2 : (l1i+l1d));
arch/x86/kernel/cpu/common.c +2 -12
@@ -75,18 +75,6 @@ u32 elf_hwcap2 __read_mostly;int smp_num_siblings =1 ;EXPORT_SYMBOL (smp_num_siblings); -/* Last level cache ID of each logical CPU */ -DEFINE_PER_CPU_READ_MOSTLY (u16, cpu_llc_id) =BAD_APICID ; - -u16 get_llc_id (unsigned int cpu) -{ -return per_cpu (cpu_llc_id, cpu); -} -EXPORT_SYMBOL_GPL (get_llc_id); - -/* L2 cache ID of each logical CPU */ -DEFINE_PER_CPU_READ_MOSTLY (u16, cpu_l2c_id) =BAD_APICID ; - static struct ppin_info { int feature; int msr_ppin_ctl;
@@ -1790,6 +1778,8 @@ static void identify_cpu(struct cpuinfo_ c->x86_max_cores =1 ; c->x86_coreid_bits =0 ; c->topo.cu_id =0xff ; + c->topo.llc_id =BAD_APICID ; + c->topo.l2c_id =BAD_APICID ;#ifdef CONFIG_X86_64 c->x86_clflush_size =64 ; c->x86_phys_bits =36 ;
arch/x86/kernel/cpu/cpu.h +3 -0
@@ -78,6 +78,9 @@ extern int detect_ht_early(struct cpuinfextern void detect_ht (struct cpuinfo_x86 *c);extern void check_null_seg_clears_base (struct cpuinfo_x86 *c); +void cacheinfo_amd_init_llc_id (struct cpuinfo_x86 *c); +void cacheinfo_hygon_init_llc_id (struct cpuinfo_x86 *c); +unsigned int aperfmperf_get_khz (int cpu);void cpu_select_mitigations (void );
arch/x86/kernel/cpu/hygon.c +5 -9
@@ -63,8 +63,6 @@ static void hygon_get_topology_early(str*/ static void hygon_get_topology (struct cpuinfo_x86 *c) { -int cpu =smp_processor_id (); -/* get information required for multi-node processors */ if (boot_cpu_has (X86_FEATURE_TOPOEXT )) {int err;
@@ -94,14 +92,13 @@ static void hygon_get_topology(struct cpif (!boot_cpu_has (X86_FEATURE_HYPERVISOR ) && c->x86_model <=0x3 ) c->topo.pkg_id = c->topo.apicid >>APICID_SOCKET_ID_BIT ; -cacheinfo_hygon_init_llc_id (c, cpu); +cacheinfo_hygon_init_llc_id (c); }else if (cpu_has (c,X86_FEATURE_NODEID_MSR )) {u64 value;rdmsrl (MSR_FAM10H_NODE_ID , value); c->topo.die_id = value &7 ; - -per_cpu (cpu_llc_id, cpu) = c->topo.die_id; + c->topo.llc_id = c->topo.die_id; }else return ;
@@ -116,15 +113,14 @@ static void hygon_get_topology(struct cpstatic void hygon_detect_cmp (struct cpuinfo_x86 *c) {unsigned int bits; -int cpu =smp_processor_id (); bits = c->x86_coreid_bits;/* Low order bits define the core id (index of core in socket) */ c->topo.core_id = c->topo.initial_apicid & ((1 << bits)-1 );/* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits; -/* use socket ID also for last level cache */ -per_cpu (cpu_llc_id, cpu) = c->topo.die_id = c->topo.pkg_id; +/* Use package ID also for last level cache */ + c->topo.llc_id = c->topo.die_id = c->topo.pkg_id; }static void srat_detect_node (struct cpuinfo_x86 *c)
@@ -136,7 +132,7 @@ static void srat_detect_node(struct cpui node =numa_cpu_node (cpu);if (node ==NUMA_NO_NODE ) - node =per_cpu (cpu_llc_id, cpu); + node = c->topo.llc_id;/* * On multi-fabric platform (e.g. Numascale NumaChip) a
arch/x86/kernel/smpboot.c +5 -5
@@ -486,7 +486,7 @@ static bool match_smt(struct cpuinfo_x86if (c->topo.pkg_id == o->topo.pkg_id && c->topo.die_id == o->topo.die_id && -per_cpu (cpu_llc_id, cpu1) ==per_cpu (cpu_llc_id, cpu2)) { +per_cpu_llc_id (cpu1) ==per_cpu_llc_id (cpu2)) {if (c->topo.core_id == o->topo.core_id)return topology_sane (c, o,"smt" );
@@ -518,11 +518,11 @@ static bool match_l2c(struct cpuinfo_x86int cpu1 = c->cpu_index, cpu2 = o->cpu_index;/* If the arch didn't set up l2c_id, fall back to SMT */ -if (per_cpu (cpu_l2c_id, cpu1) ==BAD_APICID ) +if (per_cpu_l2c_id (cpu1) ==BAD_APICID )return match_smt (c, o);/* Do not match if L2 cache id does not match: */ -if (per_cpu (cpu_l2c_id, cpu1) !=per_cpu (cpu_l2c_id, cpu2)) +if (per_cpu_l2c_id (cpu1) !=per_cpu_l2c_id (cpu2))return false;return topology_sane (c, o,"l2c" );
@@ -568,11 +568,11 @@ static bool match_llc(struct cpuinfo_x86bool intel_snc = id && id->driver_data;/* Do not match if we do not have a valid APICID for cpu: */ -if (per_cpu (cpu_llc_id, cpu1) ==BAD_APICID ) +if (per_cpu_llc_id (cpu1) ==BAD_APICID )return false;/* Do not match if LLC id does not match: */ -if (per_cpu (cpu_llc_id, cpu1) !=per_cpu (cpu_llc_id, cpu2)) +if (per_cpu_llc_id (cpu1) !=per_cpu_llc_id (cpu2))return false;/*
[tip: x86/core] x86/cpu: Move cpu_l[l2]c_id into topology info
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 6e29032340b60f7aa7475c8234b17273e4424007 Gitweb: https://git.kernel.org/tip/6e29032340b60f7aa7475c8234b17273e4424007 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:38 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:18 +02:00
x86/cpu: Move cpu_l[l2]c_id into topology info
The topology IDs which identify the LLC and L2 domains clearly belong to the per CPU topology information.
Move them into cpuinfo_x86::cpuinfo_topo and get rid of the extra per CPU data and the related exports.
This also paves the way to do proper topology evaluation during early boot because it removes the only per CPU dependency for that.
No functional change.
--- Documentation/arch/x86/topology.rst | 4 +--- arch/x86/events/amd/uncore.c | 2 +- arch/x86/include/asm/cacheinfo.h | 3 +-- arch/x86/include/asm/processor.h | 14 ++++++++++- arch/x86/include/asm/smp.h | 2 +-- arch/x86/include/asm/topology.h | 2 +- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/cpu/amd.c | 12 +++------- arch/x86/kernel/cpu/cacheinfo.c | 33 +++++++++------------------ arch/x86/kernel/cpu/common.c | 14 +---------- arch/x86/kernel/cpu/cpu.h | 3 ++- arch/x86/kernel/cpu/hygon.c | 14 +++-------- arch/x86/kernel/smpboot.c | 10 ++++---- 13 files changed, 48 insertions(+), 67 deletions(-)
Documentation/arch/x86/topology.rst +1 -3
@@ -79,9 +79,7 @@ Package-related topology information in the kernel: The maximum possible number of packages in the system. Helpful for per package facilities to preallocate per package information. - - cpu_llc_id: - - A per-CPU variable containing: + - cpuinfo_x86.topo.llc_id: - On Intel, the first APIC ID of the list of CPUs sharing the Last Level Cache
arch/x86/events/amd/uncore.c +1 -1
@@ -537,7 +537,7 @@ static int amd_uncore_cpu_starting(unsigned int cpu)if (amd_uncore_llc) { uncore = *per_cpu_ptr (amd_uncore_llc, cpu); - uncore->id =get_llc_id (cpu); + uncore->id =per_cpu_llc_id (cpu); uncore =amd_uncore_find_online_sibling (uncore, amd_uncore_llc); *per_cpu_ptr (amd_uncore_llc, cpu) = uncore;
arch/x86/include/asm/cacheinfo.h +0 -3
@@ -7,9 +7,6 @@ extern unsigned int memory_caching_control;#define CACHE_MTRR 0x01#define CACHE_PAT 0x02 -void cacheinfo_amd_init_llc_id (struct cpuinfo_x86 *c,int cpu); -void cacheinfo_hygon_init_llc_id (struct cpuinfo_x86 *c,int cpu); -void cache_disable (void );void cache_enable (void );void set_cache_aps_delayed_init (bool val);
arch/x86/include/asm/processor.h +13 -1
@@ -99,6 +99,10 @@ struct cpuinfo_topology {// Logical ID mappings u32 logical_pkg_id;u32 logical_die_id; + +// Cache level topology IDs +u32 llc_id; +u32 l2c_id; };struct cpuinfo_x86 {
@@ -689,7 +693,15 @@ extern int set_tsc_mode(unsigned int val);DECLARE_PER_CPU (u64, msr_misc_features_shadow); -extern u16 get_llc_id (unsigned int cpu); +static inline u16 per_cpu_llc_id (unsigned int cpu) +{ +return per_cpu (cpu_info.topo.llc_id, cpu); +} + +static inline u16 per_cpu_l2c_id (unsigned int cpu) +{ +return per_cpu (cpu_info.topo.l2c_id, cpu); +}#ifdef CONFIG_CPU_SUP_AMD extern u32 amd_get_nodes_per_socket (void );
arch/x86/include/asm/smp.h +0 -2
@@ -17,8 +17,6 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_die_map);/* cpus sharing the last level cache: */ DECLARE_PER_CPU_READ_MOSTLY (cpumask_var_t, cpu_llc_shared_map);DECLARE_PER_CPU_READ_MOSTLY (cpumask_var_t, cpu_l2c_shared_map); -DECLARE_PER_CPU_READ_MOSTLY (u16, cpu_llc_id); -DECLARE_PER_CPU_READ_MOSTLY (u16, cpu_l2c_id);DECLARE_EARLY_PER_CPU_READ_MOSTLY (u16, x86_cpu_to_apicid);DECLARE_EARLY_PER_CPU_READ_MOSTLY (u32, x86_cpu_to_acpiid);
arch/x86/include/asm/topology.h +1 -1
@@ -115,7 +115,7 @@ extern const struct cpumask *cpu_clustergroup_mask(int cpu);extern unsigned int __max_die_per_package;#ifdef CONFIG_SMP -#define topology_cluster_id (cpu) (per_cpu(cpu_l2c_id, cpu)) +#define topology_cluster_id (cpu) (cpu_data(cpu).topo.l2c_id)#define topology_die_cpumask (cpu) (per_cpu(cpu_die_map, cpu))#define topology_cluster_cpumask (cpu) (cpu_clustergroup_mask(cpu))#define topology_core_cpumask (cpu) (per_cpu(cpu_core_map, cpu))
arch/x86/kernel/apic/apic_numachip.c +1 -1
@@ -161,7 +161,7 @@ static void fixup_cpu_id(struct cpuinfo_x86 *c, int node)u64 val;u32 nodes =1 ; -this_cpu_write (cpu_llc_id, node); + c->topo.llc_id = node;/* Account for nodes per socket in multi-core-module processors */ if (boot_cpu_has (X86_FEATURE_NODEID_MSR )) {
arch/x86/kernel/cpu/amd.c +4 -8
@@ -401,8 +401,6 @@ static void legacy_fixup_core_id(struct cpuinfo_x86 *c)*/ static void amd_get_topology (struct cpuinfo_x86 *c) { -int cpu =smp_processor_id (); -/* get information required for multi-node processors */ if (boot_cpu_has (X86_FEATURE_TOPOEXT )) {int err;
@@ -430,15 +428,14 @@ static void amd_get_topology(struct cpuinfo_x86 *c)if (!err) c->x86_coreid_bits =get_count_order (c->x86_max_cores); -cacheinfo_amd_init_llc_id (c, cpu); +cacheinfo_amd_init_llc_id (c); }else if (cpu_has (c,X86_FEATURE_NODEID_MSR )) {u64 value;rdmsrl (MSR_FAM10H_NODE_ID , value); c->topo.die_id = value &7 ; - -per_cpu (cpu_llc_id, cpu) = c->topo.die_id; + c->topo.llc_id = c->topo.die_id; }else return ;
@@ -455,7 +452,6 @@ static void amd_get_topology(struct cpuinfo_x86 *c)static void amd_detect_cmp (struct cpuinfo_x86 *c) {unsigned bits; -int cpu =smp_processor_id (); bits = c->x86_coreid_bits;/* Low order bits define the core id (index of core in socket) */
@@ -463,7 +459,7 @@ static void amd_detect_cmp(struct cpuinfo_x86 *c)/* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits;/* use socket ID also for last level cache */ -per_cpu (cpu_llc_id, cpu) = c->topo.die_id = c->topo.pkg_id; + c->topo.llc_id = c->topo.die_id = c->topo.pkg_id; }u32 amd_get_nodes_per_socket (void )
@@ -481,7 +477,7 @@ static void srat_detect_node(struct cpuinfo_x86 *c) node =numa_cpu_node (cpu);if (node ==NUMA_NO_NODE ) - node =get_llc_id (cpu); + node =per_cpu_llc_id (cpu);/* * On multi-fabric platform (e.g. Numascale NumaChip) a
arch/x86/kernel/cpu/cacheinfo.c +12 -21
@@ -661,7 +661,7 @@ static int find_num_cache_leaves(struct cpuinfo_x86 *c)return i; } -void cacheinfo_amd_init_llc_id (struct cpuinfo_x86 *c,int cpu) +void cacheinfo_amd_init_llc_id (struct cpuinfo_x86 *c) {/* * We may have multiple LLCs if L3 caches exist, so check if we
@@ -672,13 +672,13 @@ void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu)if (c->x86 <0x17 ) {/* LLC is at the node level. */ -per_cpu (cpu_llc_id, cpu) = c->topo.die_id; + c->topo.llc_id = c->topo.die_id; }else if (c->x86 ==0x17 && c->x86_model <=0x1F ) {/* * LLC is at the core complex level. * Core complex ID is ApicId[3] for these processors. */ -per_cpu (cpu_llc_id, cpu) = c->topo.apicid >>3 ; + c->topo.llc_id = c->topo.apicid >>3 ; }else {/* * LLC ID is calculated from the number of threads sharing the
@@ -694,12 +694,12 @@ void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu)if (num_sharing_cache) {int bits =get_count_order (num_sharing_cache); -per_cpu (cpu_llc_id, cpu) = c->topo.apicid >> bits; + c->topo.llc_id = c->topo.apicid >> bits; } } } -void cacheinfo_hygon_init_llc_id (struct cpuinfo_x86 *c,int cpu) +void cacheinfo_hygon_init_llc_id (struct cpuinfo_x86 *c) {/* * We may have multiple LLCs if L3 caches exist, so check if we
@@ -712,7 +712,7 @@ void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c, int cpu)* LLC is at the core complex level. * Core complex ID is ApicId[3] for these processors. */ -per_cpu (cpu_llc_id, cpu) = c->topo.apicid >>3 ; + c->topo.llc_id = c->topo.apicid >>3 ; }void init_amd_cacheinfo (struct cpuinfo_x86 *c)
@@ -740,9 +740,6 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c)unsigned int new_l1d =0 , new_l1i =0 ;/* Cache sizes from cpuid(4) */ unsigned int new_l2 =0 , new_l3 =0 , i;/* Cache sizes from cpuid(4) */ unsigned int l2_id =0 , l3_id =0 , num_threads_sharing, index_msb; -#ifdef CONFIG_SMP -unsigned int cpu = c->cpu_index; -#endif if (c->cpuid_level >3 ) {static int is_initialized;
@@ -856,30 +853,24 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c)if (new_l2) { l2 = new_l2; -#ifdef CONFIG_SMP -per_cpu (cpu_llc_id, cpu) = l2_id; -per_cpu (cpu_l2c_id, cpu) = l2_id; -#endif + c->topo.llc_id = l2_id; + c->topo.l2c_id = l2_id; }if (new_l3) { l3 = new_l3; -#ifdef CONFIG_SMP -per_cpu (cpu_llc_id, cpu) = l3_id; -#endif + c->topo.llc_id = l3_id; } -#ifdef CONFIG_SMP /* -* If cpu_llc_id is not yet set, this means cpuid_level < 4 which in +* If llc_id is not yet set, this means cpuid_level < 4 which in * turns means that the only possibility is SMT (as indicated in * cpuid1). Since cpuid2 doesn't specify shared caches, and we know * that SMT shares all caches, we can unconditionally set cpu_llc_id to * c->topo.pkg_id. */ -if (per_cpu (cpu_llc_id, cpu) ==BAD_APICID ) -per_cpu (cpu_llc_id, cpu) = c->topo.pkg_id; -#endif +if (c->topo.llc_id ==BAD_APICID ) + c->topo.llc_id = c->topo.pkg_id; c->x86_cache_size = l3 ? l3 : (l2 ? l2 : (l1i+l1d));
arch/x86/kernel/cpu/common.c +2 -12
@@ -74,18 +74,6 @@ u32 elf_hwcap2 __read_mostly;int smp_num_siblings =1 ;EXPORT_SYMBOL (smp_num_siblings); -/* Last level cache ID of each logical CPU */ -DEFINE_PER_CPU_READ_MOSTLY (u16, cpu_llc_id) =BAD_APICID ; - -u16 get_llc_id (unsigned int cpu) -{ -return per_cpu (cpu_llc_id, cpu); -} -EXPORT_SYMBOL_GPL (get_llc_id); - -/* L2 cache ID of each logical CPU */ -DEFINE_PER_CPU_READ_MOSTLY (u16, cpu_l2c_id) =BAD_APICID ; - static struct ppin_info { int feature; int msr_ppin_ctl;
@@ -1830,6 +1818,8 @@ static void identify_cpu(struct cpuinfo_x86 *c) c->x86_max_cores =1 ; c->x86_coreid_bits =0 ; c->topo.cu_id =0xff ; + c->topo.llc_id =BAD_APICID ; + c->topo.l2c_id =BAD_APICID ;#ifdef CONFIG_X86_64 c->x86_clflush_size =64 ; c->x86_phys_bits =36 ;
arch/x86/kernel/cpu/cpu.h +3 -0
@@ -78,6 +78,9 @@ extern int detect_ht_early(struct cpuinfo_x86 *c);extern void detect_ht (struct cpuinfo_x86 *c);extern void check_null_seg_clears_base (struct cpuinfo_x86 *c); +void cacheinfo_amd_init_llc_id (struct cpuinfo_x86 *c); +void cacheinfo_hygon_init_llc_id (struct cpuinfo_x86 *c); +unsigned int aperfmperf_get_khz (int cpu);void cpu_select_mitigations (void );
arch/x86/kernel/cpu/hygon.c +5 -9
@@ -63,8 +63,6 @@ static void hygon_get_topology_early(struct cpuinfo_x86 *c)*/ static void hygon_get_topology (struct cpuinfo_x86 *c) { -int cpu =smp_processor_id (); -/* get information required for multi-node processors */ if (boot_cpu_has (X86_FEATURE_TOPOEXT )) {int err;
@@ -94,14 +92,13 @@ static void hygon_get_topology(struct cpuinfo_x86 *c)if (!boot_cpu_has (X86_FEATURE_HYPERVISOR ) && c->x86_model <=0x3 ) c->topo.pkg_id = c->topo.apicid >>APICID_SOCKET_ID_BIT ; -cacheinfo_hygon_init_llc_id (c, cpu); +cacheinfo_hygon_init_llc_id (c); }else if (cpu_has (c,X86_FEATURE_NODEID_MSR )) {u64 value;rdmsrl (MSR_FAM10H_NODE_ID , value); c->topo.die_id = value &7 ; - -per_cpu (cpu_llc_id, cpu) = c->topo.die_id; + c->topo.llc_id = c->topo.die_id; }else return ;
@@ -116,15 +113,14 @@ static void hygon_get_topology(struct cpuinfo_x86 *c)static void hygon_detect_cmp (struct cpuinfo_x86 *c) {unsigned int bits; -int cpu =smp_processor_id (); bits = c->x86_coreid_bits;/* Low order bits define the core id (index of core in socket) */ c->topo.core_id = c->topo.initial_apicid & ((1 << bits)-1 );/* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits; -/* use socket ID also for last level cache */ -per_cpu (cpu_llc_id, cpu) = c->topo.die_id = c->topo.pkg_id; +/* Use package ID also for last level cache */ + c->topo.llc_id = c->topo.die_id = c->topo.pkg_id; }static void srat_detect_node (struct cpuinfo_x86 *c)
@@ -136,7 +132,7 @@ static void srat_detect_node(struct cpuinfo_x86 *c) node =numa_cpu_node (cpu);if (node ==NUMA_NO_NODE ) - node =per_cpu (cpu_llc_id, cpu); + node = c->topo.llc_id;/* * On multi-fabric platform (e.g. Numascale NumaChip) a
arch/x86/kernel/smpboot.c +5 -5
@@ -478,7 +478,7 @@ static bool match_smt(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)if (c->topo.pkg_id == o->topo.pkg_id && c->topo.die_id == o->topo.die_id && -per_cpu (cpu_llc_id, cpu1) ==per_cpu (cpu_llc_id, cpu2)) { +per_cpu_llc_id (cpu1) ==per_cpu_llc_id (cpu2)) {if (c->topo.core_id == o->topo.core_id)return topology_sane (c, o,"smt" );
@@ -510,11 +510,11 @@ static bool match_l2c(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)int cpu1 = c->cpu_index, cpu2 = o->cpu_index;/* If the arch didn't set up l2c_id, fall back to SMT */ -if (per_cpu (cpu_l2c_id, cpu1) ==BAD_APICID ) +if (per_cpu_l2c_id (cpu1) ==BAD_APICID )return match_smt (c, o);/* Do not match if L2 cache id does not match: */ -if (per_cpu (cpu_l2c_id, cpu1) !=per_cpu (cpu_l2c_id, cpu2)) +if (per_cpu_l2c_id (cpu1) !=per_cpu_l2c_id (cpu2))return false;return topology_sane (c, o,"l2c" );
@@ -560,11 +560,11 @@ static bool match_llc(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)bool intel_snc = id && id->driver_data;/* Do not match if we do not have a valid APICID for cpu: */ -if (per_cpu (cpu_llc_id, cpu1) ==BAD_APICID ) +if (per_cpu_llc_id (cpu1) ==BAD_APICID )return false;/* Do not match if LLC id does not match: */ -if (per_cpu (cpu_llc_id, cpu1) !=per_cpu (cpu_llc_id, cpu2)) +if (per_cpu_llc_id (cpu1) !=per_cpu_llc_id (cpu2))return false;/*
PATCH v4 14/41 x86/apic: Use BAD_APICID consistently
In reply to Thomas GleixnerAPIC ID checks compare with BAD_APICID all over the place, but some initializers and some code which fiddles with global data structure use -1[U] instead. That simply cannot work at all.
Fix it up and use BAD_APICID consistently all over the place.
---
V3: Fixed changelog typos - Sohil
--- arch/x86/kernel/acpi/boot.c | 2 +- arch/x86/kernel/apic/apic.c | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-)
arch/x86/kernel/acpi/boot.c +1 -1
@@ -852,7 +852,7 @@ int acpi_unmap_cpu(int cpu)set_apicid_to_node (per_cpu (x86_cpu_to_apicid, cpu),NUMA_NO_NODE );#endif -per_cpu (x86_cpu_to_apicid, cpu) =-1 ; +per_cpu (x86_cpu_to_apicid, cpu) =BAD_APICID ;set_cpu_present (cpu, false); num_processors--;
arch/x86/kernel/apic/apic.c +2 -4
@@ -72,7 +72,7 @@ unsigned int num_processors;unsigned disabled_cpus;/* Processor that is doing the boot up */ -unsigned int boot_cpu_physical_apicid__ro_after_init =-1U ; +unsigned int boot_cpu_physical_apicid__ro_after_init =BAD_APICID ;EXPORT_SYMBOL_GPL (boot_cpu_physical_apicid);u8 boot_cpu_apic_version__ro_after_init ;
@@ -2318,9 +2318,7 @@ static int nr_logical_cpuids = 1;/* * Used to store mapping between logical CPU IDs and APIC IDs. */ -int cpuid_to_apicid[] = { - [0 ...NR_CPUS -1 ] =-1 , -}; +int cpuid_to_apicid[] = { [0 ...NR_CPUS -1 ] =BAD_APICID , };bool arch_match_cpu_phys_id (int cpu,u64 phys_id) {
[tip: x86/core] x86/apic: Use BAD_APICID consistently
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 9ff4275bc8fd7bd5ac4677e2724397f8db3209bf Gitweb: https://git.kernel.org/tip/9ff4275bc8fd7bd5ac4677e2724397f8db3209bf Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:39 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:18 +02:00
x86/apic: Use BAD_APICID consistently
APIC ID checks compare with BAD_APICID all over the place, but some initializers and some code which fiddles with global data structure use -1[U] instead. That simply cannot work at all.
Fix it up and use BAD_APICID consistently all over the place.
--- arch/x86/kernel/acpi/boot.c | 2 +- arch/x86/kernel/apic/apic.c | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-)
arch/x86/kernel/acpi/boot.c +1 -1
@@ -856,7 +856,7 @@ int acpi_unmap_cpu(int cpu)set_apicid_to_node (per_cpu (x86_cpu_to_apicid, cpu),NUMA_NO_NODE );#endif -per_cpu (x86_cpu_to_apicid, cpu) =-1 ; +per_cpu (x86_cpu_to_apicid, cpu) =BAD_APICID ;set_cpu_present (cpu, false); num_processors--;
arch/x86/kernel/apic/apic.c +2 -4
@@ -72,7 +72,7 @@ unsigned int num_processors;unsigned disabled_cpus;/* Processor that is doing the boot up */ -unsigned int boot_cpu_physical_apicid__ro_after_init =-1U ; +unsigned int boot_cpu_physical_apicid__ro_after_init =BAD_APICID ;EXPORT_SYMBOL_GPL (boot_cpu_physical_apicid);u8 boot_cpu_apic_version__ro_after_init ;
@@ -2318,9 +2318,7 @@ static int nr_logical_cpuids = 1;/* * Used to store mapping between logical CPU IDs and APIC IDs. */ -int cpuid_to_apicid[] = { - [0 ...NR_CPUS -1 ] =-1 , -}; +int cpuid_to_apicid[] = { [0 ...NR_CPUS -1 ] =BAD_APICID , };bool arch_match_cpu_phys_id (int cpu,u64 phys_id) {
PATCH v4 15/41 x86/apic: Use u32 for APIC IDs in global data
In reply to Thomas GleixnerAPIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long.
Make it all consistently use u32 because that reflects the hardware register width and fixup the most obvious usage sites of that.
The APIC callbacks will be addressed separately.
--- arch/x86/include/asm/apic.h | 8 ++++---- arch/x86/include/asm/mpspec.h | 2 +- arch/x86/include/asm/processor.h | 4 ++-- arch/x86/include/asm/smp.h | 2 +- arch/x86/kernel/apic/apic.c | 16 ++++++++-------- arch/x86/kernel/apic/ipi.c | 5 +++-- arch/x86/kernel/kvm.c | 6 +++--- arch/x86/mm/numa.c | 4 ++-- 8 files changed, 24 insertions(+), 23 deletions(-)
arch/x86/include/asm/apic.h +4 -4
@@ -54,7 +54,7 @@ extern int local_apic_timer_c2_ok;extern bool apic_is_disabled;extern unsigned int lapic_timer_period; -extern int cpuid_to_apicid[]; +extern u32 cpuid_to_apicid[];extern enum apic_intr_mode_id apic_intr_mode;enum apic_intr_mode_id {
@@ -517,9 +517,9 @@ extern void generic_bigsmp_probe(void);extern struct apic apic_noop; -static inline unsigned int read_apic_id (void ) +static inline u32 read_apic_id (void ) { -unsigned int reg =apic_read (APIC_ID ); +u32 reg =apic_read (APIC_ID );return apic->get_apic_id (reg); }
@@ -544,7 +544,7 @@ extern int default_cpu_present_to_apicid#else /* CONFIG_X86_LOCAL_APIC */ -static inline unsigned int read_apic_id (void ) {return 0 ; } +static inline u32 read_apic_id (void ) {return 0 ; }#endif /* !CONFIG_X86_LOCAL_APIC */
arch/x86/include/asm/mpspec.h +1 -1
@@ -37,7 +37,7 @@ extern int mp_bus_id_to_type[MAX_MP_BUSS extern DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES); -extern unsigned int boot_cpu_physical_apicid; +extern u32 boot_cpu_physical_apicid;extern u8 boot_cpu_apic_version;#ifdef CONFIG_X86_LOCAL_APIC
arch/x86/include/asm/processor.h +2 -2
@@ -691,12 +691,12 @@ extern int set_tsc_mode(unsigned int valDECLARE_PER_CPU (u64, msr_misc_features_shadow); -static inline u16 per_cpu_llc_id (unsigned int cpu) +static inline u32 per_cpu_llc_id (unsigned int cpu) {return per_cpu (cpu_info.topo.llc_id, cpu); } -static inline u16 per_cpu_l2c_id (unsigned int cpu) +static inline u32 per_cpu_l2c_id (unsigned int cpu) {return per_cpu (cpu_info.topo.l2c_id, cpu); }
arch/x86/include/asm/smp.h +1 -1
@@ -18,7 +18,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_DECLARE_PER_CPU_READ_MOSTLY (cpumask_var_t, cpu_llc_shared_map);DECLARE_PER_CPU_READ_MOSTLY (cpumask_var_t, cpu_l2c_shared_map); -DECLARE_EARLY_PER_CPU_READ_MOSTLY (u16, x86_cpu_to_apicid); +DECLARE_EARLY_PER_CPU_READ_MOSTLY (u32, x86_cpu_to_apicid);DECLARE_EARLY_PER_CPU_READ_MOSTLY (u32, x86_cpu_to_acpiid);struct task_struct ;
arch/x86/kernel/apic/apic.c +8 -8
@@ -72,7 +72,7 @@ unsigned int num_processors;unsigned disabled_cpus;/* Processor that is doing the boot up */ -unsigned int boot_cpu_physical_apicid__ro_after_init =BAD_APICID ; +u32 boot_cpu_physical_apicid__ro_after_init =BAD_APICID ;EXPORT_SYMBOL_GPL (boot_cpu_physical_apicid);u8 boot_cpu_apic_version__ro_after_init ;
@@ -87,7 +87,7 @@ physid_mask_t phys_cpu_present_map;* disable_cpu_apicid=<int>, mostly used for the kdump 2nd kernel to * avoid undefined behaviour caused by sending INIT from AP to BSP. */ -static unsigned int disabled_cpu_apicid__ro_after_init =BAD_APICID ; +static u32 disabled_cpu_apicid__ro_after_init =BAD_APICID ;/* * This variable controls which CPUs receive external NMIs. By default,
@@ -111,7 +111,7 @@ static inline bool apic_accessible(void)/* * Map cpu index to physical APIC ID */ -DEFINE_EARLY_PER_CPU_READ_MOSTLY (u16, x86_cpu_to_apicid,BAD_APICID ); +DEFINE_EARLY_PER_CPU_READ_MOSTLY (u32, x86_cpu_to_apicid,BAD_APICID );DEFINE_EARLY_PER_CPU_READ_MOSTLY (u32, x86_cpu_to_acpiid,U32_MAX );EXPORT_EARLY_PER_CPU_SYMBOL (x86_cpu_to_apicid);EXPORT_EARLY_PER_CPU_SYMBOL (x86_cpu_to_acpiid);
@@ -1765,7 +1765,7 @@ static void __x2apic_enable(void)static int __init setup_nox2apic (char *str) {if (x2apic_enabled ()) { -int apicid =native_apic_msr_read (APIC_ID ); +u32 apicid =native_apic_msr_read (APIC_ID );if (apicid >=255 ) { pr_warn("Apicid: %08x, cannot enforce nox2apic\n",
@@ -2318,11 +2318,11 @@ static int nr_logical_cpuids = 1;/* * Used to store mapping between logical CPU IDs and APIC IDs. */ -int cpuid_to_apicid[] = { [0 ...NR_CPUS -1 ] =BAD_APICID , }; +u32 cpuid_to_apicid[] = { [0 ...NR_CPUS -1 ] =BAD_APICID , };bool arch_match_cpu_phys_id (int cpu,u64 phys_id) { -return phys_id == cpuid_to_apicid[cpu]; +return phys_id == (u64 )cpuid_to_apicid[cpu]; }#ifdef CONFIG_SMP
@@ -2391,7 +2391,7 @@ static int allocate_logical_cpuid(int apreturn nr_logical_cpuids++; } -static void cpu_update_apic (int cpu,int apicid) +static void cpu_update_apic (int cpu,u32 apicid) {#if defined(CONFIG_SMP ) || defined(CONFIG_X86_64 )early_per_cpu (x86_cpu_to_apicid, cpu) = apicid;
@@ -2544,7 +2544,7 @@ static struct {*/ int active;/* r/w apic fields */ -unsigned int apic_id; +u32 apic_id;unsigned int apic_taskpri;unsigned int apic_ldr;unsigned int apic_dfr;
arch/x86/kernel/apic/ipi.c +3 -2
@@ -280,7 +280,7 @@ void default_send_IPI_mask_logical(constlocal_irq_restore (flags); } -static int convert_apicid_to_cpu (int apic_id) +static int convert_apicid_to_cpu (u32 apic_id) {int i;
@@ -293,7 +293,8 @@ static int convert_apicid_to_cpu(int apiint safe_smp_processor_id (void ) { -int apicid, cpuid; +u32 apicid; +int cpuid;if (!boot_cpu_has (X86_FEATURE_APIC ))return 0 ;
arch/x86/kernel/kvm.c +3 -3
@@ -500,13 +500,13 @@ static bool pv_sched_yield_supported(voistatic void __send_ipi_mask (const struct cpumask *mask,int vector) {unsigned long flags; -int cpu, apic_id, icr; -int min =0 , max =0 ; +int cpu, min =0 , max =0 ;#ifdef CONFIG_X86_64 __uint128_t ipi_bitmap =0 ;#else u64 ipi_bitmap =0 ;#endif +u32 apic_id, icr;long ret;if (cpumask_empty (mask))
@@ -1030,8 +1030,8 @@ arch_initcall(activate_jump_labels);/* Kick a cpu by its apicid. Used to wake up a halted vcpu */ static void kvm_kick_cpu (int cpu) { -int apicid;unsigned long flags =0 ; +u32 apicid; apicid =per_cpu (x86_cpu_to_apicid, cpu);kvm_hypercall2 (KVM_HC_KICK_CPU , flags, apicid);
arch/x86/mm/numa.c +2 -2
@@ -56,7 +56,7 @@ s16 __apicid_to_node[MAX_LOCAL_APIC] = {int numa_cpu_node (int cpu) { -int apicid =early_per_cpu (x86_cpu_to_apicid, cpu); +u32 apicid =early_per_cpu (x86_cpu_to_apicid, cpu);if (apicid !=BAD_APICID )return __apicid_to_node[apicid];
@@ -786,7 +786,7 @@ void __init init_gi_nodes(void)void __init init_cpu_to_node (void ) {int cpu; -u16 *cpu_to_apicid =early_per_cpu_ptr (x86_cpu_to_apicid); +u32 *cpu_to_apicid =early_per_cpu_ptr (x86_cpu_to_apicid);BUG_ON (cpu_to_apicid ==NULL );
[tip: x86/core] x86/apic: Use u32 for APIC IDs in global data
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 4705243d237ab6abd8696e9672ad3fb36587c6f6 Gitweb: https://git.kernel.org/tip/4705243d237ab6abd8696e9672ad3fb36587c6f6 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:40 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:18 +02:00
x86/apic: Use u32 for APIC IDs in global data
APIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long.
Make it all consistently use u32 because that reflects the hardware register width and fixup the most obvious usage sites of that.
The APIC callbacks will be addressed separately.
--- arch/x86/include/asm/apic.h | 8 ++++---- arch/x86/include/asm/mpspec.h | 2 +- arch/x86/include/asm/processor.h | 4 ++-- arch/x86/include/asm/smp.h | 2 +- arch/x86/kernel/apic/apic.c | 16 ++++++++-------- arch/x86/kernel/apic/ipi.c | 5 +++-- arch/x86/kernel/kvm.c | 6 +++--- arch/x86/mm/numa.c | 4 ++-- 8 files changed, 24 insertions(+), 23 deletions(-)
arch/x86/include/asm/apic.h +4 -4
@@ -54,7 +54,7 @@ extern int local_apic_timer_c2_ok;extern bool apic_is_disabled;extern unsigned int lapic_timer_period; -extern int cpuid_to_apicid[]; +extern u32 cpuid_to_apicid[];extern enum apic_intr_mode_id apic_intr_mode;enum apic_intr_mode_id {
@@ -517,9 +517,9 @@ extern void generic_bigsmp_probe(void);extern struct apic apic_noop; -static inline unsigned int read_apic_id (void ) +static inline u32 read_apic_id (void ) { -unsigned int reg =apic_read (APIC_ID ); +u32 reg =apic_read (APIC_ID );return apic->get_apic_id (reg); }
@@ -544,7 +544,7 @@ extern int default_cpu_present_to_apicid(int mps_cpu);#else /* CONFIG_X86_LOCAL_APIC */ -static inline unsigned int read_apic_id (void ) {return 0 ; } +static inline u32 read_apic_id (void ) {return 0 ; }#endif /* !CONFIG_X86_LOCAL_APIC */
arch/x86/include/asm/mpspec.h +1 -1
@@ -37,7 +37,7 @@ extern int mp_bus_id_to_type[MAX_MP_BUSSES]; extern DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES); -extern unsigned int boot_cpu_physical_apicid; +extern u32 boot_cpu_physical_apicid;extern u8 boot_cpu_apic_version;#ifdef CONFIG_X86_LOCAL_APIC
arch/x86/include/asm/processor.h +2 -2
@@ -693,12 +693,12 @@ extern int set_tsc_mode(unsigned int val);DECLARE_PER_CPU (u64, msr_misc_features_shadow); -static inline u16 per_cpu_llc_id (unsigned int cpu) +static inline u32 per_cpu_llc_id (unsigned int cpu) {return per_cpu (cpu_info.topo.llc_id, cpu); } -static inline u16 per_cpu_l2c_id (unsigned int cpu) +static inline u32 per_cpu_l2c_id (unsigned int cpu) {return per_cpu (cpu_info.topo.l2c_id, cpu); }
arch/x86/include/asm/smp.h +1 -1
@@ -18,7 +18,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_die_map);DECLARE_PER_CPU_READ_MOSTLY (cpumask_var_t, cpu_llc_shared_map);DECLARE_PER_CPU_READ_MOSTLY (cpumask_var_t, cpu_l2c_shared_map); -DECLARE_EARLY_PER_CPU_READ_MOSTLY (u16, x86_cpu_to_apicid); +DECLARE_EARLY_PER_CPU_READ_MOSTLY (u32, x86_cpu_to_apicid);DECLARE_EARLY_PER_CPU_READ_MOSTLY (u32, x86_cpu_to_acpiid);struct task_struct ;
arch/x86/kernel/apic/apic.c +8 -8
@@ -72,7 +72,7 @@ unsigned int num_processors;unsigned disabled_cpus;/* Processor that is doing the boot up */ -unsigned int boot_cpu_physical_apicid__ro_after_init =BAD_APICID ; +u32 boot_cpu_physical_apicid__ro_after_init =BAD_APICID ;EXPORT_SYMBOL_GPL (boot_cpu_physical_apicid);u8 boot_cpu_apic_version__ro_after_init ;
@@ -87,7 +87,7 @@ physid_mask_t phys_cpu_present_map;* disable_cpu_apicid=<int>, mostly used for the kdump 2nd kernel to * avoid undefined behaviour caused by sending INIT from AP to BSP. */ -static unsigned int disabled_cpu_apicid__ro_after_init =BAD_APICID ; +static u32 disabled_cpu_apicid__ro_after_init =BAD_APICID ;/* * This variable controls which CPUs receive external NMIs. By default,
@@ -111,7 +111,7 @@ static inline bool apic_accessible(void)/* * Map cpu index to physical APIC ID */ -DEFINE_EARLY_PER_CPU_READ_MOSTLY (u16, x86_cpu_to_apicid,BAD_APICID ); +DEFINE_EARLY_PER_CPU_READ_MOSTLY (u32, x86_cpu_to_apicid,BAD_APICID );DEFINE_EARLY_PER_CPU_READ_MOSTLY (u32, x86_cpu_to_acpiid,U32_MAX );EXPORT_EARLY_PER_CPU_SYMBOL (x86_cpu_to_apicid);EXPORT_EARLY_PER_CPU_SYMBOL (x86_cpu_to_acpiid);
@@ -1765,7 +1765,7 @@ static void __x2apic_enable(void)static int __init setup_nox2apic (char *str) {if (x2apic_enabled ()) { -int apicid =native_apic_msr_read (APIC_ID ); +u32 apicid =native_apic_msr_read (APIC_ID );if (apicid >=255 ) { pr_warn("Apicid: %08x, cannot enforce nox2apic\n",
@@ -2318,11 +2318,11 @@ static int nr_logical_cpuids = 1;/* * Used to store mapping between logical CPU IDs and APIC IDs. */ -int cpuid_to_apicid[] = { [0 ...NR_CPUS -1 ] =BAD_APICID , }; +u32 cpuid_to_apicid[] = { [0 ...NR_CPUS -1 ] =BAD_APICID , };bool arch_match_cpu_phys_id (int cpu,u64 phys_id) { -return phys_id == cpuid_to_apicid[cpu]; +return phys_id == (u64 )cpuid_to_apicid[cpu]; }#ifdef CONFIG_SMP
@@ -2391,7 +2391,7 @@ static int allocate_logical_cpuid(int apicid)return nr_logical_cpuids++; } -static void cpu_update_apic (int cpu,int apicid) +static void cpu_update_apic (int cpu,u32 apicid) {#if defined(CONFIG_SMP ) || defined(CONFIG_X86_64 )early_per_cpu (x86_cpu_to_apicid, cpu) = apicid;
@@ -2544,7 +2544,7 @@ static struct {*/ int active;/* r/w apic fields */ -unsigned int apic_id; +u32 apic_id;unsigned int apic_taskpri;unsigned int apic_ldr;unsigned int apic_dfr;
arch/x86/kernel/apic/ipi.c +3 -2
@@ -281,7 +281,7 @@ void default_send_IPI_mask_logical(const struct cpumask *cpumask, int vector) }#ifdef CONFIG_SMP -static int convert_apicid_to_cpu (int apic_id) +static int convert_apicid_to_cpu (u32 apic_id) {int i;
@@ -294,7 +294,8 @@ static int convert_apicid_to_cpu(int apic_id)int safe_smp_processor_id (void ) { -int apicid, cpuid; +u32 apicid; +int cpuid;if (!boot_cpu_has (X86_FEATURE_APIC ))return 0 ;
arch/x86/kernel/kvm.c +3 -3
@@ -500,13 +500,13 @@ static bool pv_sched_yield_supported(void)static void __send_ipi_mask (const struct cpumask *mask,int vector) {unsigned long flags; -int cpu, apic_id, icr; -int min =0 , max =0 ; +int cpu, min =0 , max =0 ;#ifdef CONFIG_X86_64 __uint128_t ipi_bitmap =0 ;#else u64 ipi_bitmap =0 ;#endif +u32 apic_id, icr;long ret;if (cpumask_empty (mask))
@@ -1028,8 +1028,8 @@ arch_initcall(activate_jump_labels);/* Kick a cpu by its apicid. Used to wake up a halted vcpu */ static void kvm_kick_cpu (int cpu) { -int apicid;unsigned long flags =0 ; +u32 apicid; apicid =per_cpu (x86_cpu_to_apicid, cpu);kvm_hypercall2 (KVM_HC_KICK_CPU , flags, apicid);
arch/x86/mm/numa.c +2 -2
@@ -56,7 +56,7 @@ s16 __apicid_to_node[MAX_LOCAL_APIC] = {int numa_cpu_node (int cpu) { -int apicid =early_per_cpu (x86_cpu_to_apicid, cpu); +u32 apicid =early_per_cpu (x86_cpu_to_apicid, cpu);if (apicid !=BAD_APICID )return __apicid_to_node[apicid];
@@ -786,7 +786,7 @@ void __init init_gi_nodes(void)void __init init_cpu_to_node (void ) {int cpu; -u16 *cpu_to_apicid =early_per_cpu_ptr (x86_cpu_to_apicid); +u32 *cpu_to_apicid =early_per_cpu_ptr (x86_cpu_to_apicid);BUG_ON (cpu_to_apicid ==NULL );
PATCH v4 16/41 x86/apic: Use u32 for check_apicid_used()
In reply to Thomas GleixnerAPIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long.
Make it all consistently use u32 because that reflects the hardware register width and move the default implementation to local.h as there are no users outside the apic directory.
--- arch/x86/include/asm/apic.h | 3 +-- arch/x86/kernel/apic/apic_common.c | 2 +- arch/x86/kernel/apic/apic_flat_64.c | 2 -- arch/x86/kernel/apic/apic_noop.c | 2 ++ arch/x86/kernel/apic/bigsmp_32.c | 2 +- arch/x86/kernel/apic/local.h | 1 + 6 files changed, 6 insertions(+), 6 deletions(-)
arch/x86/include/asm/apic.h +1 -2
@@ -292,7 +292,7 @@ struct apic {int (*acpi_madt_oem_check)(char *oem_id,char *oem_table_id);bool (*apic_id_registered)(void ); -bool (*check_apicid_used)(physid_mask_t *map,int apicid); +bool (*check_apicid_used)(physid_mask_t *map,u32 apicid);void (*init_apic_ldr)(void );void (*ioapic_phys_id_map)(physid_mask_t *phys_map,physid_mask_t *retmap);int (*cpu_present_to_apicid)(int mps_cpu);
@@ -538,7 +538,6 @@ extern int default_apic_id_valid(u32 apiextern u32 apic_default_calc_apicid (unsigned int cpu);extern u32 apic_flat_calc_apicid (unsigned int cpu); -extern bool default_check_apicid_used (physid_mask_t *map,int apicid);extern void default_ioapic_phys_id_map (physid_mask_t *phys_map,physid_mask_t *retmap);extern int default_cpu_present_to_apicid (int mps_cpu);
arch/x86/kernel/apic/apic_common.c +1 -1
@@ -18,7 +18,7 @@ u32 apic_flat_calc_apicid(unsigned int creturn 1U << cpu; } -bool default_check_apicid_used (physid_mask_t *map,int apicid) +bool default_check_apicid_used (physid_mask_t *map,u32 apicid) {return physid_isset (apicid, *map); }
arch/x86/kernel/apic/apic_flat_64.c +0 -2
@@ -158,8 +158,6 @@ static struct apic apic_physflat __ro_af .disable_esr = 0, - .check_apicid_used = NULL, - .ioapic_phys_id_map = NULL, .cpu_present_to_apicid = default_cpu_present_to_apicid, .phys_pkg_id = flat_phys_pkg_id,
arch/x86/kernel/apic/apic_noop.c +2 -0
@@ -18,6 +18,8 @@#include <asm/apic.h> +#include "local.h" +static void noop_send_IPI (int cpu,int vector) { }static void noop_send_IPI_mask (const struct cpumask *cpumask,int vector) { }static void noop_send_IPI_mask_allbutself (const struct cpumask *cpumask,int vector) { }
arch/x86/kernel/apic/bigsmp_32.c +1 -1
@@ -18,7 +18,7 @@ static unsigned bigsmp_get_apic_id(unsigreturn (x >>24 ) &0xFF ; } -static bool bigsmp_check_apicid_used (physid_mask_t *map,int apicid) +static bool bigsmp_check_apicid_used (physid_mask_t *map,u32 apicid) {return false; }
arch/x86/kernel/apic/local.h +1 -0
@@ -64,6 +64,7 @@ void default_send_IPI_all(int vector);void default_send_IPI_self (int vector);bool default_apic_id_registered (void ); +bool default_check_apicid_used (physid_mask_t *map,u32 apicid);#ifdef CONFIG_X86_32 void default_send_IPI_mask_sequence_logical (const struct cpumask *mask,int vector);
[tip: x86/core] x86/apic: Use u32 for check_apicid_used()
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 5d376b8fb165eca33ea166ee43a637c8e912abd4 Gitweb: https://git.kernel.org/tip/5d376b8fb165eca33ea166ee43a637c8e912abd4 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:41 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:18 +02:00
x86/apic: Use u32 for check_apicid_used()
APIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long.
Make it all consistently use u32 because that reflects the hardware register width and move the default implementation to local.h as there are no users outside the apic directory.
--- arch/x86/include/asm/apic.h | 3 +-- arch/x86/kernel/apic/apic_common.c | 2 +- arch/x86/kernel/apic/apic_flat_64.c | 2 -- arch/x86/kernel/apic/apic_noop.c | 2 ++ arch/x86/kernel/apic/bigsmp_32.c | 2 +- arch/x86/kernel/apic/local.h | 1 + 6 files changed, 6 insertions(+), 6 deletions(-)
arch/x86/include/asm/apic.h +1 -2
@@ -292,7 +292,7 @@ struct apic {int (*acpi_madt_oem_check)(char *oem_id,char *oem_table_id);bool (*apic_id_registered)(void ); -bool (*check_apicid_used)(physid_mask_t *map,int apicid); +bool (*check_apicid_used)(physid_mask_t *map,u32 apicid);void (*init_apic_ldr)(void );void (*ioapic_phys_id_map)(physid_mask_t *phys_map,physid_mask_t *retmap);int (*cpu_present_to_apicid)(int mps_cpu);
@@ -538,7 +538,6 @@ extern int default_apic_id_valid(u32 apicid);extern u32 apic_default_calc_apicid (unsigned int cpu);extern u32 apic_flat_calc_apicid (unsigned int cpu); -extern bool default_check_apicid_used (physid_mask_t *map,int apicid);extern void default_ioapic_phys_id_map (physid_mask_t *phys_map,physid_mask_t *retmap);extern int default_cpu_present_to_apicid (int mps_cpu);
arch/x86/kernel/apic/apic_common.c +1 -1
@@ -18,7 +18,7 @@ u32 apic_flat_calc_apicid(unsigned int cpu)return 1U << cpu; } -bool default_check_apicid_used (physid_mask_t *map,int apicid) +bool default_check_apicid_used (physid_mask_t *map,u32 apicid) {return physid_isset (apicid, *map); }
arch/x86/kernel/apic/apic_flat_64.c +0 -2
@@ -158,8 +158,6 @@ static struct apic apic_physflat __ro_after_init = { .disable_esr = 0, - .check_apicid_used = NULL, - .ioapic_phys_id_map = NULL, .cpu_present_to_apicid = default_cpu_present_to_apicid, .phys_pkg_id = flat_phys_pkg_id,
arch/x86/kernel/apic/apic_noop.c +2 -0
@@ -18,6 +18,8 @@#include <asm/apic.h> +#include "local.h" +static void noop_send_IPI (int cpu,int vector) { }static void noop_send_IPI_mask (const struct cpumask *cpumask,int vector) { }static void noop_send_IPI_mask_allbutself (const struct cpumask *cpumask,int vector) { }
arch/x86/kernel/apic/bigsmp_32.c +1 -1
@@ -18,7 +18,7 @@ static unsigned bigsmp_get_apic_id(unsigned long x)return (x >>24 ) &0xFF ; } -static bool bigsmp_check_apicid_used (physid_mask_t *map,int apicid) +static bool bigsmp_check_apicid_used (physid_mask_t *map,u32 apicid) {return false; }
arch/x86/kernel/apic/local.h +1 -0
@@ -64,6 +64,7 @@ void default_send_IPI_all(int vector);void default_send_IPI_self (int vector);bool default_apic_id_registered (void ); +bool default_check_apicid_used (physid_mask_t *map,u32 apicid);#ifdef CONFIG_X86_32 void default_send_IPI_mask_sequence_logical (const struct cpumask *mask,int vector);
PATCH v4 17/41 x86/apic: Use u32 for cpu_present_to_apicid()
In reply to Thomas GleixnerAPIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long.
Make it all consistently use u32 because that reflects the hardware register width and fixup a few related usage sites for consistency sake.
--- arch/x86/include/asm/apic.h | 4 ++-- arch/x86/kernel/apic/apic_common.c | 2 +- arch/x86/kernel/cpu/common.c | 3 ++- arch/x86/kernel/smpboot.c | 10 +++++----- arch/x86/xen/apic.c | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-)
arch/x86/include/asm/apic.h +2 -2
@@ -295,7 +295,7 @@ struct apic {bool (*check_apicid_used)(physid_mask_t *map,u32 apicid);void (*init_apic_ldr)(void );void (*ioapic_phys_id_map)(physid_mask_t *phys_map,physid_mask_t *retmap); -int (*cpu_present_to_apicid)(int mps_cpu); +u32 (*cpu_present_to_apicid)(int mps_cpu);int (*phys_pkg_id)(int cpuid_apic,int index_msb);u32 (*get_apic_id)(unsigned long x);
@@ -539,7 +539,7 @@ extern u32 apic_default_calc_apicid(unsiextern u32 apic_flat_calc_apicid (unsigned int cpu);extern void default_ioapic_phys_id_map (physid_mask_t *phys_map,physid_mask_t *retmap); -extern int default_cpu_present_to_apicid (int mps_cpu); +extern u32 default_cpu_present_to_apicid (int mps_cpu);#else /* CONFIG_X86_LOCAL_APIC */
arch/x86/kernel/apic/apic_common.c +1 -1
@@ -28,7 +28,7 @@ void default_ioapic_phys_id_map(physid_m *retmap = *phys_map; } -int default_cpu_present_to_apicid (int mps_cpu) +u32 default_cpu_present_to_apicid (int mps_cpu) {if (mps_cpu < nr_cpu_ids &&cpu_present (mps_cpu))return (int )per_cpu (x86_cpu_to_apicid, mps_cpu);
arch/x86/kernel/cpu/common.c +2 -1
@@ -1747,7 +1747,8 @@ static void generic_identify(struct cpuistatic void validate_apic_and_package_id (struct cpuinfo_x86 *c) {#ifdef CONFIG_SMP -unsigned int apicid, cpu =smp_processor_id (); +unsigned int cpu =smp_processor_id (); +u32 apicid; apicid = apic->cpu_present_to_apicid (cpu);
arch/x86/kernel/smpboot.c +5 -5
@@ -816,7 +816,7 @@ static void __init smp_quirk_init_udelay/* * Wake up AP by INIT, INIT, STARTUP sequence. */ -static void send_init_sequence (int phys_apicid) +static void send_init_sequence (u32 phys_apicid) {int maxlvt =lapic_get_maxlvt ();
@@ -842,7 +842,7 @@ static void send_init_sequence(int phys_/* * Wake up AP by INIT, INIT, STARTUP sequence. */ -static int wakeup_secondary_cpu_via_init (int phys_apicid,unsigned long start_eip) +static int wakeup_secondary_cpu_via_init (u32 phys_apicid,unsigned long start_eip) {unsigned long send_status =0 , accept_status =0 ;int num_starts, j, maxlvt;
@@ -989,7 +989,7 @@ int common_cpu_up(unsigned int cpu, stru* Returns zero if startup was successfully sent, else error code from * ->wakeup_secondary_cpu. */ -static int do_boot_cpu (int apicid,int cpu,struct task_struct *idle) +static int do_boot_cpu (u32 apicid,int cpu,struct task_struct *idle) {unsigned long start_ip = real_mode_header->trampoline_start;int ret;
@@ -1057,7 +1057,7 @@ static int do_boot_cpu(int apicid, int cint native_kick_ap (unsigned int cpu,struct task_struct *tidle) { -int apicid = apic->cpu_present_to_apicid (cpu); +u32 apicid = apic->cpu_present_to_apicid (cpu);int err;lockdep_assert_irqs_enabled ();
@@ -1250,7 +1250,7 @@ void arch_thaw_secondary_cpus_end(void)bool smp_park_other_cpus_in_init (void ) {unsigned int cpu, this_cpu =smp_processor_id (); -unsigned int apicid; +u32 apicid;if (apic->wakeup_secondary_cpu_64 || apic->wakeup_secondary_cpu)return false;
arch/x86/xen/apic.c +1 -1
@@ -115,7 +115,7 @@ static int xen_phys_pkg_id(int initial_areturn initial_apic_id >> index_msb; } -static int xen_cpu_present_to_apicid (int cpu) +static u32 xen_cpu_present_to_apicid (int cpu) {if (cpu_present (cpu))return cpu_data (cpu).topo.apicid;
[tip: x86/core] x86/apic: Use u32 for cpu_present_to_apicid()
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 8aa2a4178dc535591ac0c17de45b14fe7f6a05c7 Gitweb: https://git.kernel.org/tip/8aa2a4178dc535591ac0c17de45b14fe7f6a05c7 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:42 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:19 +02:00
x86/apic: Use u32 for cpu_present_to_apicid()
APIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long.
Make it all consistently use u32 because that reflects the hardware register width and fixup a few related usage sites for consistency sake.
--- arch/x86/include/asm/apic.h | 4 ++-- arch/x86/kernel/apic/apic_common.c | 2 +- arch/x86/kernel/cpu/common.c | 3 ++- arch/x86/kernel/smpboot.c | 10 +++++----- arch/x86/xen/apic.c | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-)
arch/x86/include/asm/apic.h +2 -2
@@ -295,7 +295,7 @@ struct apic {bool (*check_apicid_used)(physid_mask_t *map,u32 apicid);void (*init_apic_ldr)(void );void (*ioapic_phys_id_map)(physid_mask_t *phys_map,physid_mask_t *retmap); -int (*cpu_present_to_apicid)(int mps_cpu); +u32 (*cpu_present_to_apicid)(int mps_cpu);int (*phys_pkg_id)(int cpuid_apic,int index_msb);u32 (*get_apic_id)(unsigned long x);
@@ -539,7 +539,7 @@ extern u32 apic_default_calc_apicid(unsigned int cpu);extern u32 apic_flat_calc_apicid (unsigned int cpu);extern void default_ioapic_phys_id_map (physid_mask_t *phys_map,physid_mask_t *retmap); -extern int default_cpu_present_to_apicid (int mps_cpu); +extern u32 default_cpu_present_to_apicid (int mps_cpu);#else /* CONFIG_X86_LOCAL_APIC */
arch/x86/kernel/apic/apic_common.c +1 -1
@@ -28,7 +28,7 @@ void default_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap) *retmap = *phys_map; } -int default_cpu_present_to_apicid (int mps_cpu) +u32 default_cpu_present_to_apicid (int mps_cpu) {if (mps_cpu < nr_cpu_ids &&cpu_present (mps_cpu))return (int )per_cpu (x86_cpu_to_apicid, mps_cpu);
arch/x86/kernel/cpu/common.c +2 -1
@@ -1787,7 +1787,8 @@ static void generic_identify(struct cpuinfo_x86 *c)static void validate_apic_and_package_id (struct cpuinfo_x86 *c) {#ifdef CONFIG_SMP -unsigned int apicid, cpu =smp_processor_id (); +unsigned int cpu =smp_processor_id (); +u32 apicid; apicid = apic->cpu_present_to_apicid (cpu);
arch/x86/kernel/smpboot.c +5 -5
@@ -803,7 +803,7 @@ static void __init smp_quirk_init_udelay(void)/* * Wake up AP by INIT, INIT, STARTUP sequence. */ -static void send_init_sequence (int phys_apicid) +static void send_init_sequence (u32 phys_apicid) {int maxlvt =lapic_get_maxlvt ();
@@ -829,7 +829,7 @@ static void send_init_sequence(int phys_apicid)/* * Wake up AP by INIT, INIT, STARTUP sequence. */ -static int wakeup_secondary_cpu_via_init (int phys_apicid,unsigned long start_eip) +static int wakeup_secondary_cpu_via_init (u32 phys_apicid,unsigned long start_eip) {unsigned long send_status =0 , accept_status =0 ;int num_starts, j, maxlvt;
@@ -976,7 +976,7 @@ int common_cpu_up(unsigned int cpu, struct task_struct *idle)* Returns zero if startup was successfully sent, else error code from * ->wakeup_secondary_cpu. */ -static int do_boot_cpu (int apicid,int cpu,struct task_struct *idle) +static int do_boot_cpu (u32 apicid,int cpu,struct task_struct *idle) {unsigned long start_ip = real_mode_header->trampoline_start;int ret;
@@ -1044,7 +1044,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)int native_kick_ap (unsigned int cpu,struct task_struct *tidle) { -int apicid = apic->cpu_present_to_apicid (cpu); +u32 apicid = apic->cpu_present_to_apicid (cpu);int err;lockdep_assert_irqs_enabled ();
@@ -1237,7 +1237,7 @@ void arch_thaw_secondary_cpus_end(void)bool smp_park_other_cpus_in_init (void ) {unsigned int cpu, this_cpu =smp_processor_id (); -unsigned int apicid; +u32 apicid;if (apic->wakeup_secondary_cpu_64 || apic->wakeup_secondary_cpu)return false;
arch/x86/xen/apic.c +1 -1
@@ -115,7 +115,7 @@ static int xen_phys_pkg_id(int initial_apic_id, int index_msb)return initial_apic_id >> index_msb; } -static int xen_cpu_present_to_apicid (int cpu) +static u32 xen_cpu_present_to_apicid (int cpu) {if (cpu_present (cpu))return cpu_data (cpu).topo.apicid;
PATCH v4 18/41 x86/apic: Use u32 for phys_pkg_id()
In reply to Thomas GleixnerAPIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long.
Make it all consistently use u32 because that reflects the hardware register width even if that callback going to be removed soonish.
--- arch/x86/include/asm/apic.h | 2 +- arch/x86/kernel/apic/apic_flat_64.c | 2 +- arch/x86/kernel/apic/apic_noop.c | 2 +- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/apic/bigsmp_32.c | 2 +- arch/x86/kernel/apic/local.h | 2 +- arch/x86/kernel/apic/probe_32.c | 2 +- arch/x86/kernel/apic/x2apic_phys.c | 2 +- arch/x86/kernel/apic/x2apic_uv_x.c | 2 +- arch/x86/kernel/vsmp_64.c | 2 +- arch/x86/xen/apic.c | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-)
arch/x86/include/asm/apic.h +1 -1
@@ -296,7 +296,7 @@ struct apic {void (*init_apic_ldr)(void );void (*ioapic_phys_id_map)(physid_mask_t *phys_map,physid_mask_t *retmap);u32 (*cpu_present_to_apicid)(int mps_cpu); -int (*phys_pkg_id)(int cpuid_apic,int index_msb); +u32 (*phys_pkg_id)(u32 cpuid_apic,int index_msb);u32 (*get_apic_id)(unsigned long x);u32 (*set_apic_id)(unsigned int id);
arch/x86/kernel/apic/apic_flat_64.c +1 -1
@@ -66,7 +66,7 @@ static u32 set_apic_id(unsigned int id)return (id &0xFF ) <<24 ; } -static int flat_phys_pkg_id (int initial_apic_id,int index_msb) +static u32 flat_phys_pkg_id (u32 initial_apic_id,int index_msb) {return initial_apic_id >> index_msb; }
arch/x86/kernel/apic/apic_noop.c +1 -1
@@ -29,7 +29,7 @@ static void noop_send_IPI_self(int vectostatic void noop_apic_icr_write (u32 low,u32 id) { }static int noop_wakeup_secondary_cpu (int apicid,unsigned long start_eip) {return -1 ; }static u64 noop_apic_icr_read (void ) {return 0 ; } -static int noop_phys_pkg_id (int cpuid_apic,int index_msb) {return 0 ; } +static u32 noop_phys_pkg_id (u32 cpuid_apic,int index_msb) {return 0 ; }static unsigned int noop_get_apic_id (unsigned long x) {return 0 ; }static void noop_apic_eoi (void ) { }
arch/x86/kernel/apic/apic_numachip.c +1 -1
@@ -56,7 +56,7 @@ static u32 numachip2_set_apic_id(unsignereturn id <<24 ; } -static int numachip_phys_pkg_id (int initial_apic_id,int index_msb) +static u32 numachip_phys_pkg_id (u32 initial_apic_id,int index_msb) {return initial_apic_id >> index_msb; }
arch/x86/kernel/apic/bigsmp_32.c +1 -1
@@ -29,7 +29,7 @@ static void bigsmp_ioapic_phys_id_map(phphysids_promote (0xFFL , retmap); } -static int bigsmp_phys_pkg_id (int cpuid_apic,int index_msb) +static u32 bigsmp_phys_pkg_id (u32 cpuid_apic,int index_msb) {return cpuid_apic >> index_msb; }
arch/x86/kernel/apic/local.h +1 -1
@@ -17,7 +17,7 @@void __x2apic_send_IPI_dest (unsigned int apicid,int vector,unsigned int dest);unsigned int x2apic_get_apic_id (unsigned long id);u32 x2apic_set_apic_id (unsigned int id); -int x2apic_phys_pkg_id (int initial_apicid,int index_msb); +u32 x2apic_phys_pkg_id (u32 initial_apicid,int index_msb);void x2apic_send_IPI_all (int vector);void x2apic_send_IPI_allbutself (int vector);
arch/x86/kernel/apic/probe_32.c +1 -1
@@ -18,7 +18,7 @@#include "local.h" -static int default_phys_pkg_id (int cpuid_apic,int index_msb) +static u32 default_phys_pkg_id (u32 cpuid_apic,int index_msb) {return cpuid_apic >> index_msb; }
arch/x86/kernel/apic/x2apic_phys.c +1 -1
@@ -134,7 +134,7 @@ u32 x2apic_set_apic_id(unsigned int id)return id; } -int x2apic_phys_pkg_id (int initial_apicid,int index_msb) +u32 x2apic_phys_pkg_id (u32 initial_apicid,int index_msb) {return initial_apicid >> index_msb; }
arch/x86/kernel/apic/x2apic_uv_x.c +1 -1
@@ -790,7 +790,7 @@ static unsigned int uv_read_apic_id(voidreturn x2apic_get_apic_id (apic_read (APIC_ID )); } -static int uv_phys_pkg_id (int initial_apicid,int index_msb) +static u32 uv_phys_pkg_id (u32 initial_apicid,int index_msb) {return uv_read_apic_id () >> index_msb; }
arch/x86/kernel/vsmp_64.c +1 -1
@@ -127,7 +127,7 @@ static void __init vsmp_cap_cpus(void)#endif } -static int apicid_phys_pkg_id (int initial_apic_id,int index_msb) +static u32 apicid_phys_pkg_id (u32 initial_apic_id,int index_msb) {return read_apic_id () >> index_msb; }
arch/x86/xen/apic.c +1 -1
@@ -110,7 +110,7 @@ static int xen_madt_oem_check(char *oem_return xen_pv_domain (); } -static int xen_phys_pkg_id (int initial_apic_id,int index_msb) +static u32 xen_phys_pkg_id (u32 initial_apic_id,int index_msb) {return initial_apic_id >> index_msb; }
[tip: x86/core] x86/apic: Use u32 for phys_pkg_id()
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 01ccf9bbd25fa32baa6ed8ae16700cf2e4487cf5 Gitweb: https://git.kernel.org/tip/01ccf9bbd25fa32baa6ed8ae16700cf2e4487cf5 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:43 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:19 +02:00
x86/apic: Use u32 for phys_pkg_id()
APIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long.
Make it all consistently use u32 because that reflects the hardware register width even if that callback going to be removed soonish.
--- arch/x86/include/asm/apic.h | 2 +- arch/x86/kernel/apic/apic_flat_64.c | 2 +- arch/x86/kernel/apic/apic_noop.c | 2 +- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/apic/bigsmp_32.c | 2 +- arch/x86/kernel/apic/local.h | 2 +- arch/x86/kernel/apic/probe_32.c | 2 +- arch/x86/kernel/apic/x2apic_phys.c | 2 +- arch/x86/kernel/apic/x2apic_uv_x.c | 2 +- arch/x86/kernel/vsmp_64.c | 2 +- arch/x86/xen/apic.c | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-)
arch/x86/include/asm/apic.h +1 -1
@@ -296,7 +296,7 @@ struct apic {void (*init_apic_ldr)(void );void (*ioapic_phys_id_map)(physid_mask_t *phys_map,physid_mask_t *retmap);u32 (*cpu_present_to_apicid)(int mps_cpu); -int (*phys_pkg_id)(int cpuid_apic,int index_msb); +u32 (*phys_pkg_id)(u32 cpuid_apic,int index_msb);u32 (*get_apic_id)(unsigned long x);u32 (*set_apic_id)(unsigned int id);
arch/x86/kernel/apic/apic_flat_64.c +1 -1
@@ -66,7 +66,7 @@ static u32 set_apic_id(unsigned int id)return (id &0xFF ) <<24 ; } -static int flat_phys_pkg_id (int initial_apic_id,int index_msb) +static u32 flat_phys_pkg_id (u32 initial_apic_id,int index_msb) {return initial_apic_id >> index_msb; }
arch/x86/kernel/apic/apic_noop.c +1 -1
@@ -29,7 +29,7 @@ static void noop_send_IPI_self(int vector) { }static void noop_apic_icr_write (u32 low,u32 id) { }static int noop_wakeup_secondary_cpu (int apicid,unsigned long start_eip) {return -1 ; }static u64 noop_apic_icr_read (void ) {return 0 ; } -static int noop_phys_pkg_id (int cpuid_apic,int index_msb) {return 0 ; } +static u32 noop_phys_pkg_id (u32 cpuid_apic,int index_msb) {return 0 ; }static unsigned int noop_get_apic_id (unsigned long x) {return 0 ; }static void noop_apic_eoi (void ) { }
arch/x86/kernel/apic/apic_numachip.c +1 -1
@@ -56,7 +56,7 @@ static u32 numachip2_set_apic_id(unsigned int id)return id <<24 ; } -static int numachip_phys_pkg_id (int initial_apic_id,int index_msb) +static u32 numachip_phys_pkg_id (u32 initial_apic_id,int index_msb) {return initial_apic_id >> index_msb; }
arch/x86/kernel/apic/bigsmp_32.c +1 -1
@@ -29,7 +29,7 @@ static void bigsmp_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *rephysids_promote (0xFFL , retmap); } -static int bigsmp_phys_pkg_id (int cpuid_apic,int index_msb) +static u32 bigsmp_phys_pkg_id (u32 cpuid_apic,int index_msb) {return cpuid_apic >> index_msb; }
arch/x86/kernel/apic/local.h +1 -1
@@ -17,7 +17,7 @@void __x2apic_send_IPI_dest (unsigned int apicid,int vector,unsigned int dest);unsigned int x2apic_get_apic_id (unsigned long id);u32 x2apic_set_apic_id (unsigned int id); -int x2apic_phys_pkg_id (int initial_apicid,int index_msb); +u32 x2apic_phys_pkg_id (u32 initial_apicid,int index_msb);void x2apic_send_IPI_all (int vector);void x2apic_send_IPI_allbutself (int vector);
arch/x86/kernel/apic/probe_32.c +1 -1
@@ -18,7 +18,7 @@#include "local.h" -static int default_phys_pkg_id (int cpuid_apic,int index_msb) +static u32 default_phys_pkg_id (u32 cpuid_apic,int index_msb) {return cpuid_apic >> index_msb; }
arch/x86/kernel/apic/x2apic_phys.c +1 -1
@@ -134,7 +134,7 @@ u32 x2apic_set_apic_id(unsigned int id)return id; } -int x2apic_phys_pkg_id (int initial_apicid,int index_msb) +u32 x2apic_phys_pkg_id (u32 initial_apicid,int index_msb) {return initial_apicid >> index_msb; }
arch/x86/kernel/apic/x2apic_uv_x.c +1 -1
@@ -789,7 +789,7 @@ static unsigned int uv_read_apic_id(void)return x2apic_get_apic_id (apic_read (APIC_ID )); } -static int uv_phys_pkg_id (int initial_apicid,int index_msb) +static u32 uv_phys_pkg_id (u32 initial_apicid,int index_msb) {return uv_read_apic_id () >> index_msb; }
arch/x86/kernel/vsmp_64.c +1 -1
@@ -127,7 +127,7 @@ static void __init vsmp_cap_cpus(void)#endif } -static int apicid_phys_pkg_id (int initial_apic_id,int index_msb) +static u32 apicid_phys_pkg_id (u32 initial_apic_id,int index_msb) {return read_apic_id () >> index_msb; }
arch/x86/xen/apic.c +1 -1
@@ -110,7 +110,7 @@ static int xen_madt_oem_check(char *oem_id, char *oem_table_id)return xen_pv_domain (); } -static int xen_phys_pkg_id (int initial_apic_id,int index_msb) +static u32 xen_phys_pkg_id (u32 initial_apic_id,int index_msb) {return initial_apic_id >> index_msb; }
PATCH v4 19/41 x86/apic: Use u32 for [gs]et_apic_id()
In reply to Thomas GleixnerAPIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long.
Make it all consistently use u32 because that reflects the hardware register width.
--- arch/x86/include/asm/apic.h | 14 ++------------ arch/x86/kernel/apic/apic_flat_64.c | 4 ++-- arch/x86/kernel/apic/apic_noop.c | 2 +- arch/x86/kernel/apic/apic_numachip.c | 8 ++++---- arch/x86/kernel/apic/bigsmp_32.c | 2 +- arch/x86/kernel/apic/local.h | 4 ++-- arch/x86/kernel/apic/probe_32.c | 10 ++++++++++ arch/x86/kernel/apic/x2apic_phys.c | 4 ++-- arch/x86/kernel/apic/x2apic_uv_x.c | 2 +- arch/x86/xen/apic.c | 4 ++-- 10 files changed, 27 insertions(+), 27 deletions(-)
arch/x86/include/asm/apic.h +2 -12
@@ -298,8 +298,8 @@ struct apic {u32 (*cpu_present_to_apicid)(int mps_cpu);u32 (*phys_pkg_id)(u32 cpuid_apic,int index_msb); -u32 (*get_apic_id)(unsigned long x); -u32 (*set_apic_id)(unsigned int id); +u32 (*get_apic_id)(u32 id); +u32 (*set_apic_id)(u32 apicid);/* wakeup_secondary_cpu */ int (*wakeup_secondary_cpu)(int apicid,unsigned long start_eip);
@@ -493,16 +493,6 @@ static inline bool lapic_vector_set_in_ireturn !!(irr & (1U << (vector %32 ))); } -static inline unsigned default_get_apic_id (unsigned long x) -{ -unsigned int ver =GET_APIC_VERSION (apic_read (APIC_LVR )); - -if (APIC_XAPIC (ver) ||boot_cpu_has (X86_FEATURE_EXTD_APICID )) -return (x >>24 ) &0xFF ; -else -return (x >>24 ) &0x0F ; -} -/* * Warm reset vector position: */
arch/x86/kernel/apic/apic_flat_64.c +2 -2
@@ -56,12 +56,12 @@ flat_send_IPI_mask_allbutself(const stru_flat_send_IPI_mask (mask, vector); } -static unsigned int flat_get_apic_id (unsigned long x) +static u32 flat_get_apic_id (u32 x) {return (x >>24 ) &0xFF ; } -static u32 set_apic_id (unsigned int id) +static u32 set_apic_id (u32 id) {return (id &0xFF ) <<24 ; }
arch/x86/kernel/apic/apic_noop.c +1 -1
@@ -30,7 +30,7 @@ static void noop_apic_icr_write(u32 low,static int noop_wakeup_secondary_cpu (int apicid,unsigned long start_eip) {return -1 ; }static u64 noop_apic_icr_read (void ) {return 0 ; }static u32 noop_phys_pkg_id (u32 cpuid_apic,int index_msb) {return 0 ; } -static unsigned int noop_get_apic_id (unsigned long x) {return 0 ; } +static u32 noop_get_apic_id (u32 apicid) {return 0 ; }static void noop_apic_eoi (void ) { }static u32 noop_apic_read (u32 reg)
arch/x86/kernel/apic/apic_numachip.c +4 -4
@@ -25,7 +25,7 @@ static const struct apic apic_numachip1;static const struct apic apic_numachip2;static void (*numachip_apic_icr_write)(int apicid,unsigned int val)__read_mostly ; -static unsigned int numachip1_get_apic_id (unsigned long x) +static u32 numachip1_get_apic_id (u32 x) {unsigned long value;unsigned int id = (x >>24 ) &0xff ;
@@ -38,12 +38,12 @@ static unsigned int numachip1_get_apic_ireturn id; } -static u32 numachip1_set_apic_id (unsigned int id) +static u32 numachip1_set_apic_id (u32 id) {return (id &0xff ) <<24 ; } -static unsigned int numachip2_get_apic_id (unsigned long x) +static u32 numachip2_get_apic_id (u32 x) {u64 mcfg;
@@ -51,7 +51,7 @@ static unsigned int numachip2_get_apic_ireturn ((mcfg >> (28 -8 )) &0xfff00 ) | (x >>24 ); } -static u32 numachip2_set_apic_id (unsigned int id) +static u32 numachip2_set_apic_id (u32 id) {return id <<24 ; }
arch/x86/kernel/apic/bigsmp_32.c +1 -1
@@ -13,7 +13,7 @@#include "local.h" -static unsigned bigsmp_get_apic_id (unsigned long x) +static u32 bigsmp_get_apic_id (u32 x) {return (x >>24 ) &0xFF ; }
arch/x86/kernel/apic/local.h +2 -2
@@ -15,8 +15,8 @@/* X2APIC */ void __x2apic_send_IPI_dest (unsigned int apicid,int vector,unsigned int dest); -unsigned int x2apic_get_apic_id (unsigned long id); -u32 x2apic_set_apic_id (unsigned int id); +u32 x2apic_get_apic_id (u32 id); +u32 x2apic_set_apic_id (u32 id);u32 x2apic_phys_pkg_id (u32 initial_apicid,int index_msb);void x2apic_send_IPI_all (int vector);
arch/x86/kernel/apic/probe_32.c +10 -0
@@ -23,6 +23,16 @@ static u32 default_phys_pkg_id(u32 cpuidreturn cpuid_apic >> index_msb; } +static u32 default_get_apic_id (u32 x) +{ +unsigned int ver =GET_APIC_VERSION (apic_read (APIC_LVR )); + +if (APIC_XAPIC (ver) ||boot_cpu_has (X86_FEATURE_EXTD_APICID )) +return (x >>24 ) &0xFF ; +else +return (x >>24 ) &0x0F ; +} +/* should be called last. */ static int probe_default (void ) {
arch/x86/kernel/apic/x2apic_phys.c +2 -2
@@ -124,12 +124,12 @@ static int x2apic_phys_probe(void)return apic == &apic_x2apic_phys; } -unsigned int x2apic_get_apic_id (unsigned long id) +u32 x2apic_get_apic_id (u32 id) {return id; } -u32 x2apic_set_apic_id (unsigned int id) +u32 x2apic_set_apic_id (u32 id) {return id; }
arch/x86/kernel/apic/x2apic_uv_x.c +1 -1
@@ -780,7 +780,7 @@ static void uv_send_IPI_all(int vector)uv_send_IPI_mask (cpu_online_mask, vector); } -static u32 set_apic_id (unsigned int id) +static u32 set_apic_id (u32 id) {return id; }
arch/x86/xen/apic.c +2 -2
@@ -33,13 +33,13 @@ static unsigned int xen_io_apic_read(unsreturn 0xfd ; } -static u32 xen_set_apic_id (unsigned int x) +static u32 xen_set_apic_id (u32 x) {WARN_ON (1 );return x; } -static unsigned int xen_get_apic_id (unsigned long x) +static u32 xen_get_apic_id (u32 x) {return ((x)>>24 ) &0xFFu ; }
[tip: x86/core] x86/apic: Use u32 for [gs]et_apic_id()
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 59f7928cd46316371bee71b0cb34e133567e5b35 Gitweb: https://git.kernel.org/tip/59f7928cd46316371bee71b0cb34e133567e5b35 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:44 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:19 +02:00
x86/apic: Use u32 for [gs]et_apic_id()
APIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long.
Make it all consistently use u32 because that reflects the hardware register width.
--- arch/x86/include/asm/apic.h | 14 ++------------ arch/x86/kernel/apic/apic_flat_64.c | 4 ++-- arch/x86/kernel/apic/apic_noop.c | 2 +- arch/x86/kernel/apic/apic_numachip.c | 8 ++++---- arch/x86/kernel/apic/bigsmp_32.c | 2 +- arch/x86/kernel/apic/local.h | 4 ++-- arch/x86/kernel/apic/probe_32.c | 10 ++++++++++ arch/x86/kernel/apic/x2apic_phys.c | 4 ++-- arch/x86/kernel/apic/x2apic_uv_x.c | 2 +- arch/x86/xen/apic.c | 4 ++-- 10 files changed, 27 insertions(+), 27 deletions(-)
arch/x86/include/asm/apic.h +2 -12
@@ -298,8 +298,8 @@ struct apic {u32 (*cpu_present_to_apicid)(int mps_cpu);u32 (*phys_pkg_id)(u32 cpuid_apic,int index_msb); -u32 (*get_apic_id)(unsigned long x); -u32 (*set_apic_id)(unsigned int id); +u32 (*get_apic_id)(u32 id); +u32 (*set_apic_id)(u32 apicid);/* wakeup_secondary_cpu */ int (*wakeup_secondary_cpu)(int apicid,unsigned long start_eip);
@@ -493,16 +493,6 @@ static inline bool lapic_vector_set_in_irr(unsigned int vector)return !!(irr & (1U << (vector %32 ))); } -static inline unsigned default_get_apic_id (unsigned long x) -{ -unsigned int ver =GET_APIC_VERSION (apic_read (APIC_LVR )); - -if (APIC_XAPIC (ver) ||boot_cpu_has (X86_FEATURE_EXTD_APICID )) -return (x >>24 ) &0xFF ; -else -return (x >>24 ) &0x0F ; -} -/* * Warm reset vector position: */
arch/x86/kernel/apic/apic_flat_64.c +2 -2
@@ -56,12 +56,12 @@ flat_send_IPI_mask_allbutself(const struct cpumask *cpumask, int vector)_flat_send_IPI_mask (mask, vector); } -static unsigned int flat_get_apic_id (unsigned long x) +static u32 flat_get_apic_id (u32 x) {return (x >>24 ) &0xFF ; } -static u32 set_apic_id (unsigned int id) +static u32 set_apic_id (u32 id) {return (id &0xFF ) <<24 ; }
arch/x86/kernel/apic/apic_noop.c +1 -1
@@ -30,7 +30,7 @@ static void noop_apic_icr_write(u32 low, u32 id) { }static int noop_wakeup_secondary_cpu (int apicid,unsigned long start_eip) {return -1 ; }static u64 noop_apic_icr_read (void ) {return 0 ; }static u32 noop_phys_pkg_id (u32 cpuid_apic,int index_msb) {return 0 ; } -static unsigned int noop_get_apic_id (unsigned long x) {return 0 ; } +static u32 noop_get_apic_id (u32 apicid) {return 0 ; }static void noop_apic_eoi (void ) { }static u32 noop_apic_read (u32 reg)
arch/x86/kernel/apic/apic_numachip.c +4 -4
@@ -25,7 +25,7 @@ static const struct apic apic_numachip1;static const struct apic apic_numachip2;static void (*numachip_apic_icr_write)(int apicid,unsigned int val)__read_mostly ; -static unsigned int numachip1_get_apic_id (unsigned long x) +static u32 numachip1_get_apic_id (u32 x) {unsigned long value;unsigned int id = (x >>24 ) &0xff ;
@@ -38,12 +38,12 @@ static unsigned int numachip1_get_apic_id(unsigned long x)return id; } -static u32 numachip1_set_apic_id (unsigned int id) +static u32 numachip1_set_apic_id (u32 id) {return (id &0xff ) <<24 ; } -static unsigned int numachip2_get_apic_id (unsigned long x) +static u32 numachip2_get_apic_id (u32 x) {u64 mcfg;
@@ -51,7 +51,7 @@ static unsigned int numachip2_get_apic_id(unsigned long x)return ((mcfg >> (28 -8 )) &0xfff00 ) | (x >>24 ); } -static u32 numachip2_set_apic_id (unsigned int id) +static u32 numachip2_set_apic_id (u32 id) {return id <<24 ; }
arch/x86/kernel/apic/bigsmp_32.c +1 -1
@@ -13,7 +13,7 @@#include "local.h" -static unsigned bigsmp_get_apic_id (unsigned long x) +static u32 bigsmp_get_apic_id (u32 x) {return (x >>24 ) &0xFF ; }
arch/x86/kernel/apic/local.h +2 -2
@@ -15,8 +15,8 @@/* X2APIC */ void __x2apic_send_IPI_dest (unsigned int apicid,int vector,unsigned int dest); -unsigned int x2apic_get_apic_id (unsigned long id); -u32 x2apic_set_apic_id (unsigned int id); +u32 x2apic_get_apic_id (u32 id); +u32 x2apic_set_apic_id (u32 id);u32 x2apic_phys_pkg_id (u32 initial_apicid,int index_msb);void x2apic_send_IPI_all (int vector);
arch/x86/kernel/apic/probe_32.c +10 -0
@@ -23,6 +23,16 @@ static u32 default_phys_pkg_id(u32 cpuid_apic, int index_msb)return cpuid_apic >> index_msb; } +static u32 default_get_apic_id (u32 x) +{ +unsigned int ver =GET_APIC_VERSION (apic_read (APIC_LVR )); + +if (APIC_XAPIC (ver) ||boot_cpu_has (X86_FEATURE_EXTD_APICID )) +return (x >>24 ) &0xFF ; +else +return (x >>24 ) &0x0F ; +} +/* should be called last. */ static int probe_default (void ) {
arch/x86/kernel/apic/x2apic_phys.c +2 -2
@@ -124,12 +124,12 @@ static int x2apic_phys_probe(void)return apic == &apic_x2apic_phys; } -unsigned int x2apic_get_apic_id (unsigned long id) +u32 x2apic_get_apic_id (u32 id) {return id; } -u32 x2apic_set_apic_id (unsigned int id) +u32 x2apic_set_apic_id (u32 id) {return id; }
arch/x86/kernel/apic/x2apic_uv_x.c +1 -1
@@ -779,7 +779,7 @@ static void uv_send_IPI_all(int vector)uv_send_IPI_mask (cpu_online_mask, vector); } -static u32 set_apic_id (unsigned int id) +static u32 set_apic_id (u32 id) {return id; }
arch/x86/xen/apic.c +2 -2
@@ -33,13 +33,13 @@ static unsigned int xen_io_apic_read(unsigned apic, unsigned reg)return 0xfd ; } -static u32 xen_set_apic_id (unsigned int x) +static u32 xen_set_apic_id (u32 x) {WARN_ON (1 );return x; } -static unsigned int xen_get_apic_id (unsigned long x) +static u32 xen_get_apic_id (u32 x) {return ((x)>>24 ) &0xFFu ; }
PATCH v4 20/41 x86/apic: Use u32 for wakeup_secondary_cpu[_64]()
In reply to Thomas GleixnerAPIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long.
Make it all consistently use u32 because that reflects the hardware register width.
--- arch/x86/hyperv/hv_vtl.c | 2 +- arch/x86/include/asm/apic.h | 8 ++++---- arch/x86/kernel/acpi/boot.c | 2 +- arch/x86/kernel/apic/apic_noop.c | 2 +- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/apic/x2apic_uv_x.c | 2 +- arch/x86/kernel/sev.c | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-)
arch/x86/hyperv/hv_vtl.c +1 -1
@@ -192,7 +192,7 @@ static int hv_vtl_apicid_to_vp_id(u32 apreturn ret; } -static int hv_vtl_wakeup_secondary_cpu (int apicid,unsigned long start_eip) +static int hv_vtl_wakeup_secondary_cpu (u32 apicid,unsigned long start_eip) {int vp_id;
arch/x86/include/asm/apic.h +4 -4
@@ -302,9 +302,9 @@ struct apic {u32 (*set_apic_id)(u32 apicid);/* wakeup_secondary_cpu */ -int (*wakeup_secondary_cpu)(int apicid,unsigned long start_eip); +int (*wakeup_secondary_cpu)(u32 apicid,unsigned long start_eip);/* wakeup secondary CPU using 64-bit wakeup point */ -int (*wakeup_secondary_cpu_64)(int apicid,unsigned long start_eip); +int (*wakeup_secondary_cpu_64)(u32 apicid,unsigned long start_eip);char *name; };
@@ -322,8 +322,8 @@ struct apic_override {void (*send_IPI_self)(int vector);u64 (*icr_read)(void);void (*icr_write)(u32 low,u32 high); -int (*wakeup_secondary_cpu)(int apicid,unsigned long start_eip); -int (*wakeup_secondary_cpu_64)(int apicid,unsigned long start_eip); +int (*wakeup_secondary_cpu)(u32 apicid,unsigned long start_eip); +int (*wakeup_secondary_cpu_64)(u32 apicid,unsigned long start_eip); };/*
arch/x86/kernel/acpi/boot.c +1 -1
@@ -358,7 +358,7 @@ acpi_parse_lapic_nmi(union acpi_subtable }#ifdef CONFIG_X86_64 -static int acpi_wakeup_cpu (int apicid,unsigned long start_ip) +static int acpi_wakeup_cpu (u32 apicid,unsigned long start_ip) {/* * Remap mailbox memory only for the first call to acpi_wakeup_cpu().
arch/x86/kernel/apic/apic_noop.c +1 -1
@@ -27,7 +27,7 @@ static void noop_send_IPI_allbutself(intstatic void noop_send_IPI_all (int vector) { }static void noop_send_IPI_self (int vector) { }static void noop_apic_icr_write (u32 low,u32 id) { } -static int noop_wakeup_secondary_cpu (int apicid,unsigned long start_eip) {return -1 ; } +static int noop_wakeup_secondary_cpu (u32 apicid,unsigned long start_eip) {return -1 ; }static u64 noop_apic_icr_read (void ) {return 0 ; }static u32 noop_phys_pkg_id (u32 cpuid_apic,int index_msb) {return 0 ; }static u32 noop_get_apic_id (u32 apicid) {return 0 ; }
arch/x86/kernel/apic/apic_numachip.c +1 -1
@@ -71,7 +71,7 @@ static void numachip2_apic_icr_write(intnumachip2_write32_lcsr (NUMACHIP2_APIC_ICR , (apicid <<12 ) | val); } -static int numachip_wakeup_secondary (int phys_apicid,unsigned long start_rip) +static int numachip_wakeup_secondary (u32 phys_apicid,unsigned long start_rip) {numachip_apic_icr_write (phys_apicid,APIC_DM_INIT ); numachip_apic_icr_write(phys_apicid, APIC_DM_STARTUP |
arch/x86/kernel/apic/x2apic_uv_x.c +1 -1
@@ -702,7 +702,7 @@ static __init void build_uv_gr_table(voi } } -static int uv_wakeup_secondary (int phys_apicid,unsigned long start_rip) +static int uv_wakeup_secondary (u32 phys_apicid,unsigned long start_rip) {unsigned long val;int pnode;
arch/x86/kernel/sev.c +1 -1
@@ -940,7 +940,7 @@ static void snp_cleanup_vmsa(struct sev_free_page ((unsigned long )vmsa); } -static int wakeup_cpu_via_vmgexit (int apic_id,unsigned long start_ip) +static int wakeup_cpu_via_vmgexit (u32 apic_id,unsigned long start_ip) {struct sev_es_save_area *cur_vmsa, *vmsa;struct ghcb_state state;
[tip: x86/core] x86/apic: Use u32 for wakeup_secondary_cpu[_64]()
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: db4a4086a223bd5cbfa5a66701c493124d808d55 Gitweb: https://git.kernel.org/tip/db4a4086a223bd5cbfa5a66701c493124d808d55 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:45 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:19 +02:00
x86/apic: Use u32 for wakeup_secondary_cpu[_64]()
APIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long.
Make it all consistently use u32 because that reflects the hardware register width.
--- arch/x86/hyperv/hv_vtl.c | 2 +- arch/x86/include/asm/apic.h | 8 ++++---- arch/x86/kernel/acpi/boot.c | 2 +- arch/x86/kernel/apic/apic_noop.c | 2 +- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/apic/x2apic_uv_x.c | 2 +- arch/x86/kernel/sev.c | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-)
arch/x86/hyperv/hv_vtl.c +1 -1
@@ -196,7 +196,7 @@ static int hv_vtl_apicid_to_vp_id(u32 apic_id)return ret; } -static int hv_vtl_wakeup_secondary_cpu (int apicid,unsigned long start_eip) +static int hv_vtl_wakeup_secondary_cpu (u32 apicid,unsigned long start_eip) {int vp_id;
arch/x86/include/asm/apic.h +4 -4
@@ -302,9 +302,9 @@ struct apic {u32 (*set_apic_id)(u32 apicid);/* wakeup_secondary_cpu */ -int (*wakeup_secondary_cpu)(int apicid,unsigned long start_eip); +int (*wakeup_secondary_cpu)(u32 apicid,unsigned long start_eip);/* wakeup secondary CPU using 64-bit wakeup point */ -int (*wakeup_secondary_cpu_64)(int apicid,unsigned long start_eip); +int (*wakeup_secondary_cpu_64)(u32 apicid,unsigned long start_eip);char *name; };
@@ -322,8 +322,8 @@ struct apic_override {void (*send_IPI_self)(int vector);u64 (*icr_read)(void);void (*icr_write)(u32 low,u32 high); -int (*wakeup_secondary_cpu)(int apicid,unsigned long start_eip); -int (*wakeup_secondary_cpu_64)(int apicid,unsigned long start_eip); +int (*wakeup_secondary_cpu)(u32 apicid,unsigned long start_eip); +int (*wakeup_secondary_cpu_64)(u32 apicid,unsigned long start_eip); };/*
arch/x86/kernel/acpi/boot.c +1 -1
@@ -359,7 +359,7 @@ acpi_parse_lapic_nmi(union acpi_subtable_headers * header, const unsigned long e }#ifdef CONFIG_X86_64 -static int acpi_wakeup_cpu (int apicid,unsigned long start_ip) +static int acpi_wakeup_cpu (u32 apicid,unsigned long start_ip) {/* * Remap mailbox memory only for the first call to acpi_wakeup_cpu().
arch/x86/kernel/apic/apic_noop.c +1 -1
@@ -27,7 +27,7 @@ static void noop_send_IPI_allbutself(int vector) { }static void noop_send_IPI_all (int vector) { }static void noop_send_IPI_self (int vector) { }static void noop_apic_icr_write (u32 low,u32 id) { } -static int noop_wakeup_secondary_cpu (int apicid,unsigned long start_eip) {return -1 ; } +static int noop_wakeup_secondary_cpu (u32 apicid,unsigned long start_eip) {return -1 ; }static u64 noop_apic_icr_read (void ) {return 0 ; }static u32 noop_phys_pkg_id (u32 cpuid_apic,int index_msb) {return 0 ; }static u32 noop_get_apic_id (u32 apicid) {return 0 ; }
arch/x86/kernel/apic/apic_numachip.c +1 -1
@@ -71,7 +71,7 @@ static void numachip2_apic_icr_write(int apicid, unsigned int val)numachip2_write32_lcsr (NUMACHIP2_APIC_ICR , (apicid <<12 ) | val); } -static int numachip_wakeup_secondary (int phys_apicid,unsigned long start_rip) +static int numachip_wakeup_secondary (u32 phys_apicid,unsigned long start_rip) {numachip_apic_icr_write (phys_apicid,APIC_DM_INIT ); numachip_apic_icr_write(phys_apicid, APIC_DM_STARTUP |
arch/x86/kernel/apic/x2apic_uv_x.c +1 -1
@@ -701,7 +701,7 @@ static __init void build_uv_gr_table(void) } } -static int uv_wakeup_secondary (int phys_apicid,unsigned long start_rip) +static int uv_wakeup_secondary (u32 phys_apicid,unsigned long start_rip) {unsigned long val;int pnode;
arch/x86/kernel/sev.c +1 -1
@@ -940,7 +940,7 @@ static void snp_cleanup_vmsa(struct sev_es_save_area *vmsa)free_page ((unsigned long )vmsa); } -static int wakeup_cpu_via_vmgexit (int apic_id,unsigned long start_ip) +static int wakeup_cpu_via_vmgexit (u32 apic_id,unsigned long start_ip) {struct sev_es_save_area *cur_vmsa, *vmsa;struct ghcb_state state;
[tip: x86/core] x86/apic, x86/hyperv: Use u32 in hv_snp_boot_ap() too
In reply to Thomas GleixnerThe following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 92fe9bb77b0c9fade150350fdb0629a662f0923f Gitweb: https://git.kernel.org/tip/92fe9bb77b0c9fade150350fdb0629a662f0923f Author: Ingo Molnar <[email protected]> AuthorDate: Fri, 13 Oct 2023 12:14:27 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 13 Oct 2023 12:26:58 +02:00
x86/apic, x86/hyperv: Use u32 in hv_snp_boot_ap() too
The data type for APIC IDs was standardized to 'u32' in the following recent commit:
db4a4086a223 ("x86/apic: Use u32 for wakeup_secondary_cpu[_64]()")
Which changed the function arguments type signature of the apic->wakeup_secondary_cpu() APIC driver function.
Propagate this to hv_snp_boot_ap() as well, which also addresses a 'assignment from incompatible pointer type' build warning that triggers under the -Werror=incompatible-pointer-types GCC warning.
--- arch/x86/hyperv/ivm.c | 2 +- arch/x86/include/asm/mshyperv.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/hyperv/ivm.c +1 -1
@@ -288,7 +288,7 @@ static void snp_cleanup_vmsa(struct sev_es_save_area *vmsa)free_page ((unsigned long )vmsa); } -int hv_snp_boot_ap (int cpu,unsigned long start_ip) +int hv_snp_boot_ap (u32 cpu,unsigned long start_ip) {struct sev_es_save_area *vmsa = (struct sev_es_save_area *)__get_free_page (GFP_KERNEL | __GFP_ZERO);
arch/x86/include/asm/mshyperv.h +2 -2
@@ -276,11 +276,11 @@ int hv_unmap_ioapic_interrupt(int ioapic_id, struct hv_interrupt_entry *entry);#ifdef CONFIG_AMD_MEM_ENCRYPT bool hv_ghcb_negotiate_protocol (void );void __noreturn hv_ghcb_terminate (unsigned int set,unsigned int reason); -int hv_snp_boot_ap (int cpu,unsigned long start_ip); +int hv_snp_boot_ap (u32 cpu,unsigned long start_ip);#else static inline bool hv_ghcb_negotiate_protocol (void ) {return false; }static inline void hv_ghcb_terminate (unsigned int set,unsigned int reason) {} -static inline int hv_snp_boot_ap (int cpu,unsigned long start_ip) {return 0 ; } +static inline int hv_snp_boot_ap (u32 cpu,unsigned long start_ip) {return 0 ; }#endif #if defined(CONFIG_AMD_MEM_ENCRYPT ) || defined(CONFIG_INTEL_TDX_GUEST )
PATCH v4 21/41 x86/cpu/topology: Cure the abuse of cpuinfo for persisting logical ids
In reply to Thomas GleixnerPer CPU cpuinfo is used to persist the logical package and die IDs. That's really not the right place simply because cpuinfo is subject to be reinitialized when a CPU goes through an offline/online cycle.
This works by chance today, but that's far from correct and neither obvious nor documented.
Add a per cpu datastructure which persists those logical IDs, which allows to cleanup the CPUID evaluation code.
This is a temporary workaround until the larger topology management is in place, which makes all of this logical management mechanics obsolete.
--- arch/x86/kernel/smpboot.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-)
arch/x86/kernel/smpboot.c +23 -10
@@ -124,7 +124,20 @@ struct mwait_cpu_dead {*/ static DEFINE_PER_CPU_ALIGNED(struct mwait_cpu_dead, mwait_cpu_dead); -/* Logical package management. We might want to allocate that dynamically */ +/* Logical package management. */ +struct logical_maps { +u32 phys_pkg_id; +u32 phys_die_id; +u32 logical_pkg_id; +u32 logical_die_id; +}; + +/* Temporary workaround until the full topology mechanics is in place */ +static DEFINE_PER_CPU_READ_MOSTLY(struct logical_maps, logical_maps) = { + .phys_pkg_id =U32_MAX , + .phys_die_id =U32_MAX , +}; +unsigned int __max_logical_packages__read_mostly ;EXPORT_SYMBOL (__max_logical_packages);static unsigned int logical_packages__read_mostly ;
@@ -345,10 +358,8 @@ int topology_phys_to_logical_pkg(unsigneint cpu;for_each_possible_cpu (cpu) { -struct cpuinfo_x86 *c = &cpu_data (cpu); - -if (c->initialized && c->topo.pkg_id == phys_pkg) -return c->topo.logical_pkg_id; +if (per_cpu (logical_maps.phys_pkg_id, cpu) == phys_pkg) +return per_cpu (logical_maps.logical_pkg_id, cpu); }return -1 ; }
@@ -366,11 +377,9 @@ static int topology_phys_to_logical_die(int cpu, proc_id =cpu_data (cur_cpu).topo.pkg_id;for_each_possible_cpu (cpu) { -struct cpuinfo_x86 *c = &cpu_data (cpu); - -if (c->initialized && c->topo.die_id == die_id && - c->topo.pkg_id == proc_id) -return c->topo.logical_die_id; +if (per_cpu (logical_maps.phys_pkg_id, cpu) == proc_id && +per_cpu (logical_maps.phys_die_id, cpu) == die_id) +return per_cpu (logical_maps.logical_die_id, cpu); }return -1 ; }
@@ -395,6 +404,8 @@ int topology_update_package_map(unsigned cpu, pkg, new); } found: +per_cpu (logical_maps.phys_pkg_id, cpu) = pkg; +per_cpu (logical_maps.logical_pkg_id, cpu) = new;cpu_data (cpu).topo.logical_pkg_id = new;return 0 ; }
@@ -418,6 +429,8 @@ int topology_update_die_map(unsigned int cpu, die, new); } found: +per_cpu (logical_maps.phys_die_id, cpu) = die; +per_cpu (logical_maps.logical_die_id, cpu) = new;cpu_data (cpu).topo.logical_die_id = new;return 0 ; }
[tip: x86/core] x86/cpu/topology: Cure the abuse of cpuinfo for persisting logical ids
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 90781f0c4c41a41043e39d9acbc66cc3644769ba Gitweb: https://git.kernel.org/tip/90781f0c4c41a41043e39d9acbc66cc3644769ba Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:46 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:19 +02:00
x86/cpu/topology: Cure the abuse of cpuinfo for persisting logical ids
Per CPU cpuinfo is used to persist the logical package and die IDs. That's really not the right place simply because cpuinfo is subject to be reinitialized when a CPU goes through an offline/online cycle.
This works by chance today, but that's far from correct and neither obvious nor documented.
Add a per cpu datastructure which persists those logical IDs, which allows to cleanup the CPUID evaluation code.
This is a temporary workaround until the larger topology management is in place, which makes all of this logical management mechanics obsolete.
--- arch/x86/kernel/smpboot.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-)
arch/x86/kernel/smpboot.c +23 -10
@@ -124,7 +124,20 @@ struct mwait_cpu_dead {*/ static DEFINE_PER_CPU_ALIGNED(struct mwait_cpu_dead, mwait_cpu_dead); -/* Logical package management. We might want to allocate that dynamically */ +/* Logical package management. */ +struct logical_maps { +u32 phys_pkg_id; +u32 phys_die_id; +u32 logical_pkg_id; +u32 logical_die_id; +}; + +/* Temporary workaround until the full topology mechanics is in place */ +static DEFINE_PER_CPU_READ_MOSTLY(struct logical_maps, logical_maps) = { + .phys_pkg_id =U32_MAX , + .phys_die_id =U32_MAX , +}; +unsigned int __max_logical_packages__read_mostly ;EXPORT_SYMBOL (__max_logical_packages);static unsigned int logical_packages__read_mostly ;
@@ -337,10 +350,8 @@ int topology_phys_to_logical_pkg(unsigned int phys_pkg)int cpu;for_each_possible_cpu (cpu) { -struct cpuinfo_x86 *c = &cpu_data (cpu); - -if (c->initialized && c->topo.pkg_id == phys_pkg) -return c->topo.logical_pkg_id; +if (per_cpu (logical_maps.phys_pkg_id, cpu) == phys_pkg) +return per_cpu (logical_maps.logical_pkg_id, cpu); }return -1 ; }
@@ -358,11 +369,9 @@ static int topology_phys_to_logical_die(unsigned int die_id, unsigned int cur_cpint cpu, proc_id =cpu_data (cur_cpu).topo.pkg_id;for_each_possible_cpu (cpu) { -struct cpuinfo_x86 *c = &cpu_data (cpu); - -if (c->initialized && c->topo.die_id == die_id && - c->topo.pkg_id == proc_id) -return c->topo.logical_die_id; +if (per_cpu (logical_maps.phys_pkg_id, cpu) == proc_id && +per_cpu (logical_maps.phys_die_id, cpu) == die_id) +return per_cpu (logical_maps.logical_die_id, cpu); }return -1 ; }
@@ -387,6 +396,8 @@ int topology_update_package_map(unsigned int pkg, unsigned int cpu) cpu, pkg, new); } found: +per_cpu (logical_maps.phys_pkg_id, cpu) = pkg; +per_cpu (logical_maps.logical_pkg_id, cpu) = new;cpu_data (cpu).topo.logical_pkg_id = new;return 0 ; }
@@ -410,6 +421,8 @@ int topology_update_die_map(unsigned int die, unsigned int cpu) cpu, die, new); } found: +per_cpu (logical_maps.phys_die_id, cpu) = die; +per_cpu (logical_maps.logical_die_id, cpu) = new;cpu_data (cpu).topo.logical_die_id = new;return 0 ; }
PATCH v4 22/41 x86/cpu: Provide debug interface
In reply to Thomas GleixnerProvide debug files which dump the topology related information of cpuinfo_x86. This is useful to validate the upcoming conversion of the topology evaluation for correctness or bug compatibility.
---
V2: Don't return ENODEV when offline and make online a field.
--- arch/x86/kernel/cpu/Makefile | 2 + arch/x86/kernel/cpu/debugfs.c | 58 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+)
arch/x86/kernel/cpu/Makefile +2 -0
@@ -54,6 +54,8 @@ obj-$(CONFIG_X86_LOCAL_APIC) += perfctr obj-$(CONFIG_HYPERVISOR_GUEST) += vmware.o hypervisor.o mshyperv.o obj-$(CONFIG_ACRN_GUEST) += acrn.o +obj-$(CONFIG_DEBUG_FS) += debugfs.o + quiet_cmd_mkcapflags = MKCAP $@ cmd_mkcapflags = $(CONFIG_SHELL) $(srctree)/$(src)/mkcapflags.sh $@ $^
arch/x86/kernel/cpu/debugfs.c new file +58 -0
58 lines not on this page · raw message
[tip: x86/core] x86/cpu: Provide debug interface
The following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: 48525fd1ea1cfa059a580e77b10ea8790914efa2 Gitweb: https://git.kernel.org/tip/48525fd1ea1cfa059a580e77b10ea8790914efa2 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 14 Aug 2023 10:18:47 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 10 Oct 2023 14:38:19 +02:00
x86/cpu: Provide debug interface
Provide debug files which dump the topology related information of cpuinfo_x86. This is useful to validate the upcoming conversion of the topology evaluation for correctness or bug compatibility.
--- arch/x86/kernel/cpu/Makefile | 2 +- arch/x86/kernel/cpu/debugfs.c | 58 ++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+) create mode 100644 arch/x86/kernel/cpu/debugfs.c
arch/x86/kernel/cpu/Makefile +2 -0
@@ -54,6 +54,8 @@ obj-$(CONFIG_X86_LOCAL_APIC) += perfctr-watchdog.o obj-$(CONFIG_HYPERVISOR_GUEST) += vmware.o hypervisor.o mshyperv.o obj-$(CONFIG_ACRN_GUEST) += acrn.o +obj-$(CONFIG_DEBUG_FS) += debugfs.o + quiet_cmd_mkcapflags = MKCAP $@ cmd_mkcapflags = $(CONFIG_SHELL) $(srctree)/$(src)/mkcapflags.sh $@ $^
arch/x86/kernel/cpu/debugfs.c new file +58 -0
58 lines not on this page · raw message
PATCH v4 23/41 x86/cpu: Provide cpuid_read() et al.
In reply to Thomas GleixnerProvide a few helper functions to read CPUID leafs or individual registers into a data structure without requiring unions.
--- arch/x86/include/asm/cpuid.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
arch/x86/include/asm/cpuid.h +36 -0
@@ -127,6 +127,42 @@ static inline unsigned int cpuid_edx(unsreturn edx; } +static inline void __cpuid_read (unsigned int leaf,unsigned int subleaf,u32 *regs) +{ + regs[CPUID_EAX ] = leaf; + regs[CPUID_ECX ] = subleaf; +__cpuid (regs, regs +1 , regs +2 , regs +3 ); +} + +#define cpuid_subleaf (leaf, subleaf, regs) { \ + BUILD_BUG_ON(sizeof(*(regs)) != 16); \ + __cpuid_read(leaf, subleaf, (u32 *)(regs)); \ +} + +#define cpuid_leaf (leaf, regs) { \ + BUILD_BUG_ON(sizeof(*(regs)) != 16); \ + __cpuid_read(leaf, 0, (u32 *)(regs)); \ +} + +static inline void __cpuid_read_reg (unsigned int leaf,unsigned int subleaf, +enum cpuid_regs_idx regidx,u32 *reg) +{ +u32 regs[4 ]; + +__cpuid_read (leaf, subleaf, regs); + *reg = regs[regidx]; +} + +#define cpuid_subleaf_reg (leaf, subleaf, regidx, reg) { \ + BUILD_BUG_ON(sizeof(*(reg)) != 4); \ + __cpuid_read_reg(leaf, subleaf, regidx, (u32 *)(reg)); \ +} + +#define cpuid_leaf_reg (leaf, regidx, reg) { \ + BUILD_BUG_ON(sizeof(*(reg)) != 4); \ + __cpuid_read_reg(leaf, 0, regidx, (u32 *)(reg)); \ +} + static __always_inline bool cpuid_function_is_indexed(u32 function) {switch (function) {
PATCH v4 24/41 x86/cpu: Provide cpu_init/parse_topology()
In reply to Thomas GleixnerTopology evaluation is a complete disaster and impenetrable mess. It's scattered all over the place with some vendor implementations doing early evaluation and some not. The most horrific part is the permanent overwriting of smt_max_siblings and __max_die_per_package, instead of establishing them once on the boot CPU and validating the result on the APs.
The goals are:
- One topology evaluation entry point
- Proper sharing of pointlessly duplicated code
- Proper structuring of the evaluation logic and preferences.
- Evaluating important system wide information only once on the boot CPU
- Making the 0xb/0x1f leaf parsing less convoluted and actually fixing
the short comings of leaf 0x1f evaluation.
Start to consolidate the topology evaluation code by providing the entry points for the early boot CPU evaluation and for the final parsing on the boot CPU and the APs.
Move the trivial pieces into that new code:
- The initialization of cpuinfo_x86::topo
- The evaluation of CPUID leaf 1, which presets topo::initial_apicid
- topo_apicid is set to topo::initial_apicid when invoked from early boot. When invoked for the final evaluation on the boot CPU it reads the actual APIC ID, which makes apic_get_initial_apicid() obsolete once everything is converted over.
Provide a temporary helper function topo_converted() which shields off the not yet converted CPU vendors from invoking code which would break them. This shielding covers all vendor CPUs which support SMP, but not the historical pure UP ones as they only need the topology info init and eventually the initial APIC initialization.
Provide two new members in cpuinfo_x86::topo to store the maximum number of SMT siblings and the number of dies per package and add them to the debugfs readout. These two members will be used to populate this information on the boot CPU and to validate the APs against it.
---
V2: Make core ID package relativ not relative to the next level - Rui
--- arch/x86/include/asm/topology.h | 19 +++ arch/x86/kernel/cpu/Makefile | 3 arch/x86/kernel/cpu/common.c | 23 +--- arch/x86/kernel/cpu/cpu.h | 6 + arch/x86/kernel/cpu/debugfs.c | 37 ++++++ arch/x86/kernel/cpu/topology.h | 36 ++++++ arch/x86/kernel/cpu/topology_common.c | 188 ++++++++++++++++++++++++++++++++++ 7 files changed, 295 insertions(+), 17 deletions(-)
arch/x86/include/asm/topology.h +19 -0
@@ -102,6 +102,25 @@ static inline void setup_node_to_cpumask#include <asm-generic/topology.h> +/* Topology information */ +enum x86_topology_domains { +TOPO_SMT_DOMAIN , +TOPO_CORE_DOMAIN , +TOPO_MODULE_DOMAIN , +TOPO_TILE_DOMAIN , +TOPO_DIE_DOMAIN , +TOPO_PKG_DOMAIN , +TOPO_ROOT_DOMAIN , +TOPO_MAX_DOMAIN , +}; + +struct x86_topology_system { +unsigned int dom_shifts[TOPO_MAX_DOMAIN ]; +unsigned int dom_size[TOPO_MAX_DOMAIN ]; +}; + +extern struct x86_topology_system x86_topo_system; +extern const struct cpumask *cpu_coregroup_mask (int cpu);extern const struct cpumask *cpu_clustergroup_mask (int cpu);
arch/x86/kernel/cpu/Makefile +2 -1
@@ -17,7 +17,8 @@ KMSAN_SANITIZE_common.o := n # As above, instrumenting secondary CPU boot code causes boot hangs. KCSAN_SANITIZE_common.o := n -obj-y := cacheinfo.o scattered.o topology.o +obj-y := cacheinfo.o scattered.o +obj-y += topology_common.o topology.o obj-y += common.o obj-y += rdrand.o obj-y += match.o
arch/x86/kernel/cpu/common.c +7 -16
@@ -1553,6 +1553,8 @@ static void __init early_identify_cpu(stsetup_force_cpu_cap (X86_FEATURE_CPUID );cpu_parse_early_param (); +cpu_init_topology (c); +if (this_cpu->c_early_init) this_cpu->c_early_init (c);
@@ -1563,6 +1565,7 @@ static void __init early_identify_cpu(st this_cpu->c_bsp_init (c); }else {setup_clear_cpu_cap (X86_FEATURE_CPUID ); +cpu_init_topology (c); }setup_force_cpu_cap (X86_FEATURE_ALWAYS );
@@ -1708,18 +1711,6 @@ static void generic_identify(struct cpuiget_cpu_address_sizes (c); -if (c->cpuid_level >=0x00000001 ) { - c->topo.initial_apicid = (cpuid_ebx (1 ) >>24 ) &0xFF ; -#ifdef CONFIG_X86_32 -# ifdef CONFIG_SMP - c->topo.apicid = apic->phys_pkg_id (c->topo.initial_apicid,0 ); -# else - c->topo.apicid = c->topo.initial_apicid; -# endif -#endif - c->topo.pkg_id = c->topo.initial_apicid; - } -get_model_name (c);/* Default name */ /*
@@ -1778,9 +1769,6 @@ static void identify_cpu(struct cpuinfo_ c->x86_model_id[0 ] ='\0' ;/* Unset */ c->x86_max_cores =1 ; c->x86_coreid_bits =0 ; - c->topo.cu_id =0xff ; - c->topo.llc_id =BAD_APICID ; - c->topo.l2c_id =BAD_APICID ;#ifdef CONFIG_X86_64 c->x86_clflush_size =64 ; c->x86_phys_bits =36 ;
@@ -1799,6 +1787,8 @@ static void identify_cpu(struct cpuinfo_generic_identify (c); +cpu_parse_topology (c); +if (this_cpu->c_identify) this_cpu->c_identify (c);
@@ -1806,7 +1796,8 @@ static void identify_cpu(struct cpuinfo_apply_forced_caps (c);#ifdef CONFIG_X86_64 - c->topo.apicid = apic->phys_pkg_id (c->topo.initial_apicid,0 ); +if (!topo_is_converted (c)) + c->topo.apicid = apic->phys_pkg_id (c->topo.initial_apicid,0 );#endif /*
arch/x86/kernel/cpu/cpu.h +6 -0
@@ -2,6 +2,11 @@ #ifndef ARCH_X86_CPU_H #define ARCH_X86_CPU_H +#include <asm/cpu.h> +#include <asm/topology.h> + +#include "topology.h" + /* attempt to consolidate cpu attributes */ struct cpu_dev { const char *c_vendor;
@@ -95,4 +100,5 @@ static inline bool spectre_v2_in_eibrs_m mode ==SPECTRE_V2_EIBRS_RETPOLINE || mode == SPECTRE_V2_EIBRS_LFENCE; } +#endif /* ARCH_X86_CPU_H */
arch/x86/kernel/cpu/debugfs.c +37 -0
@@ -5,6 +5,8 @@#include <asm/apic.h> #include <asm/processor.h> +#include "cpu.h" +static int cpu_debug_show (struct seq_file *m,void *p) {unsigned long cpu = (unsigned long )m->private;
@@ -42,12 +44,47 @@ static const struct file_operations dfs_ .release = single_release, }; +static int dom_debug_show (struct seq_file *m,void *p) +{ +static const char *domain_names[TOPO_ROOT_DOMAIN ] = { + [TOPO_SMT_DOMAIN ] ="Thread" , + [TOPO_CORE_DOMAIN ] ="Core" , + [TOPO_MODULE_DOMAIN ] ="Module" , + [TOPO_TILE_DOMAIN ] ="Tile" , + [TOPO_DIE_DOMAIN ] ="Die" , + [TOPO_PKG_DOMAIN ] ="Package" , + }; +unsigned int dom, nthreads =1 ; + +for (dom =0 ; dom <TOPO_ROOT_DOMAIN ; dom++) { + nthreads *= x86_topo_system.dom_size[dom]; +seq_printf (m,"domain: %-10s shift: %u dom_size: %5u max_threads: %5u\n" , + domain_names[dom], x86_topo_system.dom_shifts[dom], + x86_topo_system.dom_size[dom], nthreads); + } +return 0 ; +} + +static int dom_debug_open (struct inode *inode,struct file *file) +{ +return single_open (file, dom_debug_show, inode->i_private); +} + +static const struct file_operations dfs_dom_ops = { + .open = dom_debug_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +static __init int cpu_init_debugfs (void ) {struct dentry *dir, *base =debugfs_create_dir ("topo" , arch_debugfs_dir);unsigned long id;char name[10 ]; +debugfs_create_file ("domains" ,0444 , base,NULL , &dfs_dom_ops); + dir =debugfs_create_dir ("cpus" , base);for_each_possible_cpu (id) {sprintf (name,"%lu" , id);
arch/x86/kernel/cpu/topology.h new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef ARCH_X86_TOPOLOGY_H +#define ARCH_X86_TOPOLOGY_H + +struct topo_scan { +struct cpuinfo_x86 *c; +unsigned int dom_shifts[TOPO_MAX_DOMAIN ]; +unsigned int dom_ncpus[TOPO_MAX_DOMAIN ]; +}; + +bool topo_is_converted (struct cpuinfo_x86 *c); +void cpu_init_topology (struct cpuinfo_x86 *c); +void cpu_parse_topology (struct cpuinfo_x86 *c); +void topology_set_dom (struct topo_scan *tscan,enum x86_topology_domains dom, +unsigned int shift,unsigned int ncpus); + +static inline u32 topo_shift_apicid (u32 apicid,enum x86_topology_domains dom) +{ +if (dom ==TOPO_SMT_DOMAIN ) +return apicid; +return apicid >> x86_topo_system.dom_shifts[dom -1 ]; +} + +static inline u32 topo_relative_domain_id (u32 apicid,enum x86_topology_domains dom) +{ +if (dom !=TOPO_SMT_DOMAIN ) + apicid >>= x86_topo_system.dom_shifts[dom -1 ]; +return apicid & (x86_topo_system.dom_size[dom] -1 ); +} + +static inline u32 topo_domain_mask (enum x86_topology_domains dom) +{ +return (1U << x86_topo_system.dom_shifts[dom]) -1 ; +} + +#endif /* ARCH_X86_TOPOLOGY_H */
arch/x86/kernel/cpu/topology_common.c new file +188 -0
188 lines not on this page · raw message
Re: [patch V4 24/41] x86/cpu: Provide cpu_init/parse_topology()
Hello Thomas,
Quoted 70 lines · Thomas Gleixner
Topology evaluation is a complete disaster and impenetrable mess. It's scattered all over the place with some vendor implementations doing early evaluation and some not. The most horrific part is the permanent overwriting of
smt_max_siblingsand__max_die_per_package, instead of establishing them once on the boot CPU and validating the result on the APs.The goals are:
- One topology evaluation entry point
- Proper sharing of pointlessly duplicated code
- Proper structuring of the evaluation logic and preferences.
- Evaluating important system wide information only once on the boot CPU
- Making the 0xb/0x1f leaf parsing less convoluted and actually fixing
the short comings of leaf 0x1f evaluation.Start to consolidate the topology evaluation code by providing the entry points for the early boot CPU evaluation and for the final parsing on the boot CPU and the APs.
Move the trivial pieces into that new code:
- The initialization of
cpuinfo_x86::topo- The evaluation of CPUID leaf 1, which presets
topo::initial_apicid-
topo_apicidis set totopo::initial_apicidwhen invoked from early boot. When invoked for the final evaluation on the boot CPU it reads the actual APIC ID, which makesapic_get_initial_apicid()obsolete once everything is converted over.Provide a temporary helper function
topo_converted()which shields off the not yet converted CPU vendors from invoking code which would break them. This shielding covers all vendor CPUs which support SMP, but not the historical pure UP ones as they only need the topology info init and eventually the initial APIC initialization.Provide two new members in
cpuinfo_x86::topoto store the maximum number of SMT siblings and the number of dies per package and add them to the debugfs readout. These two members will be used to populate this information on the boot CPU and to validate the APs against it.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]>---
V2: Make core ID package relativ not relative to the next level - Rui--- arch/x86/include/asm/topology.h | 19 +++ arch/x86/kernel/cpu/Makefile | 3 arch/x86/kernel/cpu/common.c | 23 +--- arch/x86/kernel/cpu/cpu.h | 6 + arch/x86/kernel/cpu/debugfs.c | 37 ++++++ arch/x86/kernel/cpu/topology.h | 36 ++++++ arch/x86/kernel/cpu/topology_common.c | 188 ++++++++++++++++++++++++++++++++++ 7 files changed, 295 insertions(+), 17 deletions(-)arch/x86/include/asm/topology.h +1
-0@@ -102,6 +102,25 @@ static inline void setup_node_to_cpumask#include <asm-generic/topology.h> +/* Topology information */
arch/x86/include/asm/topology.h static inline void setup_node_to_cpumask · line 115
Quoted 10 lines
arch/x86/include/asm/topology.h +10
-0+enum x86_topology_domains { +TOPO_SMT_DOMAIN , +TOPO_CORE_DOMAIN , +TOPO_MODULE_DOMAIN , +TOPO_TILE_DOMAIN , +TOPO_DIE_DOMAIN , +TOPO_PKG_DOMAIN , +TOPO_ROOT_DOMAIN , +TOPO_MAX_DOMAIN , +};
Since these enums come from the description of level type of CPUID leaf 0x1f, can we have a short description clarifying what each signify. This will also help clarify the mappings for AMD's extended CPUID leaf 0x80000026 (specifically for CCX and CCD level types). I had following in my mind:
arch/x86/include/asm/topology.h +36 -0
@@ -104,12 +104,48 @@ static inline void setup_node_to_cpumask_map(void) { }/* Topology information */ enum x86_topology_domains { +/* Represents group of threads within a core */ TOPO_SMT_DOMAIN , +/* +* Represents group of cores within an instance of +* the next domain +*/ TOPO_CORE_DOMAIN , +/* +* If exists, represents a group of modules within +* an instance of the next domain +*/ TOPO_MODULE_DOMAIN , +/* +* If exists, represents a group of tiles within +* an instance of the next domain +* +* On Intel: This level contains a group of Tile +* type as described by CPUID leaf 0x1f +* +* On AMD: This is the group of "Complex" type +* instances as described by CPUID leaf +* 0x8000_0026 +*/ TOPO_TILE_DOMAIN , +/* +* If exists, represents a group of dies within an +* instance of the next domain +* +* On Intel: This level contains group of Die +* type as described by CPUID leaf 0x1f +* +* On AMD: This is the group of "CCD (Die)" +* type instances as described by CPUID leaf +* 0x8000_0026 +*/ TOPO_DIE_DOMAIN , +/* +* If exists, represents a group of packages +* within the root domain +*/ TOPO_PKG_DOMAIN , +/* Topmost domain with a singular instance */ TOPO_ROOT_DOMAIN ,TOPO_MAX_DOMAIN , };
--
Quoted 3 lines
[..snip..]
--
Thanks and Regards,
Prateek
Re: [patch V4 24/41] x86/cpu: Provide cpu_init/parse_topology()
Prateek!
Quoted 7 lines · K. Prateek Nayak
On 8/14/2023 2:24 PM, Thomas Gleixner wrote:
Since these enums come from the description of level type of CPUID leaf
0x1f, can we have a short description clarifying what each signify. This will also help clarify the mappings for AMD's extended CPUID leaf0x80000026(specifically for CCX and CCD level types). I had following in my mind:
Makes sense.
Quoted 24 lines
arch/x86/include/asm/topology.h +22
-0TOPO_MODULE_DOMAIN , +/* +* If exists, represents a group of tiles within +* an instance of the next domain +* +* On Intel: This level contains a group of Tile +* type as described by CPUID leaf 0x1f +* +* On AMD: This is the group of "Complex" type +* instances as described by CPUID leaf +* 0x8000_0026 +*/ TOPO_TILE_DOMAIN , +/* +* If exists, represents a group of dies within an +* instance of the next domain +* +* On Intel: This level contains group of Die +* type as described by CPUID leaf 0x1f +* +* On AMD: This is the group of "CCD (Die)" +* type instances as described by CPUID leaf +* 0x8000_0026 + */
arch/x86/include/asm/topology.h static inline void setup_node_to_cpumask_map(void) { } · line 151
Quoted 10 lines
arch/x86/include/asm/topology.h +5
-0TOPO_DIE_DOMAIN , +/* +* If exists, represents a group of packages +* within the root domain +*/ TOPO_PKG_DOMAIN , +/* Topmost domain with a singular instance */ TOPO_ROOT_DOMAIN , TOPO_MAX_DOMAIN, };
Now this begs the obvious question what the actual meaning of these domains is and what's their relevance for the kernel.
It's probably undisputed what SMT/CORE mean and what their relevance is. The PKG/DIE domains are pretty clear too.
Now we have:
MODULE (Intel only)
TILE Intel, AMD names it "Complex"
So here are the questions:
- is TILE to "Complex" the proper mapping?
- which information is conveyed by MODULE and TILE?
- Are these really different between AMD and Intel or is this some naming convention issue which needs to be resolved?
Thanks,
tglx
Re: [patch V4 24/41] x86/cpu: Provide cpu_init/parse_topology()
Quoted 2 lines · Thomas Gleixner
- Are these really different between AMD and Intel or is this some naming convention issue which needs to be resolved?
if you want a 3rd name that neither uses "chiplet" could work I suppose
Re: [patch V4 24/41] x86/cpu: Provide cpu_init/parse_topology()
In reply to Thomas GleixnerHello Thomas,
Quoted 51 lines · Thomas Gleixner
Prateek!
Quoted 7 lines · K. Prateek Nayak
On 8/14/2023 2:24 PM, Thomas Gleixner wrote:
Since these enums come from the description of level type of CPUID leaf
0x1f, can we have a short description clarifying what each signify. This will also help clarify the mappings for AMD's extended CPUID leaf0x80000026(specifically for CCX and CCD level types). I had following in my mind:Makes sense.
Quoted 24 lines
arch/x86/include/asm/topology.h +22
-0TOPO_MODULE_DOMAIN , +/* +* If exists, represents a group of tiles within +* an instance of the next domain +* +* On Intel: This level contains a group of Tile +* type as described by CPUID leaf 0x1f +* +* On AMD: This is the group of "Complex" type +* instances as described by CPUID leaf +* 0x8000_0026 +*/ TOPO_TILE_DOMAIN , +/* +* If exists, represents a group of dies within an +* instance of the next domain +* +* On Intel: This level contains group of Die +* type as described by CPUID leaf 0x1f +* +* On AMD: This is the group of "CCD (Die)" +* type instances as described by CPUID leaf +* 0x8000_0026 + */arch/x86/include/asm/topology.h static inline void setup_node_to_cpumask_map(void) { } · line 151
Quoted 10 lines
arch/x86/include/asm/topology.h +5
-0TOPO_DIE_DOMAIN , +/* +* If exists, represents a group of packages +* within the root domain +*/ TOPO_PKG_DOMAIN , +/* Topmost domain with a singular instance */ TOPO_ROOT_DOMAIN , TOPO_MAX_DOMAIN, };Now this begs the obvious question what the actual meaning of these domains is and what's their relevance for the kernel.
Quoted 2 lines
It's probably undisputed what SMT/CORE mean and what their relevance is. The PKG/DIE domains are pretty clear too.
Yup! Those seem to be clear.
Quoted 6 lines
Now we have:
MODULE (Intel only)
TILE Intel, AMD names it "Complex"
So here is my interpretation of 0x1f since I could not find much in the SDM for these level types. The interpretations are based on some of the past discussions in the community (I'll give the relevant links below).
Intel Jacobsville has a group of cores sharing the L2 cache which the scheduler currently models as a cluster. Some information about the same has been shared by Tim Chen in:
https://lore.kernel.org/lkml/[email protected]/
Logically, this is what a module should map to IMO but Intel folks can clarify.
In AMD processors, Complex (CCX) refers to chiplet where all the CPUs share the same Last Level Cache (L3). Tiles are slightly different on Intel since they do not necessarily mark the LLC boundary.
As suggested by Arjan on the thread, perhaps "chiplet" could be used as a neutral term that describes Tiles on Intel and CCX on AMD.
With this information:
Quoted 4 lines
So here are the questions:
- is TILE to "Complex" the proper mapping?
Since "Module", based on my description above, translates to a group of cores sharing the L2 cache, and since CCD is interpreted as a "Die", that leaves us with "Complex" mapping to a "Tile". Chiplet could be a neutral term as suggested by Arjan.
Quoted 2 lines
- which information is conveyed by MODULE and TILE?
Module: Groups of cores sharing L2 cache (Purely my
interpretation)
Tile: Chiplet. On AMD it also marks the L3 boundary.
Quoted 3 lines
- Are these really different between AMD and Intel or is this some naming convention issue which needs to be resolved?
They do have different characteristics since, on Sapphire Rapids, the LLC is at a socket boundary despite having multiple tiles. (Please correct me if I'm wrong, I'm going off of llc_id shared in this report by Qiuxu Zhuo -
https://lore.kernel.org/all/[email protected]/)
Quoted 5 lines
Thanks,
tglx
Most of this is based on my interpretation. Please correct me if I've misinterpreted anything, especially the Intel bits :)
--
Thanks and Regards,
Prateek
Re: [patch V4 24/41] x86/cpu: Provide cpu_init/parse_topology()
Quoted 8 lines · K Prateek Nayak
Quoted 2 lines
- Are these really different between AMD and Intel or is this some naming convention issue which needs to be resolved?
They do have different characteristics since, on Sapphire Rapids, the LLC is at a socket boundary despite having multiple tiles. (Please correct me if I'm wrong, I'm going off of
llc_idshared in this report by Qiuxu Zhuo -
https://lore.kernel.org/all/[email protected]/)
Sapphire reports itself as 1 tile though (since logically it is) as far as I know
Re: [patch V4 24/41] x86/cpu: Provide cpu_init/parse_topology()
Hello Arjan,
Quoted 12 lines · Arjan van de Ven
Quoted 8 lines · K Prateek Nayak
Quoted 2 lines
- Are these really different between AMD and Intel or is this some naming convention issue which needs to be resolved?
They do have different characteristics since, on Sapphire Rapids, the LLC is at a socket boundary despite having multiple tiles. (Please correct me if I'm wrong, I'm going off of
llc_idshared in this report by Qiuxu Zhuo -
https://lore.kernel.org/all/[email protected]/)Sapphire reports itself as 1 tile though (since logically it is) as far as I know
I believe there are some variants with multiple tiles, at least the following press-release suggests that:
specifically "... combining up to four Intel 7-built tiles on a single package, connected using Intel EMIB ...". Perhaps the one from Qiuxu Zhuo's report does not contain multiple tiles.
But coming back to the characteristics, would it be safe to say "Tile" would marks the LLC (L3) boundary if 0x1f reports multiple tiles in a die?
--
Thanks and Regards,
Prateek
Peter Zijlstra
maintainerRe: [patch V4 24/41] x86/cpu: Provide cpu_init/parse_topology()
Quoted 16 lines · K Prateek Nayak
Hello Arjan,
Quoted 12 lines · Arjan van de Ven
Quoted 8 lines · K Prateek Nayak
Quoted 2 lines
- Are these really different between AMD and Intel or is this some naming convention issue which needs to be resolved?
They do have different characteristics since, on Sapphire Rapids, the LLC is at a socket boundary despite having multiple tiles. (Please correct me if I'm wrong, I'm going off of
llc_idshared in this report by Qiuxu Zhuo -
https://lore.kernel.org/all/[email protected]/)Sapphire reports itself as 1 tile though (since logically it is) as far as I know
Quoted 8 lines
I believe there are some variants with multiple tiles, at least the following press-release suggests that:
specifically "... combining up to four Intel 7-built tiles on a single package, connected using Intel EMIB ...". Perhaps the one from Qiuxu Zhuo's report does not contain multiple tiles.
I think what Arjan was saying that despite them being build using multipe physical tiles, they describe themselves, in the topology leave, as being a single tile.
Re: [patch V4 24/41] x86/cpu: Provide cpu_init/parse_topology()
Quoted 22 lines · Peter Zijlstra
Quoted 21 lines · K Prateek Nayak
Hello Arjan,
Quoted 12 lines · Arjan van de Ven
Quoted 8 lines · K Prateek Nayak
Quoted 2 lines
- Are these really different between AMD and Intel or is this some naming convention issue which needs to be resolved?
They do have different characteristics since, on Sapphire Rapids, the LLC is at a socket boundary despite having multiple tiles. (Please correct me if I'm wrong, I'm going off of
llc_idshared in this report by Qiuxu Zhuo -
https://lore.kernel.org/all/[email protected]/)Sapphire reports itself as 1 tile though (since logically it is) as far as I know
I believe there are some variants with multiple tiles, at least the following press-release suggests that:
Quoted 7 lines
Quoted 3 lines
specifically "... combining up to four Intel 7-built tiles on a single package, connected using Intel EMIB ...". Perhaps the one from Qiuxu Zhuo's report does not contain multiple tiles.
I think what Arjan was saying that despite them being build using multipe physical tiles, they describe themselves, in the topology leave, as being a single tile.
and more than that -- from a software perspective, they truely act as if they are 1 tile (you can do SNC to break that sort of but that's not default and has its own list of downsides)
Re: [patch V4 24/41] x86/cpu: Provide cpu_init/parse_topology()
Hello Arjan, Peter,
Quoted 27 lines · Arjan van de Ven
Quoted 26 lines · Peter Zijlstra
Quoted 24 lines · K Prateek Nayak
Hello Arjan,
Quoted 12 lines · Arjan van de Ven
Quoted 8 lines · K Prateek Nayak
Quoted 2 lines
- Are these really different between AMD and Intel or is this some naming convention issue which needs to be resolved?
They do have different characteristics since, on Sapphire Rapids, the LLC is at a socket boundary despite having multiple tiles. (Please correct me if I'm wrong, I'm going off of
llc_idshared in this report by Qiuxu Zhuo -
https://lore.kernel.org/all/[email protected]/)Sapphire reports itself as 1 tile though (since logically it is) as far as I know
I believe there are some variants with multiple tiles, at least the following press-release suggests that:
specifically "... combining up to four Intel 7-built tiles on a single package, connected using Intel EMIB ...". Perhaps the one from Qiuxu Zhuo's report does not contain multiple tiles.
Quoted 5 lines
Quoted 3 lines
I think what Arjan was saying that despite them being build using multipe physical tiles, they describe themselves, in the topology leave, as being a single tile.
and more than that -- from a software perspective, they truely act as if they are 1 tile
If possible, can you please elaborate on the "software perspective". Say CPUID leaf 0x1f reports multiple tile, would the data access latency or cache to cache latency see a noticeable difference?
I would like to understand what the characteristics of a "Tile" are and whether they are similar to AMD's CCX instances discoverable by AMD's extended CPUID leaf 0x80000026. That way, in future, when the generic topology is used by other subsystems, the data from "TOPO_TILE_DOMAIN" can be used generically for both Intel and AMD.
Quoted 2 lines
(you can do SNC to break that sort of but that's not default and has its own list of downsides)
Thank you for giving the basic clarification of the Tile instances.
--
Thanks and Regards,
Prateek
Re: [patch V4 24/41] x86/cpu: Provide cpu_init/parse_topology()
Quoted 9 lines · K Prateek Nayak
If possible, can you please elaborate on the "software perspective". Say CPUID leaf
0x1freports multiple tile, would the data access latency or cache to cache latency see a noticeable difference?I would like to understand what the characteristics of a "Tile" are and whether they are similar to AMD's CCX instances discoverable by AMD's extended CPUID leaf
0x80000026. That way, in future, when the generic topology is used by other subsystems, the data from "TOPO_TILE_DOMAIN" can be used generically for both Intel and AMD.
I'm not convinced that this is possible. The meaning of these elements is unfortunately not cast in stone, so the association of e.g. cache boundaries is not necessarily static accross a larger range of CPU generations..
We really need to differentiate performance characteristic, hardware feature scope, power management scope etc. and create abstractions which are actually useful for kernel facilities and user space.
From a performance perspective it's irrelevant whether the scope is TILE or whatever. The information needed is the hierarchy, the performance characteristics of a segment in the hierarchy and the costs for cross segment access and cross segment migration.
For hardware features like perf the information needed is what the scope of a particular resource is. Again it's not necessarily useful to know what particular domain type it is.
Powermanagement does not care about the particual type either. It needs to know which scopes affect c-states, clock speeds ... to give the scheduler informtion of how to steer workloads in the most efficient way.
Thanks,
tglx
Re: [patch V4 24/41] x86/cpu: Provide cpu_init/parse_topology()
Hello Thomas,
Quoted 16 lines · Thomas Gleixner
Quoted 9 lines · K Prateek Nayak
If possible, can you please elaborate on the "software perspective". Say CPUID leaf
0x1freports multiple tile, would the data access latency or cache to cache latency see a noticeable difference?I would like to understand what the characteristics of a "Tile" are and whether they are similar to AMD's CCX instances discoverable by AMD's extended CPUID leaf
0x80000026. That way, in future, when the generic topology is used by other subsystems, the data from "TOPO_TILE_DOMAIN" can be used generically for both Intel and AMD.I'm not convinced that this is possible. The meaning of these elements is unfortunately not cast in stone, so the association of e.g. cache boundaries is not necessarily static accross a larger range of CPU generations..
Quoted 8 lines
We really need to differentiate performance characteristic, hardware feature scope, power management scope etc. and create abstractions which are actually useful for kernel facilities and user space.
From a performance perspective it's irrelevant whether the scope is TILE or whatever. The information needed is the hierarchy, the performance characteristics of a segment in the hierarchy and the costs for cross segment access and cross segment migration.
That makes sense. Thank you for the detailed explanation.
Quoted 5 lines
For hardware features like perf the information needed is what the scope of a particular resource is. Again it's not necessarily useful to know what particular domain type it is.
Quoted 7 lines
Powermanagement does not care about the particual type either. It needs to know which scopes affect c-states, clock speeds ... to give the scheduler informtion of how to steer workloads in the most efficient way.
Thanks,
tglx
--
Thanks and Regards,
Prateek
Re: [patch V4 24/41] x86/cpu: Provide cpu_init/parse_topology()
In reply to K Prateek NayakQuoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
specifically "... combining up to four Intel 7-built tiles on a single package, connected using Intel EMIB ...". Perhaps the one from Qiuxu Zhuo's report does not contain multiple tiles.
I think what Arjan was saying that despite them being build using multipe physical tiles, they describe themselves, in the topology leave, as being a single tile.
Quoted 5 lines
Quoted 1 line
and more than that -- from a software perspective, they truely act as if they are 1 tile
If possible, can you please elaborate on the "software perspective". Say CPUID leaf
0x1freports multiple tile, would the data access latency or cache to cache latency see a noticeable difference?
no. (not on SPR unless you turn on SNC, which is a whole different world)
Quoted 6 lines
I would like to understand what the characteristics of a "Tile" are and whether they are similar to AMD's CCX instances discoverable by AMD's extended CPUID leaf
0x80000026. That way, in future, when the generic topology is used by other subsystems, the data from "TOPO_TILE_DOMAIN" can be used generically for both Intel and AMD.
SPR for all intents and purposes for software does not have tiles. So please lets not design for that ;-)
The reality is that we really should not hardcode topology things to cache things. Sure today tile is an L3 boundary for AMD, and on all no-tile systems by construction of the topology tree.
But maybe some smart person in AMD decides
that for a next generation, it's faster to split the L3 in half -- or to make that extra HBM-like cache span 2 tiles or .. or ..
CPUID enumerates cache domains pretty much separate and that;s a good thing. We absolutely need a "cache view" of the system, but that is a mapping to topology, not hardcoded in topology (so one level of indirection + of course cached/computed bitmaps etc for cheap access)
Re: [patch V4 24/41] x86/cpu: Provide cpu_init/parse_topology()
Hello Arjan,
Quoted 34 lines · Arjan van de Ven
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
specifically "... combining up to four Intel 7-built tiles on a single package, connected using Intel EMIB ...". Perhaps the one from Qiuxu Zhuo's report does not contain multiple tiles.
I think what Arjan was saying that despite them being build using multipe physical tiles, they describe themselves, in the topology leave, as being a single tile.
Quoted 5 lines
Quoted 1 line
and more than that -- from a software perspective, they truely act as if they are 1 tile
If possible, can you please elaborate on the "software perspective". Say CPUID leaf
0x1freports multiple tile, would the data access latency or cache to cache latency see a noticeable difference?no. (not on SPR unless you turn on SNC, which is a whole different world)
Quoted 6 lines
I would like to understand what the characteristics of a "Tile" are and whether they are similar to AMD's CCX instances discoverable by AMD's extended CPUID leaf
0x80000026. That way, in future, when the generic topology is used by other subsystems, the data from "TOPO_TILE_DOMAIN" can be used generically for both Intel and AMD.SPR for all intents and purposes for software does not have tiles. So please lets not design for that ;-)
The reality is that we really should not hardcode topology things to cache things. Sure today tile is an L3 boundary for AMD, and on all no-tile systems by construction of the topology tree.
But maybe some smart person in AMD decides
that for a next generation, it's faster to split the L3 in half -- or to make that extra HBM-like cache span 2 tiles or .. or ..
Quoted 6 lines
CPUID enumerates cache domains pretty much separate and that;s a good thing. We absolutely need a "cache view" of the system, but that is a mapping to topology, not hardcoded in topology (so one level of indirection + of course cached/computed bitmaps etc for cheap access)
Makes sense! I think that is the reason we have Cache Identifiers in the first place. I'm satisfied with the explanation from Thomas
(https://lore.kernel.org/lkml/87y1h2wpfw.ffs@tglx/) as long as their use in the future, in generic code, does not assume any characteristics that is not generic to the whole of x86 :)
--
Thanks and Regards,
Prateek
Re: [patch V4 24/41] x86/cpu: Provide cpu_init/parse_topology()
In reply to K Prateek NayakHello Thomas,
Quoted 60 lines · K Prateek Nayak
Hello Thomas,
Quoted 51 lines · Thomas Gleixner
Prateek!
Quoted 7 lines · K. Prateek Nayak
On 8/14/2023 2:24 PM, Thomas Gleixner wrote:
Since these enums come from the description of level type of CPUID leaf
0x1f, can we have a short description clarifying what each signify. This will also help clarify the mappings for AMD's extended CPUID leaf0x80000026(specifically for CCX and CCD level types). I had following in my mind:Makes sense.
Quoted 24 lines
arch/x86/include/asm/topology.h +22
-0TOPO_MODULE_DOMAIN , +/* +* If exists, represents a group of tiles within +* an instance of the next domain +* +* On Intel: This level contains a group of Tile +* type as described by CPUID leaf 0x1f +* +* On AMD: This is the group of "Complex" type +* instances as described by CPUID leaf +* 0x8000_0026 +*/ TOPO_TILE_DOMAIN , +/* +* If exists, represents a group of dies within an +* instance of the next domain +* +* On Intel: This level contains group of Die +* type as described by CPUID leaf 0x1f +* +* On AMD: This is the group of "CCD (Die)" +* type instances as described by CPUID leaf +* 0x8000_0026 + */arch/x86/include/asm/topology.h static inline void setup_node_to_cpumask_map(void) { } · line 151
Quoted 10 lines
arch/x86/include/asm/topology.h +5
-0TOPO_DIE_DOMAIN , +/* +* If exists, represents a group of packages +* within the root domain +*/ TOPO_PKG_DOMAIN , +/* Topmost domain with a singular instance */ TOPO_ROOT_DOMAIN , TOPO_MAX_DOMAIN, };Now this begs the obvious question what the actual meaning of these domains is and what's their relevance for the kernel.
Quoted 2 lines
It's probably undisputed what SMT/CORE mean and what their relevance is. The PKG/DIE domains are pretty clear too.
Yup! Those seem to be clear.
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Now we have:
MODULE (Intel only)
TILE Intel, AMD names it "Complex"
So here is my interpretation of
0x1fsince I could not find much in the SDM for these level types.
Turns out, there is indeed more information about these types in SDM. Intel SDM Vol. 3A, in Sec. 9.9.1 "Hierarchical Mapping of Shared Resources" contains description of these level. I'll quote it here for ease of readers:
"""
The decomposition of an APIC_ID may consist of several sub fields representing the topology within a physical processor package, the higher-order bits of an APIC ID may also be used by cluster vendors to represent the topology of cluster nodes of each coherent multiprocessor systems:
o Cluster : Some multi-threading environments consists of multiple clusters of multi-processor systems. The CLUSTER_ID sub-field is usually supported by vendor firmware to distinguish different clusters. For nonclustered systems, CLUSTER_ID is usually 0 and system topology is reduced.
o Package : A physical processor package mates with a socket. A package may contain one or more software visible die. The PACKAGE_ID sub-field distinguishes different physical packages within a cluster.
o Die : A software-visible chip inside a package. The DIE_ID
sub-field distinguishes different die within a package. If there are no software visible die, the width of this bit field is 0.
o DieGrp : A group of die that share certain resources.
o Tile : A set of cores that share certain resources. The TILE_ID
sub-field distinguishes different tiles. If there are no software visible tiles, the width of this bit field is 0.
o Module : A set of cores that share certain resources. The MODULE_ID sub-field distinguishes different modules. If there are no software visible modules, the width of this bit field is 0.
o Core : Processor cores may be contained within modules, within
tiles, on software-visible die, or appear directly at the package domain. The CORE_ID sub-field distinguishes processor cores. For a single-core processor, the width of this bit field is 0.
o Logical Processor : A processor core provides one or more logical processors sharing execution resources. The LOGICAL_PROCESSOR_ID sub-field distinguishes logical processors in a core. The width of this bit field is non-zero if a processor core provides more than one logical processors.
"""
So some questions to Intel folks to determine whether mapping AMD's Complex to Tile makes sense or not:
- What are the "certain resources" a group of module / tile share?
- Module and Tile both use the phrase "set of cores" in their description. Does this mean their existence is mutually exclusive?
AMD's Complex (CCX) marks the L3 cache boundary. If either of the "certain resources" refer to L3 cache, then Complex can be safely mapped to the respective level without any fear of misinterpretation of the characteristics.
Also, I do not see a "DieGrp" domain in the "x86_topology_domains". Is this because of the lack of "software visible" aspect of it despite its possible existence?
Quoted 1 line
[..snip..]
--
Thanks and Regards,
Prateek
Re: [patch V4 24/41] x86/cpu: Provide cpu_init/parse_topology()
Prateek!
Quoted 9 lines · K. Prateek Nayak
On 8/28/2023 7:58 PM, K Prateek Nayak wrote:
o Logical Processor : A processor core provides one or more logical processors sharing execution resources. TheLOGICAL_PROCESSOR_IDsub-field distinguishes logical processors in a core. The width of this bit field is non-zero if a processor core provides more than one logical processors.
"""
Quoted 7 lines
So some questions to Intel folks to determine whether mapping AMD's Complex to Tile makes sense or not:
- What are the "certain resources" a group of module / tile share?
- Module and Tile both use the phrase "set of cores" in their description. Does this mean their existence is mutually exclusive?
That's definitely a good question.
Quoted 4 lines
AMD's Complex (CCX) marks the L3 cache boundary. If either of the "certain resources" refer to L3 cache, then Complex can be safely mapped to the respective level without any fear of misinterpretation of the characteristics.
I don't think it's a good idea to try deducing cache hierarchy from the basic topology. The boundaries have changed over time and AMD has made it impossible on older CPUs to use the CPU topology for that.
I tried to do that and gave up because I realized that we need both and then do the proper association by combining the information.
Quoted 3 lines
Also, I do not see a "DieGrp" domain in the "
x86_topology_domains". Is this because of the lack of "software visible" aspect of it despite its possible existence?
No. It's subsumed by the package domain. Let me look at the mechanics some more to make this more obvious.
Thanks,
tglx
PATCH v4 25/41 x86/cpu: Add legacy topology parser
In reply to Thomas GleixnerThe legacy topology detection via CPUID leaf 4, which provides the number of cores in the package and CPUID leaf 1 which provides the number of logical CPUs in case that FEATURE_HT is enabled and the CMP_LEGACY feature is not set, is shared for Intel, Centaur amd Zhaoxin CPUs.
Lift the code from common.c without the early detection hack and provide it as common fallback mechanism.
Will be utilized in later changes.
---
V4: Cure the off by one in fake_topology()
V3: Provide legacy data in leaf 0xb/0x1f format as expected by the rest of
the code - Borislav
--- arch/x86/kernel/cpu/common.c | 3 ++ arch/x86/kernel/cpu/topology.h | 3 ++ arch/x86/kernel/cpu/topology_common.c | 46 +++++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/common.c +3 -0
@@ -883,6 +883,9 @@ void detect_ht(struct cpuinfo_x86 *c)#ifdef CONFIG_SMP int index_msb, core_bits; +if (topo_is_converted (c)) +return ; +if (detect_ht_early (c) <0 )return ;
arch/x86/kernel/cpu/topology.h +3 -0
@@ -6,6 +6,9 @@ struct topo_scan {struct cpuinfo_x86 *c;unsigned int dom_shifts[TOPO_MAX_DOMAIN ];unsigned int dom_ncpus[TOPO_MAX_DOMAIN ]; + +// Legacy CPUID[1]:EBX[23:16] number of logical processors +unsigned int ebx1_nproc_shift; };bool topo_is_converted (struct cpuinfo_x86 *c);
arch/x86/kernel/cpu/topology_common.c +45 -1
64 lines not on this page · raw message
PATCH v4 26/41 x86/cpu: Use common topology code for Centaur and Zhaoxin
In reply to Thomas GleixnerCentaur and Zhaoxin CPUs use only the legacy SMP detection. Remove the invocations from their 32bit path and exempt them from the call 64bit.
No functional change intended.
--- arch/x86/kernel/cpu/centaur.c | 4 ---- arch/x86/kernel/cpu/topology_common.c | 11 ++++++++--- arch/x86/kernel/cpu/zhaoxin.c | 4 ---- 3 files changed, 8 insertions(+), 11 deletions(-)
arch/x86/kernel/cpu/centaur.c +0 -4
@@ -128,10 +128,6 @@ static void init_centaur(struct cpuinfo_#endif early_init_centaur (c);init_intel_cacheinfo (c); -detect_num_cpu_cores (c); -#ifdef CONFIG_X86_32 -detect_ht (c); -#endif if (c->cpuid_level >9 ) {unsigned int eax =cpuid_eax (10 );
arch/x86/kernel/cpu/topology_common.c +8 -3
@@ -42,7 +42,7 @@ static unsigned int parse_num_cores(strureturn eax.ncores +1 ; } -static void __maybe_unused parse_legacy (struct topo_scan *tscan) +static void parse_legacy (struct topo_scan *tscan) {unsigned int cores, core_shift, smt_shift =0 ;struct cpuinfo_x86 *c = tscan->c;
@@ -71,10 +71,8 @@ bool topo_is_converted(struct cpuinfo_x8/* Temporary until everything is converted over. */ switch (boot_cpu_data.x86_vendor) {case X86_VENDOR_AMD : -case X86_VENDOR_CENTAUR :case X86_VENDOR_INTEL :case X86_VENDOR_HYGON : -case X86_VENDOR_ZHAOXIN :return false;default :/* Let all UP systems use the below */
@@ -132,6 +130,13 @@ static void parse_topology(struct topo_sreturn ; tscan->ebx1_nproc_shift =get_count_order (ebx.nproc); + +switch (c->x86_vendor) { +case X86_VENDOR_CENTAUR : +case X86_VENDOR_ZHAOXIN : +parse_legacy (tscan); +break ; + } }static void topo_set_ids (struct topo_scan *tscan)
arch/x86/kernel/cpu/zhaoxin.c +0 -4
@@ -71,10 +71,6 @@ static void init_zhaoxin(struct cpuinfo_ {early_init_zhaoxin (c);init_intel_cacheinfo (c); -detect_num_cpu_cores (c); -#ifdef CONFIG_X86_32 -detect_ht (c); -#endif if (c->cpuid_level >9 ) {unsigned int eax =cpuid_eax (10 );
PATCH v4 27/41 x86/cpu: Move __max_die_per_package to common.c
In reply to Thomas GleixnerIn preparation of a complete replacement for the topology leaf 0xb/0x1f evaluation, move __max_die_per_package into the common code.
Will be removed once everything is converted over.
--- arch/x86/kernel/cpu/common.c | 3 +++ arch/x86/kernel/cpu/topology.c | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/common.c +3 -0
@@ -75,6 +75,9 @@ u32 elf_hwcap2 __read_mostly;int smp_num_siblings =1 ;EXPORT_SYMBOL (smp_num_siblings); +unsigned int __max_die_per_package__read_mostly =1 ; +EXPORT_SYMBOL (__max_die_per_package); + static struct ppin_info { int feature; int msr_ppin_ctl;
arch/x86/kernel/cpu/topology.c +0 -3
@@ -25,9 +25,6 @@#define BITS_SHIFT_NEXT_LEVEL (eax) ((eax) & 0x1f)#define LEVEL_MAX_SIBLINGS (ebx) ((ebx) & 0xffff) -unsigned int __max_die_per_package__read_mostly =1 ; -EXPORT_SYMBOL (__max_die_per_package); -#ifdef CONFIG_SMP /* * Check if given CPUID extended topology "leaf" is implemented
PATCH v4 28/41 x86/cpu: Provide a sane leaf 0xb/0x1f parser
In reply to Thomas Gleixnerdetect_extended_topology() along with it's early() variant is a classic example for duct tape engineering:
- It evaluates an array of subleafs with a boatload of local variables for the relevant topology levels instead of using an array to save the enumerated information and propagate it to the right level
- It has no boundary checks for subleafs
- It prevents updating the die_id with a crude workaround instead of
checking for leaf 0xb which does not provide die information.
- It's broken vs. the number of dies evaluation as it uses:
num_processors[DIE_LEVEL] / num_processors[CORE_LEVEL]
which "works" only correctly if there is none of the intermediate topology levels (MODULE/TILE) enumerated.
There is zero value in trying to "fix" that code as the only proper fix is to rewrite it from scratch.
Implement a sane parser with proper code documentation, which will be used for the consolidated topology evaluation in the next step.
---
V4: Handle unknown domain types gracefully - Rui
V2: Fixed up the comment alignment for registers - Peterz
--- arch/x86/kernel/cpu/Makefile | 2 arch/x86/kernel/cpu/topology.h | 12 +++ arch/x86/kernel/cpu/topology_ext.c | 132 +++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/Makefile +1 -1
@@ -18,7 +18,7 @@ KMSAN_SANITIZE_common.o := n KCSAN_SANITIZE_common.o := n obj-y := cacheinfo.o scattered.o -obj-y += topology_common.o topology.o +obj-y += topology_common.o topology_ext.o topology.o obj-y += common.o obj-y += rdrand.o obj-y += match.o
arch/x86/kernel/cpu/topology.h +12 -0
@@ -16,6 +16,7 @@ void cpu_init_topology(struct cpuinfo_x8void cpu_parse_topology (struct cpuinfo_x86 *c);void topology_set_dom (struct topo_scan *tscan,enum x86_topology_domains dom,unsigned int shift,unsigned int ncpus); +bool cpu_parse_topology_ext (struct topo_scan *tscan);static inline u32 topo_shift_apicid (u32 apicid,enum x86_topology_domains dom) {
@@ -36,4 +37,15 @@ static inline u32 topo_domain_mask(enum return (1U << x86_topo_system.dom_shifts[dom]) - 1; } +/* +* Update a domain level after the fact without propagating. Used to fixup +* broken CPUID enumerations. +*/ +static inline void topology_update_dom (struct topo_scan *tscan,enum x86_topology_domains dom, +unsigned int shift,unsigned int ncpus) +{ + tscan->dom_shifts[dom] = shift; + tscan->dom_ncpus[dom] = ncpus; +} +#endif /* ARCH_X86_TOPOLOGY_H */
arch/x86/kernel/cpu/topology_ext.c new file +132 -0
132 lines not on this page · raw message
Re: [patch V4 28/41] x86/cpu: Provide a sane leaf 0xb/0x1f parser
Quoted 66 lines
(quoted diff) +2
-0+ +static inline bool topo_subleaf(struct topo_scan *tscan, u32 leaf,u32 subleaf,
+ unsigned int*last_dom)
+{
+ unsigned int dom, maxtype = leaf ==0xb?CORE_TYPE+ 1 :MAX_TYPE;
+ struct {
+ // eax
+ u32 x2apic_shift : 5, // Number of bits to shift APIC ID right
+ // for the topology ID at the next level
+ __rsvd0 : 27; // Reserved + // ebx
+ u32 num_processors : 16, // Number of processors at current level
+ __rsvd1 : 16; // Reserved + // ecx
+ u32 level : 8, // Current topology level. Same as sub leaf number
+ type : 8, // Level type. If 0, invalid
+ __rsvd2 : 16; // Reserved + // edx
+ u32 x2apic_id : 32; // X2APIC ID of the current logical processor
+ } sl;arch/x86/kernel/cpu/topology_ext.c new file +8
-0+ + cpuid_subleaf(leaf, subleaf, &sl); + + if (!sl.num_processors || sl.type == INVALID_TYPE) + return false; + + if (sl.type >= maxtype) { + pr_err_once("Topology: leaf 0x%x:%d Unknown domaintype %u\n",
+ leaf, subleaf, sl.type);
+ /*
+ * The subleafs are ordered in domain level order so + * propagate it into the next domain level carefully:
if
+ * the last domain level was PKG, then overwrite PKG + * as otherwise this would end up in the root domain. + *
+ * It really would have been too obvious to make the domain
+ * type space sparse and leave a few reserved types between
+ * the points which might change instead of following the
+ * usual "this can be fixed in software" principle. + */
+ dom =*last_dom==TOPO_PKG_DOMAIN?TOPO_PKG_DOMAIN:*last_dom+ 1;
+ } else {
+ dom = topo_domain_map[sl.type];
+ *last_dom = dom;
+ }
+
+ if (!dom) {
+ tscan->c->topo.initial_apicid = sl.x2apic_id; + } else if (tscan->c->topo.initial_apicid!= sl.x2apic_id) { + pr_warn_once(FW_BUG "CPUID leaf 0x%x subleaf %d APIC ID mismatch %x != %x\n",
+ leaf, subleaf, tscan->c-
Quoted 3 lines
Quoted 1 line
topo.initial_apicid, sl.x2apic_id);
+ }
+
Maybe worth a warning somewhere if sl.x2apic_shift != x86_topo_system.dom_shifts[dom], because invariant x2apic_shift (for the same level) among different CPUs is critical for this patch series. And I do see variant x2apic_shift on an Intel AlderLake NUC, which has been identified to be a microcode bug later.
thanks,
rui
Re: [patch V4 28/41] x86/cpu: Provide a sane leaf 0xb/0x1f parser
Quoted 5 lines · Rui Zhang
Quoted 5 lines
+ } else if (
tscan->c->topo.initial_apicid!= sl.x2apic_id) { + pr_warn_once(FW_BUG "CPUID leaf 0x%x subleaf %d APIC ID mismatch %x != %x\n",
+ leaf, subleaf, tscan->c-Quoted 1 line
topo.initial_apicid, sl.x2apic_id);
Quoted 8 lines
Quoted 2 lines
+ }
+Maybe worth a warning somewhere if sl.x2apic_shift != x86_topo_system.dom_shifts[dom], because invariant
x2apic_shift(for the same level) among different CPUs is critical for this patch series. And I do see variantx2apic_shifton an Intel AlderLake NUC, which has been identified to be a microcode bug later.
Yes, we can do that.
PATCH v4 29/41 x86/cpu: Use common topology code for Intel
In reply to Thomas GleixnerIntel 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.
--- arch/x86/kernel/cpu/common.c | 65 ---------------------------------- arch/x86/kernel/cpu/cpu.h | 4 -- arch/x86/kernel/cpu/intel.c | 25 ------------- arch/x86/kernel/cpu/topology_common.c | 5 ++ 4 files changed, 4 insertions(+), 95 deletions(-)
arch/x86/kernel/cpu/common.c +0 -65
@@ -784,19 +784,6 @@ static void get_model_name(struct cpuinf *(s +1 ) ='\0' ; } -void detect_num_cpu_cores (struct cpuinfo_x86 *c) -{ -unsigned int eax, ebx, ecx, edx; - - c->x86_max_cores =1 ; -if (!IS_ENABLED (CONFIG_SMP ) || c->cpuid_level <4 ) -return ; - -cpuid_count (4 ,0 , &eax, &ebx, &ecx, &edx); -if (eax &0x1f ) - c->x86_max_cores = (eax >>26 ) +1 ; -} -void cpu_detect_cache_sizes (struct cpuinfo_x86 *c) {unsigned int n, dummy, ebx, ecx, edx, l2size;
@@ -858,54 +845,6 @@ static void cpu_detect_tlb(struct cpuinf tlb_lld_4m[ENTRIES], tlb_lld_1g[ENTRIES]); } -int detect_ht_early (struct cpuinfo_x86 *c) -{ -#ifdef CONFIG_SMP -u32 eax, ebx, ecx, edx; - -if (!cpu_has (c,X86_FEATURE_HT )) -return -1 ; - -if (cpu_has (c,X86_FEATURE_CMP_LEGACY )) -return -1 ; - -if (cpu_has (c,X86_FEATURE_XTOPOLOGY )) -return -1 ; - -cpuid (1 , &eax, &ebx, &ecx, &edx); - - smp_num_siblings = (ebx &0xff0000 ) >>16 ; -if (smp_num_siblings ==1 ) -pr_info_once ("CPU0: Hyper-Threading is disabled\n" ); -#endif -return 0 ; -} - -void detect_ht (struct cpuinfo_x86 *c) -{ -#ifdef CONFIG_SMP -int index_msb, core_bits; - -if (topo_is_converted (c)) -return ; - -if (detect_ht_early (c) <0 ) -return ; - - index_msb =get_count_order (smp_num_siblings); - c->topo.pkg_id = apic->phys_pkg_id (c->topo.initial_apicid, index_msb); - - smp_num_siblings = smp_num_siblings / c->x86_max_cores; - - index_msb =get_count_order (smp_num_siblings); - - core_bits =get_count_order (c->x86_max_cores); - - c->topo.core_id = apic->phys_pkg_id (c->topo.initial_apicid, index_msb) & - ((1 << core_bits) -1 ); -#endif -} -static void get_cpu_vendor (struct cpuinfo_x86 *c) {char *v = c->x86_vendor_id;
@@ -1853,10 +1792,6 @@ static void identify_cpu(struct cpuinfo_ c->x86, c->x86_model); } -#ifdef CONFIG_X86_64 -detect_ht (c); -#endif -x86_init_rdrand (c);setup_pku (c);setup_cet (c);
arch/x86/kernel/cpu/cpu.h +0 -4
@@ -76,11 +76,7 @@ extern void init_intel_cacheinfo(structextern void init_amd_cacheinfo (struct cpuinfo_x86 *c);extern void init_hygon_cacheinfo (struct cpuinfo_x86 *c); -extern void detect_num_cpu_cores (struct cpuinfo_x86 *c); -extern int detect_extended_topology_early (struct cpuinfo_x86 *c);extern int detect_extended_topology (struct cpuinfo_x86 *c); -extern int detect_ht_early (struct cpuinfo_x86 *c); -extern void detect_ht (struct cpuinfo_x86 *c);extern void check_null_seg_clears_base (struct cpuinfo_x86 *c);void cacheinfo_amd_init_llc_id (struct cpuinfo_x86 *c);
arch/x86/kernel/cpu/intel.c +0 -25
@@ -489,13 +489,6 @@ static void early_init_intel(struct cpui }check_memory_type_self_snoop_errata (c); - -/* -* Get the number of SMT siblings early from the extended topology -* leaf, if available. Otherwise try the legacy SMT detection. -*/ -if (detect_extended_topology_early (c) <0 ) -detect_ht_early (c); }static void bsp_init_intel (struct cpuinfo_x86 *c)
@@ -777,24 +770,6 @@ static void init_intel(struct cpuinfo_x8intel_workarounds (c); -/* -* Detect the extended topology information if available. This -* will reinitialise the initial_apicid which will be used -* in init_intel_cacheinfo() -*/ -detect_extended_topology (c); - -if (!cpu_has (c,X86_FEATURE_XTOPOLOGY )) { -/* -* let's use the legacy cpuid vector 0x1 and 0x4 for topology -* detection. -*/ -detect_num_cpu_cores (c); -#ifdef CONFIG_X86_32 -detect_ht (c); -#endif - } -init_intel_cacheinfo (c);if (c->cpuid_level >9 ) {
arch/x86/kernel/cpu/topology_common.c +4 -1
@@ -71,7 +71,6 @@ bool topo_is_converted(struct cpuinfo_x8/* Temporary until everything is converted over. */ switch (boot_cpu_data.x86_vendor) {case X86_VENDOR_AMD : -case X86_VENDOR_INTEL :case X86_VENDOR_HYGON :return false;default :
@@ -136,6 +135,10 @@ static void parse_topology(struct topo_scase X86_VENDOR_ZHAOXIN :parse_legacy (tscan);break ; +case X86_VENDOR_INTEL : +if (!IS_ENABLED (CONFIG_CPU_SUP_INTEL ) || !cpu_parse_topology_ext (tscan)) +parse_legacy (tscan); +break ; } }
PATCH v4 30/41 x86/cpu/amd: Provide a separate accessor for Node ID
In reply to Thomas GleixnerAMD (ab)uses topology_die_id() to store the Node ID information and topology_max_dies_per_pkg to store the number of nodes per package.
This collides with the proper processor die level enumeration which is coming on AMD with CPUID 8000_0026, unless there is a correlation between the two. There is zero documentation about that.
So provide new storage and new accessors which for now still access die_id and topology_max_dies_per_pkg. Will be mopped up after AMD and HYGON are converted over.
--- arch/x86/events/amd/core.c | 2 +- arch/x86/include/asm/processor.h | 3 +++ arch/x86/include/asm/topology.h | 8 ++++++++ arch/x86/kernel/amd_nb.c | 4 ++-- arch/x86/kernel/cpu/cacheinfo.c | 2 +- arch/x86/kernel/cpu/mce/amd.c | 4 ++-- arch/x86/kernel/cpu/mce/inject.c | 4 ++-- drivers/edac/amd64_edac.c | 4 ++-- drivers/edac/mce_amd.c | 4 ++-- 9 files changed, 23 insertions(+), 12 deletions(-)
arch/x86/events/amd/core.c +1 -1
@@ -574,7 +574,7 @@ static void amd_pmu_cpu_starting(int cpuif (!x86_pmu.amd_nb_constraints)return ; - nb_id =topology_die_id (cpu); + nb_id =topology_amd_node_id (cpu);WARN_ON_ONCE (nb_id ==BAD_APICID );for_each_online_cpu (i) {
arch/x86/include/asm/processor.h +3 -0
@@ -99,6 +99,9 @@ struct cpuinfo_topology {u32 logical_pkg_id;u32 logical_die_id; +// AMD Node ID and Nodes per Package info +u32 amd_node_id; +// Cache level topology IDs u32 llc_id;u32 l2c_id;
arch/x86/include/asm/topology.h +8 -0
@@ -131,6 +131,8 @@ extern const struct cpumask *cpu_cluster#define topology_core_id (cpu) (cpu_data(cpu).topo.core_id)#define topology_ppin (cpu) (cpu_data(cpu).ppin) +#define topology_amd_node_id (cpu) (cpu_data(cpu).topo.die_id) +extern unsigned int __max_die_per_package;#ifdef CONFIG_SMP
@@ -160,6 +162,11 @@ int topology_update_die_map(unsigned intint topology_phys_to_logical_pkg (unsigned int pkg);bool topology_smt_supported (void ); +static inline unsigned int topology_amd_nodes_per_pkg (void ) +{ +return __max_die_per_package; +} +extern struct cpumask __cpu_primary_thread_mask;#define cpu_primary_thread_mask ((const struct cpumask *)&__cpu_primary_thread_mask)
@@ -182,6 +189,7 @@ static inline int topology_max_die_per_pstatic inline int topology_max_smt_threads (void ) {return 1 ; }static inline bool topology_is_primary_thread (unsigned int cpu) {return true; }static inline bool topology_smt_supported (void ) {return false; } +static inline unsigned int topology_amd_nodes_per_pkg (void ) {return 0 ; };#endif /* !CONFIG_SMP */ static inline void arch_fix_phys_package_id (int num,u32 slot)
arch/x86/kernel/amd_nb.c +2 -2
@@ -370,7 +370,7 @@ struct resource *amd_get_mmconfig_range(int amd_get_subcaches (int cpu) { -struct pci_dev *link =node_to_amd_nb (topology_die_id (cpu))->link; +struct pci_dev *link =node_to_amd_nb (topology_amd_node_id (cpu))->link;unsigned int mask;if (!amd_nb_has_feature (AMD_NB_L3_PARTITIONING ))
@@ -384,7 +384,7 @@ int amd_get_subcaches(int cpu)int amd_set_subcaches (int cpu,unsigned long mask) {static unsigned int reset, ban; -struct amd_northbridge *nb =node_to_amd_nb (topology_die_id (cpu)); +struct amd_northbridge *nb =node_to_amd_nb (topology_amd_node_id (cpu));unsigned int reg;int cuid;
arch/x86/kernel/cpu/cacheinfo.c +1 -1
@@ -595,7 +595,7 @@ static void amd_init_l3_cache(struct _cpif (index <3 )return ; - node =topology_die_id (smp_processor_id ()); + node =topology_amd_node_id (smp_processor_id ()); this_leaf->nb =node_to_amd_nb (node);if (this_leaf->nb && !this_leaf->nb->l3_cache.indices)amd_calc_l3_indices (this_leaf->nb);
arch/x86/kernel/cpu/mce/amd.c +2 -2
@@ -1181,7 +1181,7 @@ static int threshold_create_bank(structreturn -ENODEV ;if (is_shared_bank (bank)) { - nb =node_to_amd_nb (topology_die_id (cpu)); + nb =node_to_amd_nb (topology_amd_node_id (cpu));/* threshold descriptor already initialized on this node? */ if (nb && nb->bank4) {
@@ -1285,7 +1285,7 @@ static void threshold_remove_bank(struct* The last CPU on this node using the shared bank is going * away, remove that bank now. */ - nb =node_to_amd_nb (topology_die_id (smp_processor_id ())); + nb =node_to_amd_nb (topology_amd_node_id (smp_processor_id ())); nb->bank4 =NULL ; }
arch/x86/kernel/cpu/mce/inject.c +2 -2
@@ -543,8 +543,8 @@ static void do_inject(void)if (boot_cpu_has (X86_FEATURE_AMD_DCM ) && b ==4 && boot_cpu_data.x86 <0x17 ) { -toggle_nb_mca_mst_cpu (topology_die_id (cpu)); - cpu =get_nbc_for_node (topology_die_id (cpu)); +toggle_nb_mca_mst_cpu (topology_amd_node_id (cpu)); + cpu =get_nbc_for_node (topology_amd_node_id (cpu)); }cpus_read_lock ();
drivers/edac/amd64_edac.c +2 -2
@@ -1907,7 +1907,7 @@ static void dct_determine_memory_type(st/* On F10h and later ErrAddr is MC4_ADDR[47:1] */ static u64 get_error_address (struct amd64_pvt *pvt,struct mce *m) { -u16 mce_nid =topology_die_id (m->extcpu); +u16 mce_nid =topology_amd_node_id (m->extcpu);struct mem_ctl_info *mci;u8 start_bit =1 ;u8 end_bit =47 ;
@@ -3438,7 +3438,7 @@ static void get_cpus_on_this_dct_cpumaskint cpu;for_each_online_cpu (cpu) -if (topology_die_id (cpu) == nid) +if (topology_amd_node_id (cpu) == nid)cpumask_set_cpu (cpu, mask); }
drivers/edac/mce_amd.c +2 -2
@@ -1060,7 +1060,7 @@ static void decode_mc3_mce(struct mce *mstatic void decode_mc4_mce (struct mce *m) {unsigned int fam =x86_family (m->cpuid); -int node_id =topology_die_id (m->extcpu); +int node_id =topology_amd_node_id (m->extcpu);u16 ec =EC (m->status);u8 xec =XEC (m->status,0x1f );u8 offset =0 ;
@@ -1188,7 +1188,7 @@ static void decode_smca_error(struct mceif ((bank_type ==SMCA_UMC || bank_type ==SMCA_UMC_V2 ) && xec ==0 && decode_dram_ecc) -decode_dram_ecc (topology_die_id (m->extcpu), m); +decode_dram_ecc (topology_amd_node_id (m->extcpu), m); }static inline void amd_decode_err_code (u16 ec)
PATCH v4 31/41 x86/cpu: Provide an AMD/HYGON specific topology parser
In reply to Thomas GleixnerAMD/HYGON uses various methods for topology evaluation:
- Leaf 0x80000008 and 0x8000001e based with an optional leaf 0xb,
which is the preferred variant for modern CPUs.
Leaf 0xb will be superseded by leaf 0x80000026 soon, which is just
another variant of the Intel 0x1f leaf for whatever reasons. - Subleaf 0x80000008 and NODEID_MSR base
- Legacy fallback
That code is following the principle of random bits and pieces all over the place which results in multiple evaluations and impenetrable code flows in the same way as the Intel parsing did.
Provide a sane implementation by clearly separating the three variants and bringing them in the proper preference order in one place.
This provides the parsing for both AMD and HYGON because there is no point in having a separate HYGON parser which only differs by 3 lines of code. Any further divergence between AMD and HYGON can be handled in different functions, while still sharing the existing parsers.
---
V4: Fix the off by one completely - Michael
V4: Integrate the Hygon fixup - Pu
V3: Fix the off by one with leaf 0x8000001e::ebx::threads_per_cu - Michael
--- arch/x86/include/asm/topology.h | 2 arch/x86/kernel/cpu/Makefile | 2 arch/x86/kernel/cpu/amd.c | 2 arch/x86/kernel/cpu/cacheinfo.c | 4 arch/x86/kernel/cpu/cpu.h | 2 arch/x86/kernel/cpu/debugfs.c | 2 arch/x86/kernel/cpu/topology.h | 6 + arch/x86/kernel/cpu/topology_amd.c | 182 ++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/topology_common.c | 19 +++ 9 files changed, 214 insertions(+), 7 deletions(-)
arch/x86/include/asm/topology.h +2 -0
@@ -162,6 +162,8 @@ int topology_update_die_map(unsigned intint topology_phys_to_logical_pkg (unsigned int pkg);bool topology_smt_supported (void ); +extern unsigned int __amd_nodes_per_pkg; +static inline unsigned int topology_amd_nodes_per_pkg (void ) {return __max_die_per_package;
arch/x86/kernel/cpu/Makefile +1 -1
@@ -18,7 +18,7 @@ KMSAN_SANITIZE_common.o := n KCSAN_SANITIZE_common.o := n obj-y := cacheinfo.o scattered.o -obj-y += topology_common.o topology_ext.o topology.o +obj-y += topology_common.o topology_ext.o topology_amd.o topology.o obj-y += common.o obj-y += rdrand.o obj-y += match.o
arch/x86/kernel/cpu/amd.c +1 -1
@@ -423,7 +423,7 @@ static void amd_get_topology(struct cpuiif (!err) c->x86_coreid_bits =get_count_order (c->x86_max_cores); -cacheinfo_amd_init_llc_id (c); +cacheinfo_amd_init_llc_id (c, c->topo.die_id); }else if (cpu_has (c,X86_FEATURE_NODEID_MSR )) {u64 value;
arch/x86/kernel/cpu/cacheinfo.c +2 -2
@@ -661,7 +661,7 @@ static int find_num_cache_leaves(structreturn i; } -void cacheinfo_amd_init_llc_id (struct cpuinfo_x86 *c) +void cacheinfo_amd_init_llc_id (struct cpuinfo_x86 *c,u16 die_id) {/* * We may have multiple LLCs if L3 caches exist, so check if we
@@ -672,7 +672,7 @@ void cacheinfo_amd_init_llc_id(struct cpif (c->x86 <0x17 ) {/* LLC is at the node level. */ - c->topo.llc_id = c->topo.die_id; + c->topo.llc_id = die_id; }else if (c->x86 ==0x17 && c->x86_model <=0x1F ) {/* * LLC is at the core complex level.
arch/x86/kernel/cpu/cpu.h +1 -1
@@ -79,7 +79,7 @@ extern void init_hygon_cacheinfo(structextern int detect_extended_topology (struct cpuinfo_x86 *c);extern void check_null_seg_clears_base (struct cpuinfo_x86 *c); -void cacheinfo_amd_init_llc_id (struct cpuinfo_x86 *c); +void cacheinfo_amd_init_llc_id (struct cpuinfo_x86 *c,u16 die_id);void cacheinfo_hygon_init_llc_id (struct cpuinfo_x86 *c);unsigned int aperfmperf_get_khz (int cpu);
arch/x86/kernel/cpu/debugfs.c +2 -0
@@ -26,6 +26,8 @@ static int cpu_debug_show(struct seq_filseq_printf (m,"logical_die_id: %u\n" , c->topo.logical_die_id);seq_printf (m,"llc_id: %u\n" , c->topo.llc_id);seq_printf (m,"l2c_id: %u\n" , c->topo.l2c_id); +seq_printf (m,"amd_node_id: %u\n" , c->topo.amd_node_id); +seq_printf (m,"amd_nodes_per_pkg: %u\n" ,topology_amd_nodes_per_pkg ());seq_printf (m,"max_cores: %u\n" , c->x86_max_cores);seq_printf (m,"max_die_per_pkg: %u\n" , __max_die_per_package);seq_printf (m,"smp_num_siblings: %u\n" , smp_num_siblings);
arch/x86/kernel/cpu/topology.h +6 -0
@@ -9,6 +9,10 @@ struct topo_scan {// Legacy CPUID[1]:EBX[23:16] number of logical processors unsigned int ebx1_nproc_shift; + +// AMD specific node ID which cannot be mapped into APIC space. +u16 amd_nodes_per_pkg; +u16 amd_node_id; };bool topo_is_converted (struct cpuinfo_x86 *c);
@@ -17,6 +21,8 @@ void cpu_parse_topology(struct cpuinfo_xvoid topology_set_dom (struct topo_scan *tscan,enum x86_topology_domains dom,unsigned int shift,unsigned int ncpus);bool cpu_parse_topology_ext (struct topo_scan *tscan); +void cpu_parse_topology_amd (struct topo_scan *tscan); +void cpu_topology_fixup_amd (struct topo_scan *tscan);static inline u32 topo_shift_apicid (u32 apicid,enum x86_topology_domains dom) {
arch/x86/kernel/cpu/topology_amd.c new file +182 -0
182 lines not on this page · raw message
arch/x86/kernel/cpu/topology_common.c +17 -2
@@ -11,11 +11,13 @@struct x86_topology_system x86_topo_system__ro_after_init ; +unsigned int __amd_nodes_per_pkg__ro_after_init ; +EXPORT_SYMBOL_GPL (__amd_nodes_per_pkg); +void topology_set_dom (struct topo_scan *tscan,enum x86_topology_domains dom,unsigned int shift,unsigned int ncpus) { - tscan->dom_shifts[dom] = shift; - tscan->dom_ncpus[dom] = ncpus; +topology_update_dom (tscan, dom, shift, ncpus);/* Propagate to the upper levels */ for (dom++; dom <TOPO_MAX_DOMAIN ; dom++) {
@@ -153,6 +155,13 @@ static void topo_set_ids(struct topo_sca/* Package relative core ID */ c->topo.core_id = (apicid &topo_domain_mask (TOPO_PKG_DOMAIN )) >> x86_topo_system.dom_shifts[TOPO_SMT_DOMAIN ]; + +/* Temporary workaround */ +if (tscan->amd_nodes_per_pkg) + c->topo.amd_node_id = c->topo.die_id = tscan->amd_node_id; + +if (c->x86_vendor ==X86_VENDOR_AMD ) +cpu_topology_fixup_amd (tscan); }static void topo_set_max_cores (struct topo_scan *tscan)
@@ -237,4 +246,10 @@ void __init cpu_init_topology(struct cpu*/ __max_die_per_package = tscan.dom_ncpus[TOPO_DIE_DOMAIN ] / tscan.dom_ncpus[TOPO_DIE_DOMAIN -1 ]; +/* +* AMD systems have Nodes per package which cannot be mapped to +* APIC ID (yet). +*/ +if (c->x86_vendor ==X86_VENDOR_AMD || c->x86_vendor ==X86_VENDOR_HYGON ) + __amd_nodes_per_pkg = __max_die_per_package = tscan.amd_nodes_per_pkg; }
PATCH v4 32/41 x86/smpboot: Teach it about topo.amd_node_id
In reply to Thomas GleixnerWhen switching AMD over to the new topology parser then the match functions need to look for AMD systems with the extended topology feature at the new topo.amd_node_id member which is then holding the node id information.
--- arch/x86/kernel/smpboot.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
arch/x86/kernel/smpboot.c +8 -4
@@ -499,6 +499,7 @@ static bool match_smt(struct cpuinfo_x86if (c->topo.pkg_id == o->topo.pkg_id && c->topo.die_id == o->topo.die_id && + c->topo.amd_node_id == o->topo.amd_node_id &&per_cpu_llc_id (cpu1) ==per_cpu_llc_id (cpu2)) {if (c->topo.core_id == o->topo.core_id)return topology_sane (c, o,"smt" );
@@ -520,10 +521,13 @@ static bool match_smt(struct cpuinfo_x86static bool match_die (struct cpuinfo_x86 *c,struct cpuinfo_x86 *o) { -if (c->topo.pkg_id == o->topo.pkg_id && - c->topo.die_id == o->topo.die_id) -return true; -return false; +if (c->topo.pkg_id != o->topo.pkg_id || c->topo.die_id != o->topo.die_id) +return false; + +if (boot_cpu_has (X86_FEATURE_TOPOEXT ) &&topology_amd_nodes_per_pkg () >1 ) +return c->topo.amd_node_id == o->topo.amd_node_id; + +return true; }static bool match_l2c (struct cpuinfo_x86 *c,struct cpuinfo_x86 *o)
PATCH v4 33/41 x86/cpu: Use common topology code for AMD
In reply to Thomas GleixnerSwitch it over to the new topology evaluation mechanism and remove the random bits and pieces which are sprinkled all over the place.
No functional change intended.
--- arch/x86/include/asm/processor.h | 2 arch/x86/include/asm/topology.h | 5 + arch/x86/kernel/cpu/amd.c | 146 ---------------------------------- arch/x86/kernel/cpu/mce/inject.c | 3 arch/x86/kernel/cpu/topology_common.c | 5 - 5 files changed, 10 insertions(+), 151 deletions(-)
arch/x86/include/asm/processor.h +0 -2
@@ -705,10 +705,8 @@ static inline u32 per_cpu_l2c_id(unsigne }#ifdef CONFIG_CPU_SUP_AMD -extern u32 amd_get_nodes_per_socket (void );extern u32 amd_get_highest_perf (void );#else -static inline u32 amd_get_nodes_per_socket (void ) {return 0 ; }static inline u32 amd_get_highest_perf (void ) {return 0 ; }#endif
arch/x86/include/asm/topology.h +5 -0
@@ -121,6 +121,11 @@ struct x86_topology_system {extern struct x86_topology_system x86_topo_system; +static inline unsigned int topology_get_domain_size (enum x86_topology_domains dom) +{ +return x86_topo_system.dom_size[dom]; +} +extern const struct cpumask *cpu_coregroup_mask (int cpu);extern const struct cpumask *cpu_clustergroup_mask (int cpu);
arch/x86/kernel/cpu/amd.c +0 -146
194 lines not on this page · raw message
arch/x86/kernel/cpu/mce/inject.c +1 -2
@@ -433,8 +433,7 @@ static u32 get_nbc_for_node(int node_id)struct cpuinfo_x86 *c = &boot_cpu_data;u32 cores_per_node; - cores_per_node = (c->x86_max_cores * smp_num_siblings) /amd_get_nodes_per_socket (); - + cores_per_node = (c->x86_max_cores * smp_num_siblings) /topology_amd_nodes_per_pkg ();return cores_per_node * node_id; }
arch/x86/kernel/cpu/topology_common.c +4 -1
@@ -72,7 +72,6 @@ bool topo_is_converted(struct cpuinfo_x8 {/* Temporary until everything is converted over. */ switch (boot_cpu_data.x86_vendor) { -case X86_VENDOR_AMD :case X86_VENDOR_HYGON :return false;default :
@@ -133,6 +132,10 @@ static void parse_topology(struct topo_s tscan->ebx1_nproc_shift =get_count_order (ebx.nproc);switch (c->x86_vendor) { +case X86_VENDOR_AMD : +if (IS_ENABLED (CONFIG_CPU_SUP_AMD )) +cpu_parse_topology_amd (tscan); +break ;case X86_VENDOR_CENTAUR :case X86_VENDOR_ZHAOXIN :parse_legacy (tscan);
PATCH v4 34/41 x86/cpu: Use common topology code for HYGON
In reply to Thomas GleixnerSwitch it over to use the consolidated topology evaluation and remove the temporary safe guards which are not longer needed.
No functional change intended.
---
V4: Remove the stale define - Pu
--- arch/x86/kernel/cpu/common.c | 5 - arch/x86/kernel/cpu/cpu.h | 1 arch/x86/kernel/cpu/hygon.c | 129 ---------------------------------- arch/x86/kernel/cpu/topology.h | 1 arch/x86/kernel/cpu/topology_common.c | 22 +---- 5 files changed, 4 insertions(+), 154 deletions(-)
arch/x86/kernel/cpu/common.c +0 -5
@@ -1740,11 +1740,6 @@ static void identify_cpu(struct cpuinfo_/* Clear/Set all flags overridden by options, after probe */ apply_forced_caps (c); -#ifdef CONFIG_X86_64 -if (!topo_is_converted (c)) - c->topo.apicid = apic->phys_pkg_id (c->topo.initial_apicid,0 ); -#endif -/* * Vendor-specific initialization. In this section we * canonicalize the feature flags, meaning if there are
arch/x86/kernel/cpu/cpu.h +0 -1
@@ -76,7 +76,6 @@ extern void init_intel_cacheinfo(structextern void init_amd_cacheinfo (struct cpuinfo_x86 *c);extern void init_hygon_cacheinfo (struct cpuinfo_x86 *c); -extern int detect_extended_topology (struct cpuinfo_x86 *c);extern void check_null_seg_clears_base (struct cpuinfo_x86 *c);void cacheinfo_amd_init_llc_id (struct cpuinfo_x86 *c,u16 die_id);
arch/x86/kernel/cpu/hygon.c +0 -129
177 lines not on this page · raw message
arch/x86/kernel/cpu/topology.h +0 -1
@@ -15,7 +15,6 @@ struct topo_scan {u16 amd_node_id; }; -bool topo_is_converted (struct cpuinfo_x86 *c);void cpu_init_topology (struct cpuinfo_x86 *c);void cpu_parse_topology (struct cpuinfo_x86 *c); void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains dom,
arch/x86/kernel/cpu/topology_common.c +4 -18
@@ -68,18 +68,6 @@ static void parse_legacy(struct topo_scatopology_set_dom (tscan,TOPO_CORE_DOMAIN , core_shift, cores); } -bool topo_is_converted (struct cpuinfo_x86 *c) -{ -/* Temporary until everything is converted over. */ -switch (boot_cpu_data.x86_vendor) { -case X86_VENDOR_HYGON : -return false; -default : -/* Let all UP systems use the below */ -return true; - } -} -static bool fake_topology (struct topo_scan *tscan) {/*
@@ -144,6 +132,10 @@ static void parse_topology(struct topo_sif (!IS_ENABLED (CONFIG_CPU_SUP_INTEL ) || !cpu_parse_topology_ext (tscan))parse_legacy (tscan);break ; +case X86_VENDOR_HYGON : +if (IS_ENABLED (CONFIG_CPU_SUP_HYGON )) +cpu_parse_topology_amd (tscan); +break ; } }
@@ -187,9 +179,6 @@ void cpu_parse_topology(struct cpuinfo_xparse_topology (&tscan, false); -if (!topo_is_converted (c)) -return ; -for (dom =TOPO_SMT_DOMAIN ; dom <TOPO_MAX_DOMAIN ; dom++) {if (tscan.dom_shifts[dom] == x86_topo_system.dom_shifts[dom])continue ;
@@ -218,9 +207,6 @@ void __init cpu_init_topology(struct cpuparse_topology (&tscan, true); -if (!topo_is_converted (c)) -return ; -/* Copy the shift values and calculate the unit sizes. */ memcpy (x86_topo_system.dom_shifts, tscan.dom_shifts,sizeof (x86_topo_system.dom_shifts));
PATCH v4 35/41 x86/mm/numa: Use core domain size on AMD
In reply to Thomas Gleixnercpuinfo::topo::x86_coreid_bits is about to be phased out. Use the core domain size from the topology information.
Add a comment why the early MPTABLE parsing is required and decrapify the loop which sets the APIC ID to node map.
--- arch/x86/mm/amdtopology.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-)
arch/x86/mm/amdtopology.c +16 -19
@@ -54,13 +54,11 @@ static __init int find_northbridge(void)int __init amd_numa_init (void ) { -u64 start =PFN_PHYS (0 ); +unsigned int numnodes, cores, apicid; +u64 prevbase, start =PFN_PHYS (0 );u64 end =PFN_PHYS (max_pfn); -unsigned numnodes; -u64 prevbase; -int i, j, nb;u32 nodeid, reg; -unsigned int bits, cores, apicid_base; +int i, j, nb;if (!early_pci_allowed ())return -EINVAL ;
@@ -158,26 +156,25 @@ int __init amd_numa_init(void)return -ENOENT ;/* -* We seem to have valid NUMA configuration. Map apicids to nodes -* using the coreid bits from early_identify_cpu. +* We seem to have valid NUMA configuration. Map apicids to nodes +* using the size of the core domain in the APIC space. */ - bits = boot_cpu_data.x86_coreid_bits; - cores =1 << bits; - apicid_base =0 ; + cores =topology_get_domain_size (TOPO_CORE_DOMAIN );/* -* get boot-time SMP configuration: +* Scan MPTABLE to map the local APIC and ensure that the boot CPU +* APIC ID is valid. This is required because on pre ACPI/SRAT +* systems IO-APICs are mapped before the boot CPU. */ early_get_smp_config (); -if (boot_cpu_physical_apicid >0 ) { -pr_info ("BSP APIC ID: %02x\n" , boot_cpu_physical_apicid); - apicid_base = boot_cpu_physical_apicid; + apicid = boot_cpu_physical_apicid; +if (apicid >0 ) +pr_info ("BSP APIC ID: %02x\n" , apicid); + +for_each_node_mask (i, numa_nodes_parsed) { +for (j =0 ; j < cores; j++, apicid++) +set_apicid_to_node (apicid, i); } - -for_each_node_mask (i, numa_nodes_parsed) -for (j = apicid_base; j < cores + apicid_base; j++) -set_apicid_to_node ((i << bits) + j, i); -return 0 ; }
PATCH v4 36/41 x86/cpu: Make topology_amd_node_id() use the actual node info
In reply to Thomas GleixnerNow that everything is converted switch it over and remove the intermediate operation.
--- arch/x86/include/asm/topology.h | 4 ++-- arch/x86/kernel/cpu/topology_common.c | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-)
arch/x86/include/asm/topology.h +2 -2
@@ -136,7 +136,7 @@ extern const struct cpumask *cpu_cluster#define topology_core_id (cpu) (cpu_data(cpu).topo.core_id)#define topology_ppin (cpu) (cpu_data(cpu).ppin) -#define topology_amd_node_id (cpu) (cpu_data(cpu).topo.die_id) +#define topology_amd_node_id (cpu) (cpu_data(cpu).topo.amd_node_id)extern unsigned int __max_die_per_package;
@@ -171,7 +171,7 @@ extern unsigned int __amd_nodes_per_pkg;static inline unsigned int topology_amd_nodes_per_pkg (void ) { -return __max_die_per_package; +return __amd_nodes_per_pkg; }extern struct cpumask __cpu_primary_thread_mask;
arch/x86/kernel/cpu/topology_common.c +2 -5
@@ -151,9 +151,7 @@ static void topo_set_ids(struct topo_sca c->topo.core_id = (apicid &topo_domain_mask (TOPO_PKG_DOMAIN )) >> x86_topo_system.dom_shifts[TOPO_SMT_DOMAIN ]; -/* Temporary workaround */ -if (tscan->amd_nodes_per_pkg) - c->topo.amd_node_id = c->topo.die_id = tscan->amd_node_id; + c->topo.amd_node_id = tscan->amd_node_id;if (c->x86_vendor ==X86_VENDOR_AMD )cpu_topology_fixup_amd (tscan);
@@ -239,6 +237,5 @@ void __init cpu_init_topology(struct cpu* AMD systems have Nodes per package which cannot be mapped to * APIC ID (yet). */ -if (c->x86_vendor ==X86_VENDOR_AMD || c->x86_vendor ==X86_VENDOR_HYGON ) - __amd_nodes_per_pkg = __max_die_per_package = tscan.amd_nodes_per_pkg; + __amd_nodes_per_pkg = tscan.amd_nodes_per_pkg; }
PATCH v4 37/41 x86/cpu: Remove topology.c
In reply to Thomas GleixnerNo more users. Stick it into the ugly code museum.
--- arch/x86/kernel/cpu/Makefile | 2 arch/x86/kernel/cpu/topology.c | 164 ----------------------------------------- 2 files changed, 1 insertion(+), 165 deletions(-)
arch/x86/kernel/cpu/Makefile +1 -1
@@ -18,7 +18,7 @@ KMSAN_SANITIZE_common.o := n KCSAN_SANITIZE_common.o := n obj-y := cacheinfo.o scattered.o -obj-y += topology_common.o topology_ext.o topology_amd.o topology.o +obj-y += topology_common.o topology_ext.o topology_amd.o obj-y += common.o obj-y += rdrand.o obj-y += match.o
arch/x86/kernel/cpu/topology.c deleted +0 -164
164 lines not on this page · raw message
PATCH v4 38/41 x86/cpu: Remove x86_coreid_bits
In reply to Thomas GleixnerNo more users.
--- arch/x86/include/asm/processor.h | 2 -- arch/x86/kernel/cpu/common.c | 1 - 2 files changed, 3 deletions(-)
arch/x86/include/asm/processor.h +0 -2
@@ -119,8 +119,6 @@ struct cpuinfo_x86 {#endif __u8 x86_virt_bits;__u8 x86_phys_bits; -/* CPUID returned core id bits: */ -__u8 x86_coreid_bits;/* Max extended CPUID function supported: */ __u32 extended_cpuid_level;/* Maximum supported CPUID level, -1=no CPUID: */
arch/x86/kernel/cpu/common.c +0 -1
@@ -1712,7 +1712,6 @@ static void identify_cpu(struct cpuinfo_ c->x86_vendor_id[0 ] ='\0' ;/* Unset */ c->x86_model_id[0 ] ='\0' ;/* Unset */ c->x86_max_cores =1 ; - c->x86_coreid_bits =0 ;#ifdef CONFIG_X86_64 c->x86_clflush_size =64 ; c->x86_phys_bits =36 ;
PATCH v4 39/41 x86/apic: Remove unused phys_pkg_id() callback
In reply to Thomas GleixnerNow that the core code does not use this monstrosity anymore, it's time to put it to rest.
The only real purpose was to read the APIC ID on UV and VSMP systems for the actual evaluation. That's what the core code does now.
For doing the actual shift operation there is truly no APIC callback required.
--- arch/x86/include/asm/apic.h | 1 - arch/x86/kernel/apic/apic_flat_64.c | 7 ------- arch/x86/kernel/apic/apic_noop.c | 3 --- arch/x86/kernel/apic/apic_numachip.c | 7 ------- arch/x86/kernel/apic/bigsmp_32.c | 6 ------ arch/x86/kernel/apic/local.h | 1 - arch/x86/kernel/apic/probe_32.c | 6 ------ arch/x86/kernel/apic/x2apic_cluster.c | 1 - arch/x86/kernel/apic/x2apic_phys.c | 6 ------ arch/x86/kernel/apic/x2apic_uv_x.c | 11 ----------- arch/x86/kernel/vsmp_64.c | 13 ------------- arch/x86/xen/apic.c | 6 ------ 12 files changed, 68 deletions(-)
arch/x86/include/asm/apic.h +0 -1
@@ -296,7 +296,6 @@ struct apic {void (*init_apic_ldr)(void );void (*ioapic_phys_id_map)(physid_mask_t *phys_map,physid_mask_t *retmap);u32 (*cpu_present_to_apicid)(int mps_cpu); -u32 (*phys_pkg_id)(u32 cpuid_apic,int index_msb);u32 (*get_apic_id)(u32 id);u32 (*set_apic_id)(u32 apicid);
arch/x86/kernel/apic/apic_flat_64.c +0 -7
@@ -66,11 +66,6 @@ static u32 set_apic_id(u32 id)return (id &0xFF ) <<24 ; } -static u32 flat_phys_pkg_id (u32 initial_apic_id,int index_msb) -{ -return initial_apic_id >> index_msb; -} -static int flat_probe (void ) {return 1 ;
@@ -89,7 +84,6 @@ static struct apic apic_flat __ro_after_ .init_apic_ldr = default_init_apic_ldr, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = flat_phys_pkg_id, .max_apic_id = 0xFE, .get_apic_id = flat_get_apic_id,
@@ -159,7 +153,6 @@ static struct apic apic_physflat __ro_af .disable_esr = 0, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = flat_phys_pkg_id, .max_apic_id = 0xFE, .get_apic_id = flat_get_apic_id,
arch/x86/kernel/apic/apic_noop.c +0 -3
@@ -29,7 +29,6 @@ static void noop_send_IPI_self(int vectostatic void noop_apic_icr_write (u32 low,u32 id) { }static int noop_wakeup_secondary_cpu (u32 apicid,unsigned long start_eip) {return -1 ; }static u64 noop_apic_icr_read (void ) {return 0 ; } -static u32 noop_phys_pkg_id (u32 cpuid_apic,int index_msb) {return 0 ; }static u32 noop_get_apic_id (u32 apicid) {return 0 ; }static void noop_apic_eoi (void ) { }
@@ -56,8 +55,6 @@ struct apic apic_noop __ro_after_init = .ioapic_phys_id_map = default_ioapic_phys_id_map, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = noop_phys_pkg_id, - .max_apic_id = 0xFE, .get_apic_id = noop_get_apic_id,
arch/x86/kernel/apic/apic_numachip.c +0 -7
@@ -56,11 +56,6 @@ static u32 numachip2_set_apic_id(u32 id)return id <<24 ; } -static u32 numachip_phys_pkg_id (u32 initial_apic_id,int index_msb) -{ -return initial_apic_id >> index_msb; -} -static void numachip1_apic_icr_write (int apicid,unsigned int val) {write_lcsr (CSR_G3_EXT_IRQ_GEN , (apicid <<16 ) | val);
@@ -228,7 +223,6 @@ static const struct apic apic_numachip1 .disable_esr = 0, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = numachip_phys_pkg_id, .max_apic_id = UINT_MAX, .get_apic_id = numachip1_get_apic_id,
@@ -265,7 +259,6 @@ static const struct apic apic_numachip2 .disable_esr = 0, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = numachip_phys_pkg_id, .max_apic_id = UINT_MAX, .get_apic_id = numachip2_get_apic_id,
arch/x86/kernel/apic/bigsmp_32.c +0 -6
@@ -29,11 +29,6 @@ static void bigsmp_ioapic_phys_id_map(phphysids_promote (0xFFL , retmap); } -static u32 bigsmp_phys_pkg_id (u32 cpuid_apic,int index_msb) -{ -return cpuid_apic >> index_msb; -} -static void bigsmp_send_IPI_allbutself (int vector) {default_send_IPI_mask_allbutself_phys (cpu_online_mask, vector);
@@ -88,7 +83,6 @@ static struct apic apic_bigsmp __ro_afte .check_apicid_used = bigsmp_check_apicid_used, .ioapic_phys_id_map = bigsmp_ioapic_phys_id_map, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = bigsmp_phys_pkg_id, .max_apic_id = 0xFE, .get_apic_id = bigsmp_get_apic_id,
arch/x86/kernel/apic/local.h +0 -1
@@ -17,7 +17,6 @@void __x2apic_send_IPI_dest (unsigned int apicid,int vector,unsigned int dest);u32 x2apic_get_apic_id (u32 id);u32 x2apic_set_apic_id (u32 id); -u32 x2apic_phys_pkg_id (u32 initial_apicid,int index_msb);void x2apic_send_IPI_all (int vector);void x2apic_send_IPI_allbutself (int vector);
arch/x86/kernel/apic/probe_32.c +0 -6
@@ -18,11 +18,6 @@#include "local.h" -static u32 default_phys_pkg_id (u32 cpuid_apic,int index_msb) -{ -return cpuid_apic >> index_msb; -} -static u32 default_get_apic_id (u32 x) {unsigned int ver =GET_APIC_VERSION (apic_read (APIC_LVR ));
@@ -54,7 +49,6 @@ static struct apic apic_default __ro_aft .init_apic_ldr = default_init_apic_ldr, .ioapic_phys_id_map = default_ioapic_phys_id_map, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = default_phys_pkg_id, .max_apic_id = 0xFE, .get_apic_id = default_get_apic_id,
arch/x86/kernel/apic/x2apic_cluster.c +0 -1
@@ -236,7 +236,6 @@ static struct apic apic_x2apic_cluster _ .init_apic_ldr = init_x2apic_ldr, .ioapic_phys_id_map = NULL, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = x2apic_phys_pkg_id, .max_apic_id = UINT_MAX, .x2apic_set_max_apicid = true,
arch/x86/kernel/apic/x2apic_phys.c +0 -6
@@ -134,11 +134,6 @@ u32 x2apic_set_apic_id(u32 id)return id; } -u32 x2apic_phys_pkg_id (u32 initial_apicid,int index_msb) -{ -return initial_apicid >> index_msb; -} -static struct apic apic_x2apic_phys__ro_after_init = { .name ="physical x2apic" ,
@@ -151,7 +146,6 @@ static struct apic apic_x2apic_phys __ro .disable_esr = 0, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = x2apic_phys_pkg_id, .max_apic_id = UINT_MAX, .x2apic_set_max_apicid = true,
arch/x86/kernel/apic/x2apic_uv_x.c +0 -11
@@ -785,16 +785,6 @@ static u32 set_apic_id(u32 id)return id; } -static unsigned int uv_read_apic_id (void ) -{ -return x2apic_get_apic_id (apic_read (APIC_ID )); -} - -static u32 uv_phys_pkg_id (u32 initial_apicid,int index_msb) -{ -return uv_read_apic_id () >> index_msb; -} -static int uv_probe (void ) {return apic == &apic_x2apic_uv_x;
@@ -812,7 +802,6 @@ static struct apic apic_x2apic_uv_x __ro .disable_esr = 0, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = uv_phys_pkg_id, .max_apic_id = UINT_MAX, .get_apic_id = x2apic_get_apic_id,
arch/x86/kernel/vsmp_64.c +0 -13
@@ -127,25 +127,12 @@ static void __init vsmp_cap_cpus(void)#endif } -static u32 apicid_phys_pkg_id (u32 initial_apic_id,int index_msb) -{ -return read_apic_id () >> index_msb; -} - -static void vsmp_apic_post_init (void ) -{ -/* need to update phys_pkg_id */ - apic->phys_pkg_id = apicid_phys_pkg_id; -} -void __init vsmp_init (void ) {detect_vsmp_box ();if (!is_vsmp_box ())return ; - x86_platform.apic_post_init = vsmp_apic_post_init; -vsmp_cap_cpus ();set_vsmp_ctl ();
arch/x86/xen/apic.c +0 -6
@@ -110,11 +110,6 @@ static int xen_madt_oem_check(char *oem_return xen_pv_domain (); } -static u32 xen_phys_pkg_id (u32 initial_apic_id,int index_msb) -{ -return initial_apic_id >> index_msb; -} -static u32 xen_cpu_present_to_apicid (int cpu) {if (cpu_present (cpu))
@@ -133,7 +128,6 @@ static struct apic xen_pv_apic __ro_afte .disable_esr = 0, .cpu_present_to_apicid = xen_cpu_present_to_apicid, - .phys_pkg_id = xen_phys_pkg_id, /* detect_ht */ .max_apic_id = UINT_MAX, .get_apic_id = xen_get_apic_id,
PATCH v4 40/41 x86/xen/smp_pv: Remove cpudata fiddling
In reply to Thomas GleixnerThe new topology CPUID parser installs already fake topology for XEN/PV, which ends up with cpuinfo::max_cores = 1.
---
V2: New patch
--- arch/x86/xen/smp_pv.c | 3 --- 1 file changed, 3 deletions(-)
arch/x86/xen/smp_pv.c +0 -3
@@ -73,7 +73,6 @@ static void cpu_bringup(void) } cpu =smp_processor_id ();smp_store_cpu_info (cpu); -cpu_data (cpu).x86_max_cores =1 ;set_cpu_sibling_map (cpu);speculative_store_bypass_ht_init ();
@@ -223,8 +222,6 @@ static void __init xen_pv_smp_prepare_cpsmp_prepare_cpus_common (); -cpu_data (0 ).x86_max_cores =1 ; -speculative_store_bypass_ht_init ();xen_pmu_init (0 );
PATCH v4 41/41 x86/apic/uv: Remove the private leaf 0xb parser
In reply to Thomas GleixnerThe package shift has been already evaluated by the early CPU init.
Put the mindless copy right next to the original leaf 0xb parser.
--- arch/x86/include/asm/topology.h | 5 +++ arch/x86/kernel/apic/x2apic_uv_x.c | 52 ++++++------------------------------- 2 files changed, 14 insertions(+), 43 deletions(-)
arch/x86/include/asm/topology.h +5 -0
@@ -126,6 +126,11 @@ static inline unsigned int topology_get_return x86_topo_system.dom_size[dom]; } +static inline unsigned int topology_get_domain_shift (enum x86_topology_domains dom) +{ +return dom ==TOPO_SMT_DOMAIN ?0 : x86_topo_system.dom_shifts[dom -1 ]; +} +extern const struct cpumask *cpu_coregroup_mask (int cpu);extern const struct cpumask *cpu_clustergroup_mask (int cpu);
arch/x86/kernel/apic/x2apic_uv_x.c +9 -43
63 lines not on this page · raw message
Quoted 8 lines · Thomas Gleixner
Hi!
This is the follow up to V3:
https://lore.kernel.org/lkml/[email protected]
which addresses the review feedback.
Quoted 9 lines
TLDR:
This reworks the way how topology information is evaluated via CPUID in preparation for a larger topology management overhaul to address shortcomings of the current code vs. hybrid systems and systems which make use of the extended topology domains in leaf
0x1f. Aside of that it's an overdue spring cleaning to get rid of accumulated layers of duct tape and haywire.
Given how often you had me reboot the adl thing ;-)
Quoted 40 lines · Thomas Gleixner
Hi!
This is the follow up to V3:
https://lore.kernel.org/lkml/[email protected]
which addresses the review feedback.
TLDR:
This reworks the way how topology information is evaluated via CPUID in preparation for a larger topology management overhaul to address shortcomings of the current code vs. hybrid systems and systems which make
use of the extended topology domains in leaf0x1f. Aside of that it's an
overdue spring cleaning to get rid of accumulated layers of duct tape and
haywire.What changed vs. V3:
- Added the Hygon fix from Pu Wen and adjusted the new code accordingly
- Fixed the off by one in the AMD parser for real - Michael
- Reworked the unknown domain type handling in the 0xb/01f parser - Rui
- Made core ID package relative - Rui
- Folded the missing u32 conversions - Qiuxu
- Folded the
fake_topology()fixup from the full topology series- Small cleanups and enhancements
- Picked up Tested-by tags
Quoted 10 lines
The series is based on the the APIC cleanup series in tip:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.gitx86/apicand also available on top of that from git:
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git topo- cpuid-v4
Although there is still discussion ongoing, I tested this patch series on two different platforms with Module Type enumerated, and the lscpu output as well as the topology sysfs look good, so
thanks,
rui