Skip to content

Commit 789f3fa

Browse files
Merge tag 'riscv-topo-on-6.0-rc1' of https://git.kernel.org/pub/scm/linux/kernel/git/conor/linux.git/ into for-next
Fix RISC-V's topology reporting The goal here is the fix the incorrectly reported arch topology on RISC-V which seems to have been broken since it was added. cpu, package and thread IDs are all currently reported as -1, so tools like lstopo think systems have multiple threads on the same core when this is not true: open-mpi/hwloc#536 arm64's topology code basically applies to RISC-V too, so it has been made generic along with the removal of MPIDR related code, which appears to be redudant code since '3102bc0e6ac7 ("arm64: topology: Stop using MPIDR for topology information")' replaced the code that actually interacted with MPIDR with default values. * tag 'riscv-topo-on-6.0-rc1' of https://git.kernel.org/pub/scm/linux/kernel/git/conor/linux.git/: riscv: topology: fix default topology reporting arm64: topology: move store_cpu_topology() to shared code
2 parents 568035b + fbd9280 commit 789f3fa

4 files changed

Lines changed: 22 additions & 42 deletions

File tree

arch/arm64/kernel/topology.c

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,46 +22,6 @@
2222
#include <asm/cputype.h>
2323
#include <asm/topology.h>
2424

25-
void store_cpu_topology(unsigned int cpuid)
26-
{
27-
struct cpu_topology *cpuid_topo = &cpu_topology[cpuid];
28-
u64 mpidr;
29-
30-
if (cpuid_topo->package_id != -1)
31-
goto topology_populated;
32-
33-
mpidr = read_cpuid_mpidr();
34-
35-
/* Uniprocessor systems can rely on default topology values */
36-
if (mpidr & MPIDR_UP_BITMASK)
37-
return;
38-
39-
/*
40-
* This would be the place to create cpu topology based on MPIDR.
41-
*
42-
* However, it cannot be trusted to depict the actual topology; some
43-
* pieces of the architecture enforce an artificial cap on Aff0 values
44-
* (e.g. GICv3's ICC_SGI1R_EL1 limits it to 15), leading to an
45-
* artificial cycling of Aff1, Aff2 and Aff3 values. IOW, these end up
46-
* having absolutely no relationship to the actual underlying system
47-
* topology, and cannot be reasonably used as core / package ID.
48-
*
49-
* If the MT bit is set, Aff0 *could* be used to define a thread ID, but
50-
* we still wouldn't be able to obtain a sane core ID. This means we
51-
* need to entirely ignore MPIDR for any topology deduction.
52-
*/
53-
cpuid_topo->thread_id = -1;
54-
cpuid_topo->core_id = cpuid;
55-
cpuid_topo->package_id = cpu_to_node(cpuid);
56-
57-
pr_debug("CPU%u: cluster %d core %d thread %d mpidr %#016llx\n",
58-
cpuid, cpuid_topo->package_id, cpuid_topo->core_id,
59-
cpuid_topo->thread_id, mpidr);
60-
61-
topology_populated:
62-
update_siblings_masks(cpuid);
63-
}
64-
6525
#ifdef CONFIG_ACPI
6626
static bool __init acpi_cpu_is_threaded(int cpu)
6727
{

arch/riscv/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ config RISCV
5252
select COMMON_CLK
5353
select CPU_PM if CPU_IDLE
5454
select EDAC_SUPPORT
55-
select GENERIC_ARCH_TOPOLOGY if SMP
55+
select GENERIC_ARCH_TOPOLOGY
5656
select GENERIC_ATOMIC64 if !64BIT
5757
select GENERIC_CLOCKEVENTS_BROADCAST if SMP
5858
select GENERIC_EARLY_IOREMAP

arch/riscv/kernel/smpboot.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
4949
unsigned int curr_cpuid;
5050

5151
curr_cpuid = smp_processor_id();
52+
store_cpu_topology(curr_cpuid);
5253
numa_store_cpu_info(curr_cpuid);
5354
numa_add_cpu(curr_cpuid);
5455

@@ -162,9 +163,9 @@ asmlinkage __visible void smp_callin(void)
162163
mmgrab(mm);
163164
current->active_mm = mm;
164165

166+
store_cpu_topology(curr_cpuid);
165167
notify_cpu_starting(curr_cpuid);
166168
numa_add_cpu(curr_cpuid);
167-
update_siblings_masks(curr_cpuid);
168169
set_cpu_online(curr_cpuid, 1);
169170

170171
/*

drivers/base/arch_topology.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,4 +841,23 @@ void __init init_cpu_topology(void)
841841
return;
842842
}
843843
}
844+
845+
void store_cpu_topology(unsigned int cpuid)
846+
{
847+
struct cpu_topology *cpuid_topo = &cpu_topology[cpuid];
848+
849+
if (cpuid_topo->package_id != -1)
850+
goto topology_populated;
851+
852+
cpuid_topo->thread_id = -1;
853+
cpuid_topo->core_id = cpuid;
854+
cpuid_topo->package_id = cpu_to_node(cpuid);
855+
856+
pr_debug("CPU%u: package %d core %d thread %d\n",
857+
cpuid, cpuid_topo->package_id, cpuid_topo->core_id,
858+
cpuid_topo->thread_id);
859+
860+
topology_populated:
861+
update_siblings_masks(cpuid);
862+
}
844863
#endif

0 commit comments

Comments
 (0)