Skip to content

Commit 5a2bf1a

Browse files
committed
Merge branch 'smp-hotplug-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull CPU hotplug updates from Ingo Molnar: "Two changes in this cycle: - Make the /sys/devices/system/cpu/smt/* files available on all arches, so user space has a consistent way to detect whether SMT is enabled. - Sparse annotation fix" * 'smp-hotplug-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: smpboot: Place the __percpu annotation correctly cpu/hotplug: Create SMT sysfs interface for all arches
2 parents e00d413 + d4645d3 commit 5a2bf1a

4 files changed

Lines changed: 48 additions & 31 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,12 @@ Description: Control Symetric Multi Threading (SMT)
511511
control: Read/write interface to control SMT. Possible
512512
values:
513513

514-
"on" SMT is enabled
515-
"off" SMT is disabled
516-
"forceoff" SMT is force disabled. Cannot be changed.
517-
"notsupported" SMT is not supported by the CPU
514+
"on" SMT is enabled
515+
"off" SMT is disabled
516+
"forceoff" SMT is force disabled. Cannot be changed.
517+
"notsupported" SMT is not supported by the CPU
518+
"notimplemented" SMT runtime toggling is not
519+
implemented for the architecture
518520

519521
If control status is "forceoff" or "notsupported" writes
520522
are rejected.

‎include/linux/cpu.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,15 @@ enum cpuhp_smt_control {
192192
CPU_SMT_DISABLED,
193193
CPU_SMT_FORCE_DISABLED,
194194
CPU_SMT_NOT_SUPPORTED,
195+
CPU_SMT_NOT_IMPLEMENTED,
195196
};
196197

197198
#if defined(CONFIG_SMP) && defined(CONFIG_HOTPLUG_SMT)
198199
extern enum cpuhp_smt_control cpu_smt_control;
199200
extern void cpu_smt_disable(bool force);
200201
extern void cpu_smt_check_topology(void);
201202
#else
202-
# define cpu_smt_control (CPU_SMT_ENABLED)
203+
# define cpu_smt_control (CPU_SMT_NOT_IMPLEMENTED)
203204
static inline void cpu_smt_disable(bool force) { }
204205
static inline void cpu_smt_check_topology(void) { }
205206
#endif

‎include/linux/smpboot.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct smpboot_thread_data;
2929
* @thread_comm: The base name of the thread
3030
*/
3131
struct smp_hotplug_thread {
32-
struct task_struct __percpu **store;
32+
struct task_struct * __percpu *store;
3333
struct list_head list;
3434
int (*thread_should_run)(unsigned int cpu);
3535
void (*thread_fn)(unsigned int cpu);

‎kernel/cpu.c‎

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,19 +2041,6 @@ static const struct attribute_group cpuhp_cpu_root_attr_group = {
20412041

20422042
#ifdef CONFIG_HOTPLUG_SMT
20432043

2044-
static const char *smt_states[] = {
2045-
[CPU_SMT_ENABLED] = "on",
2046-
[CPU_SMT_DISABLED] = "off",
2047-
[CPU_SMT_FORCE_DISABLED] = "forceoff",
2048-
[CPU_SMT_NOT_SUPPORTED] = "notsupported",
2049-
};
2050-
2051-
static ssize_t
2052-
show_smt_control(struct device *dev, struct device_attribute *attr, char *buf)
2053-
{
2054-
return snprintf(buf, PAGE_SIZE - 2, "%s\n", smt_states[cpu_smt_control]);
2055-
}
2056-
20572044
static void cpuhp_offline_cpu_device(unsigned int cpu)
20582045
{
20592046
struct device *dev = get_cpu_device(cpu);
@@ -2124,9 +2111,10 @@ static int cpuhp_smt_enable(void)
21242111
return ret;
21252112
}
21262113

2114+
21272115
static ssize_t
2128-
store_smt_control(struct device *dev, struct device_attribute *attr,
2129-
const char *buf, size_t count)
2116+
__store_smt_control(struct device *dev, struct device_attribute *attr,
2117+
const char *buf, size_t count)
21302118
{
21312119
int ctrlval, ret;
21322120

@@ -2164,14 +2152,44 @@ store_smt_control(struct device *dev, struct device_attribute *attr,
21642152
unlock_device_hotplug();
21652153
return ret ? ret : count;
21662154
}
2155+
2156+
#else /* !CONFIG_HOTPLUG_SMT */
2157+
static ssize_t
2158+
__store_smt_control(struct device *dev, struct device_attribute *attr,
2159+
const char *buf, size_t count)
2160+
{
2161+
return -ENODEV;
2162+
}
2163+
#endif /* CONFIG_HOTPLUG_SMT */
2164+
2165+
static const char *smt_states[] = {
2166+
[CPU_SMT_ENABLED] = "on",
2167+
[CPU_SMT_DISABLED] = "off",
2168+
[CPU_SMT_FORCE_DISABLED] = "forceoff",
2169+
[CPU_SMT_NOT_SUPPORTED] = "notsupported",
2170+
[CPU_SMT_NOT_IMPLEMENTED] = "notimplemented",
2171+
};
2172+
2173+
static ssize_t
2174+
show_smt_control(struct device *dev, struct device_attribute *attr, char *buf)
2175+
{
2176+
const char *state = smt_states[cpu_smt_control];
2177+
2178+
return snprintf(buf, PAGE_SIZE - 2, "%s\n", state);
2179+
}
2180+
2181+
static ssize_t
2182+
store_smt_control(struct device *dev, struct device_attribute *attr,
2183+
const char *buf, size_t count)
2184+
{
2185+
return __store_smt_control(dev, attr, buf, count);
2186+
}
21672187
static DEVICE_ATTR(control, 0644, show_smt_control, store_smt_control);
21682188

21692189
static ssize_t
21702190
show_smt_active(struct device *dev, struct device_attribute *attr, char *buf)
21712191
{
2172-
bool active = topology_max_smt_threads() > 1;
2173-
2174-
return snprintf(buf, PAGE_SIZE - 2, "%d\n", active);
2192+
return snprintf(buf, PAGE_SIZE - 2, "%d\n", sched_smt_active());
21752193
}
21762194
static DEVICE_ATTR(active, 0444, show_smt_active, NULL);
21772195

@@ -2187,21 +2205,17 @@ static const struct attribute_group cpuhp_smt_attr_group = {
21872205
NULL
21882206
};
21892207

2190-
static int __init cpu_smt_state_init(void)
2208+
static int __init cpu_smt_sysfs_init(void)
21912209
{
21922210
return sysfs_create_group(&cpu_subsys.dev_root->kobj,
21932211
&cpuhp_smt_attr_group);
21942212
}
21952213

2196-
#else
2197-
static inline int cpu_smt_state_init(void) { return 0; }
2198-
#endif
2199-
22002214
static int __init cpuhp_sysfs_init(void)
22012215
{
22022216
int cpu, ret;
22032217

2204-
ret = cpu_smt_state_init();
2218+
ret = cpu_smt_sysfs_init();
22052219
if (ret)
22062220
return ret;
22072221

@@ -2222,7 +2236,7 @@ static int __init cpuhp_sysfs_init(void)
22222236
return 0;
22232237
}
22242238
device_initcall(cpuhp_sysfs_init);
2225-
#endif
2239+
#endif /* CONFIG_SYSFS && CONFIG_HOTPLUG_CPU */
22262240

22272241
/*
22282242
* cpu_bit_bitmap[] is a special, "compressed" data structure that

0 commit comments

Comments
 (0)