diff options
Diffstat (limited to 'kernel/cpu.c')
-rw-r--r-- | kernel/cpu.c | 145 |
1 files changed, 100 insertions, 45 deletions
diff --git a/kernel/cpu.c b/kernel/cpu.c index 8ea32e8d68b0..47fff3b63cbf 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c | |||
@@ -15,29 +15,8 @@ | |||
15 | #include <linux/stop_machine.h> | 15 | #include <linux/stop_machine.h> |
16 | #include <linux/mutex.h> | 16 | #include <linux/mutex.h> |
17 | 17 | ||
18 | /* | 18 | #ifdef CONFIG_SMP |
19 | * Represents all cpu's present in the system | 19 | /* Serializes the updates to cpu_online_mask, cpu_present_mask */ |
20 | * In systems capable of hotplug, this map could dynamically grow | ||
21 | * as new cpu's are detected in the system via any platform specific | ||
22 | * method, such as ACPI for e.g. | ||
23 | */ | ||
24 | cpumask_t cpu_present_map __read_mostly; | ||
25 | EXPORT_SYMBOL(cpu_present_map); | ||
26 | |||
27 | #ifndef CONFIG_SMP | ||
28 | |||
29 | /* | ||
30 | * Represents all cpu's that are currently online. | ||
31 | */ | ||
32 | cpumask_t cpu_online_map __read_mostly = CPU_MASK_ALL; | ||
33 | EXPORT_SYMBOL(cpu_online_map); | ||
34 | |||
35 | cpumask_t cpu_possible_map __read_mostly = CPU_MASK_ALL; | ||
36 | EXPORT_SYMBOL(cpu_possible_map); | ||
37 | |||
38 | #else /* CONFIG_SMP */ | ||
39 | |||
40 | /* Serializes the updates to cpu_online_map, cpu_present_map */ | ||
41 | static DEFINE_MUTEX(cpu_add_remove_lock); | 20 | static DEFINE_MUTEX(cpu_add_remove_lock); |
42 | 21 | ||
43 | static __cpuinitdata RAW_NOTIFIER_HEAD(cpu_chain); | 22 | static __cpuinitdata RAW_NOTIFIER_HEAD(cpu_chain); |
@@ -64,8 +43,6 @@ void __init cpu_hotplug_init(void) | |||
64 | cpu_hotplug.refcount = 0; | 43 | cpu_hotplug.refcount = 0; |
65 | } | 44 | } |
66 | 45 | ||
67 | cpumask_t cpu_active_map; | ||
68 | |||
69 | #ifdef CONFIG_HOTPLUG_CPU | 46 | #ifdef CONFIG_HOTPLUG_CPU |
70 | 47 | ||
71 | void get_online_cpus(void) | 48 | void get_online_cpus(void) |
@@ -96,7 +73,7 @@ EXPORT_SYMBOL_GPL(put_online_cpus); | |||
96 | 73 | ||
97 | /* | 74 | /* |
98 | * The following two API's must be used when attempting | 75 | * The following two API's must be used when attempting |
99 | * to serialize the updates to cpu_online_map, cpu_present_map. | 76 | * to serialize the updates to cpu_online_mask, cpu_present_mask. |
100 | */ | 77 | */ |
101 | void cpu_maps_update_begin(void) | 78 | void cpu_maps_update_begin(void) |
102 | { | 79 | { |
@@ -217,7 +194,7 @@ static int __ref take_cpu_down(void *_param) | |||
217 | static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) | 194 | static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) |
218 | { | 195 | { |
219 | int err, nr_calls = 0; | 196 | int err, nr_calls = 0; |
220 | cpumask_t old_allowed, tmp; | 197 | cpumask_var_t old_allowed; |
221 | void *hcpu = (void *)(long)cpu; | 198 | void *hcpu = (void *)(long)cpu; |
222 | unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0; | 199 | unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0; |
223 | struct take_cpu_down_param tcd_param = { | 200 | struct take_cpu_down_param tcd_param = { |
@@ -231,6 +208,9 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) | |||
231 | if (!cpu_online(cpu)) | 208 | if (!cpu_online(cpu)) |
232 | return -EINVAL; | 209 | return -EINVAL; |
233 | 210 | ||
211 | if (!alloc_cpumask_var(&old_allowed, GFP_KERNEL)) | ||
212 | return -ENOMEM; | ||
213 | |||
234 | cpu_hotplug_begin(); | 214 | cpu_hotplug_begin(); |
235 | err = __raw_notifier_call_chain(&cpu_chain, CPU_DOWN_PREPARE | mod, | 215 | err = __raw_notifier_call_chain(&cpu_chain, CPU_DOWN_PREPARE | mod, |
236 | hcpu, -1, &nr_calls); | 216 | hcpu, -1, &nr_calls); |
@@ -245,13 +225,11 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) | |||
245 | } | 225 | } |
246 | 226 | ||
247 | /* Ensure that we are not runnable on dying cpu */ | 227 | /* Ensure that we are not runnable on dying cpu */ |
248 | old_allowed = current->cpus_allowed; | 228 | cpumask_copy(old_allowed, ¤t->cpus_allowed); |
249 | cpus_setall(tmp); | 229 | set_cpus_allowed_ptr(current, |
250 | cpu_clear(cpu, tmp); | 230 | cpumask_of(cpumask_any_but(cpu_online_mask, cpu))); |
251 | set_cpus_allowed_ptr(current, &tmp); | ||
252 | tmp = cpumask_of_cpu(cpu); | ||
253 | 231 | ||
254 | err = __stop_machine(take_cpu_down, &tcd_param, &tmp); | 232 | err = __stop_machine(take_cpu_down, &tcd_param, cpumask_of(cpu)); |
255 | if (err) { | 233 | if (err) { |
256 | /* CPU didn't die: tell everyone. Can't complain. */ | 234 | /* CPU didn't die: tell everyone. Can't complain. */ |
257 | if (raw_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED | mod, | 235 | if (raw_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED | mod, |
@@ -277,7 +255,7 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) | |||
277 | check_for_tasks(cpu); | 255 | check_for_tasks(cpu); |
278 | 256 | ||
279 | out_allowed: | 257 | out_allowed: |
280 | set_cpus_allowed_ptr(current, &old_allowed); | 258 | set_cpus_allowed_ptr(current, old_allowed); |
281 | out_release: | 259 | out_release: |
282 | cpu_hotplug_done(); | 260 | cpu_hotplug_done(); |
283 | if (!err) { | 261 | if (!err) { |
@@ -285,6 +263,7 @@ out_release: | |||
285 | hcpu) == NOTIFY_BAD) | 263 | hcpu) == NOTIFY_BAD) |
286 | BUG(); | 264 | BUG(); |
287 | } | 265 | } |
266 | free_cpumask_var(old_allowed); | ||
288 | return err; | 267 | return err; |
289 | } | 268 | } |
290 | 269 | ||
@@ -303,7 +282,7 @@ int __ref cpu_down(unsigned int cpu) | |||
303 | 282 | ||
304 | /* | 283 | /* |
305 | * Make sure the all cpus did the reschedule and are not | 284 | * Make sure the all cpus did the reschedule and are not |
306 | * using stale version of the cpu_active_map. | 285 | * using stale version of the cpu_active_mask. |
307 | * This is not strictly necessary becuase stop_machine() | 286 | * This is not strictly necessary becuase stop_machine() |
308 | * that we run down the line already provides the required | 287 | * that we run down the line already provides the required |
309 | * synchronization. But it's really a side effect and we do not | 288 | * synchronization. But it's really a side effect and we do not |
@@ -367,7 +346,7 @@ out_notify: | |||
367 | int __cpuinit cpu_up(unsigned int cpu) | 346 | int __cpuinit cpu_up(unsigned int cpu) |
368 | { | 347 | { |
369 | int err = 0; | 348 | int err = 0; |
370 | if (!cpu_isset(cpu, cpu_possible_map)) { | 349 | if (!cpu_possible(cpu)) { |
371 | printk(KERN_ERR "can't online cpu %d because it is not " | 350 | printk(KERN_ERR "can't online cpu %d because it is not " |
372 | "configured as may-hotadd at boot time\n", cpu); | 351 | "configured as may-hotadd at boot time\n", cpu); |
373 | #if defined(CONFIG_IA64) || defined(CONFIG_X86_64) | 352 | #if defined(CONFIG_IA64) || defined(CONFIG_X86_64) |
@@ -392,25 +371,25 @@ out: | |||
392 | } | 371 | } |
393 | 372 | ||
394 | #ifdef CONFIG_PM_SLEEP_SMP | 373 | #ifdef CONFIG_PM_SLEEP_SMP |
395 | static cpumask_t frozen_cpus; | 374 | static cpumask_var_t frozen_cpus; |
396 | 375 | ||
397 | int disable_nonboot_cpus(void) | 376 | int disable_nonboot_cpus(void) |
398 | { | 377 | { |
399 | int cpu, first_cpu, error = 0; | 378 | int cpu, first_cpu, error = 0; |
400 | 379 | ||
401 | cpu_maps_update_begin(); | 380 | cpu_maps_update_begin(); |
402 | first_cpu = first_cpu(cpu_online_map); | 381 | first_cpu = cpumask_first(cpu_online_mask); |
403 | /* We take down all of the non-boot CPUs in one shot to avoid races | 382 | /* We take down all of the non-boot CPUs in one shot to avoid races |
404 | * with the userspace trying to use the CPU hotplug at the same time | 383 | * with the userspace trying to use the CPU hotplug at the same time |
405 | */ | 384 | */ |
406 | cpus_clear(frozen_cpus); | 385 | cpumask_clear(frozen_cpus); |
407 | printk("Disabling non-boot CPUs ...\n"); | 386 | printk("Disabling non-boot CPUs ...\n"); |
408 | for_each_online_cpu(cpu) { | 387 | for_each_online_cpu(cpu) { |
409 | if (cpu == first_cpu) | 388 | if (cpu == first_cpu) |
410 | continue; | 389 | continue; |
411 | error = _cpu_down(cpu, 1); | 390 | error = _cpu_down(cpu, 1); |
412 | if (!error) { | 391 | if (!error) { |
413 | cpu_set(cpu, frozen_cpus); | 392 | cpumask_set_cpu(cpu, frozen_cpus); |
414 | printk("CPU%d is down\n", cpu); | 393 | printk("CPU%d is down\n", cpu); |
415 | } else { | 394 | } else { |
416 | printk(KERN_ERR "Error taking CPU%d down: %d\n", | 395 | printk(KERN_ERR "Error taking CPU%d down: %d\n", |
@@ -436,11 +415,11 @@ void __ref enable_nonboot_cpus(void) | |||
436 | /* Allow everyone to use the CPU hotplug again */ | 415 | /* Allow everyone to use the CPU hotplug again */ |
437 | cpu_maps_update_begin(); | 416 | cpu_maps_update_begin(); |
438 | cpu_hotplug_disabled = 0; | 417 | cpu_hotplug_disabled = 0; |
439 | if (cpus_empty(frozen_cpus)) | 418 | if (cpumask_empty(frozen_cpus)) |
440 | goto out; | 419 | goto out; |
441 | 420 | ||
442 | printk("Enabling non-boot CPUs ...\n"); | 421 | printk("Enabling non-boot CPUs ...\n"); |
443 | for_each_cpu_mask_nr(cpu, frozen_cpus) { | 422 | for_each_cpu(cpu, frozen_cpus) { |
444 | error = _cpu_up(cpu, 1); | 423 | error = _cpu_up(cpu, 1); |
445 | if (!error) { | 424 | if (!error) { |
446 | printk("CPU%d is up\n", cpu); | 425 | printk("CPU%d is up\n", cpu); |
@@ -448,10 +427,18 @@ void __ref enable_nonboot_cpus(void) | |||
448 | } | 427 | } |
449 | printk(KERN_WARNING "Error taking CPU%d up: %d\n", cpu, error); | 428 | printk(KERN_WARNING "Error taking CPU%d up: %d\n", cpu, error); |
450 | } | 429 | } |
451 | cpus_clear(frozen_cpus); | 430 | cpumask_clear(frozen_cpus); |
452 | out: | 431 | out: |
453 | cpu_maps_update_done(); | 432 | cpu_maps_update_done(); |
454 | } | 433 | } |
434 | |||
435 | static int alloc_frozen_cpus(void) | ||
436 | { | ||
437 | if (!alloc_cpumask_var(&frozen_cpus, GFP_KERNEL|__GFP_ZERO)) | ||
438 | return -ENOMEM; | ||
439 | return 0; | ||
440 | } | ||
441 | core_initcall(alloc_frozen_cpus); | ||
455 | #endif /* CONFIG_PM_SLEEP_SMP */ | 442 | #endif /* CONFIG_PM_SLEEP_SMP */ |
456 | 443 | ||
457 | /** | 444 | /** |
@@ -467,7 +454,7 @@ void __cpuinit notify_cpu_starting(unsigned int cpu) | |||
467 | unsigned long val = CPU_STARTING; | 454 | unsigned long val = CPU_STARTING; |
468 | 455 | ||
469 | #ifdef CONFIG_PM_SLEEP_SMP | 456 | #ifdef CONFIG_PM_SLEEP_SMP |
470 | if (cpu_isset(cpu, frozen_cpus)) | 457 | if (frozen_cpus != NULL && cpumask_test_cpu(cpu, frozen_cpus)) |
471 | val = CPU_STARTING_FROZEN; | 458 | val = CPU_STARTING_FROZEN; |
472 | #endif /* CONFIG_PM_SLEEP_SMP */ | 459 | #endif /* CONFIG_PM_SLEEP_SMP */ |
473 | raw_notifier_call_chain(&cpu_chain, val, (void *)(long)cpu); | 460 | raw_notifier_call_chain(&cpu_chain, val, (void *)(long)cpu); |
@@ -479,7 +466,7 @@ void __cpuinit notify_cpu_starting(unsigned int cpu) | |||
479 | * cpu_bit_bitmap[] is a special, "compressed" data structure that | 466 | * cpu_bit_bitmap[] is a special, "compressed" data structure that |
480 | * represents all NR_CPUS bits binary values of 1<<nr. | 467 | * represents all NR_CPUS bits binary values of 1<<nr. |
481 | * | 468 | * |
482 | * It is used by cpumask_of_cpu() to get a constant address to a CPU | 469 | * It is used by cpumask_of() to get a constant address to a CPU |
483 | * mask value that has a single bit set only. | 470 | * mask value that has a single bit set only. |
484 | */ | 471 | */ |
485 | 472 | ||
@@ -502,3 +489,71 @@ EXPORT_SYMBOL_GPL(cpu_bit_bitmap); | |||
502 | 489 | ||
503 | const DECLARE_BITMAP(cpu_all_bits, NR_CPUS) = CPU_BITS_ALL; | 490 | const DECLARE_BITMAP(cpu_all_bits, NR_CPUS) = CPU_BITS_ALL; |
504 | EXPORT_SYMBOL(cpu_all_bits); | 491 | EXPORT_SYMBOL(cpu_all_bits); |
492 | |||
493 | #ifdef CONFIG_INIT_ALL_POSSIBLE | ||
494 | static DECLARE_BITMAP(cpu_possible_bits, CONFIG_NR_CPUS) __read_mostly | ||
495 | = CPU_BITS_ALL; | ||
496 | #else | ||
497 | static DECLARE_BITMAP(cpu_possible_bits, CONFIG_NR_CPUS) __read_mostly; | ||
498 | #endif | ||
499 | const struct cpumask *const cpu_possible_mask = to_cpumask(cpu_possible_bits); | ||
500 | EXPORT_SYMBOL(cpu_possible_mask); | ||
501 | |||
502 | static DECLARE_BITMAP(cpu_online_bits, CONFIG_NR_CPUS) __read_mostly; | ||
503 | const struct cpumask *const cpu_online_mask = to_cpumask(cpu_online_bits); | ||
504 | EXPORT_SYMBOL(cpu_online_mask); | ||
505 | |||
506 | static DECLARE_BITMAP(cpu_present_bits, CONFIG_NR_CPUS) __read_mostly; | ||
507 | const struct cpumask *const cpu_present_mask = to_cpumask(cpu_present_bits); | ||
508 | EXPORT_SYMBOL(cpu_present_mask); | ||
509 | |||
510 | static DECLARE_BITMAP(cpu_active_bits, CONFIG_NR_CPUS) __read_mostly; | ||
511 | const struct cpumask *const cpu_active_mask = to_cpumask(cpu_active_bits); | ||
512 | EXPORT_SYMBOL(cpu_active_mask); | ||
513 | |||
514 | void set_cpu_possible(unsigned int cpu, bool possible) | ||
515 | { | ||
516 | if (possible) | ||
517 | cpumask_set_cpu(cpu, to_cpumask(cpu_possible_bits)); | ||
518 | else | ||
519 | cpumask_clear_cpu(cpu, to_cpumask(cpu_possible_bits)); | ||
520 | } | ||
521 | |||
522 | void set_cpu_present(unsigned int cpu, bool present) | ||
523 | { | ||
524 | if (present) | ||
525 | cpumask_set_cpu(cpu, to_cpumask(cpu_present_bits)); | ||
526 | else | ||
527 | cpumask_clear_cpu(cpu, to_cpumask(cpu_present_bits)); | ||
528 | } | ||
529 | |||
530 | void set_cpu_online(unsigned int cpu, bool online) | ||
531 | { | ||
532 | if (online) | ||
533 | cpumask_set_cpu(cpu, to_cpumask(cpu_online_bits)); | ||
534 | else | ||
535 | cpumask_clear_cpu(cpu, to_cpumask(cpu_online_bits)); | ||
536 | } | ||
537 | |||
538 | void set_cpu_active(unsigned int cpu, bool active) | ||
539 | { | ||
540 | if (active) | ||
541 | cpumask_set_cpu(cpu, to_cpumask(cpu_active_bits)); | ||
542 | else | ||
543 | cpumask_clear_cpu(cpu, to_cpumask(cpu_active_bits)); | ||
544 | } | ||
545 | |||
546 | void init_cpu_present(const struct cpumask *src) | ||
547 | { | ||
548 | cpumask_copy(to_cpumask(cpu_present_bits), src); | ||
549 | } | ||
550 | |||
551 | void init_cpu_possible(const struct cpumask *src) | ||
552 | { | ||
553 | cpumask_copy(to_cpumask(cpu_possible_bits), src); | ||
554 | } | ||
555 | |||
556 | void init_cpu_online(const struct cpumask *src) | ||
557 | { | ||
558 | cpumask_copy(to_cpumask(cpu_online_bits), src); | ||
559 | } | ||