Skip to content

Commit f306b90

Browse files
committed
Merge tag 'smp-urgent-2021-09-12' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull CPU hotplug updates from Thomas Gleixner: "Updates for the SMP and CPU hotplug: - Remove DEFINE_SMP_CALL_CACHE_FUNCTION() which is a left over of the original hotplug code and now causing trouble with the ARM64 cache topology setup due to the pointless SMP function call. It's not longer required as the hotplug callbacks are guaranteed to be invoked on the upcoming CPU. - Remove the deprecated and now unused CPU hotplug functions - Rewrite the CPU hotplug API documentation" * tag 'smp-urgent-2021-09-12' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: Documentation: core-api/cpuhotplug: Rewrite the API section cpu/hotplug: Remove deprecated CPU-hotplug functions. thermal: Replace deprecated CPU-hotplug functions. drivers: base: cacheinfo: Get rid of DEFINE_SMP_CALL_CACHE_FUNCTION()
2 parents d8e988b + c9871c8 commit f306b90

File tree

8 files changed

+598
-165
lines changed

8 files changed

+598
-165
lines changed

Documentation/core-api/cpu_hotplug.rst

Lines changed: 480 additions & 99 deletions
Large diffs are not rendered by default.

arch/arm64/kernel/cacheinfo.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static void ci_leaf_init(struct cacheinfo *this_leaf,
4343
this_leaf->type = type;
4444
}
4545

46-
static int __init_cache_level(unsigned int cpu)
46+
int init_cache_level(unsigned int cpu)
4747
{
4848
unsigned int ctype, level, leaves, fw_level;
4949
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
@@ -78,7 +78,7 @@ static int __init_cache_level(unsigned int cpu)
7878
return 0;
7979
}
8080

81-
static int __populate_cache_leaves(unsigned int cpu)
81+
int populate_cache_leaves(unsigned int cpu)
8282
{
8383
unsigned int level, idx;
8484
enum cache_type type;
@@ -97,6 +97,3 @@ static int __populate_cache_leaves(unsigned int cpu)
9797
}
9898
return 0;
9999
}
100-
101-
DEFINE_SMP_CALL_CACHE_FUNCTION(init_cache_level)
102-
DEFINE_SMP_CALL_CACHE_FUNCTION(populate_cache_leaves)

arch/mips/kernel/cacheinfo.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ do { \
1717
leaf++; \
1818
} while (0)
1919

20-
static int __init_cache_level(unsigned int cpu)
20+
int init_cache_level(unsigned int cpu)
2121
{
2222
struct cpuinfo_mips *c = &current_cpu_data;
2323
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
@@ -74,7 +74,7 @@ static void fill_cpumask_cluster(int cpu, cpumask_t *cpu_map)
7474
cpumask_set_cpu(cpu1, cpu_map);
7575
}
7676

77-
static int __populate_cache_leaves(unsigned int cpu)
77+
int populate_cache_leaves(unsigned int cpu)
7878
{
7979
struct cpuinfo_mips *c = &current_cpu_data;
8080
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
@@ -114,6 +114,3 @@ static int __populate_cache_leaves(unsigned int cpu)
114114

115115
return 0;
116116
}
117-
118-
DEFINE_SMP_CALL_CACHE_FUNCTION(init_cache_level)
119-
DEFINE_SMP_CALL_CACHE_FUNCTION(populate_cache_leaves)

arch/riscv/kernel/cacheinfo.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static void fill_cacheinfo(struct cacheinfo **this_leaf,
113113
}
114114
}
115115

116-
static int __init_cache_level(unsigned int cpu)
116+
int init_cache_level(unsigned int cpu)
117117
{
118118
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
119119
struct device_node *np = of_cpu_device_node_get(cpu);
@@ -155,7 +155,7 @@ static int __init_cache_level(unsigned int cpu)
155155
return 0;
156156
}
157157

158-
static int __populate_cache_leaves(unsigned int cpu)
158+
int populate_cache_leaves(unsigned int cpu)
159159
{
160160
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
161161
struct cacheinfo *this_leaf = this_cpu_ci->info_list;
@@ -187,6 +187,3 @@ static int __populate_cache_leaves(unsigned int cpu)
187187

188188
return 0;
189189
}
190-
191-
DEFINE_SMP_CALL_CACHE_FUNCTION(init_cache_level)
192-
DEFINE_SMP_CALL_CACHE_FUNCTION(populate_cache_leaves)

arch/x86/kernel/cpu/cacheinfo.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ static void ci_leaf_init(struct cacheinfo *this_leaf,
985985
this_leaf->priv = base->nb;
986986
}
987987

988-
static int __init_cache_level(unsigned int cpu)
988+
int init_cache_level(unsigned int cpu)
989989
{
990990
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
991991

@@ -1014,7 +1014,7 @@ static void get_cache_id(int cpu, struct _cpuid4_info_regs *id4_regs)
10141014
id4_regs->id = c->apicid >> index_msb;
10151015
}
10161016

1017-
static int __populate_cache_leaves(unsigned int cpu)
1017+
int populate_cache_leaves(unsigned int cpu)
10181018
{
10191019
unsigned int idx, ret;
10201020
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
@@ -1033,6 +1033,3 @@ static int __populate_cache_leaves(unsigned int cpu)
10331033

10341034
return 0;
10351035
}
1036-
1037-
DEFINE_SMP_CALL_CACHE_FUNCTION(init_cache_level)
1038-
DEFINE_SMP_CALL_CACHE_FUNCTION(populate_cache_leaves)

include/linux/cacheinfo.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,6 @@ struct cpu_cacheinfo {
7979
bool cpu_map_populated;
8080
};
8181

82-
/*
83-
* Helpers to make sure "func" is executed on the cpu whose cache
84-
* attributes are being detected
85-
*/
86-
#define DEFINE_SMP_CALL_CACHE_FUNCTION(func) \
87-
static inline void _##func(void *ret) \
88-
{ \
89-
int cpu = smp_processor_id(); \
90-
*(int *)ret = __##func(cpu); \
91-
} \
92-
\
93-
int func(unsigned int cpu) \
94-
{ \
95-
int ret; \
96-
smp_call_function_single(cpu, _##func, &ret, true); \
97-
return ret; \
98-
}
99-
10082
struct cpu_cacheinfo *get_cpu_cacheinfo(unsigned int cpu);
10183
int init_cache_level(unsigned int cpu);
10284
int populate_cache_leaves(unsigned int cpu);

include/linux/cpu.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,6 @@ static inline int remove_cpu(unsigned int cpu) { return -EPERM; }
143143
static inline void smp_shutdown_nonboot_cpus(unsigned int primary_cpu) { }
144144
#endif /* !CONFIG_HOTPLUG_CPU */
145145

146-
/* Wrappers which go away once all code is converted */
147-
static inline void cpu_hotplug_begin(void) { cpus_write_lock(); }
148-
static inline void cpu_hotplug_done(void) { cpus_write_unlock(); }
149-
static inline void get_online_cpus(void) { cpus_read_lock(); }
150-
static inline void put_online_cpus(void) { cpus_read_unlock(); }
151-
152146
#ifdef CONFIG_PM_SLEEP_SMP
153147
extern int freeze_secondary_cpus(int primary);
154148
extern void thaw_secondary_cpus(void);

include/linux/cpuhotplug.h

Lines changed: 110 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,42 @@
2222
* AP_ACTIVE AP_ACTIVE
2323
*/
2424

25+
/*
26+
* CPU hotplug states. The state machine invokes the installed state
27+
* startup callbacks sequentially from CPUHP_OFFLINE + 1 to CPUHP_ONLINE
28+
* during a CPU online operation. During a CPU offline operation the
29+
* installed teardown callbacks are invoked in the reverse order from
30+
* CPU_ONLINE - 1 down to CPUHP_OFFLINE.
31+
*
32+
* The state space has three sections: PREPARE, STARTING and ONLINE.
33+
*
34+
* PREPARE: The callbacks are invoked on a control CPU before the
35+
* hotplugged CPU is started up or after the hotplugged CPU has died.
36+
*
37+
* STARTING: The callbacks are invoked on the hotplugged CPU from the low level
38+
* hotplug startup/teardown code with interrupts disabled.
39+
*
40+
* ONLINE: The callbacks are invoked on the hotplugged CPU from the per CPU
41+
* hotplug thread with interrupts and preemption enabled.
42+
*
43+
* Adding explicit states to this enum is only necessary when:
44+
*
45+
* 1) The state is within the STARTING section
46+
*
47+
* 2) The state has ordering constraints vs. other states in the
48+
* same section.
49+
*
50+
* 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
52+
* for the @state argument of the setup function.
53+
*
54+
* See Documentation/core-api/cpu_hotplug.rst for further information and
55+
* examples.
56+
*/
2557
enum cpuhp_state {
2658
CPUHP_INVALID = -1,
59+
60+
/* PREPARE section invoked on a control CPU */
2761
CPUHP_OFFLINE = 0,
2862
CPUHP_CREATE_THREADS,
2963
CPUHP_PERF_PREPARE,
@@ -95,6 +129,11 @@ enum cpuhp_state {
95129
CPUHP_BP_PREPARE_DYN,
96130
CPUHP_BP_PREPARE_DYN_END = CPUHP_BP_PREPARE_DYN + 20,
97131
CPUHP_BRINGUP_CPU,
132+
133+
/*
134+
* STARTING section invoked on the hotplugged CPU in low level
135+
* bringup and teardown code.
136+
*/
98137
CPUHP_AP_IDLE_DEAD,
99138
CPUHP_AP_OFFLINE,
100139
CPUHP_AP_SCHED_STARTING,
@@ -155,6 +194,8 @@ enum cpuhp_state {
155194
CPUHP_AP_ARM_CACHE_B15_RAC_DYING,
156195
CPUHP_AP_ONLINE,
157196
CPUHP_TEARDOWN_CPU,
197+
198+
/* Online section invoked on the hotplugged CPU from the hotplug thread */
158199
CPUHP_AP_ONLINE_IDLE,
159200
CPUHP_AP_SCHED_WAIT_EMPTY,
160201
CPUHP_AP_SMPBOOT_THREADS,
@@ -216,14 +257,15 @@ int __cpuhp_setup_state_cpuslocked(enum cpuhp_state state, const char *name,
216257
int (*teardown)(unsigned int cpu),
217258
bool multi_instance);
218259
/**
219-
* cpuhp_setup_state - Setup hotplug state callbacks with calling the callbacks
260+
* cpuhp_setup_state - Setup hotplug state callbacks with calling the @startup
261+
* callback
220262
* @state: The state for which the calls are installed
221263
* @name: Name of the callback (will be used in debug output)
222-
* @startup: startup callback function
223-
* @teardown: teardown callback function
264+
* @startup: startup callback function or NULL if not required
265+
* @teardown: teardown callback function or NULL if not required
224266
*
225-
* Installs the callback functions and invokes the startup callback on
226-
* the present cpus which have already reached the @state.
267+
* Installs the callback functions and invokes the @startup callback on
268+
* the online cpus which have already reached the @state.
227269
*/
228270
static inline int cpuhp_setup_state(enum cpuhp_state state,
229271
const char *name,
@@ -233,6 +275,18 @@ static inline int cpuhp_setup_state(enum cpuhp_state state,
233275
return __cpuhp_setup_state(state, name, true, startup, teardown, false);
234276
}
235277

278+
/**
279+
* cpuhp_setup_state_cpuslocked - Setup hotplug state callbacks with calling
280+
* @startup callback from a cpus_read_lock()
281+
* held region
282+
* @state: The state for which the calls are installed
283+
* @name: Name of the callback (will be used in debug output)
284+
* @startup: startup callback function or NULL if not required
285+
* @teardown: teardown callback function or NULL if not required
286+
*
287+
* Same as cpuhp_setup_state() except that it must be invoked from within a
288+
* cpus_read_lock() held region.
289+
*/
236290
static inline int cpuhp_setup_state_cpuslocked(enum cpuhp_state state,
237291
const char *name,
238292
int (*startup)(unsigned int cpu),
@@ -244,14 +298,14 @@ static inline int cpuhp_setup_state_cpuslocked(enum cpuhp_state state,
244298

245299
/**
246300
* cpuhp_setup_state_nocalls - Setup hotplug state callbacks without calling the
247-
* callbacks
301+
* @startup callback
248302
* @state: The state for which the calls are installed
249303
* @name: Name of the callback.
250-
* @startup: startup callback function
251-
* @teardown: teardown callback function
304+
* @startup: startup callback function or NULL if not required
305+
* @teardown: teardown callback function or NULL if not required
252306
*
253-
* Same as @cpuhp_setup_state except that no calls are executed are invoked
254-
* during installation of this callback. NOP if SMP=n or HOTPLUG_CPU=n.
307+
* Same as cpuhp_setup_state() except that the @startup callback is not
308+
* invoked during installation. NOP if SMP=n or HOTPLUG_CPU=n.
255309
*/
256310
static inline int cpuhp_setup_state_nocalls(enum cpuhp_state state,
257311
const char *name,
@@ -262,6 +316,19 @@ static inline int cpuhp_setup_state_nocalls(enum cpuhp_state state,
262316
false);
263317
}
264318

319+
/**
320+
* cpuhp_setup_state_nocalls_cpuslocked - Setup hotplug state callbacks without
321+
* invoking the @startup callback from
322+
* a cpus_read_lock() held region
323+
* callbacks
324+
* @state: The state for which the calls are installed
325+
* @name: Name of the callback.
326+
* @startup: startup callback function or NULL if not required
327+
* @teardown: teardown callback function or NULL if not required
328+
*
329+
* Same as cpuhp_setup_state_nocalls() except that it must be invoked from
330+
* within a cpus_read_lock() held region.
331+
*/
265332
static inline int cpuhp_setup_state_nocalls_cpuslocked(enum cpuhp_state state,
266333
const char *name,
267334
int (*startup)(unsigned int cpu),
@@ -275,13 +342,13 @@ static inline int cpuhp_setup_state_nocalls_cpuslocked(enum cpuhp_state state,
275342
* cpuhp_setup_state_multi - Add callbacks for multi state
276343
* @state: The state for which the calls are installed
277344
* @name: Name of the callback.
278-
* @startup: startup callback function
279-
* @teardown: teardown callback function
345+
* @startup: startup callback function or NULL if not required
346+
* @teardown: teardown callback function or NULL if not required
280347
*
281348
* Sets the internal multi_instance flag and prepares a state to work as a multi
282349
* instance callback. No callbacks are invoked at this point. The callbacks are
283350
* invoked once an instance for this state are registered via
284-
* @cpuhp_state_add_instance or @cpuhp_state_add_instance_nocalls.
351+
* cpuhp_state_add_instance() or cpuhp_state_add_instance_nocalls()
285352
*/
286353
static inline int cpuhp_setup_state_multi(enum cpuhp_state state,
287354
const char *name,
@@ -306,9 +373,10 @@ int __cpuhp_state_add_instance_cpuslocked(enum cpuhp_state state,
306373
* @state: The state for which the instance is installed
307374
* @node: The node for this individual state.
308375
*
309-
* Installs the instance for the @state and invokes the startup callback on
310-
* the present cpus which have already reached the @state. The @state must have
311-
* been earlier marked as multi-instance by @cpuhp_setup_state_multi.
376+
* Installs the instance for the @state and invokes the registered startup
377+
* callback on the online cpus which have already reached the @state. The
378+
* @state must have been earlier marked as multi-instance by
379+
* cpuhp_setup_state_multi().
312380
*/
313381
static inline int cpuhp_state_add_instance(enum cpuhp_state state,
314382
struct hlist_node *node)
@@ -322,15 +390,27 @@ static inline int cpuhp_state_add_instance(enum cpuhp_state state,
322390
* @state: The state for which the instance is installed
323391
* @node: The node for this individual state.
324392
*
325-
* Installs the instance for the @state The @state must have been earlier
326-
* marked as multi-instance by @cpuhp_setup_state_multi.
393+
* Installs the instance for the @state. The @state must have been earlier
394+
* marked as multi-instance by cpuhp_setup_state_multi. NOP if SMP=n or
395+
* HOTPLUG_CPU=n.
327396
*/
328397
static inline int cpuhp_state_add_instance_nocalls(enum cpuhp_state state,
329398
struct hlist_node *node)
330399
{
331400
return __cpuhp_state_add_instance(state, node, false);
332401
}
333402

403+
/**
404+
* cpuhp_state_add_instance_nocalls_cpuslocked - Add an instance for a state
405+
* without invoking the startup
406+
* callback from a cpus_read_lock()
407+
* held region.
408+
* @state: The state for which the instance is installed
409+
* @node: The node for this individual state.
410+
*
411+
* Same as cpuhp_state_add_instance_nocalls() except that it must be
412+
* invoked from within a cpus_read_lock() held region.
413+
*/
334414
static inline int
335415
cpuhp_state_add_instance_nocalls_cpuslocked(enum cpuhp_state state,
336416
struct hlist_node *node)
@@ -346,7 +426,7 @@ void __cpuhp_remove_state_cpuslocked(enum cpuhp_state state, bool invoke);
346426
* @state: The state for which the calls are removed
347427
*
348428
* Removes the callback functions and invokes the teardown callback on
349-
* the present cpus which have already reached the @state.
429+
* the online cpus which have already reached the @state.
350430
*/
351431
static inline void cpuhp_remove_state(enum cpuhp_state state)
352432
{
@@ -355,14 +435,22 @@ static inline void cpuhp_remove_state(enum cpuhp_state state)
355435

356436
/**
357437
* cpuhp_remove_state_nocalls - Remove hotplug state callbacks without invoking
358-
* teardown
438+
* the teardown callback
359439
* @state: The state for which the calls are removed
360440
*/
361441
static inline void cpuhp_remove_state_nocalls(enum cpuhp_state state)
362442
{
363443
__cpuhp_remove_state(state, false);
364444
}
365445

446+
/**
447+
* cpuhp_remove_state_nocalls_cpuslocked - Remove hotplug state callbacks without invoking
448+
* teardown from a cpus_read_lock() held region.
449+
* @state: The state for which the calls are removed
450+
*
451+
* Same as cpuhp_remove_state nocalls() except that it must be invoked
452+
* from within a cpus_read_lock() held region.
453+
*/
366454
static inline void cpuhp_remove_state_nocalls_cpuslocked(enum cpuhp_state state)
367455
{
368456
__cpuhp_remove_state_cpuslocked(state, false);
@@ -390,8 +478,8 @@ int __cpuhp_state_remove_instance(enum cpuhp_state state,
390478
* @state: The state from which the instance is removed
391479
* @node: The node for this individual state.
392480
*
393-
* Removes the instance and invokes the teardown callback on the present cpus
394-
* which have already reached the @state.
481+
* Removes the instance and invokes the teardown callback on the online cpus
482+
* which have already reached @state.
395483
*/
396484
static inline int cpuhp_state_remove_instance(enum cpuhp_state state,
397485
struct hlist_node *node)

0 commit comments

Comments
 (0)