Blame view
kernel/cpu.c
19.4 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 9 10 11 12 |
/* CPU control. * (C) 2001, 2002, 2003, 2004 Rusty Russell * * This code is licenced under the GPL. */ #include <linux/proc_fs.h> #include <linux/smp.h> #include <linux/init.h> #include <linux/notifier.h> #include <linux/sched.h> #include <linux/unistd.h> #include <linux/cpu.h> |
cb79295e2 cpu: introduce cl... |
13 14 |
#include <linux/oom.h> #include <linux/rcupdate.h> |
9984de1a5 kernel: Map most ... |
15 |
#include <linux/export.h> |
e4cc2f873 kernel/cpu.c: doc... |
16 |
#include <linux/bug.h> |
1da177e4c Linux-2.6.12-rc2 |
17 18 |
#include <linux/kthread.h> #include <linux/stop_machine.h> |
81615b624 [PATCH] Convert k... |
19 |
#include <linux/mutex.h> |
5a0e3ad6a include cleanup: ... |
20 |
#include <linux/gfp.h> |
79cfbdfa8 PM / Sleep: Fix r... |
21 |
#include <linux/suspend.h> |
a19423b98 CPU hotplug: Add ... |
22 |
#include <linux/lockdep.h> |
bb3632c61 PM / sleep: trace... |
23 |
#include <trace/events/power.h> |
1da177e4c Linux-2.6.12-rc2 |
24 |
|
38498a67a smp: Add generic ... |
25 |
#include "smpboot.h" |
98a79d6a5 cpumask: centrali... |
26 |
#ifdef CONFIG_SMP |
b3199c025 cpumask: switch o... |
27 |
/* Serializes the updates to cpu_online_mask, cpu_present_mask */ |
aa9538777 cpu hotplug: simp... |
28 |
static DEFINE_MUTEX(cpu_add_remove_lock); |
1da177e4c Linux-2.6.12-rc2 |
29 |
|
79a6cdeb7 cpuhotplug: do no... |
30 |
/* |
93ae4f978 CPU hotplug: Prov... |
31 32 33 34 35 |
* The following two APIs (cpu_maps_update_begin/done) must be used when * attempting to serialize the updates to cpu_online_mask & cpu_present_mask. * The APIs cpu_notifier_register_begin/done() must be used to protect CPU * hotplug callback (un)registration performed using __register_cpu_notifier() * or __unregister_cpu_notifier(). |
79a6cdeb7 cpuhotplug: do no... |
36 37 38 39 40 |
*/ void cpu_maps_update_begin(void) { mutex_lock(&cpu_add_remove_lock); } |
93ae4f978 CPU hotplug: Prov... |
41 |
EXPORT_SYMBOL(cpu_notifier_register_begin); |
79a6cdeb7 cpuhotplug: do no... |
42 43 44 45 46 |
void cpu_maps_update_done(void) { mutex_unlock(&cpu_add_remove_lock); } |
93ae4f978 CPU hotplug: Prov... |
47 |
EXPORT_SYMBOL(cpu_notifier_register_done); |
79a6cdeb7 cpuhotplug: do no... |
48 |
|
5c113fbee fix cpu_chain sec... |
49 |
static RAW_NOTIFIER_HEAD(cpu_chain); |
1da177e4c Linux-2.6.12-rc2 |
50 |
|
e3920fb42 [PATCH] Disable C... |
51 52 53 54 |
/* If set, cpu_up and cpu_down will return -EBUSY and do nothing. * Should always be manipulated under cpu_add_remove_lock */ static int cpu_hotplug_disabled; |
79a6cdeb7 cpuhotplug: do no... |
55 |
#ifdef CONFIG_HOTPLUG_CPU |
d221938c0 cpu-hotplug: refc... |
56 57 58 59 60 61 62 63 |
static struct { struct task_struct *active_writer; struct mutex lock; /* Synchronizes accesses to refcount, */ /* * Also blocks the new readers during * an ongoing cpu hotplug operation. */ int refcount; |
b2c4623dc rcu: More on dead... |
64 65 |
/* And allows lockless put_online_cpus(). */ atomic_t puts_pending; |
a19423b98 CPU hotplug: Add ... |
66 67 68 69 |
#ifdef CONFIG_DEBUG_LOCK_ALLOC struct lockdep_map dep_map; #endif |
31950eb66 mm/init: cpu_hotp... |
70 71 72 73 |
} cpu_hotplug = { .active_writer = NULL, .lock = __MUTEX_INITIALIZER(cpu_hotplug.lock), .refcount = 0, |
a19423b98 CPU hotplug: Add ... |
74 75 76 |
#ifdef CONFIG_DEBUG_LOCK_ALLOC .dep_map = {.name = "cpu_hotplug.lock" }, #endif |
31950eb66 mm/init: cpu_hotp... |
77 |
}; |
d221938c0 cpu-hotplug: refc... |
78 |
|
a19423b98 CPU hotplug: Add ... |
79 80 |
/* Lockdep annotations for get/put_online_cpus() and cpu_hotplug_begin/end() */ #define cpuhp_lock_acquire_read() lock_map_acquire_read(&cpu_hotplug.dep_map) |
dd56af42b rcu: Eliminate de... |
81 82 |
#define cpuhp_lock_acquire_tryread() \ lock_map_acquire_tryread(&cpu_hotplug.dep_map) |
a19423b98 CPU hotplug: Add ... |
83 84 |
#define cpuhp_lock_acquire() lock_map_acquire(&cpu_hotplug.dep_map) #define cpuhp_lock_release() lock_map_release(&cpu_hotplug.dep_map) |
62db99f47 cpu: Avoid puts_p... |
85 86 87 88 89 90 91 92 93 |
static void apply_puts_pending(int max) { int delta; if (atomic_read(&cpu_hotplug.puts_pending) >= max) { delta = atomic_xchg(&cpu_hotplug.puts_pending, 0); cpu_hotplug.refcount -= delta; } } |
86ef5c9a8 cpu-hotplug: repl... |
94 |
void get_online_cpus(void) |
a9d9baa1e [PATCH] clean up ... |
95 |
{ |
d221938c0 cpu-hotplug: refc... |
96 97 |
might_sleep(); if (cpu_hotplug.active_writer == current) |
aa9538777 cpu hotplug: simp... |
98 |
return; |
a19423b98 CPU hotplug: Add ... |
99 |
cpuhp_lock_acquire_read(); |
d221938c0 cpu-hotplug: refc... |
100 |
mutex_lock(&cpu_hotplug.lock); |
62db99f47 cpu: Avoid puts_p... |
101 |
apply_puts_pending(65536); |
d221938c0 cpu-hotplug: refc... |
102 103 |
cpu_hotplug.refcount++; mutex_unlock(&cpu_hotplug.lock); |
a9d9baa1e [PATCH] clean up ... |
104 |
} |
86ef5c9a8 cpu-hotplug: repl... |
105 |
EXPORT_SYMBOL_GPL(get_online_cpus); |
90d45d17f [PATCH] cpu hotpl... |
106 |
|
dd56af42b rcu: Eliminate de... |
107 108 109 110 111 112 113 |
bool try_get_online_cpus(void) { if (cpu_hotplug.active_writer == current) return true; if (!mutex_trylock(&cpu_hotplug.lock)) return false; cpuhp_lock_acquire_tryread(); |
62db99f47 cpu: Avoid puts_p... |
114 |
apply_puts_pending(65536); |
dd56af42b rcu: Eliminate de... |
115 116 117 118 119 |
cpu_hotplug.refcount++; mutex_unlock(&cpu_hotplug.lock); return true; } EXPORT_SYMBOL_GPL(try_get_online_cpus); |
86ef5c9a8 cpu-hotplug: repl... |
120 |
void put_online_cpus(void) |
a9d9baa1e [PATCH] clean up ... |
121 |
{ |
d221938c0 cpu-hotplug: refc... |
122 |
if (cpu_hotplug.active_writer == current) |
aa9538777 cpu hotplug: simp... |
123 |
return; |
b2c4623dc rcu: More on dead... |
124 125 126 127 128 |
if (!mutex_trylock(&cpu_hotplug.lock)) { atomic_inc(&cpu_hotplug.puts_pending); cpuhp_lock_release(); return; } |
075663d19 CPU hotplug, debu... |
129 130 131 |
if (WARN_ON(!cpu_hotplug.refcount)) cpu_hotplug.refcount++; /* try to fix things up */ |
d2ba7e2ae simplify cpu_hotp... |
132 133 |
if (!--cpu_hotplug.refcount && unlikely(cpu_hotplug.active_writer)) wake_up_process(cpu_hotplug.active_writer); |
d221938c0 cpu-hotplug: refc... |
134 |
mutex_unlock(&cpu_hotplug.lock); |
a19423b98 CPU hotplug: Add ... |
135 |
cpuhp_lock_release(); |
d221938c0 cpu-hotplug: refc... |
136 |
|
a9d9baa1e [PATCH] clean up ... |
137 |
} |
86ef5c9a8 cpu-hotplug: repl... |
138 |
EXPORT_SYMBOL_GPL(put_online_cpus); |
a9d9baa1e [PATCH] clean up ... |
139 |
|
d221938c0 cpu-hotplug: refc... |
140 141 142 143 144 145 146 |
/* * This ensures that the hotplug operation can begin only when the * refcount goes to zero. * * Note that during a cpu-hotplug operation, the new readers, if any, * will be blocked by the cpu_hotplug.lock * |
d2ba7e2ae simplify cpu_hotp... |
147 148 |
* Since cpu_hotplug_begin() is always called after invoking * cpu_maps_update_begin(), we can be sure that only one writer is active. |
d221938c0 cpu-hotplug: refc... |
149 150 151 152 153 154 155 156 157 158 |
* * Note that theoretically, there is a possibility of a livelock: * - Refcount goes to zero, last reader wakes up the sleeping * writer. * - Last reader unlocks the cpu_hotplug.lock. * - A new reader arrives at this moment, bumps up the refcount. * - The writer acquires the cpu_hotplug.lock finds the refcount * non zero and goes to sleep again. * * However, this is very difficult to achieve in practice since |
86ef5c9a8 cpu-hotplug: repl... |
159 |
* get_online_cpus() not an api which is called all that often. |
d221938c0 cpu-hotplug: refc... |
160 161 |
* */ |
b9d10be7a ACPI / processor:... |
162 |
void cpu_hotplug_begin(void) |
d221938c0 cpu-hotplug: refc... |
163 |
{ |
d221938c0 cpu-hotplug: refc... |
164 |
cpu_hotplug.active_writer = current; |
d2ba7e2ae simplify cpu_hotp... |
165 |
|
a19423b98 CPU hotplug: Add ... |
166 |
cpuhp_lock_acquire(); |
d2ba7e2ae simplify cpu_hotp... |
167 168 |
for (;;) { mutex_lock(&cpu_hotplug.lock); |
62db99f47 cpu: Avoid puts_p... |
169 |
apply_puts_pending(1); |
d2ba7e2ae simplify cpu_hotp... |
170 171 172 |
if (likely(!cpu_hotplug.refcount)) break; __set_current_state(TASK_UNINTERRUPTIBLE); |
d221938c0 cpu-hotplug: refc... |
173 174 |
mutex_unlock(&cpu_hotplug.lock); schedule(); |
d221938c0 cpu-hotplug: refc... |
175 |
} |
d221938c0 cpu-hotplug: refc... |
176 |
} |
b9d10be7a ACPI / processor:... |
177 |
void cpu_hotplug_done(void) |
d221938c0 cpu-hotplug: refc... |
178 179 180 |
{ cpu_hotplug.active_writer = NULL; mutex_unlock(&cpu_hotplug.lock); |
a19423b98 CPU hotplug: Add ... |
181 |
cpuhp_lock_release(); |
d221938c0 cpu-hotplug: refc... |
182 |
} |
79a6cdeb7 cpuhotplug: do no... |
183 |
|
16e53dbf1 CPU hotplug: prov... |
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
/* * Wait for currently running CPU hotplug operations to complete (if any) and * disable future CPU hotplug (from sysfs). The 'cpu_add_remove_lock' protects * the 'cpu_hotplug_disabled' flag. The same lock is also acquired by the * hotplug path before performing hotplug operations. So acquiring that lock * guarantees mutual exclusion from any currently running hotplug operations. */ void cpu_hotplug_disable(void) { cpu_maps_update_begin(); cpu_hotplug_disabled = 1; cpu_maps_update_done(); } void cpu_hotplug_enable(void) { cpu_maps_update_begin(); cpu_hotplug_disabled = 0; cpu_maps_update_done(); } |
b9d10be7a ACPI / processor:... |
204 |
#endif /* CONFIG_HOTPLUG_CPU */ |
79a6cdeb7 cpuhotplug: do no... |
205 |
|
1da177e4c Linux-2.6.12-rc2 |
206 |
/* Need to know about CPUs going up/down? */ |
f7b16c108 cpu: fix section ... |
207 |
int __ref register_cpu_notifier(struct notifier_block *nb) |
1da177e4c Linux-2.6.12-rc2 |
208 |
{ |
bd5349cfd [PATCH] Convert c... |
209 |
int ret; |
d221938c0 cpu-hotplug: refc... |
210 |
cpu_maps_update_begin(); |
bd5349cfd [PATCH] Convert c... |
211 |
ret = raw_notifier_chain_register(&cpu_chain, nb); |
d221938c0 cpu-hotplug: refc... |
212 |
cpu_maps_update_done(); |
bd5349cfd [PATCH] Convert c... |
213 |
return ret; |
1da177e4c Linux-2.6.12-rc2 |
214 |
} |
65edc68c3 [PATCH] cpu hotpl... |
215 |
|
93ae4f978 CPU hotplug: Prov... |
216 217 218 219 |
int __ref __register_cpu_notifier(struct notifier_block *nb) { return raw_notifier_chain_register(&cpu_chain, nb); } |
e9fb7631e cpu-hotplug: intr... |
220 221 222 |
static int __cpu_notify(unsigned long val, void *v, int nr_to_call, int *nr_calls) { |
e6bde73b0 cpu-hotplug: retu... |
223 224 225 |
int ret; ret = __raw_notifier_call_chain(&cpu_chain, val, v, nr_to_call, |
e9fb7631e cpu-hotplug: intr... |
226 |
nr_calls); |
e6bde73b0 cpu-hotplug: retu... |
227 228 |
return notifier_to_errno(ret); |
e9fb7631e cpu-hotplug: intr... |
229 230 231 232 233 234 |
} static int cpu_notify(unsigned long val, void *v) { return __cpu_notify(val, v, -1, NULL); } |
00b9b0af5 Avoid warning whe... |
235 |
#ifdef CONFIG_HOTPLUG_CPU |
e9fb7631e cpu-hotplug: intr... |
236 237 |
static void cpu_notify_nofail(unsigned long val, void *v) { |
00b9b0af5 Avoid warning whe... |
238 |
BUG_ON(cpu_notify(val, v)); |
e9fb7631e cpu-hotplug: intr... |
239 |
} |
1da177e4c Linux-2.6.12-rc2 |
240 |
EXPORT_SYMBOL(register_cpu_notifier); |
93ae4f978 CPU hotplug: Prov... |
241 |
EXPORT_SYMBOL(__register_cpu_notifier); |
1da177e4c Linux-2.6.12-rc2 |
242 |
|
9647155ff cpu: fix section ... |
243 |
void __ref unregister_cpu_notifier(struct notifier_block *nb) |
1da177e4c Linux-2.6.12-rc2 |
244 |
{ |
d221938c0 cpu-hotplug: refc... |
245 |
cpu_maps_update_begin(); |
bd5349cfd [PATCH] Convert c... |
246 |
raw_notifier_chain_unregister(&cpu_chain, nb); |
d221938c0 cpu-hotplug: refc... |
247 |
cpu_maps_update_done(); |
1da177e4c Linux-2.6.12-rc2 |
248 249 |
} EXPORT_SYMBOL(unregister_cpu_notifier); |
93ae4f978 CPU hotplug: Prov... |
250 251 252 253 254 |
void __ref __unregister_cpu_notifier(struct notifier_block *nb) { raw_notifier_chain_unregister(&cpu_chain, nb); } EXPORT_SYMBOL(__unregister_cpu_notifier); |
e4cc2f873 kernel/cpu.c: doc... |
255 256 257 258 259 260 261 262 263 264 265 266 |
/** * clear_tasks_mm_cpumask - Safely clear tasks' mm_cpumask for a CPU * @cpu: a CPU id * * This function walks all processes, finds a valid mm struct for each one and * then clears a corresponding bit in mm's cpumask. While this all sounds * trivial, there are various non-obvious corner cases, which this function * tries to solve in a safe manner. * * Also note that the function uses a somewhat relaxed locking scheme, so it may * be called only for an already offlined CPU. */ |
cb79295e2 cpu: introduce cl... |
267 268 269 270 271 272 273 274 275 276 277 |
void clear_tasks_mm_cpumask(int cpu) { struct task_struct *p; /* * This function is called after the cpu is taken down and marked * offline, so its not like new tasks will ever get this cpu set in * their mm mask. -- Peter Zijlstra * Thus, we may use rcu_read_lock() here, instead of grabbing * full-fledged tasklist_lock. */ |
e4cc2f873 kernel/cpu.c: doc... |
278 |
WARN_ON(cpu_online(cpu)); |
cb79295e2 cpu: introduce cl... |
279 280 281 |
rcu_read_lock(); for_each_process(p) { struct task_struct *t; |
e4cc2f873 kernel/cpu.c: doc... |
282 283 284 285 |
/* * Main thread might exit, but other threads may still have * a valid mm. Find one. */ |
cb79295e2 cpu: introduce cl... |
286 287 288 289 290 291 292 293 |
t = find_lock_task_mm(p); if (!t) continue; cpumask_clear_cpu(cpu, mm_cpumask(t->mm)); task_unlock(t); } rcu_read_unlock(); } |
b728ca060 sched: Rework che... |
294 |
static inline void check_for_tasks(int dead_cpu) |
1da177e4c Linux-2.6.12-rc2 |
295 |
{ |
b728ca060 sched: Rework che... |
296 |
struct task_struct *g, *p; |
1da177e4c Linux-2.6.12-rc2 |
297 |
|
b728ca060 sched: Rework che... |
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
read_lock_irq(&tasklist_lock); do_each_thread(g, p) { if (!p->on_rq) continue; /* * We do the check with unlocked task_rq(p)->lock. * Order the reading to do not warn about a task, * which was running on this cpu in the past, and * it's just been woken on another cpu. */ rmb(); if (task_cpu(p) != dead_cpu) continue; pr_warn("Task %s (pid=%d) is on cpu %d (state=%ld, flags=%x) ", p->comm, task_pid_nr(p), dead_cpu, p->state, p->flags); } while_each_thread(g, p); read_unlock_irq(&tasklist_lock); |
1da177e4c Linux-2.6.12-rc2 |
317 |
} |
db912f963 HOTPLUG: Add CPU_... |
318 319 320 321 |
struct take_cpu_down_param { unsigned long mod; void *hcpu; }; |
1da177e4c Linux-2.6.12-rc2 |
322 |
/* Take this CPU down. */ |
514a20a5d cpu: fix section ... |
323 |
static int __ref take_cpu_down(void *_param) |
1da177e4c Linux-2.6.12-rc2 |
324 |
{ |
db912f963 HOTPLUG: Add CPU_... |
325 |
struct take_cpu_down_param *param = _param; |
1da177e4c Linux-2.6.12-rc2 |
326 |
int err; |
1da177e4c Linux-2.6.12-rc2 |
327 328 329 |
/* Ensure this CPU doesn't handle any more interrupts. */ err = __cpu_disable(); if (err < 0) |
f37051364 [PATCH] i386 CPU ... |
330 |
return err; |
1da177e4c Linux-2.6.12-rc2 |
331 |
|
e9fb7631e cpu-hotplug: intr... |
332 |
cpu_notify(CPU_DYING | param->mod, param->hcpu); |
14e568e78 stop_machine: Use... |
333 334 |
/* Park the stopper thread */ kthread_park(current); |
f37051364 [PATCH] i386 CPU ... |
335 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
336 |
} |
e3920fb42 [PATCH] Disable C... |
337 |
/* Requires cpu_add_remove_lock to be held */ |
514a20a5d cpu: fix section ... |
338 |
static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) |
1da177e4c Linux-2.6.12-rc2 |
339 |
{ |
e7407dcc6 call cpu_chain wi... |
340 |
int err, nr_calls = 0; |
e7407dcc6 call cpu_chain wi... |
341 |
void *hcpu = (void *)(long)cpu; |
8bb784428 Add suspend-relat... |
342 |
unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0; |
db912f963 HOTPLUG: Add CPU_... |
343 344 345 346 |
struct take_cpu_down_param tcd_param = { .mod = mod, .hcpu = hcpu, }; |
1da177e4c Linux-2.6.12-rc2 |
347 |
|
e3920fb42 [PATCH] Disable C... |
348 349 |
if (num_online_cpus() == 1) return -EBUSY; |
1da177e4c Linux-2.6.12-rc2 |
350 |
|
e3920fb42 [PATCH] Disable C... |
351 352 |
if (!cpu_online(cpu)) return -EINVAL; |
1da177e4c Linux-2.6.12-rc2 |
353 |
|
d221938c0 cpu-hotplug: refc... |
354 |
cpu_hotplug_begin(); |
4d51985e4 kernel/cpu.c: fix... |
355 |
|
e9fb7631e cpu-hotplug: intr... |
356 |
err = __cpu_notify(CPU_DOWN_PREPARE | mod, hcpu, -1, &nr_calls); |
e6bde73b0 cpu-hotplug: retu... |
357 |
if (err) { |
a0d8cdb65 cpu hotplug: cpu:... |
358 |
nr_calls--; |
e9fb7631e cpu-hotplug: intr... |
359 |
__cpu_notify(CPU_DOWN_FAILED | mod, hcpu, nr_calls, NULL); |
84117da5b kernel/cpu.c: con... |
360 361 362 |
pr_warn("%s: attempt to take down CPU %u failed ", __func__, cpu); |
baaca49f4 Define and use ne... |
363 |
goto out_release; |
1da177e4c Linux-2.6.12-rc2 |
364 |
} |
6acce3ef8 sched: Remove get... |
365 366 367 368 369 370 371 |
/* * By now we've cleared cpu_active_mask, wait for all preempt-disabled * and RCU users of this state to go away such that all new such users * will observe it. * * For CONFIG_PREEMPT we have preemptible RCU and its sync_rcu() might * not imply sync_sched(), so explicitly call both. |
106dd5afd sched: Fix endles... |
372 373 |
* * Do sync before park smpboot threads to take care the rcu boost case. |
6acce3ef8 sched: Remove get... |
374 375 376 377 378 |
*/ #ifdef CONFIG_PREEMPT synchronize_sched(); #endif synchronize_rcu(); |
106dd5afd sched: Fix endles... |
379 |
smpboot_park_threads(cpu); |
6acce3ef8 sched: Remove get... |
380 381 382 |
/* * So now all preempt/rcu users must observe !cpu_active(). */ |
e0b582ec5 cpumask: convert ... |
383 |
err = __stop_machine(take_cpu_down, &tcd_param, cpumask_of(cpu)); |
043215875 Hotplug CPU: don'... |
384 |
if (err) { |
1da177e4c Linux-2.6.12-rc2 |
385 |
/* CPU didn't die: tell everyone. Can't complain. */ |
f97f8f06a smpboot: Provide ... |
386 |
smpboot_unpark_threads(cpu); |
e9fb7631e cpu-hotplug: intr... |
387 |
cpu_notify_nofail(CPU_DOWN_FAILED | mod, hcpu); |
6a1bdc1b5 sched: _cpu_down(... |
388 |
goto out_release; |
8fa1d7d3b [PATCH] cpu-hotpl... |
389 |
} |
043215875 Hotplug CPU: don'... |
390 |
BUG_ON(cpu_online(cpu)); |
1da177e4c Linux-2.6.12-rc2 |
391 |
|
48c5ccae8 sched: Simplify c... |
392 393 394 395 |
/* * The migration_call() CPU_DYING callback will have removed all * runnable tasks from the cpu, there's only the idle task left now * that the migration thread is done doing the stop_machine thing. |
51a96c778 cpu: Remove incor... |
396 397 |
* * Wait for the stop thread to go away. |
48c5ccae8 sched: Simplify c... |
398 |
*/ |
51a96c778 cpu: Remove incor... |
399 400 |
while (!idle_cpu(cpu)) cpu_relax(); |
1da177e4c Linux-2.6.12-rc2 |
401 402 403 |
/* This actually kills the CPU. */ __cpu_die(cpu); |
1da177e4c Linux-2.6.12-rc2 |
404 |
/* CPU is completely dead: tell everyone. Too late to complain. */ |
e9fb7631e cpu-hotplug: intr... |
405 |
cpu_notify_nofail(CPU_DEAD | mod, hcpu); |
1da177e4c Linux-2.6.12-rc2 |
406 407 |
check_for_tasks(cpu); |
baaca49f4 Define and use ne... |
408 |
out_release: |
d221938c0 cpu-hotplug: refc... |
409 |
cpu_hotplug_done(); |
e9fb7631e cpu-hotplug: intr... |
410 411 |
if (!err) cpu_notify_nofail(CPU_POST_DEAD | mod, hcpu); |
e3920fb42 [PATCH] Disable C... |
412 413 |
return err; } |
514a20a5d cpu: fix section ... |
414 |
int __ref cpu_down(unsigned int cpu) |
e3920fb42 [PATCH] Disable C... |
415 |
{ |
9ea09af3b stop_machine: int... |
416 |
int err; |
e3920fb42 [PATCH] Disable C... |
417 |
|
d221938c0 cpu-hotplug: refc... |
418 |
cpu_maps_update_begin(); |
e761b7725 cpu hotplug, sche... |
419 420 |
if (cpu_hotplug_disabled) { |
e3920fb42 [PATCH] Disable C... |
421 |
err = -EBUSY; |
e761b7725 cpu hotplug, sche... |
422 423 |
goto out; } |
e761b7725 cpu hotplug, sche... |
424 |
err = _cpu_down(cpu, 0); |
e3920fb42 [PATCH] Disable C... |
425 |
|
e761b7725 cpu hotplug, sche... |
426 |
out: |
d221938c0 cpu-hotplug: refc... |
427 |
cpu_maps_update_done(); |
1da177e4c Linux-2.6.12-rc2 |
428 429 |
return err; } |
b62b8ef90 force offline the... |
430 |
EXPORT_SYMBOL(cpu_down); |
1da177e4c Linux-2.6.12-rc2 |
431 |
#endif /*CONFIG_HOTPLUG_CPU*/ |
e3920fb42 [PATCH] Disable C... |
432 |
/* Requires cpu_add_remove_lock to be held */ |
0db0628d9 kernel: delete __... |
433 |
static int _cpu_up(unsigned int cpu, int tasks_frozen) |
1da177e4c Linux-2.6.12-rc2 |
434 |
{ |
baaca49f4 Define and use ne... |
435 |
int ret, nr_calls = 0; |
1da177e4c Linux-2.6.12-rc2 |
436 |
void *hcpu = (void *)(long)cpu; |
8bb784428 Add suspend-relat... |
437 |
unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0; |
3bb5d2ee3 smp, idle: Alloca... |
438 |
struct task_struct *idle; |
1da177e4c Linux-2.6.12-rc2 |
439 |
|
d221938c0 cpu-hotplug: refc... |
440 |
cpu_hotplug_begin(); |
38498a67a smp: Add generic ... |
441 |
|
5e5041f35 ACPI / processor:... |
442 443 444 445 |
if (cpu_online(cpu) || !cpu_present(cpu)) { ret = -EINVAL; goto out; } |
3bb5d2ee3 smp, idle: Alloca... |
446 447 448 |
idle = idle_thread_get(cpu); if (IS_ERR(idle)) { ret = PTR_ERR(idle); |
38498a67a smp: Add generic ... |
449 |
goto out; |
3bb5d2ee3 smp, idle: Alloca... |
450 |
} |
38498a67a smp: Add generic ... |
451 |
|
f97f8f06a smpboot: Provide ... |
452 453 454 |
ret = smpboot_create_threads(cpu); if (ret) goto out; |
e9fb7631e cpu-hotplug: intr... |
455 |
ret = __cpu_notify(CPU_UP_PREPARE | mod, hcpu, -1, &nr_calls); |
e6bde73b0 cpu-hotplug: retu... |
456 |
if (ret) { |
a0d8cdb65 cpu hotplug: cpu:... |
457 |
nr_calls--; |
84117da5b kernel/cpu.c: con... |
458 459 460 |
pr_warn("%s: attempt to bring up CPU %u failed ", __func__, cpu); |
1da177e4c Linux-2.6.12-rc2 |
461 462 463 464 |
goto out_notify; } /* Arch-specific enabling code. */ |
3bb5d2ee3 smp, idle: Alloca... |
465 |
ret = __cpu_up(cpu, idle); |
1da177e4c Linux-2.6.12-rc2 |
466 467 |
if (ret != 0) goto out_notify; |
6978c7052 BUG_ON() Conversi... |
468 |
BUG_ON(!cpu_online(cpu)); |
1da177e4c Linux-2.6.12-rc2 |
469 |
|
f97f8f06a smpboot: Provide ... |
470 471 |
/* Wake the per cpu threads */ smpboot_unpark_threads(cpu); |
1da177e4c Linux-2.6.12-rc2 |
472 |
/* Now call notifier in preparation. */ |
e9fb7631e cpu-hotplug: intr... |
473 |
cpu_notify(CPU_ONLINE | mod, hcpu); |
1da177e4c Linux-2.6.12-rc2 |
474 475 476 |
out_notify: if (ret != 0) |
e9fb7631e cpu-hotplug: intr... |
477 |
__cpu_notify(CPU_UP_CANCELED | mod, hcpu, nr_calls, NULL); |
38498a67a smp: Add generic ... |
478 |
out: |
d221938c0 cpu-hotplug: refc... |
479 |
cpu_hotplug_done(); |
e3920fb42 [PATCH] Disable C... |
480 481 482 |
return ret; } |
0db0628d9 kernel: delete __... |
483 |
int cpu_up(unsigned int cpu) |
e3920fb42 [PATCH] Disable C... |
484 485 |
{ int err = 0; |
cf23422b9 cpu/mem hotplug: ... |
486 |
|
e0b582ec5 cpumask: convert ... |
487 |
if (!cpu_possible(cpu)) { |
84117da5b kernel/cpu.c: con... |
488 489 490 |
pr_err("can't online cpu %d because it is not configured as may-hotadd at boot time ", cpu); |
87d5e0236 kernel/cpu.c: del... |
491 |
#if defined(CONFIG_IA64) |
84117da5b kernel/cpu.c: con... |
492 493 |
pr_err("please check additional_cpus= boot parameter "); |
73e753a50 CPU HOTPLUG: avoi... |
494 495 496 |
#endif return -EINVAL; } |
e3920fb42 [PATCH] Disable C... |
497 |
|
01b0f1970 cpu/mem hotplug: ... |
498 499 500 |
err = try_online_node(cpu_to_node(cpu)); if (err) return err; |
cf23422b9 cpu/mem hotplug: ... |
501 |
|
d221938c0 cpu-hotplug: refc... |
502 |
cpu_maps_update_begin(); |
e761b7725 cpu hotplug, sche... |
503 504 |
if (cpu_hotplug_disabled) { |
e3920fb42 [PATCH] Disable C... |
505 |
err = -EBUSY; |
e761b7725 cpu hotplug, sche... |
506 507 508 509 |
goto out; } err = _cpu_up(cpu, 0); |
e761b7725 cpu hotplug, sche... |
510 |
out: |
d221938c0 cpu-hotplug: refc... |
511 |
cpu_maps_update_done(); |
e3920fb42 [PATCH] Disable C... |
512 513 |
return err; } |
a513f6bab cpu: Export cpu_up() |
514 |
EXPORT_SYMBOL_GPL(cpu_up); |
e3920fb42 [PATCH] Disable C... |
515 |
|
f3de4be9d PM: Fix dependenc... |
516 |
#ifdef CONFIG_PM_SLEEP_SMP |
e0b582ec5 cpumask: convert ... |
517 |
static cpumask_var_t frozen_cpus; |
e3920fb42 [PATCH] Disable C... |
518 519 520 |
int disable_nonboot_cpus(void) { |
e9a5f426b CPU: Avoid using ... |
521 |
int cpu, first_cpu, error = 0; |
e3920fb42 [PATCH] Disable C... |
522 |
|
d221938c0 cpu-hotplug: refc... |
523 |
cpu_maps_update_begin(); |
e0b582ec5 cpumask: convert ... |
524 |
first_cpu = cpumask_first(cpu_online_mask); |
9ee349ad6 sched: Fix set_cp... |
525 526 |
/* * We take down all of the non-boot CPUs in one shot to avoid races |
e3920fb42 [PATCH] Disable C... |
527 528 |
* with the userspace trying to use the CPU hotplug at the same time */ |
e0b582ec5 cpumask: convert ... |
529 |
cpumask_clear(frozen_cpus); |
6ad4c1888 sched: Fix balanc... |
530 |
|
84117da5b kernel/cpu.c: con... |
531 532 |
pr_info("Disabling non-boot CPUs ... "); |
e3920fb42 [PATCH] Disable C... |
533 534 535 |
for_each_online_cpu(cpu) { if (cpu == first_cpu) continue; |
bb3632c61 PM / sleep: trace... |
536 |
trace_suspend_resume(TPS("CPU_OFF"), cpu, true); |
8bb784428 Add suspend-relat... |
537 |
error = _cpu_down(cpu, 1); |
bb3632c61 PM / sleep: trace... |
538 |
trace_suspend_resume(TPS("CPU_OFF"), cpu, false); |
feae3203d timers, init: Lim... |
539 |
if (!error) |
e0b582ec5 cpumask: convert ... |
540 |
cpumask_set_cpu(cpu, frozen_cpus); |
feae3203d timers, init: Lim... |
541 |
else { |
84117da5b kernel/cpu.c: con... |
542 543 |
pr_err("Error taking CPU%d down: %d ", cpu, error); |
e3920fb42 [PATCH] Disable C... |
544 545 546 |
break; } } |
86886e55b x86, intel_txt: I... |
547 |
|
e3920fb42 [PATCH] Disable C... |
548 549 550 551 552 |
if (!error) { BUG_ON(num_online_cpus() > 1); /* Make sure the CPUs won't be enabled by someone else */ cpu_hotplug_disabled = 1; } else { |
84117da5b kernel/cpu.c: con... |
553 554 |
pr_err("Non-boot CPUs are not disabled "); |
e3920fb42 [PATCH] Disable C... |
555 |
} |
d221938c0 cpu-hotplug: refc... |
556 |
cpu_maps_update_done(); |
e3920fb42 [PATCH] Disable C... |
557 558 |
return error; } |
d0af9eed5 x86, pat/mtrr: Re... |
559 560 561 562 563 564 565 |
void __weak arch_enable_nonboot_cpus_begin(void) { } void __weak arch_enable_nonboot_cpus_end(void) { } |
fa7303e22 cpu: fix section ... |
566 |
void __ref enable_nonboot_cpus(void) |
e3920fb42 [PATCH] Disable C... |
567 568 569 570 |
{ int cpu, error; /* Allow everyone to use the CPU hotplug again */ |
d221938c0 cpu-hotplug: refc... |
571 |
cpu_maps_update_begin(); |
e3920fb42 [PATCH] Disable C... |
572 |
cpu_hotplug_disabled = 0; |
e0b582ec5 cpumask: convert ... |
573 |
if (cpumask_empty(frozen_cpus)) |
1d64b9cb1 [PATCH] Fix micro... |
574 |
goto out; |
e3920fb42 [PATCH] Disable C... |
575 |
|
84117da5b kernel/cpu.c: con... |
576 577 |
pr_info("Enabling non-boot CPUs ... "); |
d0af9eed5 x86, pat/mtrr: Re... |
578 579 |
arch_enable_nonboot_cpus_begin(); |
e0b582ec5 cpumask: convert ... |
580 |
for_each_cpu(cpu, frozen_cpus) { |
bb3632c61 PM / sleep: trace... |
581 |
trace_suspend_resume(TPS("CPU_ON"), cpu, true); |
8bb784428 Add suspend-relat... |
582 |
error = _cpu_up(cpu, 1); |
bb3632c61 PM / sleep: trace... |
583 |
trace_suspend_resume(TPS("CPU_ON"), cpu, false); |
e3920fb42 [PATCH] Disable C... |
584 |
if (!error) { |
84117da5b kernel/cpu.c: con... |
585 586 |
pr_info("CPU%d is up ", cpu); |
e3920fb42 [PATCH] Disable C... |
587 588 |
continue; } |
84117da5b kernel/cpu.c: con... |
589 590 |
pr_warn("Error taking CPU%d up: %d ", cpu, error); |
e3920fb42 [PATCH] Disable C... |
591 |
} |
d0af9eed5 x86, pat/mtrr: Re... |
592 593 |
arch_enable_nonboot_cpus_end(); |
e0b582ec5 cpumask: convert ... |
594 |
cpumask_clear(frozen_cpus); |
1d64b9cb1 [PATCH] Fix micro... |
595 |
out: |
d221938c0 cpu-hotplug: refc... |
596 |
cpu_maps_update_done(); |
1da177e4c Linux-2.6.12-rc2 |
597 |
} |
e0b582ec5 cpumask: convert ... |
598 |
|
d7268a31c CPU: Add right qu... |
599 |
static int __init alloc_frozen_cpus(void) |
e0b582ec5 cpumask: convert ... |
600 601 602 603 604 605 |
{ if (!alloc_cpumask_var(&frozen_cpus, GFP_KERNEL|__GFP_ZERO)) return -ENOMEM; return 0; } core_initcall(alloc_frozen_cpus); |
79cfbdfa8 PM / Sleep: Fix r... |
606 607 |
/* |
79cfbdfa8 PM / Sleep: Fix r... |
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 |
* When callbacks for CPU hotplug notifications are being executed, we must * ensure that the state of the system with respect to the tasks being frozen * or not, as reported by the notification, remains unchanged *throughout the * duration* of the execution of the callbacks. * Hence we need to prevent the freezer from racing with regular CPU hotplug. * * This synchronization is implemented by mutually excluding regular CPU * hotplug and Suspend/Hibernate call paths by hooking onto the Suspend/ * Hibernate notifications. */ static int cpu_hotplug_pm_callback(struct notifier_block *nb, unsigned long action, void *ptr) { switch (action) { case PM_SUSPEND_PREPARE: case PM_HIBERNATION_PREPARE: |
16e53dbf1 CPU hotplug: prov... |
626 |
cpu_hotplug_disable(); |
79cfbdfa8 PM / Sleep: Fix r... |
627 628 629 630 |
break; case PM_POST_SUSPEND: case PM_POST_HIBERNATION: |
16e53dbf1 CPU hotplug: prov... |
631 |
cpu_hotplug_enable(); |
79cfbdfa8 PM / Sleep: Fix r... |
632 633 634 635 636 637 638 639 |
break; default: return NOTIFY_DONE; } return NOTIFY_OK; } |
d7268a31c CPU: Add right qu... |
640 |
static int __init cpu_hotplug_pm_sync_init(void) |
79cfbdfa8 PM / Sleep: Fix r... |
641 |
{ |
6e32d479d kernel/cpu.c: Add... |
642 643 644 645 646 |
/* * cpu_hotplug_pm_callback has higher priority than x86 * bsp_pm_callback which depends on cpu_hotplug_pm_callback * to disable cpu hotplug to avoid cpu hotplug race. */ |
79cfbdfa8 PM / Sleep: Fix r... |
647 648 649 650 |
pm_notifier(cpu_hotplug_pm_callback, 0); return 0; } core_initcall(cpu_hotplug_pm_sync_init); |
f3de4be9d PM: Fix dependenc... |
651 |
#endif /* CONFIG_PM_SLEEP_SMP */ |
68f4f1ec0 sched: Move cpu m... |
652 |
|
e545a6140 kernel/cpu.c: cre... |
653 654 655 656 657 658 659 660 |
/** * notify_cpu_starting(cpu) - call the CPU_STARTING notifiers * @cpu: cpu that just started * * This function calls the cpu_chain notifiers with CPU_STARTING. * It must be called by the arch code on the new cpu, before the new cpu * enables interrupts and before the "boot" cpu returns from __cpu_up(). */ |
0db0628d9 kernel: delete __... |
661 |
void notify_cpu_starting(unsigned int cpu) |
e545a6140 kernel/cpu.c: cre... |
662 663 664 665 |
{ unsigned long val = CPU_STARTING; #ifdef CONFIG_PM_SLEEP_SMP |
e0b582ec5 cpumask: convert ... |
666 |
if (frozen_cpus != NULL && cpumask_test_cpu(cpu, frozen_cpus)) |
e545a6140 kernel/cpu.c: cre... |
667 668 |
val = CPU_STARTING_FROZEN; #endif /* CONFIG_PM_SLEEP_SMP */ |
e9fb7631e cpu-hotplug: intr... |
669 |
cpu_notify(val, (void *)(long)cpu); |
e545a6140 kernel/cpu.c: cre... |
670 |
} |
68f4f1ec0 sched: Move cpu m... |
671 |
#endif /* CONFIG_SMP */ |
b8d317d10 cpumask: make cpu... |
672 |
|
e56b3bc79 cpu masks: optimi... |
673 674 675 676 |
/* * cpu_bit_bitmap[] is a special, "compressed" data structure that * represents all NR_CPUS bits binary values of 1<<nr. * |
e0b582ec5 cpumask: convert ... |
677 |
* It is used by cpumask_of() to get a constant address to a CPU |
e56b3bc79 cpu masks: optimi... |
678 679 |
* mask value that has a single bit set only. */ |
b8d317d10 cpumask: make cpu... |
680 |
|
e56b3bc79 cpu masks: optimi... |
681 |
/* cpu_bit_bitmap[0] is empty - so we can back into it */ |
4d51985e4 kernel/cpu.c: fix... |
682 |
#define MASK_DECLARE_1(x) [x+1][0] = (1UL << (x)) |
e56b3bc79 cpu masks: optimi... |
683 684 685 |
#define MASK_DECLARE_2(x) MASK_DECLARE_1(x), MASK_DECLARE_1(x+1) #define MASK_DECLARE_4(x) MASK_DECLARE_2(x), MASK_DECLARE_2(x+2) #define MASK_DECLARE_8(x) MASK_DECLARE_4(x), MASK_DECLARE_4(x+4) |
b8d317d10 cpumask: make cpu... |
686 |
|
e56b3bc79 cpu masks: optimi... |
687 688 689 690 691 692 693 |
const unsigned long cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)] = { MASK_DECLARE_8(0), MASK_DECLARE_8(8), MASK_DECLARE_8(16), MASK_DECLARE_8(24), #if BITS_PER_LONG > 32 MASK_DECLARE_8(32), MASK_DECLARE_8(40), MASK_DECLARE_8(48), MASK_DECLARE_8(56), |
b8d317d10 cpumask: make cpu... |
694 695 |
#endif }; |
e56b3bc79 cpu masks: optimi... |
696 |
EXPORT_SYMBOL_GPL(cpu_bit_bitmap); |
2d3854a37 cpumask: introduc... |
697 698 699 |
const DECLARE_BITMAP(cpu_all_bits, NR_CPUS) = CPU_BITS_ALL; EXPORT_SYMBOL(cpu_all_bits); |
b3199c025 cpumask: switch o... |
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 |
#ifdef CONFIG_INIT_ALL_POSSIBLE static DECLARE_BITMAP(cpu_possible_bits, CONFIG_NR_CPUS) __read_mostly = CPU_BITS_ALL; #else static DECLARE_BITMAP(cpu_possible_bits, CONFIG_NR_CPUS) __read_mostly; #endif const struct cpumask *const cpu_possible_mask = to_cpumask(cpu_possible_bits); EXPORT_SYMBOL(cpu_possible_mask); static DECLARE_BITMAP(cpu_online_bits, CONFIG_NR_CPUS) __read_mostly; const struct cpumask *const cpu_online_mask = to_cpumask(cpu_online_bits); EXPORT_SYMBOL(cpu_online_mask); static DECLARE_BITMAP(cpu_present_bits, CONFIG_NR_CPUS) __read_mostly; const struct cpumask *const cpu_present_mask = to_cpumask(cpu_present_bits); EXPORT_SYMBOL(cpu_present_mask); static DECLARE_BITMAP(cpu_active_bits, CONFIG_NR_CPUS) __read_mostly; const struct cpumask *const cpu_active_mask = to_cpumask(cpu_active_bits); EXPORT_SYMBOL(cpu_active_mask); |
3fa415206 cpumask: make set... |
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 |
void set_cpu_possible(unsigned int cpu, bool possible) { if (possible) cpumask_set_cpu(cpu, to_cpumask(cpu_possible_bits)); else cpumask_clear_cpu(cpu, to_cpumask(cpu_possible_bits)); } void set_cpu_present(unsigned int cpu, bool present) { if (present) cpumask_set_cpu(cpu, to_cpumask(cpu_present_bits)); else cpumask_clear_cpu(cpu, to_cpumask(cpu_present_bits)); } void set_cpu_online(unsigned int cpu, bool online) { |
6acbfb969 sched: Fix hotplu... |
740 |
if (online) { |
3fa415206 cpumask: make set... |
741 |
cpumask_set_cpu(cpu, to_cpumask(cpu_online_bits)); |
6acbfb969 sched: Fix hotplu... |
742 743 |
cpumask_set_cpu(cpu, to_cpumask(cpu_active_bits)); } else { |
3fa415206 cpumask: make set... |
744 |
cpumask_clear_cpu(cpu, to_cpumask(cpu_online_bits)); |
6acbfb969 sched: Fix hotplu... |
745 |
} |
3fa415206 cpumask: make set... |
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 |
} void set_cpu_active(unsigned int cpu, bool active) { if (active) cpumask_set_cpu(cpu, to_cpumask(cpu_active_bits)); else cpumask_clear_cpu(cpu, to_cpumask(cpu_active_bits)); } void init_cpu_present(const struct cpumask *src) { cpumask_copy(to_cpumask(cpu_present_bits), src); } void init_cpu_possible(const struct cpumask *src) { cpumask_copy(to_cpumask(cpu_possible_bits), src); } void init_cpu_online(const struct cpumask *src) { cpumask_copy(to_cpumask(cpu_online_bits), src); } |