Online new threads according to the current SMT level
cover Online new threads according to the current SMT level
When a new CPU is added, the kernel is activating all its threads. This leads to weird, but functional, result when adding CPU on a SMT 4 system for instance.
Here the newly added CPU 1 has 8 threads while the other one has 4 threads active (system has been booted with the 'smt-enabled=4' kernel option):
ltcden3-lp12:~ # ppc64_cpu --info
Core 0: 0* 1* 2* 3* 4 5 6 7 Core 1: 8* 9* 10* 11* 12* 13* 14* 15*
This mixed SMT level is confusing end users and some application like lparstat are reporting wrong values.
There is no SMT level recorded in the kernel, neither in user space. Such a level could be helpful when adding new CPU or when optimizing the energy efficiency. This series introduce a new SYS FS entry named 'pseries_smt' to store the current SMT level.
The SMT level is provided in best effort, writing a new value into that entry is only recording it into the kernel. This way, it can be used when new CPU are onlined for instance. There is no real change to the CPU setup when a value is written, no CPU are onlined or offlined.
At boot time pseries_smt is loaded with smt_enabled_at_boot which is containing the SMT level set at boot time, even if no kernel option is specified.
The change is specific to pseries since CPU hot-plug is only provided for this platform.
The second patch of this series is implementing the change to online only the right number of threads when a new CPU is added.
Laurent Dufour (2):
pseries/smp: export the smt level in the SYS FS. powerpc/pseries/cpuhp: respect current SMT when adding new CPU
arch/powerpc/platforms/pseries/hotplug-cpu.c | 18 ++++++--- arch/powerpc/platforms/pseries/pseries.h | 3 ++ arch/powerpc/platforms/pseries/smp.c | 39 ++++++++++++++++++++ 3 files changed, 55 insertions(+), 5 deletions(-)
Signature · 1 line
2.40.0
PATCH 1/2 pseries/smp: export the smt level in the SYS FS.
There is no SMT level recorded in the kernel neither in user space. Indeed there is no real constraint about that and mixed SMT levels are allowed and system is working fine this way.
However when new CPU are added, the kernel is onlining all the threads which is leading to mixed SMT levels and confuse end user a bit.
To prevent this exports a SMT level from the kernel so user space application like the energy daemon, could read it to adjust their settings. There is no action unless recording the value when a SMT value is written into the new sysfs entry. User space applications like ppc64_cpu should update the sysfs when changing the SMT level to keep the system consistent.
--- arch/powerpc/platforms/pseries/pseries.h | 3 ++ arch/powerpc/platforms/pseries/smp.c | 39 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+)
arch/powerpc/platforms/pseries/pseries.h +3 -0
@@ -23,7 +23,9 @@ extern int pSeries_machine_check_exception(struct pt_regs *regs);extern long pseries_machine_check_realmode (struct pt_regs *regs);void pSeries_machine_check_log_err (void ); +#ifdef CONFIG_SMP +extern int pseries_smt;extern void smp_init_pseries (void );/* Get state of physical CPU from query_cpu_stopped */
@@ -34,6 +36,7 @@ int smp_query_cpu_stopped(unsigned int pcpu);#define QCSS_HARDWARE_ERROR -1#define QCSS_HARDWARE_BUSY -2#else +#define pseries_smt 1static inline void smp_init_pseries (void ) { }#endif
arch/powerpc/platforms/pseries/smp.c +39 -0
@@ -21,6 +21,7 @@#include <linux/device.h> #include <linux/cpu.h> #include <linux/pgtable.h> +#include <linux/sysfs.h> #include <asm/ptrace.h> #include <linux/atomic.h>
@@ -45,6 +46,8 @@#include "pseries.h" +int pseries_smt; +/* * The Primary thread of each non-boot processor was started from the OF client * interface by prom_hold_cpus and is spinning on secondary_hold_spinloop.
@@ -280,3 +283,39 @@ void __init smp_init_pseries(void)pr_debug (" <- smp_init_pSeries()\n" ); } + +static ssize_t pseries_smt_store (struct class *class, +struct class_attribute *attr, +const char *buf,size_t count) +{ +int smt; + +if (kstrtou32 (buf,0 , &smt) || !smt || smt > (u32 ) threads_per_core) { +pr_err ("Invalid pseries_smt specified.\n" ); +return -EINVAL ; + } + + pseries_smt = smt; + +return count; +} + +static ssize_t pseries_smt_show (struct class *class,struct class_attribute *attr, +char *buf) +{ +return sysfs_emit (buf,"%d\n" , pseries_smt); +} + +static CLASS_ATTR_RW (pseries_smt); + +static int __init pseries_smt_init (void ) +{ +int rc; + + pseries_smt = smt_enabled_at_boot; + rc =sysfs_create_file (kernel_kobj, &class_attr_pseries_smt.attr); +if (rc) +pr_err ("Can't create pseries_smt sysfs/kernel entry.\n" ); +return rc; +} +machine_device_initcall (pseries, pseries_smt_init);
Signature · 1 line
2.40.0
Re: [PATCH 1/2] pseries/smp: export the smt level in the SYS FS.
Hello,
Quoted 35 lines · Laurent Dufour
There is no SMT level recorded in the kernel neither in user space. Indeed there is no real constraint about that and mixed SMT levels are allowed and system is working fine this way.
However when new CPU are added, the kernel is onlining all the threads which is leading to mixed SMT levels and confuse end user a bit.
To prevent this exports a SMT level from the kernel so user space application like the energy daemon, could read it to adjust their settings. There is no action unless recording the value when a SMT value is written into the new sysfs entry. User space applications like
ppc64_cpushould update the sysfs when changing the SMT level to keep the system consistent.Suggested-by Srikar Dronamraju <[email protected]>Signed-off-by Laurent Dufour <[email protected]>--- arch/powerpc/platforms/pseries/pseries.h | 3 ++ arch/powerpc/platforms/pseries/smp.c | 39 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+)arch/powerpc/platforms/pseries/pseries.h +2
-0@@ -23,7 +23,9 @@ extern int pSeries_machine_check_exception(struct pt_regs *regs);extern long pseries_machine_check_realmode (struct pt_regs *regs);void pSeries_machine_check_log_err (void ); +#ifdef CONFIG_SMP +extern int pseries_smt;extern void smp_init_pseries (void );/* Get state of physical CPU from query_cpu_stopped */
arch/powerpc/platforms/pseries/pseries.h int smp_query_cpu_stopped(unsigned int pcpu); · line 39
Quoted 4 lines
arch/powerpc/platforms/pseries/pseries.h +1
-0@@ -34,6 +36,7 @@ int smp_query_cpu_stopped(unsigned int pcpu);#define QCSS_HARDWARE_ERROR -1#define QCSS_HARDWARE_BUSY -2#else +#define pseries_smt 1
Is this really needed for anything?
The code using pseries_smt would not compile with a define, and would be only compiled with SMP enabled anyway so we should not need this.
Thanks
Michal
Quoted 67 lines
arch/powerpc/platforms/pseries/pseries.h +0
-0static inline void smp_init_pseries (void ) { }#endif arch/powerpc/platforms/pseries/smp.c +39
-0@@ -21,6 +21,7 @@#include <linux/device.h> #include <linux/cpu.h> #include <linux/pgtable.h> +#include <linux/sysfs.h> #include <asm/ptrace.h> #include <linux/atomic.h> @@ -45,6 +46,8 @@#include "pseries.h" +int pseries_smt; +/* * The Primary thread of each non-boot processor was started from the OF client * interface by prom_hold_cpus and is spinning on secondary_hold_spinloop. @@ -280,3 +283,39 @@ void __init smp_init_pseries(void)pr_debug (" <- smp_init_pSeries()\n" ); } + +static ssize_t pseries_smt_store (struct class *class, +struct class_attribute *attr, +const char *buf,size_t count) +{ +int smt; + +if (kstrtou32 (buf,0 , &smt) || !smt || smt > (u32 ) threads_per_core) { +pr_err ("Invalid pseries_smt specified.\n" ); +return -EINVAL ; + } + + pseries_smt = smt; + +return count; +} + +static ssize_t pseries_smt_show (struct class *class,struct class_attribute *attr, +char *buf) +{ +return sysfs_emit (buf,"%d\n" , pseries_smt); +} + +static CLASS_ATTR_RW (pseries_smt); + +static int __init pseries_smt_init (void ) +{ +int rc; + + pseries_smt = smt_enabled_at_boot; + rc =sysfs_create_file (kernel_kobj, &class_attr_pseries_smt.attr); +if (rc) +pr_err ("Can't create pseries_smt sysfs/kernel entry.\n" ); +return rc; +} +machine_device_initcall (pseries, pseries_smt_init);Signature · 1 line
2.40.0
Re: [PATCH 1/2] pseries/smp: export the smt level in the SYS FS.
Quoted 45 lines · Michal Suchánek
Hello,
Quoted 35 lines · Laurent Dufour
There is no SMT level recorded in the kernel neither in user space. Indeed there is no real constraint about that and mixed SMT levels are allowed and system is working fine this way.
However when new CPU are added, the kernel is onlining all the threads which is leading to mixed SMT levels and confuse end user a bit.
To prevent this exports a SMT level from the kernel so user space application like the energy daemon, could read it to adjust their settings. There is no action unless recording the value when a SMT value is written into the new sysfs entry. User space applications like
ppc64_cpushould update the sysfs when changing the SMT level to keep the system consistent.Suggested-by Srikar Dronamraju <[email protected]>Signed-off-by Laurent Dufour <[email protected]>--- arch/powerpc/platforms/pseries/pseries.h | 3 ++ arch/powerpc/platforms/pseries/smp.c | 39 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+)arch/powerpc/platforms/pseries/pseries.h +2
-0@@ -23,7 +23,9 @@ extern int pSeries_machine_check_exception(struct pt_regs *regs);extern long pseries_machine_check_realmode (struct pt_regs *regs);void pSeries_machine_check_log_err (void ); +#ifdef CONFIG_SMP +extern int pseries_smt;extern void smp_init_pseries (void );/* Get state of physical CPU from query_cpu_stopped */ arch/powerpc/platforms/pseries/pseries.h int smp_query_cpu_stopped(unsigned int pcpu); · line 39
Quoted 4 lines
arch/powerpc/platforms/pseries/pseries.h +1
-0@@ -34,6 +36,7 @@ int smp_query_cpu_stopped(unsigned int pcpu);#define QCSS_HARDWARE_ERROR -1#define QCSS_HARDWARE_BUSY -2#else +#define pseries_smt 1Is this really needed for anything?
Quoted 3 lines
The code using
pseries_smtwould not compile with a define, and would be only compiled with SMP enabled anyway so we should not need this.
Hi Michal,
I do agree, the pseries code is implying SMP.
When writing that code, I found that SMP conditional block and just add this define to be sure the code will compile in the case SMP is not defined, but that's probably useless.
Instead of resending a new series, Michael, could you please remove that line when applying the patch to your tree?
Thanks,
Laurent.
Quoted 71 lines
Thanks
Michal
Quoted 67 lines
arch/powerpc/platforms/pseries/pseries.h +0
-0static inline void smp_init_pseries (void ) { }#endif arch/powerpc/platforms/pseries/smp.c +39
-0@@ -21,6 +21,7 @@#include <linux/device.h> #include <linux/cpu.h> #include <linux/pgtable.h> +#include <linux/sysfs.h> #include <asm/ptrace.h> #include <linux/atomic.h> @@ -45,6 +46,8 @@#include "pseries.h" +int pseries_smt; +/* * The Primary thread of each non-boot processor was started from the OF client * interface by prom_hold_cpus and is spinning on secondary_hold_spinloop. @@ -280,3 +283,39 @@ void __init smp_init_pseries(void)pr_debug (" <- smp_init_pSeries()\n" ); } + +static ssize_t pseries_smt_store (struct class *class, +struct class_attribute *attr, +const char *buf,size_t count) +{ +int smt; + +if (kstrtou32 (buf,0 , &smt) || !smt || smt > (u32 ) threads_per_core) { +pr_err ("Invalid pseries_smt specified.\n" ); +return -EINVAL ; + } + + pseries_smt = smt; + +return count; +} + +static ssize_t pseries_smt_show (struct class *class,struct class_attribute *attr, +char *buf) +{ +return sysfs_emit (buf,"%d\n" , pseries_smt); +} + +static CLASS_ATTR_RW (pseries_smt); + +static int __init pseries_smt_init (void ) +{ +int rc; + + pseries_smt = smt_enabled_at_boot; + rc =sysfs_create_file (kernel_kobj, &class_attr_pseries_smt.attr); +if (rc) +pr_err ("Can't create pseries_smt sysfs/kernel entry.\n" ); +return rc; +} +machine_device_initcall (pseries, pseries_smt_init);Signature · 1 line
2.40.0
Michael Ellerman
reviewerRe: [PATCH 1/2] pseries/smp: export the smt level in the SYS FS.
In reply to Laurent DufourHi Laurent,
Quoted 13 lines · Laurent Dufour
There is no SMT level recorded in the kernel neither in user space. Indeed there is no real constraint about that and mixed SMT levels are allowed and system is working fine this way.
However when new CPU are added, the kernel is onlining all the threads which is leading to mixed SMT levels and confuse end user a bit.
To prevent this exports a SMT level from the kernel so user space application like the energy daemon, could read it to adjust their settings. There is no action unless recording the value when a SMT value is written into the new sysfs entry. User space applications like
ppc64_cpushould update the sysfs when changing the SMT level to keep the system consistent.
Quoted 6 lines
Suggested-by Srikar Dronamraju <[email protected]>Signed-off-by Laurent Dufour <[email protected]>--- arch/powerpc/platforms/pseries/pseries.h | 3 ++ arch/powerpc/platforms/pseries/smp.c | 39 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+)
There is a generic sysfs interface for smt in /sys/devices/system/cpu/smt
I think we should be enabling that on powerpc and then adapting it to our needs, rather than adding a pseries specific file.
Currently the generic code is only aware of SMT on/off, so it would need to be taught about SMT4 and 8 at least.
There are already hooks in the generic code to check the SMT level when bringing CPUs up, see cpu_smt_allowed(), they may work for the pseries hotplug case too, though maybe we need some additional logic.
Wiring up the basic support is pretty straight forward, something like the diff below.
cheers
arch/powerpc/Kconfig +1 -0
@@ -260,6 +260,7 @@ config PPC select HAVE_SYSCALL_TRACEPOINTS select HAVE_VIRT_CPU_ACCOUNTING select HAVE_VIRT_CPU_ACCOUNTING_GEN + select HOTPLUG_SMT if HOTPLUG_CPU select HUGETLB_PAGE_SIZE_VARIABLE if PPC_BOOK3S_64 && HUGETLB_PAGE select IOMMU_HELPER if PPC64 select IRQ_DOMAIN
arch/powerpc/include/asm/topology.h +3 -0
@@ -143,5 +143,8 @@ static inline int cpu_to_coregroup_id(int cpu)#endif #endif +bool topology_is_primary_thread (unsigned int cpu); +bool topology_smt_supported (void ); +#endif /* __KERNEL__ */ #endif /* _ASM_POWERPC_TOPOLOGY_H */
arch/powerpc/kernel/smp.c +16 -0
@@ -1769,4 +1769,20 @@ void __noreturn arch_cpu_idle_dead(void) start_secondary_resume(); } +/** +* topology_is_primary_thread - Check whether CPU is the primary SMT thread +* @cpu: CPU to check +*/ +bool topology_is_primary_thread (unsigned int cpu) +{ +return cpu ==cpu_first_thread_sibling (cpu); +} + +/** +* topology_smt_supported - Check whether SMT is supported by the CPUs +*/ +bool topology_smt_supported (void ) +{ +return threads_per_core >1 ; +}#endif
Re: [PATCH 1/2] pseries/smp: export the smt level in the SYS FS.
Quoted 23 lines · Michael Ellerman
Hi Laurent,
Quoted 13 lines · Laurent Dufour
There is no SMT level recorded in the kernel neither in user space. Indeed there is no real constraint about that and mixed SMT levels are allowed and system is working fine this way.
However when new CPU are added, the kernel is onlining all the threads which is leading to mixed SMT levels and confuse end user a bit.
To prevent this exports a SMT level from the kernel so user space application like the energy daemon, could read it to adjust their settings. There is no action unless recording the value when a SMT value is written into the new sysfs entry. User space applications like
ppc64_cpushould update the sysfs when changing the SMT level to keep the system consistent.Quoted 6 lines
Suggested-by Srikar Dronamraju <[email protected]>Signed-off-by Laurent Dufour <[email protected]>--- arch/powerpc/platforms/pseries/pseries.h | 3 ++ arch/powerpc/platforms/pseries/smp.c | 39 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+)
Quoted 4 lines
There is a generic sysfs interface for smt in
/sys/devices/system/cpu/smtI think we should be enabling that on powerpc and then adapting it to our needs, rather than adding a pseries specific file.
Thanks Michael, I was not aware of this sysfs interface.
Quoted 2 lines
Currently the generic code is only aware of SMT on/off, so it would need to be taught about SMT4 and 8 at least.
Do you think we should limit our support to SMT4 and SMT8 only?
Quoted 6 lines
There are already hooks in the generic code to check the SMT level when bringing CPUs up, see
cpu_smt_allowed(), they may work for the pseries hotplug case too, though maybe we need some additional logic.Wiring up the basic support is pretty straight forward, something like the diff below.
I'll look into how to wire this up.
Thanks a lot!
Quoted 53 lines
cheers
arch/powerpc/Kconfig +1
-0@@ -260,6 +260,7 @@ config PPC select HAVE_SYSCALL_TRACEPOINTS select HAVE_VIRT_CPU_ACCOUNTING select HAVE_VIRT_CPU_ACCOUNTING_GEN + select HOTPLUG_SMT if HOTPLUG_CPU select HUGETLB_PAGE_SIZE_VARIABLE if PPC_BOOK3S_64 && HUGETLB_PAGE select IOMMU_HELPER if PPC64 select IRQ_DOMAINarch/powerpc/include/asm/topology.h +3
-0@@ -143,5 +143,8 @@ static inline int cpu_to_coregroup_id(int cpu)#endif #endif +bool topology_is_primary_thread (unsigned int cpu); +bool topology_smt_supported (void ); +#endif /* __KERNEL__ */ #endif /* _ASM_POWERPC_TOPOLOGY_H */ arch/powerpc/kernel/smp.c +16
-0@@ -1769,4 +1769,20 @@ void __noreturn arch_cpu_idle_dead(void) start_secondary_resume(); } +/** +* topology_is_primary_thread - Check whether CPU is the primary SMT thread +* @cpu: CPU to check +*/ +bool topology_is_primary_thread (unsigned int cpu) +{ +return cpu ==cpu_first_thread_sibling (cpu); +} + +/** +* topology_smt_supported - Check whether SMT is supported by the CPUs +*/ +bool topology_smt_supported (void ) +{ +return threads_per_core >1 ; +}#endif
Michael Ellerman
reviewerRe: [PATCH 1/2] pseries/smp: export the smt level in the SYS FS.
Quoted 27 lines · Laurent Dufour
Quoted 21 lines · Michael Ellerman
Quoted 13 lines · Laurent Dufour
There is no SMT level recorded in the kernel neither in user space. Indeed there is no real constraint about that and mixed SMT levels are allowed and system is working fine this way.
However when new CPU are added, the kernel is onlining all the threads which is leading to mixed SMT levels and confuse end user a bit.
To prevent this exports a SMT level from the kernel so user space application like the energy daemon, could read it to adjust their settings. There is no action unless recording the value when a SMT value is written into the new sysfs entry. User space applications like
ppc64_cpushould update the sysfs when changing the SMT level to keep the system consistent.Quoted 6 lines
Suggested-by Srikar Dronamraju <[email protected]>Signed-off-by Laurent Dufour <[email protected]>--- arch/powerpc/platforms/pseries/pseries.h | 3 ++ arch/powerpc/platforms/pseries/smp.c | 39 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+)Quoted 4 lines
There is a generic sysfs interface for smt in
/sys/devices/system/cpu/smtI think we should be enabling that on powerpc and then adapting it to our needs, rather than adding a pseries specific file.
Quoted 6 lines
Thanks Michael, I was not aware of this sysfs interface.
Quoted 2 lines
Currently the generic code is only aware of SMT on/off, so it would need to be taught about SMT4 and 8 at least.
Do you think we should limit our support to SMT4 and SMT8 only?
Possibly? Currently the SMT state is represented by an enum:
enum cpuhp_smt_control {
CPU_SMT_ENABLED,
CPU_SMT_DISABLED,
CPU_SMT_FORCE_DISABLED,
CPU_SMT_NOT_SUPPORTED,
CPU_SMT_NOT_IMPLEMENTED,
};
Adding two states for SMT4 and SMT8 seeems like it might be acceptable.
On the other hand if we want to support artbitrary SMT values from 3 to 8 then it might be better to store that value separately from the state enum.
TBH I'm not sure whether we want to support values other than 1/2/4/8 via this interface.
A user who wants some odd numbered SMT value can always configure that manually using the existing tools.
But maybe it's less confusing if this interface supports all values? Even if they're unlikely to get much usage.
Quoted 9 lines
Quoted 6 lines
There are already hooks in the generic code to check the SMT level when bringing CPUs up, see
cpu_smt_allowed(), they may work for the pseries hotplug case too, though maybe we need some additional logic.Wiring up the basic support is pretty straight forward, something like the diff below.
I'll look into how to wire this up.
Thanks a lot!
Thanks.
cheers
Re: [PATCH 1/2] pseries/smp: export the smt level in the SYS FS.
Hello,
Quoted 51 lines · Michael Ellerman
Quoted 27 lines · Laurent Dufour
Quoted 21 lines · Michael Ellerman
Quoted 13 lines · Laurent Dufour
There is no SMT level recorded in the kernel neither in user space. Indeed there is no real constraint about that and mixed SMT levels are allowed and system is working fine this way.
However when new CPU are added, the kernel is onlining all the threads which is leading to mixed SMT levels and confuse end user a bit.
To prevent this exports a SMT level from the kernel so user space application like the energy daemon, could read it to adjust their settings. There is no action unless recording the value when a SMT value is written into the new sysfs entry. User space applications like
ppc64_cpushould update the sysfs when changing the SMT level to keep the system consistent.Quoted 6 lines
Suggested-by Srikar Dronamraju <[email protected]>Signed-off-by Laurent Dufour <[email protected]>--- arch/powerpc/platforms/pseries/pseries.h | 3 ++ arch/powerpc/platforms/pseries/smp.c | 39 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+)Quoted 4 lines
There is a generic sysfs interface for smt in
/sys/devices/system/cpu/smtI think we should be enabling that on powerpc and then adapting it to our needs, rather than adding a pseries specific file.
Quoted 6 lines
Thanks Michael, I was not aware of this sysfs interface.
Quoted 2 lines
Currently the generic code is only aware of SMT on/off, so it would need to be taught about SMT4 and 8 at least.
Do you think we should limit our support to SMT4 and SMT8 only?
Possibly? Currently the SMT state is represented by an enum:
enum
cpuhp_smt_control{
CPU_SMT_ENABLED,
CPU_SMT_DISABLED,
CPU_SMT_FORCE_DISABLED,
CPU_SMT_NOT_SUPPORTED,
CPU_SMT_NOT_IMPLEMENTED,
};Adding two states for SMT4 and SMT8 seeems like it might be acceptable.
On the other hand if we want to support artbitrary SMT values from 3 to 8 then it might be better to store that value separately from the state enum.
Quoted 8 lines
TBH I'm not sure whether we want to support values other than 1/2/4/8 via this interface.
A user who wants some odd numbered SMT value can always configure that manually using the existing tools.
But maybe it's less confusing if this interface supports all values? Even if they're unlikely to get much usage.
It looks like ppc64_cpu simply enables first n threads of the CPU where n is the smt value without any interleaving hoping that the architecture does the right thing. Under this implementation smt=3 is well-defined.
For the dual cluster P9 CPUs that have two clusters of four this might work out well for some workloads, and others might want that interleaving. With that the odd smt values are not well-definedd anymore.
Nonetheless, if the kernel does support some smt=n parameter whatever the semantic this should be also supported by the runtime knob.
If it's too difficult to get right there is always that option to not enable any thread by default, and let the userspace to implement arbitrarily complex schemes :)
Thanks
Michal
Re: [PATCH 1/2] pseries/smp: export the smt level in the SYS FS.
In reply to Laurent DufourQuoted 29 lines · Laurent Dufour
Quoted 23 lines · Michael Ellerman
Hi Laurent,
Quoted 13 lines · Laurent Dufour
There is no SMT level recorded in the kernel neither in user space. Indeed there is no real constraint about that and mixed SMT levels are allowed and system is working fine this way.
However when new CPU are added, the kernel is onlining all the threads which is leading to mixed SMT levels and confuse end user a bit.
To prevent this exports a SMT level from the kernel so user space application like the energy daemon, could read it to adjust their settings. There is no action unless recording the value when a SMT value is written into the new sysfs entry. User space applications like
ppc64_cpushould update the sysfs when changing the SMT level to keep the system consistent.Quoted 6 lines
Suggested-by Srikar Dronamraju <[email protected]>Signed-off-by Laurent Dufour <[email protected]>--- arch/powerpc/platforms/pseries/pseries.h | 3 ++ arch/powerpc/platforms/pseries/smp.c | 39 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+)Quoted 4 lines
There is a generic sysfs interface for smt in
/sys/devices/system/cpu/smtI think we should be enabling that on powerpc and then adapting it to our needs, rather than adding a pseries specific file.
Quoted 6 lines
Thanks Michael, I was not aware of this sysfs interface.
Quoted 2 lines
Currently the generic code is only aware of SMT on/off, so it would need to be taught about SMT4 and 8 at least.
Do you think we should limit our support to SMT4 and SMT8 only?
smt2 is also a valid already supported configuration and we are evaluating smt6 mode based on some inputs from ISV teams.
So I believe having a value for all modes would be good.
Quoted 8 lines
Quoted 7 lines
There are already hooks in the generic code to check the SMT level when bringing CPUs up, see
cpu_smt_allowed(), they may work for the pseries hotplug case too, though maybe we need some additional logic.Wiring up the basic support is pretty straight forward, something like the diff below.
Signature · 2 lines
Thanks and Regards Srikar Dronamraju
PATCH 2/2 powerpc/pseries/cpuhp: respect current SMT when adding new CPU
In reply to Laurent DufourWhen a new CPU is added, the kernel is activating all its threads. This leads to weird, but functional, result when adding CPU on a SMT 4 system for instance.
Here the newly added CPU 1 has 8 threads while the other one has 4 threads active (system has been booted with the 'smt-enabled=4' kernel option):
ltcden3-lp12:~ # ppc64_cpu --info
Core 0: 0* 1* 2* 3* 4 5 6 7 Core 1: 8* 9* 10* 11* 12* 13* 14* 15*
We rely on the newly pseries_smt value which should be updated when changing the SMT level by ppc64_cpu --smt=x and at boot time using the smt-enabled kernel option.
This way on a LPAR running in SMT=4, newly added CPU will be running 4 threads, which is what a end user would expect.
--- arch/powerpc/platforms/pseries/hotplug-cpu.c | 18 +++++++++++++----- arch/powerpc/platforms/pseries/smp.c | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-)
arch/powerpc/platforms/pseries/hotplug-cpu.c +13 -5
@@ -382,7 +382,7 @@ static int dlpar_online_cpu(struct device_node *dn) {int rc =0 ;unsigned int cpu; -int len, nthreads, i; +int len, nthreads, i, smt;const __be32 *intserv;u32 thread;
@@ -392,6 +392,11 @@ static int dlpar_online_cpu(struct device_node *dn) nthreads = len /sizeof (u32); + smt =READ_ONCE (pseries_smt); +/* We should online at least one thread */ +if (smt <1 ) + smt =1 ; +cpu_maps_update_begin ();for (i =0 ; i < nthreads; i++) { thread =be32_to_cpu (intserv[i]);
@@ -400,10 +405,13 @@ static int dlpar_online_cpu(struct device_node *dn)continue ;cpu_maps_update_done ();find_and_update_cpu_nid (cpu); - rc =device_online (get_cpu_device (cpu)); -if (rc) { -dlpar_offline_cpu (dn); - goto out; +/* Don't active CPU over the current SMT setting */ +if (smt-- >0 ) { + rc =device_online (get_cpu_device (cpu)); +if (rc) { +dlpar_offline_cpu (dn); + goto out; + } }cpu_maps_update_begin ();
arch/powerpc/platforms/pseries/smp.c +1 -1
@@ -295,7 +295,7 @@ static ssize_t pseries_smt_store(struct class *class,return -EINVAL ; } - pseries_smt = smt; +WRITE_ONCE (pseries_smt, smt);return count; }
Signature · 1 line
2.40.0