41
41
#include "smpboot.h"
42
42
43
43
/**
44
- * cpuhp_cpu_state - Per cpu hotplug state storage
44
+ * struct cpuhp_cpu_state - Per cpu hotplug state storage
45
45
* @state: The current cpu state
46
46
* @target: The target state
47
+ * @fail: Current CPU hotplug callback state
47
48
* @thread: Pointer to the hotplug thread
48
49
* @should_run: Thread should execute
49
50
* @rollback: Perform a rollback
50
51
* @single: Single callback invocation
51
52
* @bringup: Single callback bringup or teardown selector
53
+ * @cpu: CPU number
54
+ * @node: Remote CPU node; for multi-instance, do a
55
+ * single entry callback for install/remove
56
+ * @last: For multi-instance rollback, remember how far we got
52
57
* @cb_state: The state for a single callback (install/uninstall)
53
58
* @result: Result of the operation
54
59
* @done_up: Signal completion to the issuer of the task for cpu-up
@@ -106,11 +111,12 @@ static inline void cpuhp_lock_release(bool bringup) { }
106
111
#endif
107
112
108
113
/**
109
- * cpuhp_step - Hotplug state machine step
114
+ * struct cpuhp_step - Hotplug state machine step
110
115
* @name: Name of the step
111
116
* @startup: Startup function of the step
112
117
* @teardown: Teardown function of the step
113
118
* @cant_stop: Bringup/teardown can't be stopped at this step
119
+ * @multi_instance: State has multiple instances which get added afterwards
114
120
*/
115
121
struct cpuhp_step {
116
122
const char * name ;
@@ -124,7 +130,9 @@ struct cpuhp_step {
124
130
int (* multi )(unsigned int cpu ,
125
131
struct hlist_node * node );
126
132
} teardown ;
133
+ /* private: */
127
134
struct hlist_head list ;
135
+ /* public: */
128
136
bool cant_stop ;
129
137
bool multi_instance ;
130
138
};
@@ -143,14 +151,16 @@ static bool cpuhp_step_empty(bool bringup, struct cpuhp_step *step)
143
151
}
144
152
145
153
/**
146
- * cpuhp_invoke_callback _ Invoke the callbacks for a given state
154
+ * cpuhp_invoke_callback - Invoke the callbacks for a given state
147
155
* @cpu: The cpu for which the callback should be invoked
148
156
* @state: The state to do callbacks for
149
157
* @bringup: True if the bringup callback should be invoked
150
158
* @node: For multi-instance, do a single entry callback for install/remove
151
159
* @lastp: For multi-instance rollback, remember how far we got
152
160
*
153
161
* Called from cpu hotplug and from the state register machinery.
162
+ *
163
+ * Return: %0 on success or a negative errno code
154
164
*/
155
165
static int cpuhp_invoke_callback (unsigned int cpu , enum cpuhp_state state ,
156
166
bool bringup , struct hlist_node * node ,
@@ -682,6 +692,10 @@ static int cpuhp_up_callbacks(unsigned int cpu, struct cpuhp_cpu_state *st,
682
692
683
693
ret = cpuhp_invoke_callback_range (true, cpu , st , target );
684
694
if (ret ) {
695
+ pr_debug ("CPU UP failed (%d) CPU %u state %s (%d)\n" ,
696
+ ret , cpu , cpuhp_get_step (st -> state )-> name ,
697
+ st -> state );
698
+
685
699
cpuhp_reset_state (st , prev_state );
686
700
if (can_rollback_cpu (st ))
687
701
WARN_ON (cpuhp_invoke_callback_range (false, cpu , st ,
@@ -1081,6 +1095,9 @@ static int cpuhp_down_callbacks(unsigned int cpu, struct cpuhp_cpu_state *st,
1081
1095
1082
1096
ret = cpuhp_invoke_callback_range (false, cpu , st , target );
1083
1097
if (ret ) {
1098
+ pr_debug ("CPU DOWN failed (%d) CPU %u state %s (%d)\n" ,
1099
+ ret , cpu , cpuhp_get_step (st -> state )-> name ,
1100
+ st -> state );
1084
1101
1085
1102
cpuhp_reset_state (st , prev_state );
1086
1103
@@ -1183,6 +1200,8 @@ static int cpu_down(unsigned int cpu, enum cpuhp_state target)
1183
1200
* This function is meant to be used by device core cpu subsystem only.
1184
1201
*
1185
1202
* Other subsystems should use remove_cpu() instead.
1203
+ *
1204
+ * Return: %0 on success or a negative errno code
1186
1205
*/
1187
1206
int cpu_device_down (struct device * dev )
1188
1207
{
@@ -1395,6 +1414,8 @@ static int cpu_up(unsigned int cpu, enum cpuhp_state target)
1395
1414
* This function is meant to be used by device core cpu subsystem only.
1396
1415
*
1397
1416
* Other subsystems should use add_cpu() instead.
1417
+ *
1418
+ * Return: %0 on success or a negative errno code
1398
1419
*/
1399
1420
int cpu_device_up (struct device * dev )
1400
1421
{
@@ -1420,6 +1441,8 @@ EXPORT_SYMBOL_GPL(add_cpu);
1420
1441
* On some architectures like arm64, we can hibernate on any CPU, but on
1421
1442
* wake up the CPU we hibernated on might be offline as a side effect of
1422
1443
* using maxcpus= for example.
1444
+ *
1445
+ * Return: %0 on success or a negative errno code
1423
1446
*/
1424
1447
int bringup_hibernate_cpu (unsigned int sleep_cpu )
1425
1448
{
@@ -1976,6 +1999,7 @@ EXPORT_SYMBOL_GPL(__cpuhp_state_add_instance);
1976
1999
/**
1977
2000
* __cpuhp_setup_state_cpuslocked - Setup the callbacks for an hotplug machine state
1978
2001
* @state: The state to setup
2002
+ * @name: Name of the step
1979
2003
* @invoke: If true, the startup function is invoked for cpus where
1980
2004
* cpu state >= @state
1981
2005
* @startup: startup callback function
@@ -1984,9 +2008,9 @@ EXPORT_SYMBOL_GPL(__cpuhp_state_add_instance);
1984
2008
* added afterwards.
1985
2009
*
1986
2010
* The caller needs to hold cpus read locked while calling this function.
1987
- * Returns :
2011
+ * Return :
1988
2012
* On success:
1989
- * Positive state number if @state is CPUHP_AP_ONLINE_DYN
2013
+ * Positive state number if @state is CPUHP_AP_ONLINE_DYN;
1990
2014
* 0 for all other states
1991
2015
* On failure: proper (negative) error code
1992
2016
*/
@@ -2232,18 +2256,17 @@ int cpuhp_smt_enable(void)
2232
2256
#endif
2233
2257
2234
2258
#if defined(CONFIG_SYSFS ) && defined(CONFIG_HOTPLUG_CPU )
2235
- static ssize_t show_cpuhp_state (struct device * dev ,
2236
- struct device_attribute * attr , char * buf )
2259
+ static ssize_t state_show (struct device * dev ,
2260
+ struct device_attribute * attr , char * buf )
2237
2261
{
2238
2262
struct cpuhp_cpu_state * st = per_cpu_ptr (& cpuhp_state , dev -> id );
2239
2263
2240
2264
return sprintf (buf , "%d\n" , st -> state );
2241
2265
}
2242
- static DEVICE_ATTR (state , 0444 , show_cpuhp_state , NULL );
2266
+ static DEVICE_ATTR_RO (state );
2243
2267
2244
- static ssize_t write_cpuhp_target (struct device * dev ,
2245
- struct device_attribute * attr ,
2246
- const char * buf , size_t count )
2268
+ static ssize_t target_store (struct device * dev , struct device_attribute * attr ,
2269
+ const char * buf , size_t count )
2247
2270
{
2248
2271
struct cpuhp_cpu_state * st = per_cpu_ptr (& cpuhp_state , dev -> id );
2249
2272
struct cpuhp_step * sp ;
@@ -2281,19 +2304,17 @@ static ssize_t write_cpuhp_target(struct device *dev,
2281
2304
return ret ? ret : count ;
2282
2305
}
2283
2306
2284
- static ssize_t show_cpuhp_target (struct device * dev ,
2285
- struct device_attribute * attr , char * buf )
2307
+ static ssize_t target_show (struct device * dev ,
2308
+ struct device_attribute * attr , char * buf )
2286
2309
{
2287
2310
struct cpuhp_cpu_state * st = per_cpu_ptr (& cpuhp_state , dev -> id );
2288
2311
2289
2312
return sprintf (buf , "%d\n" , st -> target );
2290
2313
}
2291
- static DEVICE_ATTR (target , 0644 , show_cpuhp_target , write_cpuhp_target );
2292
-
2314
+ static DEVICE_ATTR_RW (target );
2293
2315
2294
- static ssize_t write_cpuhp_fail (struct device * dev ,
2295
- struct device_attribute * attr ,
2296
- const char * buf , size_t count )
2316
+ static ssize_t fail_store (struct device * dev , struct device_attribute * attr ,
2317
+ const char * buf , size_t count )
2297
2318
{
2298
2319
struct cpuhp_cpu_state * st = per_cpu_ptr (& cpuhp_state , dev -> id );
2299
2320
struct cpuhp_step * sp ;
@@ -2342,15 +2363,15 @@ static ssize_t write_cpuhp_fail(struct device *dev,
2342
2363
return count ;
2343
2364
}
2344
2365
2345
- static ssize_t show_cpuhp_fail (struct device * dev ,
2346
- struct device_attribute * attr , char * buf )
2366
+ static ssize_t fail_show (struct device * dev ,
2367
+ struct device_attribute * attr , char * buf )
2347
2368
{
2348
2369
struct cpuhp_cpu_state * st = per_cpu_ptr (& cpuhp_state , dev -> id );
2349
2370
2350
2371
return sprintf (buf , "%d\n" , st -> fail );
2351
2372
}
2352
2373
2353
- static DEVICE_ATTR (fail , 0644 , show_cpuhp_fail , write_cpuhp_fail );
2374
+ static DEVICE_ATTR_RW (fail );
2354
2375
2355
2376
static struct attribute * cpuhp_cpu_attrs [] = {
2356
2377
& dev_attr_state .attr ,
@@ -2365,7 +2386,7 @@ static const struct attribute_group cpuhp_cpu_attr_group = {
2365
2386
NULL
2366
2387
};
2367
2388
2368
- static ssize_t show_cpuhp_states (struct device * dev ,
2389
+ static ssize_t states_show (struct device * dev ,
2369
2390
struct device_attribute * attr , char * buf )
2370
2391
{
2371
2392
ssize_t cur , res = 0 ;
@@ -2384,7 +2405,7 @@ static ssize_t show_cpuhp_states(struct device *dev,
2384
2405
mutex_unlock (& cpuhp_state_mutex );
2385
2406
return res ;
2386
2407
}
2387
- static DEVICE_ATTR (states , 0444 , show_cpuhp_states , NULL );
2408
+ static DEVICE_ATTR_RO (states );
2388
2409
2389
2410
static struct attribute * cpuhp_cpu_root_attrs [] = {
2390
2411
& dev_attr_states .attr ,
@@ -2457,28 +2478,27 @@ static const char *smt_states[] = {
2457
2478
[CPU_SMT_NOT_IMPLEMENTED ] = "notimplemented" ,
2458
2479
};
2459
2480
2460
- static ssize_t
2461
- show_smt_control ( struct device * dev , struct device_attribute * attr , char * buf )
2481
+ static ssize_t control_show ( struct device * dev ,
2482
+ struct device_attribute * attr , char * buf )
2462
2483
{
2463
2484
const char * state = smt_states [cpu_smt_control ];
2464
2485
2465
2486
return snprintf (buf , PAGE_SIZE - 2 , "%s\n" , state );
2466
2487
}
2467
2488
2468
- static ssize_t
2469
- store_smt_control (struct device * dev , struct device_attribute * attr ,
2470
- const char * buf , size_t count )
2489
+ static ssize_t control_store (struct device * dev , struct device_attribute * attr ,
2490
+ const char * buf , size_t count )
2471
2491
{
2472
2492
return __store_smt_control (dev , attr , buf , count );
2473
2493
}
2474
- static DEVICE_ATTR (control , 0644 , show_smt_control , store_smt_control );
2494
+ static DEVICE_ATTR_RW (control );
2475
2495
2476
- static ssize_t
2477
- show_smt_active ( struct device * dev , struct device_attribute * attr , char * buf )
2496
+ static ssize_t active_show ( struct device * dev ,
2497
+ struct device_attribute * attr , char * buf )
2478
2498
{
2479
2499
return snprintf (buf , PAGE_SIZE - 2 , "%d\n" , sched_smt_active ());
2480
2500
}
2481
- static DEVICE_ATTR (active , 0444 , show_smt_active , NULL );
2501
+ static DEVICE_ATTR_RO (active );
2482
2502
2483
2503
static struct attribute * cpuhp_smt_attrs [] = {
2484
2504
& dev_attr_control .attr ,
0 commit comments