arm64: topology: move store_cpu_topology() to shared code
Subsystems (5)
PATCH 1/2 arm64: topology: move store_cpu_topology() to shared code
commit 456797da792fa7cbf6698febf275fe9b36691f78 upstream.
arm64's method of defining a default cpu topology requires only minimal changes to apply to RISC-V also. The current arm64 implementation exits early in a uniprocessor configuration by reading MPIDR & claiming that uniprocessor can rely on the default values.
This is appears to be a hangover from prior to '3102bc0e6ac7 ("arm64:
topology: Stop using MPIDR for topology information")', because the current code just assigns default values for multiprocessor systems.
With the MPIDR references removed, store_cpu_topolgy() can be moved to the common arch_topology code.
--- arch/arm64/kernel/topology.c | 40 ------------------------------------ drivers/base/arch_topology.c | 19 +++++++++++++++++ 2 files changed, 19 insertions(+), 40 deletions(-)
arch/arm64/kernel/topology.c +0 -40
@@ -21,46 +21,6 @@#include <asm/cputype.h> #include <asm/topology.h> -void store_cpu_topology (unsigned int cpuid) -{ -struct cpu_topology *cpuid_topo = &cpu_topology[cpuid]; -u64 mpidr; - -if (cpuid_topo->package_id !=-1 ) - goto topology_populated; - - mpidr =read_cpuid_mpidr (); - -/* Uniprocessor systems can rely on default topology values */ -if (mpidr &MPIDR_UP_BITMASK ) -return ; - -/* -* This would be the place to create cpu topology based on MPIDR. -* -* However, it cannot be trusted to depict the actual topology; some -* pieces of the architecture enforce an artificial cap on Aff0 values -* (e.g. GICv3's ICC_SGI1R_EL1 limits it to 15), leading to an -* artificial cycling of Aff1, Aff2 and Aff3 values. IOW, these end up -* having absolutely no relationship to the actual underlying system -* topology, and cannot be reasonably used as core / package ID. -* -* If the MT bit is set, Aff0 *could* be used to define a thread ID, but -* we still wouldn't be able to obtain a sane core ID. This means we -* need to entirely ignore MPIDR for any topology deduction. -*/ - cpuid_topo->thread_id =-1 ; - cpuid_topo->core_id = cpuid; - cpuid_topo->package_id =cpu_to_node (cpuid); - -pr_debug ("CPU%u: cluster %d core %d thread %d mpidr %#016llx\n" , - cpuid, cpuid_topo->package_id, cpuid_topo->core_id, - cpuid_topo->thread_id, mpidr); - -topology_populated: -update_siblings_masks (cpuid); -} -#ifdef CONFIG_ACPI static bool __init acpi_cpu_is_threaded (int cpu) {
drivers/base/arch_topology.c +19 -0
@@ -538,4 +538,23 @@ void __init init_cpu_topology(void) else if (of_have_populated_dt() && parse_dt_topology()) reset_cpu_topology(); } + +void store_cpu_topology (unsigned int cpuid) +{ +struct cpu_topology *cpuid_topo = &cpu_topology[cpuid]; + +if (cpuid_topo->package_id !=-1 ) + goto topology_populated; + + cpuid_topo->thread_id =-1 ; + cpuid_topo->core_id = cpuid; + cpuid_topo->package_id =cpu_to_node (cpuid); + +pr_debug ("CPU%u: package %d core %d thread %d\n" , + cpuid, cpuid_topo->package_id, cpuid_topo->core_id, + cpuid_topo->thread_id); + +topology_populated: +update_siblings_masks (cpuid); +}#endif
Signature · 7 lines
2.38.0 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH 2/2 riscv: topology: fix default topology reporting
commit fbd92809997a391f28075f1c8b5ee314c225557c upstream.
RISC-V has no sane defaults to fall back on where there is no cpu-map in the devicetree.
Without sane defaults, the package, core and thread IDs are all set to -1. This causes user-visible inaccuracies for tools like hwloc/lstopo which rely on the sysfs cpu topology files to detect a system's topology.
On a PolarFire SoC, which should have 4 harts with a thread each, lstopo currently reports:
Machine (793MB total)
Package L#0
NUMANode L#0 (P#0 793MB)
Core L#0
L1d L#0 (32KB) + L1i L#0 (32KB) + PU L#0 (P#0)
L1d L#1 (32KB) + L1i L#1 (32KB) + PU L#1 (P#1)
L1d L#2 (32KB) + L1i L#2 (32KB) + PU L#2 (P#2)
L1d L#3 (32KB) + L1i L#3 (32KB) + PU L#3 (P#3)Adding calls to store_cpu_topology() in {boot,smp} hart bringup code results in the correct topolgy being reported:
Machine (793MB total)
Package L#0
NUMANode L#0 (P#0 793MB)
L1d L#0 (32KB) + L1i L#0 (32KB) + Core L#0 + PU L#0 (P#0)
L1d L#1 (32KB) + L1i L#1 (32KB) + Core L#1 + PU L#1 (P#1)
L1d L#2 (32KB) + L1i L#2 (32KB) + Core L#2 + PU L#2 (P#2)
L1d L#3 (32KB) + L1i L#3 (32KB) + Core L#3 + PU L#3 (P#3)---
I just resolved the conflicts. Tested in QEMU only. SMP doesn't seem to work in 5.4, using the same command that works for 5.10.
--- arch/riscv/Kconfig | 2 +- arch/riscv/kernel/smpboot.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-)
arch/riscv/Kconfig +1 -1
@@ -51,7 +51,7 @@ config RISCV select PCI_MSI if PCI select RISCV_TIMER select GENERIC_IRQ_MULTI_HANDLER - select GENERIC_ARCH_TOPOLOGY if SMP + select GENERIC_ARCH_TOPOLOGY select ARCH_HAS_PTE_SPECIAL select ARCH_HAS_MMIOWB select HAVE_EBPF_JIT if 64BIT
arch/riscv/kernel/smpboot.c +3 -1
@@ -46,6 +46,8 @@ void __init smp_prepare_cpus(unsigned int max_cpus) {int cpuid; +store_cpu_topology (smp_processor_id ()); +/* This covers non-smp usecase mandated by "nosmp" option */ if (max_cpus ==0 )return ;
@@ -142,8 +144,8 @@ asmlinkage __visible void __init smp_callin(void) current->active_mm = mm;trap_init (); +store_cpu_topology (smp_processor_id ());notify_cpu_starting (smp_processor_id ()); -update_siblings_masks (smp_processor_id ());set_cpu_online (smp_processor_id (),1 );/* * Remote TLB flushes are ignored while the CPU is offline, so emit
Signature · 7 lines
2.38.0 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Patch "riscv: topology: fix default topology reporting" has been added to the 5.4-stable tree
This is a note to let you know that I've just added the patch titled
riscv: topology: fix default topology reporting
to the 5.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
riscv-topology-fix-default-topology-reporting.patch
and it can be found in the queue-5.4 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From foo@baz Thu Oct 27 12:19:05 PM CEST 2022
From: Conor Dooley <[email protected]>
Date: Wed, 19 Oct 2022 13:52:10 +0100
Subject: riscv: topology: fix default topology reporting
To: <[email protected]>
Cc: <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, Atish Patra <[email protected]>
Message-ID: <[email protected]>
From: Conor Dooley <[email protected]>
commit fbd92809997a391f28075f1c8b5ee314c225557c upstream.
RISC-V has no sane defaults to fall back on where there is no cpu-map in the devicetree.
Without sane defaults, the package, core and thread IDs are all set to -1. This causes user-visible inaccuracies for tools like hwloc/lstopo which rely on the sysfs cpu topology files to detect a system's topology.
On a PolarFire SoC, which should have 4 harts with a thread each, lstopo currently reports:
Machine (793MB total)
Package L#0
NUMANode L#0 (P#0 793MB)
Core L#0
L1d L#0 (32KB) + L1i L#0 (32KB) + PU L#0 (P#0)
L1d L#1 (32KB) + L1i L#1 (32KB) + PU L#1 (P#1)
L1d L#2 (32KB) + L1i L#2 (32KB) + PU L#2 (P#2)
L1d L#3 (32KB) + L1i L#3 (32KB) + PU L#3 (P#3)Adding calls to store_cpu_topology() in {boot,smp} hart bringup code results in the correct topolgy being reported:
Machine (793MB total)
Package L#0
NUMANode L#0 (P#0 793MB)
L1d L#0 (32KB) + L1i L#0 (32KB) + Core L#0 + PU L#0 (P#0)
L1d L#1 (32KB) + L1i L#1 (32KB) + Core L#1 + PU L#1 (P#1)
L1d L#2 (32KB) + L1i L#2 (32KB) + Core L#2 + PU L#2 (P#2)
L1d L#3 (32KB) + L1i L#3 (32KB) + Core L#3 + PU L#3 (P#3)--- arch/riscv/Kconfig | 2 +- arch/riscv/kernel/smpboot.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-)
arch/riscv/Kconfig +1 -1
@@ -51,7 +51,7 @@ config RISCV select PCI_MSI if PCI select RISCV_TIMER select GENERIC_IRQ_MULTI_HANDLER - select GENERIC_ARCH_TOPOLOGY if SMP + select GENERIC_ARCH_TOPOLOGY select ARCH_HAS_PTE_SPECIAL select ARCH_HAS_MMIOWB select HAVE_EBPF_JIT if 64BIT
arch/riscv/kernel/smpboot.c +3 -1
@@ -46,6 +46,8 @@ void __init smp_prepare_cpus(unsigned in {int cpuid; +store_cpu_topology (smp_processor_id ()); +/* This covers non-smp usecase mandated by "nosmp" option */ if (max_cpus ==0 )return ;
@@ -142,8 +144,8 @@ asmlinkage __visible void __init smp_cal current->active_mm = mm;trap_init (); +store_cpu_topology (smp_processor_id ());notify_cpu_starting (smp_processor_id ()); -update_siblings_masks (smp_processor_id ());set_cpu_online (smp_processor_id (),1 );/* * Remote TLB flushes are ignored while the CPU is offline, so emit
Patches currently in stable-queue which might be from [email protected] are
queue-5.4/arm64-topology-move-store_cpu_topology-to-shared-code.patch queue-5.4/riscv-topology-fix-default-topology-reporting.patch
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Patch "arm64: topology: move store_cpu_topology() to shared code" has been added to the 5.4-stable tree
In reply to Conor DooleyThis is a note to let you know that I've just added the patch titled
arm64: topology: move store_cpu_topology() to shared code
to the 5.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
arm64-topology-move-store_cpu_topology-to-shared-code.patch
and it can be found in the queue-5.4 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From foo@baz Thu Oct 27 12:19:05 PM CEST 2022
From: Conor Dooley <[email protected]>
Date: Wed, 19 Oct 2022 13:52:09 +0100
Subject: arm64: topology: move store_cpu_topology() to shared code
To: <[email protected]>
Cc: <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, Atish Patra <[email protected]>
Message-ID: <[email protected]>
From: Conor Dooley <[email protected]>
commit 456797da792fa7cbf6698febf275fe9b36691f78 upstream.
arm64's method of defining a default cpu topology requires only minimal changes to apply to RISC-V also. The current arm64 implementation exits early in a uniprocessor configuration by reading MPIDR & claiming that uniprocessor can rely on the default values.
This is appears to be a hangover from prior to '3102bc0e6ac7 ("arm64:
topology: Stop using MPIDR for topology information")', because the current code just assigns default values for multiprocessor systems.
With the MPIDR references removed, store_cpu_topolgy() can be moved to the common arch_topology code.
--- arch/arm64/kernel/topology.c | 40 ---------------------------------------- drivers/base/arch_topology.c | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 40 deletions(-)
arch/arm64/kernel/topology.c +0 -40
@@ -21,46 +21,6 @@#include <asm/cputype.h> #include <asm/topology.h> -void store_cpu_topology (unsigned int cpuid) -{ -struct cpu_topology *cpuid_topo = &cpu_topology[cpuid]; -u64 mpidr; - -if (cpuid_topo->package_id !=-1 ) - goto topology_populated; - - mpidr =read_cpuid_mpidr (); - -/* Uniprocessor systems can rely on default topology values */ -if (mpidr &MPIDR_UP_BITMASK ) -return ; - -/* -* This would be the place to create cpu topology based on MPIDR. -* -* However, it cannot be trusted to depict the actual topology; some -* pieces of the architecture enforce an artificial cap on Aff0 values -* (e.g. GICv3's ICC_SGI1R_EL1 limits it to 15), leading to an -* artificial cycling of Aff1, Aff2 and Aff3 values. IOW, these end up -* having absolutely no relationship to the actual underlying system -* topology, and cannot be reasonably used as core / package ID. -* -* If the MT bit is set, Aff0 *could* be used to define a thread ID, but -* we still wouldn't be able to obtain a sane core ID. This means we -* need to entirely ignore MPIDR for any topology deduction. -*/ - cpuid_topo->thread_id =-1 ; - cpuid_topo->core_id = cpuid; - cpuid_topo->package_id =cpu_to_node (cpuid); - -pr_debug ("CPU%u: cluster %d core %d thread %d mpidr %#016llx\n" , - cpuid, cpuid_topo->package_id, cpuid_topo->core_id, - cpuid_topo->thread_id, mpidr); - -topology_populated: -update_siblings_masks (cpuid); -} -#ifdef CONFIG_ACPI static bool __init acpi_cpu_is_threaded (int cpu) {
drivers/base/arch_topology.c +19 -0
@@ -538,4 +538,23 @@ void __init init_cpu_topology(void) else if (of_have_populated_dt() && parse_dt_topology()) reset_cpu_topology(); } + +void store_cpu_topology (unsigned int cpuid) +{ +struct cpu_topology *cpuid_topo = &cpu_topology[cpuid]; + +if (cpuid_topo->package_id !=-1 ) + goto topology_populated; + + cpuid_topo->thread_id =-1 ; + cpuid_topo->core_id = cpuid; + cpuid_topo->package_id =cpu_to_node (cpuid); + +pr_debug ("CPU%u: package %d core %d thread %d\n" , + cpuid, cpuid_topo->package_id, cpuid_topo->core_id, + cpuid_topo->thread_id); + +topology_populated: +update_siblings_masks (cpuid); +}#endif
Patches currently in stable-queue which might be from [email protected] are
queue-5.4/arm64-topology-move-store_cpu_topology-to-shared-code.patch queue-5.4/riscv-topology-fix-default-topology-reporting.patch
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv