* [PATCH v12 1/4] cpu/SMT: Provide a default topology_is_primary_thread()
2025-03-11 7:51 [PATCH v12 0/4] Support SMT control on arm64 Yicong Yang
@ 2025-03-11 7:51 ` Yicong Yang
2025-03-11 14:41 ` Sudeep Holla
2025-03-11 7:51 ` [PATCH v12 2/4] arch_topology: Support SMT control for OF based system Yicong Yang
` (4 subsequent siblings)
5 siblings, 1 reply; 15+ messages in thread
From: Yicong Yang @ 2025-03-11 7:51 UTC (permalink / raw)
To: catalin.marinas, will, sudeep.holla, tglx, peterz, mpe,
linux-arm-kernel, mingo, bp, dave.hansen, pierre.gondois,
dietmar.eggemann
Cc: linuxppc-dev, x86, linux-kernel, morten.rasmussen, msuchanek,
gregkh, rafael, jonathan.cameron, prime.zeng, linuxarm,
yangyicong, xuwei5, guohanjun, sshegde
From: Yicong Yang <yangyicong@hisilicon.com>
Currently if architectures want to support HOTPLUG_SMT they need to
provide a topology_is_primary_thread() telling the framework which
thread in the SMT cannot offline. However arm64 doesn't have a
restriction on which thread in the SMT cannot offline, a simplest
choice is that just make 1st thread as the "primary" thread. So
just make this as the default implementation in the framework and
let architectures like x86 that have special primary thread to
override this function (which they've already done).
There's no need to provide a stub function if !CONFIG_SMP or
!CONFIG_HOTPLUG_SMT. In such case the testing CPU is already
the 1st CPU in the SMT so it's always the primary thread.
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Pierre Gondois <pierre.gondois@arm.com>
Reviewed-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
---
Pre questioned in v9 [1] whether this works on architectures not using
CONFIG_GENERIC_ARCH_TOPOLOGY, See [2] for demonstration hacking on LoongArch
VM and this also works. Architectures should use this on their own situation.
[1] https://lore.kernel.org/linux-arm-kernel/427bd639-33c3-47e4-9e83-68c428eb1a7d@arm.com/
[2] https://lore.kernel.org/linux-arm-kernel/a5690fee-3019-f26c-8bad-1d95e388e877@huawei.com/
arch/powerpc/include/asm/topology.h | 1 +
arch/x86/include/asm/topology.h | 2 +-
include/linux/topology.h | 24 ++++++++++++++++++++++++
3 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/include/asm/topology.h b/arch/powerpc/include/asm/topology.h
index 16bacfe8c7a2..da15b5efe807 100644
--- a/arch/powerpc/include/asm/topology.h
+++ b/arch/powerpc/include/asm/topology.h
@@ -152,6 +152,7 @@ static inline bool topology_is_primary_thread(unsigned int cpu)
{
return cpu == cpu_first_thread_sibling(cpu);
}
+#define topology_is_primary_thread topology_is_primary_thread
static inline bool topology_smt_thread_allowed(unsigned int cpu)
{
diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h
index ec134b719144..6c79ee7c0957 100644
--- a/arch/x86/include/asm/topology.h
+++ b/arch/x86/include/asm/topology.h
@@ -229,11 +229,11 @@ static inline bool topology_is_primary_thread(unsigned int cpu)
{
return cpumask_test_cpu(cpu, cpu_primary_thread_mask);
}
+#define topology_is_primary_thread topology_is_primary_thread
#else /* CONFIG_SMP */
static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return 0; }
static inline int topology_max_smt_threads(void) { return 1; }
-static inline bool topology_is_primary_thread(unsigned int cpu) { return true; }
static inline unsigned int topology_amd_nodes_per_pkg(void) { return 1; }
#endif /* !CONFIG_SMP */
diff --git a/include/linux/topology.h b/include/linux/topology.h
index 52f5850730b3..6ae995e18ff5 100644
--- a/include/linux/topology.h
+++ b/include/linux/topology.h
@@ -240,6 +240,30 @@ static inline const struct cpumask *cpu_smt_mask(int cpu)
}
#endif
+#ifndef topology_is_primary_thread
+
+#define topology_is_primary_thread topology_is_primary_thread
+
+static inline bool topology_is_primary_thread(unsigned int cpu)
+{
+ /*
+ * When disabling SMT the primary thread of the SMT will remain
+ * enabled/active. Architectures do have a special primary thread
+ * (e.g. x86) needs to override this function. Otherwise can make
+ * the first thread in the SMT as the primary thread.
+ *
+ * The sibling cpumask of an offline CPU contains always the CPU
+ * itself for architectures using the implementation of
+ * CONFIG_GENERIC_ARCH_TOPOLOGY for building their topology.
+ * Other architectures not using CONFIG_GENERIC_ARCH_TOPOLOGY for
+ * building their topology have to check whether to use this default
+ * implementation or to override it.
+ */
+ return cpu == cpumask_first(topology_sibling_cpumask(cpu));
+}
+
+#endif
+
static inline const struct cpumask *cpu_cpu_mask(int cpu)
{
return cpumask_of_node(cpu_to_node(cpu));
--
2.24.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v12 1/4] cpu/SMT: Provide a default topology_is_primary_thread()
2025-03-11 7:51 ` [PATCH v12 1/4] cpu/SMT: Provide a default topology_is_primary_thread() Yicong Yang
@ 2025-03-11 14:41 ` Sudeep Holla
0 siblings, 0 replies; 15+ messages in thread
From: Sudeep Holla @ 2025-03-11 14:41 UTC (permalink / raw)
To: Yicong Yang
Cc: catalin.marinas, will, tglx, peterz, mpe, linux-arm-kernel, mingo,
bp, dave.hansen, pierre.gondois, dietmar.eggemann, linuxppc-dev,
x86, linux-kernel, morten.rasmussen, msuchanek, gregkh, rafael,
jonathan.cameron, prime.zeng, linuxarm, yangyicong, xuwei5,
guohanjun, sshegde
On Tue, Mar 11, 2025 at 03:51:40PM +0800, Yicong Yang wrote:
> From: Yicong Yang <yangyicong@hisilicon.com>
>
> Currently if architectures want to support HOTPLUG_SMT they need to
> provide a topology_is_primary_thread() telling the framework which
> thread in the SMT cannot offline. However arm64 doesn't have a
> restriction on which thread in the SMT cannot offline, a simplest
> choice is that just make 1st thread as the "primary" thread. So
> just make this as the default implementation in the framework and
> let architectures like x86 that have special primary thread to
> override this function (which they've already done).
>
> There's no need to provide a stub function if !CONFIG_SMP or
> !CONFIG_HOTPLUG_SMT. In such case the testing CPU is already
> the 1st CPU in the SMT so it's always the primary thread.
>
LGTM:
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
> + * enabled/active. Architectures do have a special primary thread
If you respin
^^ s/do/that/ or s/do/that do/
--
Regards,
Sudeep
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v12 2/4] arch_topology: Support SMT control for OF based system
2025-03-11 7:51 [PATCH v12 0/4] Support SMT control on arm64 Yicong Yang
2025-03-11 7:51 ` [PATCH v12 1/4] cpu/SMT: Provide a default topology_is_primary_thread() Yicong Yang
@ 2025-03-11 7:51 ` Yicong Yang
2025-03-11 14:42 ` Sudeep Holla
` (2 more replies)
2025-03-11 7:51 ` [PATCH v12 3/4] arm64: topology: Support SMT control on ACPI " Yicong Yang
` (3 subsequent siblings)
5 siblings, 3 replies; 15+ messages in thread
From: Yicong Yang @ 2025-03-11 7:51 UTC (permalink / raw)
To: catalin.marinas, will, sudeep.holla, tglx, peterz, mpe,
linux-arm-kernel, mingo, bp, dave.hansen, pierre.gondois,
dietmar.eggemann
Cc: linuxppc-dev, x86, linux-kernel, morten.rasmussen, msuchanek,
gregkh, rafael, jonathan.cameron, prime.zeng, linuxarm,
yangyicong, xuwei5, guohanjun, sshegde
From: Yicong Yang <yangyicong@hisilicon.com>
On building the topology from the devicetree, we've already gotten the
SMT thread number of each core. Update the largest SMT thread number
and enable the SMT control by the end of topology parsing.
The framework's SMT control provides two interface to the users [1]
through /sys/devices/system/cpu/smt/control:
1) enable SMT by writing "on" and disable by "off"
2) enable SMT by writing max_thread_number or disable by writing 1
Both method support to completely disable/enable the SMT cores so both
work correctly for symmetric SMT platform and asymmetric platform with
non-SMT and one type SMT cores like:
core A: 1 thread
core B: X (X!=1) threads
Note that for a theoretically possible multiple SMT-X (X>1) core
platform the SMT control is also supported as expected but only
by writing the "on/off" method.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/ABI/testing/sysfs-devices-system-cpu#n542
Reviewed-by: Pierre Gondois <pierre.gondois@arm.com>
Reviewed-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
---
drivers/base/arch_topology.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index 3ebe77566788..d409d323ee64 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -11,6 +11,7 @@
#include <linux/cleanup.h>
#include <linux/cpu.h>
#include <linux/cpufreq.h>
+#include <linux/cpu_smt.h>
#include <linux/device.h>
#include <linux/of.h>
#include <linux/slab.h>
@@ -506,6 +507,10 @@ core_initcall(free_raw_capacity);
#endif
#if defined(CONFIG_ARM64) || defined(CONFIG_RISCV)
+
+/* Used to enable the SMT control */
+static unsigned int max_smt_thread_num = 1;
+
/*
* This function returns the logic cpu number of the node.
* There are basically three kinds of return values:
@@ -565,6 +570,8 @@ static int __init parse_core(struct device_node *core, int package_id,
i++;
} while (1);
+ max_smt_thread_num = max_t(unsigned int, max_smt_thread_num, i);
+
cpu = get_cpu_for_node(core);
if (cpu >= 0) {
if (!leaf) {
@@ -677,6 +684,17 @@ static int __init parse_socket(struct device_node *socket)
if (!has_socket)
ret = parse_cluster(socket, 0, -1, 0);
+ /*
+ * Reset the max_smt_thread_num to 1 on failure. Since on failure
+ * we need to notify the framework the SMT is not supported, but
+ * max_smt_thread_num can be initialized to the SMT thread number
+ * of the cores which are successfully parsed.
+ */
+ if (ret)
+ max_smt_thread_num = 1;
+
+ cpu_smt_set_num_threads(max_smt_thread_num, max_smt_thread_num);
+
return ret;
}
--
2.24.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v12 2/4] arch_topology: Support SMT control for OF based system
2025-03-11 7:51 ` [PATCH v12 2/4] arch_topology: Support SMT control for OF based system Yicong Yang
@ 2025-03-11 14:42 ` Sudeep Holla
2025-03-13 9:16 ` Jonathan Cameron
2025-03-17 9:56 ` Dietmar Eggemann
2 siblings, 0 replies; 15+ messages in thread
From: Sudeep Holla @ 2025-03-11 14:42 UTC (permalink / raw)
To: Yicong Yang
Cc: catalin.marinas, will, tglx, peterz, mpe, linux-arm-kernel, mingo,
bp, dave.hansen, pierre.gondois, dietmar.eggemann, linuxppc-dev,
x86, linux-kernel, morten.rasmussen, msuchanek, gregkh, rafael,
jonathan.cameron, prime.zeng, linuxarm, yangyicong, xuwei5,
guohanjun, sshegde
On Tue, Mar 11, 2025 at 03:51:41PM +0800, Yicong Yang wrote:
> From: Yicong Yang <yangyicong@hisilicon.com>
>
> On building the topology from the devicetree, we've already gotten the
> SMT thread number of each core. Update the largest SMT thread number
> and enable the SMT control by the end of topology parsing.
>
> The framework's SMT control provides two interface to the users [1]
> through /sys/devices/system/cpu/smt/control:
> 1) enable SMT by writing "on" and disable by "off"
> 2) enable SMT by writing max_thread_number or disable by writing 1
>
> Both method support to completely disable/enable the SMT cores so both
> work correctly for symmetric SMT platform and asymmetric platform with
> non-SMT and one type SMT cores like:
> core A: 1 thread
> core B: X (X!=1) threads
>
> Note that for a theoretically possible multiple SMT-X (X>1) core
> platform the SMT control is also supported as expected but only
> by writing the "on/off" method.
>
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/ABI/testing/sysfs-devices-system-cpu#n542
Just the path must suffice here, no need for URL.
LGTM otherwise, much simple now:
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
--
Regards,
Sudeep
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v12 2/4] arch_topology: Support SMT control for OF based system
2025-03-11 7:51 ` [PATCH v12 2/4] arch_topology: Support SMT control for OF based system Yicong Yang
2025-03-11 14:42 ` Sudeep Holla
@ 2025-03-13 9:16 ` Jonathan Cameron
2025-03-17 9:56 ` Dietmar Eggemann
2 siblings, 0 replies; 15+ messages in thread
From: Jonathan Cameron @ 2025-03-13 9:16 UTC (permalink / raw)
To: Yicong Yang
Cc: catalin.marinas, will, sudeep.holla, tglx, peterz, mpe,
linux-arm-kernel, mingo, bp, dave.hansen, pierre.gondois,
dietmar.eggemann, linuxppc-dev, x86, linux-kernel,
morten.rasmussen, msuchanek, gregkh, rafael, prime.zeng, linuxarm,
yangyicong, xuwei5, guohanjun, sshegde
On Tue, 11 Mar 2025 15:51:41 +0800
Yicong Yang <yangyicong@huawei.com> wrote:
> From: Yicong Yang <yangyicong@hisilicon.com>
>
> On building the topology from the devicetree, we've already gotten the
> SMT thread number of each core. Update the largest SMT thread number
> and enable the SMT control by the end of topology parsing.
>
> The framework's SMT control provides two interface to the users [1]
> through /sys/devices/system/cpu/smt/control:
> 1) enable SMT by writing "on" and disable by "off"
> 2) enable SMT by writing max_thread_number or disable by writing 1
>
> Both method support to completely disable/enable the SMT cores so both
> work correctly for symmetric SMT platform and asymmetric platform with
> non-SMT and one type SMT cores like:
> core A: 1 thread
> core B: X (X!=1) threads
>
> Note that for a theoretically possible multiple SMT-X (X>1) core
> platform the SMT control is also supported as expected but only
> by writing the "on/off" method.
>
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/ABI/testing/sysfs-devices-system-cpu#n542
> Reviewed-by: Pierre Gondois <pierre.gondois@arm.com>
> Reviewed-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v12 2/4] arch_topology: Support SMT control for OF based system
2025-03-11 7:51 ` [PATCH v12 2/4] arch_topology: Support SMT control for OF based system Yicong Yang
2025-03-11 14:42 ` Sudeep Holla
2025-03-13 9:16 ` Jonathan Cameron
@ 2025-03-17 9:56 ` Dietmar Eggemann
2025-03-17 11:29 ` Yicong Yang
2 siblings, 1 reply; 15+ messages in thread
From: Dietmar Eggemann @ 2025-03-17 9:56 UTC (permalink / raw)
To: Yicong Yang, catalin.marinas, will, sudeep.holla, tglx, peterz,
mpe, linux-arm-kernel, mingo, bp, dave.hansen, pierre.gondois
Cc: linuxppc-dev, x86, linux-kernel, morten.rasmussen, msuchanek,
gregkh, rafael, jonathan.cameron, prime.zeng, linuxarm,
yangyicong, xuwei5, guohanjun, sshegde
On 11/03/2025 08:51, Yicong Yang wrote:
> From: Yicong Yang <yangyicong@hisilicon.com>
>
> On building the topology from the devicetree, we've already gotten the
> SMT thread number of each core. Update the largest SMT thread number
> and enable the SMT control by the end of topology parsing.
>
> The framework's SMT control provides two interface to the users [1]
> through /sys/devices/system/cpu/smt/control:
> 1) enable SMT by writing "on" and disable by "off"
> 2) enable SMT by writing max_thread_number or disable by writing 1
>
> Both method support to completely disable/enable the SMT cores so both
> work correctly for symmetric SMT platform and asymmetric platform with
> non-SMT and one type SMT cores like:
> core A: 1 thread
> core B: X (X!=1) threads
>
> Note that for a theoretically possible multiple SMT-X (X>1) core
> platform the SMT control is also supported as expected but only
> by writing the "on/off" method.
Here we still have a little misunderstanding. IMHO, even on such a
system 2) would work too.
My qemu example with SMT-1, SMT-2 and SMT-4 in one system from your v11:
# cat /proc/schedstat | grep -v "^v\|^t" | awk '{print $1" "$2" "$3}'
cpu0 0 0
domain0 MC ff
cpu1 0 0
domain0 MC ff
cpu2 0 0
domain0 SMT 0c
domain1 MC ff
cpu3 0 0
domain0 SMT 0c
domain1 MC ff
cpu4 0 0
domain0 SMT f0
domain1 MC ff
cpu5 0 0
domain0 SMT f0
domain1 MC ff
cpu6 0 0
domain0 SMT f0
domain1 MC ff
cpu7 0 0
domain0 SMT f0
domain1 MC ff
# cat /proc/cpuinfo | grep ^processor
processor : 0
processor : 1
processor : 2
processor : 3
processor : 4
processor : 5
processor : 6
processor : 7
# echo 1 > /sys/devices/system/cpu/smt/control
# cat /proc/cpuinfo | grep ^processor
processor : 0
processor : 1
processor : 2
processor : 4
# echo 4 > /sys/devices/system/cpu/smt/control
# cat /proc/cpuinfo | grep ^processor
processor : 0
processor : 1
processor : 2
processor : 3
processor : 4
processor : 5
processor : 6
processor : 7
Whats doesn't work is to echoing a '2' but that's not
'max_thread_number' of the system.
[...]
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v12 2/4] arch_topology: Support SMT control for OF based system
2025-03-17 9:56 ` Dietmar Eggemann
@ 2025-03-17 11:29 ` Yicong Yang
2025-03-17 16:18 ` Dietmar Eggemann
0 siblings, 1 reply; 15+ messages in thread
From: Yicong Yang @ 2025-03-17 11:29 UTC (permalink / raw)
To: Dietmar Eggemann
Cc: catalin.marinas, will, sudeep.holla, tglx, peterz, mpe,
linux-arm-kernel, mingo, bp, dave.hansen, pierre.gondois,
yangyicong, linuxppc-dev, x86, linux-kernel, morten.rasmussen,
msuchanek, gregkh, rafael, jonathan.cameron, prime.zeng, linuxarm,
xuwei5, guohanjun, sshegde
On 2025/3/17 17:56, Dietmar Eggemann wrote:
> On 11/03/2025 08:51, Yicong Yang wrote:
>> From: Yicong Yang <yangyicong@hisilicon.com>
>>
>> On building the topology from the devicetree, we've already gotten the
>> SMT thread number of each core. Update the largest SMT thread number
>> and enable the SMT control by the end of topology parsing.
>>
>> The framework's SMT control provides two interface to the users [1]
>> through /sys/devices/system/cpu/smt/control:
>> 1) enable SMT by writing "on" and disable by "off"
>> 2) enable SMT by writing max_thread_number or disable by writing 1
>>
>> Both method support to completely disable/enable the SMT cores so both
>> work correctly for symmetric SMT platform and asymmetric platform with
>> non-SMT and one type SMT cores like:
>> core A: 1 thread
>> core B: X (X!=1) threads
>>
>> Note that for a theoretically possible multiple SMT-X (X>1) core
>> platform the SMT control is also supported as expected but only
>> by writing the "on/off" method.
>
> Here we still have a little misunderstanding. IMHO, even on such a
> system 2) would work too.
>
yes but only by writing the max_thread_number. e.g. a system with SMT number
of 1 (no SMT core), X, Y (Y > X), 1 works same as "off" and Y works same as
"on", as you shown below. write X will be blocked by the CPU framework:
estuary:/sys/devices/system/cpu/smt$ cat control
off
# emulated CPU 0-7,16-22 as SMT-2, CPU 8-11,24-27 as SMT-4
estuary:/sys/devices/system/cpu/smt$ cat ../online
0,2,4,6,8,12-16,18,20,22,24,28-31
estuary:/sys/devices/system/cpu/smt$ echo 2 > control
bash: echo: write error: Invalid argument
estuary:/sys/devices/system/cpu/smt$ echo 4 > control
estuary:/sys/devices/system/cpu/smt$ cat ../online
0-31
so method 1) will always match the expectation to fully enable/disable the
SMT on all cores, that's I mean here. But 2) won't work if user expected
to write 2 to enable SMT-2 (I think it'll will work if we support
CONFIG_SMT_NUM_THREADS_DYNAMIC on arm64 later).
Thanks.
> My qemu example with SMT-1, SMT-2 and SMT-4 in one system from your v11:
>
> # cat /proc/schedstat | grep -v "^v\|^t" | awk '{print $1" "$2" "$3}'
> cpu0 0 0
> domain0 MC ff
> cpu1 0 0
> domain0 MC ff
> cpu2 0 0
> domain0 SMT 0c
> domain1 MC ff
> cpu3 0 0
> domain0 SMT 0c
> domain1 MC ff
> cpu4 0 0
> domain0 SMT f0
> domain1 MC ff
> cpu5 0 0
> domain0 SMT f0
> domain1 MC ff
> cpu6 0 0
> domain0 SMT f0
> domain1 MC ff
> cpu7 0 0
> domain0 SMT f0
> domain1 MC ff
>
> # cat /proc/cpuinfo | grep ^processor
> processor : 0
> processor : 1
> processor : 2
> processor : 3
> processor : 4
> processor : 5
> processor : 6
> processor : 7
>
> # echo 1 > /sys/devices/system/cpu/smt/control
>
> # cat /proc/cpuinfo | grep ^processor
> processor : 0
> processor : 1
> processor : 2
> processor : 4
>
> # echo 4 > /sys/devices/system/cpu/smt/control
>
> # cat /proc/cpuinfo | grep ^processor
> processor : 0
> processor : 1
> processor : 2
> processor : 3
> processor : 4
> processor : 5
> processor : 6
> processor : 7
>
> Whats doesn't work is to echoing a '2' but that's not
> 'max_thread_number' of the system.
>
> [...]
>
> .
>
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v12 2/4] arch_topology: Support SMT control for OF based system
2025-03-17 11:29 ` Yicong Yang
@ 2025-03-17 16:18 ` Dietmar Eggemann
0 siblings, 0 replies; 15+ messages in thread
From: Dietmar Eggemann @ 2025-03-17 16:18 UTC (permalink / raw)
To: Yicong Yang
Cc: catalin.marinas, will, sudeep.holla, tglx, peterz, mpe,
linux-arm-kernel, mingo, bp, dave.hansen, pierre.gondois,
yangyicong, linuxppc-dev, x86, linux-kernel, morten.rasmussen,
msuchanek, gregkh, rafael, jonathan.cameron, prime.zeng, linuxarm,
xuwei5, guohanjun, sshegde
On 17/03/2025 12:29, Yicong Yang wrote:
> On 2025/3/17 17:56, Dietmar Eggemann wrote:
>> On 11/03/2025 08:51, Yicong Yang wrote:
>>> From: Yicong Yang <yangyicong@hisilicon.com>
[...]
>>> Both method support to completely disable/enable the SMT cores so both
>>> work correctly for symmetric SMT platform and asymmetric platform with
>>> non-SMT and one type SMT cores like:
>>> core A: 1 thread
>>> core B: X (X!=1) threads
>>>
>>> Note that for a theoretically possible multiple SMT-X (X>1) core
>>> platform the SMT control is also supported as expected but only
>>> by writing the "on/off" method.
>>
>> Here we still have a little misunderstanding. IMHO, even on such a
>> system 2) would work too.
>>
>
>
> yes but only by writing the max_thread_number. e.g. a system with SMT number
> of 1 (no SMT core), X, Y (Y > X), 1 works same as "off" and Y works same as
> "on", as you shown below. write X will be blocked by the CPU framework:
> estuary:/sys/devices/system/cpu/smt$ cat control
> off
> # emulated CPU 0-7,16-22 as SMT-2, CPU 8-11,24-27 as SMT-4
> estuary:/sys/devices/system/cpu/smt$ cat ../online
> 0,2,4,6,8,12-16,18,20,22,24,28-31
> estuary:/sys/devices/system/cpu/smt$ echo 2 > control
> bash: echo: write error: Invalid argument
> estuary:/sys/devices/system/cpu/smt$ echo 4 > control
> estuary:/sys/devices/system/cpu/smt$ cat ../online
> 0-31
>
> so method 1) will always match the expectation to fully enable/disable the
> SMT on all cores, that's I mean here. But 2) won't work if user expected
> to write 2 to enable SMT-2 (I think it'll will work if we support
> CONFIG_SMT_NUM_THREADS_DYNAMIC on arm64 later).
OK, looks like you're aware of this then. Just saying that technically
'4' would be the max thread number of the system and not '2' so it still
looks OK from this perspective. But OK, we don't have those systems now
anyway.
[...]
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v12 3/4] arm64: topology: Support SMT control on ACPI based system
2025-03-11 7:51 [PATCH v12 0/4] Support SMT control on arm64 Yicong Yang
2025-03-11 7:51 ` [PATCH v12 1/4] cpu/SMT: Provide a default topology_is_primary_thread() Yicong Yang
2025-03-11 7:51 ` [PATCH v12 2/4] arch_topology: Support SMT control for OF based system Yicong Yang
@ 2025-03-11 7:51 ` Yicong Yang
2025-03-11 14:42 ` Sudeep Holla
2025-03-11 7:51 ` [PATCH v12 4/4] arm64: Kconfig: Enable HOTPLUG_SMT Yicong Yang
` (2 subsequent siblings)
5 siblings, 1 reply; 15+ messages in thread
From: Yicong Yang @ 2025-03-11 7:51 UTC (permalink / raw)
To: catalin.marinas, will, sudeep.holla, tglx, peterz, mpe,
linux-arm-kernel, mingo, bp, dave.hansen, pierre.gondois,
dietmar.eggemann
Cc: linuxppc-dev, x86, linux-kernel, morten.rasmussen, msuchanek,
gregkh, rafael, jonathan.cameron, prime.zeng, linuxarm,
yangyicong, xuwei5, guohanjun, sshegde
From: Yicong Yang <yangyicong@hisilicon.com>
For ACPI we'll build the topology from PPTT and we cannot directly
get the SMT number of each core. Instead using a temporary xarray
to record the heterogeneous information (from ACPI_PPTT_ACPI_IDENTICAL)
and SMT information of the first core in its heterogeneous CPU cluster
when building the topology. Then we can know the largest SMT number
in the system. If a homogeneous system's using ACPI 6.2 or later,
all the CPUs should be under the root node of PPTT. There'll be
only one entry in the xarray and all the CPUs in the system will
be assumed identical.
The framework's SMT control provides two interface to the users [1]
through /sys/devices/system/cpu/smt/control:
1) enable SMT by writing "on" and disable by "off"
2) enable SMT by writing max_thread_number or disable by writing 1
Both method support to completely disable/enable the SMT cores so both
work correctly for symmetric SMT platform and asymmetric platform with
non-SMT and one type SMT cores like:
core A: 1 thread
core B: X (X!=1) threads
Note that for a theoretically possible multiple SMT-X (X>1) core
platform the SMT control is also supported as expected but only
by writing the "on/off" method.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/ABI/testing/sysfs-devices-system-cpu#n542
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Hanjun Guo <guohanjun@huawei.com>
Reviewed-by: Pierre Gondois <pierre.gondois@arm.com>
Reviewed-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
---
arch/arm64/kernel/topology.c | 54 ++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
index cb180684d10d..0bcea4f89ea8 100644
--- a/arch/arm64/kernel/topology.c
+++ b/arch/arm64/kernel/topology.c
@@ -15,8 +15,10 @@
#include <linux/arch_topology.h>
#include <linux/cacheinfo.h>
#include <linux/cpufreq.h>
+#include <linux/cpu_smt.h>
#include <linux/init.h>
#include <linux/percpu.h>
+#include <linux/xarray.h>
#include <asm/cpu.h>
#include <asm/cputype.h>
@@ -37,17 +39,28 @@ static bool __init acpi_cpu_is_threaded(int cpu)
return !!is_threaded;
}
+struct cpu_smt_info {
+ unsigned int thread_num;
+ int core_id;
+};
+
/*
* Propagate the topology information of the processor_topology_node tree to the
* cpu_topology array.
*/
int __init parse_acpi_topology(void)
{
+ unsigned int max_smt_thread_num = 1;
+ struct cpu_smt_info *entry;
+ struct xarray hetero_cpu;
+ unsigned long hetero_id;
int cpu, topology_id;
if (acpi_disabled)
return 0;
+ xa_init(&hetero_cpu);
+
for_each_possible_cpu(cpu) {
topology_id = find_acpi_cpu_topology(cpu, 0);
if (topology_id < 0)
@@ -57,6 +70,34 @@ int __init parse_acpi_topology(void)
cpu_topology[cpu].thread_id = topology_id;
topology_id = find_acpi_cpu_topology(cpu, 1);
cpu_topology[cpu].core_id = topology_id;
+
+ /*
+ * In the PPTT, CPUs below a node with the 'identical
+ * implementation' flag have the same number of threads.
+ * Count the number of threads for only one CPU (i.e.
+ * one core_id) among those with the same hetero_id.
+ * See the comment of find_acpi_cpu_topology_hetero_id()
+ * for more details.
+ *
+ * One entry is created for each node having:
+ * - the 'identical implementation' flag
+ * - its parent not having the flag
+ */
+ hetero_id = find_acpi_cpu_topology_hetero_id(cpu);
+ entry = xa_load(&hetero_cpu, hetero_id);
+ if (!entry) {
+ entry = kzalloc(sizeof(*entry), GFP_KERNEL);
+ WARN_ON_ONCE(!entry);
+
+ if (entry) {
+ entry->core_id = topology_id;
+ entry->thread_num = 1;
+ xa_store(&hetero_cpu, hetero_id,
+ entry, GFP_KERNEL);
+ }
+ } else if (entry->core_id == topology_id) {
+ entry->thread_num++;
+ }
} else {
cpu_topology[cpu].thread_id = -1;
cpu_topology[cpu].core_id = topology_id;
@@ -67,6 +108,19 @@ int __init parse_acpi_topology(void)
cpu_topology[cpu].package_id = topology_id;
}
+ /*
+ * This is a short loop since the number of XArray elements is the
+ * number of heterogeneous CPU clusters. On a homogeneous system
+ * there's only one entry in the XArray.
+ */
+ xa_for_each(&hetero_cpu, hetero_id, entry) {
+ max_smt_thread_num = max(max_smt_thread_num, entry->thread_num);
+ xa_erase(&hetero_cpu, hetero_id);
+ kfree(entry);
+ }
+
+ cpu_smt_set_num_threads(max_smt_thread_num, max_smt_thread_num);
+ xa_destroy(&hetero_cpu);
return 0;
}
#endif
--
2.24.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v12 3/4] arm64: topology: Support SMT control on ACPI based system
2025-03-11 7:51 ` [PATCH v12 3/4] arm64: topology: Support SMT control on ACPI " Yicong Yang
@ 2025-03-11 14:42 ` Sudeep Holla
0 siblings, 0 replies; 15+ messages in thread
From: Sudeep Holla @ 2025-03-11 14:42 UTC (permalink / raw)
To: Yicong Yang
Cc: catalin.marinas, will, tglx, peterz, mpe, linux-arm-kernel, mingo,
bp, dave.hansen, pierre.gondois, dietmar.eggemann, linuxppc-dev,
x86, linux-kernel, morten.rasmussen, msuchanek, gregkh, rafael,
jonathan.cameron, prime.zeng, linuxarm, yangyicong, xuwei5,
guohanjun, sshegde
On Tue, Mar 11, 2025 at 03:51:42PM +0800, Yicong Yang wrote:
> From: Yicong Yang <yangyicong@hisilicon.com>
>
> For ACPI we'll build the topology from PPTT and we cannot directly
> get the SMT number of each core. Instead using a temporary xarray
> to record the heterogeneous information (from ACPI_PPTT_ACPI_IDENTICAL)
> and SMT information of the first core in its heterogeneous CPU cluster
> when building the topology. Then we can know the largest SMT number
> in the system. If a homogeneous system's using ACPI 6.2 or later,
> all the CPUs should be under the root node of PPTT. There'll be
> only one entry in the xarray and all the CPUs in the system will
> be assumed identical.
>
> The framework's SMT control provides two interface to the users [1]
> through /sys/devices/system/cpu/smt/control:
> 1) enable SMT by writing "on" and disable by "off"
> 2) enable SMT by writing max_thread_number or disable by writing 1
>
> Both method support to completely disable/enable the SMT cores so both
> work correctly for symmetric SMT platform and asymmetric platform with
> non-SMT and one type SMT cores like:
> core A: 1 thread
> core B: X (X!=1) threads
>
> Note that for a theoretically possible multiple SMT-X (X>1) core
> platform the SMT control is also supported as expected but only
> by writing the "on/off" method.
>
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/ABI/testing/sysfs-devices-system-cpu#n542
Ditto, just path please.
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
--
Regards,
Sudeep
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v12 4/4] arm64: Kconfig: Enable HOTPLUG_SMT
2025-03-11 7:51 [PATCH v12 0/4] Support SMT control on arm64 Yicong Yang
` (2 preceding siblings ...)
2025-03-11 7:51 ` [PATCH v12 3/4] arm64: topology: Support SMT control on ACPI " Yicong Yang
@ 2025-03-11 7:51 ` Yicong Yang
2025-03-11 14:41 ` Sudeep Holla
2025-03-11 14:41 ` [PATCH v12 0/4] Support SMT control on arm64 Sudeep Holla
2025-03-14 18:37 ` Catalin Marinas
5 siblings, 1 reply; 15+ messages in thread
From: Yicong Yang @ 2025-03-11 7:51 UTC (permalink / raw)
To: catalin.marinas, will, sudeep.holla, tglx, peterz, mpe,
linux-arm-kernel, mingo, bp, dave.hansen, pierre.gondois,
dietmar.eggemann
Cc: linuxppc-dev, x86, linux-kernel, morten.rasmussen, msuchanek,
gregkh, rafael, jonathan.cameron, prime.zeng, linuxarm,
yangyicong, xuwei5, guohanjun, sshegde
From: Yicong Yang <yangyicong@hisilicon.com>
Enable HOTPLUG_SMT for SMT control.
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Pierre Gondois <pierre.gondois@arm.com>
Reviewed-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
---
arch/arm64/Kconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 940343beb3d4..65fe00b1922c 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -250,6 +250,7 @@ config ARM64
select HAVE_KRETPROBES
select HAVE_GENERIC_VDSO
select HOTPLUG_CORE_SYNC_DEAD if HOTPLUG_CPU
+ select HOTPLUG_SMT if HOTPLUG_CPU
select IRQ_DOMAIN
select IRQ_FORCED_THREADING
select KASAN_VMALLOC if KASAN
--
2.24.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v12 4/4] arm64: Kconfig: Enable HOTPLUG_SMT
2025-03-11 7:51 ` [PATCH v12 4/4] arm64: Kconfig: Enable HOTPLUG_SMT Yicong Yang
@ 2025-03-11 14:41 ` Sudeep Holla
0 siblings, 0 replies; 15+ messages in thread
From: Sudeep Holla @ 2025-03-11 14:41 UTC (permalink / raw)
To: Yicong Yang
Cc: catalin.marinas, will, tglx, peterz, mpe, linux-arm-kernel, mingo,
bp, dave.hansen, pierre.gondois, dietmar.eggemann, linuxppc-dev,
x86, linux-kernel, morten.rasmussen, msuchanek, gregkh, rafael,
jonathan.cameron, prime.zeng, linuxarm, yangyicong, xuwei5,
guohanjun, sshegde
On Tue, Mar 11, 2025 at 03:51:43PM +0800, Yicong Yang wrote:
> From: Yicong Yang <yangyicong@hisilicon.com>
>
> Enable HOTPLUG_SMT for SMT control.
>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
--
Regards,
Sudeep
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v12 0/4] Support SMT control on arm64
2025-03-11 7:51 [PATCH v12 0/4] Support SMT control on arm64 Yicong Yang
` (3 preceding siblings ...)
2025-03-11 7:51 ` [PATCH v12 4/4] arm64: Kconfig: Enable HOTPLUG_SMT Yicong Yang
@ 2025-03-11 14:41 ` Sudeep Holla
2025-03-14 18:37 ` Catalin Marinas
5 siblings, 0 replies; 15+ messages in thread
From: Sudeep Holla @ 2025-03-11 14:41 UTC (permalink / raw)
To: Yicong Yang
Cc: catalin.marinas, will, tglx, Sudeep Holla, peterz, mpe,
linux-arm-kernel, mingo, bp, dave.hansen, pierre.gondois,
dietmar.eggemann, linuxppc-dev, x86, linux-kernel,
morten.rasmussen, msuchanek, gregkh, rafael, jonathan.cameron,
prime.zeng, linuxarm, yangyicong, xuwei5, guohanjun, sshegde
On Tue, Mar 11, 2025 at 03:51:39PM +0800, Yicong Yang wrote:
> From: Yicong Yang <yangyicong@hisilicon.com>
>
> The core CPU control framework supports runtime SMT control which
> is not yet supported on arm64. Besides the general vulnerabilities
> concerns we want this runtime control on our arm64 server for:
>
> - better single CPU performance in some cases
> - saving overall power consumption
>
> This patchset implements it in the following aspects:
>
> - Provides a default topology_is_primary_thread()
> - support retrieve SMT thread number on OF based system
> - support retrieve SMT thread number on ACPI based system
> - select HOTPLUG_SMT for arm64
>
> Tests has been done on our ACPI based arm64 server and on ACPI/OF
> based QEMU VMs.
>
> Change since v11:
> - Remove the check and warning for heterogeneous platform as suggested and discussed
IIUC, the ask was not to remove it completely but to allow single
threaded and same number of threads in all the multi-threaded CPUs.
Anyways that is not a must, we can just stash max_smt_thread_num value
before updating with max and see if it changes from one value to another
with value != 1. It can be done later when we want to warn such systems
if they appear in the future and we can't support them. For now, it looks
fine.
--
Regards,
Sudeep
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v12 0/4] Support SMT control on arm64
2025-03-11 7:51 [PATCH v12 0/4] Support SMT control on arm64 Yicong Yang
` (4 preceding siblings ...)
2025-03-11 14:41 ` [PATCH v12 0/4] Support SMT control on arm64 Sudeep Holla
@ 2025-03-14 18:37 ` Catalin Marinas
5 siblings, 0 replies; 15+ messages in thread
From: Catalin Marinas @ 2025-03-14 18:37 UTC (permalink / raw)
To: will, sudeep.holla, tglx, peterz, mpe, linux-arm-kernel, mingo,
bp, dave.hansen, pierre.gondois, dietmar.eggemann, Yicong Yang
Cc: linuxppc-dev, x86, linux-kernel, morten.rasmussen, msuchanek,
gregkh, rafael, jonathan.cameron, prime.zeng, linuxarm,
yangyicong, xuwei5, guohanjun, sshegde
On Tue, 11 Mar 2025 15:51:39 +0800, Yicong Yang wrote:
> The core CPU control framework supports runtime SMT control which
> is not yet supported on arm64. Besides the general vulnerabilities
> concerns we want this runtime control on our arm64 server for:
>
> - better single CPU performance in some cases
> - saving overall power consumption
>
> [...]
Applied to arm64 (for-next/smt-control), thanks!
[1/4] cpu/SMT: Provide a default topology_is_primary_thread()
https://git.kernel.org/arm64/c/4b455f59945a
[2/4] arch_topology: Support SMT control for OF based system
https://git.kernel.org/arm64/c/5deb9c789ae4
[3/4] arm64: topology: Support SMT control on ACPI based system
https://git.kernel.org/arm64/c/e6b18ebfaf63
[4/4] arm64: Kconfig: Enable HOTPLUG_SMT
https://git.kernel.org/arm64/c/eed4583bcf9a
--
Catalin
^ permalink raw reply [flat|nested] 15+ messages in thread