Skip to content

Commit 6f49693

Browse files
committed
Merge tag 'smp-core-2023-08-28' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull CPU hotplug updates from Thomas Gleixner: "Updates for the CPU hotplug core: - Support partial SMT enablement. So far the sysfs SMT control only allows to toggle between SMT on and off. That's sufficient for x86 which usually has at max two threads except for the Xeon PHI platform which has four threads per core Though PowerPC has up to 16 threads per core and so far it's only possible to control the number of enabled threads per core via a command line option. There is some way to control this at runtime, but that lacks enforcement and the usability is awkward This update expands the sysfs interface and the core infrastructure to accept numerical values so PowerPC can build SMT runtime control for partial SMT enablement on top The core support has also been provided to the PowerPC maintainers who added the PowerPC related changes on top - Minor cleanups and documentation updates" * tag 'smp-core-2023-08-28' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: Documentation: core-api/cpuhotplug: Fix state names cpu/hotplug: Remove unused function declaration cpu_set_state_online() cpu/SMT: Fix cpu_smt_possible() comment cpu/SMT: Allow enabling partial SMT states via sysfs cpu/SMT: Create topology_smt_thread_allowed() cpu/SMT: Remove topology_smt_supported() cpu/SMT: Store the current/max number of threads cpu/SMT: Move smt/control simple exit cases earlier cpu/SMT: Move SMT prototypes into cpu_smt.h cpu/hotplug: Remove dependancy against cpu_primary_thread_mask
2 parents dd3f0fe + e0a99a8 commit 6f49693

File tree

10 files changed

+152
-81
lines changed

10 files changed

+152
-81
lines changed

Documentation/ABI/testing/sysfs-devices-system-cpu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ Description: Control Symmetric Multi Threading (SMT)
556556
================ =========================================
557557
"on" SMT is enabled
558558
"off" SMT is disabled
559+
"<N>" SMT is enabled with N threads per core.
559560
"forceoff" SMT is force disabled. Cannot be changed.
560561
"notsupported" SMT is not supported by the CPU
561562
"notimplemented" SMT runtime toggling is not

Documentation/core-api/cpu_hotplug.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ multi-instance state the following function is available:
395395
* cpuhp_setup_state_multi(state, name, startup, teardown)
396396

397397
The @state argument is either a statically allocated state or one of the
398-
constants for dynamically allocated states - CPUHP_PREPARE_DYN,
399-
CPUHP_ONLINE_DYN - depending on the state section (PREPARE, ONLINE) for
398+
constants for dynamically allocated states - CPUHP_BP_PREPARE_DYN,
399+
CPUHP_AP_ONLINE_DYN - depending on the state section (PREPARE, ONLINE) for
400400
which a dynamic state should be allocated.
401401

402402
The @name argument is used for sysfs output and for instrumentation. The
@@ -588,7 +588,7 @@ notifications on online and offline operations::
588588
Setup and teardown a dynamically allocated state in the ONLINE section
589589
for notifications on offline operations::
590590

591-
state = cpuhp_setup_state(CPUHP_ONLINE_DYN, "subsys:offline", NULL, subsys_cpu_offline);
591+
state = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "subsys:offline", NULL, subsys_cpu_offline);
592592
if (state < 0)
593593
return state;
594594
....
@@ -597,7 +597,7 @@ for notifications on offline operations::
597597
Setup and teardown a dynamically allocated state in the ONLINE section
598598
for notifications on online operations without invoking the callbacks::
599599

600-
state = cpuhp_setup_state_nocalls(CPUHP_ONLINE_DYN, "subsys:online", subsys_cpu_online, NULL);
600+
state = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "subsys:online", subsys_cpu_online, NULL);
601601
if (state < 0)
602602
return state;
603603
....
@@ -606,7 +606,7 @@ for notifications on online operations without invoking the callbacks::
606606
Setup, use and teardown a dynamically allocated multi-instance state in the
607607
ONLINE section for notifications on online and offline operation::
608608

609-
state = cpuhp_setup_state_multi(CPUHP_ONLINE_DYN, "subsys:online", subsys_cpu_online, subsys_cpu_offline);
609+
state = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, "subsys:online", subsys_cpu_online, subsys_cpu_offline);
610610
if (state < 0)
611611
return state;
612612
....

arch/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ config ARCH_HAS_SUBPAGE_FAULTS
3434
config HOTPLUG_SMT
3535
bool
3636

37+
config SMT_NUM_THREADS_DYNAMIC
38+
bool
39+
3740
# Selected by HOTPLUG_CORE_SYNC_DEAD or HOTPLUG_CORE_SYNC_FULL
3841
config HOTPLUG_CORE_SYNC
3942
bool

arch/x86/include/asm/topology.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,11 @@ static inline int topology_max_smt_threads(void)
136136
return __max_smt_threads;
137137
}
138138

139+
#include <linux/cpu_smt.h>
140+
139141
int topology_update_package_map(unsigned int apicid, unsigned int cpu);
140142
int topology_update_die_map(unsigned int dieid, unsigned int cpu);
141143
int topology_phys_to_logical_pkg(unsigned int pkg);
142-
bool topology_smt_supported(void);
143144

144145
extern struct cpumask __cpu_primary_thread_mask;
145146
#define cpu_primary_thread_mask ((const struct cpumask *)&__cpu_primary_thread_mask)
@@ -162,7 +163,6 @@ static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return 0; }
162163
static inline int topology_max_die_per_package(void) { return 1; }
163164
static inline int topology_max_smt_threads(void) { return 1; }
164165
static inline bool topology_is_primary_thread(unsigned int cpu) { return true; }
165-
static inline bool topology_smt_supported(void) { return false; }
166166
#endif /* !CONFIG_SMP */
167167

168168
static inline void arch_fix_phys_package_id(int num, u32 slot)

arch/x86/kernel/cpu/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2343,7 +2343,7 @@ void __init arch_cpu_finalize_init(void)
23432343
* identify_boot_cpu() initialized SMT support information, let the
23442344
* core code know.
23452345
*/
2346-
cpu_smt_check_topology();
2346+
cpu_smt_set_num_threads(smp_num_siblings, smp_num_siblings);
23472347

23482348
if (!IS_ENABLED(CONFIG_SMP)) {
23492349
pr_info("CPU: ");

arch/x86/kernel/smpboot.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,6 @@ static void notrace start_secondary(void *unused)
326326
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
327327
}
328328

329-
/**
330-
* topology_smt_supported - Check whether SMT is supported by the CPUs
331-
*/
332-
bool topology_smt_supported(void)
333-
{
334-
return smp_num_siblings > 1;
335-
}
336-
337329
/**
338330
* topology_phys_to_logical_pkg - Map a physical package id to a logical
339331
* @phys_pkg: The physical package id to map

include/linux/cpu.h

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/compiler.h>
1919
#include <linux/cpumask.h>
2020
#include <linux/cpuhotplug.h>
21+
#include <linux/cpu_smt.h>
2122

2223
struct device;
2324
struct device_node;
@@ -194,7 +195,6 @@ void arch_cpu_finalize_init(void);
194195
static inline void arch_cpu_finalize_init(void) { }
195196
#endif
196197

197-
void cpu_set_state_online(int cpu);
198198
void play_idle_precise(u64 duration_ns, u64 latency_ns);
199199

200200
static inline void play_idle(unsigned long duration_us)
@@ -208,30 +208,6 @@ void cpuhp_report_idle_dead(void);
208208
static inline void cpuhp_report_idle_dead(void) { }
209209
#endif /* #ifdef CONFIG_HOTPLUG_CPU */
210210

211-
enum cpuhp_smt_control {
212-
CPU_SMT_ENABLED,
213-
CPU_SMT_DISABLED,
214-
CPU_SMT_FORCE_DISABLED,
215-
CPU_SMT_NOT_SUPPORTED,
216-
CPU_SMT_NOT_IMPLEMENTED,
217-
};
218-
219-
#if defined(CONFIG_SMP) && defined(CONFIG_HOTPLUG_SMT)
220-
extern enum cpuhp_smt_control cpu_smt_control;
221-
extern void cpu_smt_disable(bool force);
222-
extern void cpu_smt_check_topology(void);
223-
extern bool cpu_smt_possible(void);
224-
extern int cpuhp_smt_enable(void);
225-
extern int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval);
226-
#else
227-
# define cpu_smt_control (CPU_SMT_NOT_IMPLEMENTED)
228-
static inline void cpu_smt_disable(bool force) { }
229-
static inline void cpu_smt_check_topology(void) { }
230-
static inline bool cpu_smt_possible(void) { return false; }
231-
static inline int cpuhp_smt_enable(void) { return 0; }
232-
static inline int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) { return 0; }
233-
#endif
234-
235211
extern bool cpu_mitigations_off(void);
236212
extern bool cpu_mitigations_auto_nosmt(void);
237213

include/linux/cpu_smt.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _LINUX_CPU_SMT_H_
3+
#define _LINUX_CPU_SMT_H_
4+
5+
enum cpuhp_smt_control {
6+
CPU_SMT_ENABLED,
7+
CPU_SMT_DISABLED,
8+
CPU_SMT_FORCE_DISABLED,
9+
CPU_SMT_NOT_SUPPORTED,
10+
CPU_SMT_NOT_IMPLEMENTED,
11+
};
12+
13+
#if defined(CONFIG_SMP) && defined(CONFIG_HOTPLUG_SMT)
14+
extern enum cpuhp_smt_control cpu_smt_control;
15+
extern unsigned int cpu_smt_num_threads;
16+
extern void cpu_smt_disable(bool force);
17+
extern void cpu_smt_set_num_threads(unsigned int num_threads,
18+
unsigned int max_threads);
19+
extern bool cpu_smt_possible(void);
20+
extern int cpuhp_smt_enable(void);
21+
extern int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval);
22+
#else
23+
# define cpu_smt_control (CPU_SMT_NOT_IMPLEMENTED)
24+
# define cpu_smt_num_threads 1
25+
static inline void cpu_smt_disable(bool force) { }
26+
static inline void cpu_smt_set_num_threads(unsigned int num_threads,
27+
unsigned int max_threads) { }
28+
static inline bool cpu_smt_possible(void) { return false; }
29+
static inline int cpuhp_smt_enable(void) { return 0; }
30+
static inline int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) { return 0; }
31+
#endif
32+
33+
#endif /* _LINUX_CPU_SMT_H_ */

include/linux/cpuhotplug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* same section.
4949
*
5050
* If neither #1 nor #2 apply, please use the dynamic state space when
51-
* setting up a state by using CPUHP_PREPARE_DYN or CPUHP_PREPARE_ONLINE
51+
* setting up a state by using CPUHP_BP_PREPARE_DYN or CPUHP_AP_ONLINE_DYN
5252
* for the @state argument of the setup function.
5353
*
5454
* See Documentation/core-api/cpu_hotplug.rst for further information and

0 commit comments

Comments
 (0)