10 #include <linux/sched.h>
13 #include <linux/oom.h>
15 #include <linux/export.h>
33 void cpu_maps_update_begin(
void)
38 void cpu_maps_update_done(
void)
48 static int cpu_hotplug_disabled;
50 #ifdef CONFIG_HOTPLUG_CPU
61 .active_writer =
NULL,
69 if (cpu_hotplug.active_writer ==
current)
72 cpu_hotplug.refcount++;
80 if (cpu_hotplug.active_writer ==
current)
84 if (
WARN_ON(!cpu_hotplug.refcount))
85 cpu_hotplug.refcount++;
87 if (!--cpu_hotplug.refcount &&
unlikely(cpu_hotplug.active_writer))
116 static void cpu_hotplug_begin(
void)
118 cpu_hotplug.active_writer =
current;
122 if (
likely(!cpu_hotplug.refcount))
130 static void cpu_hotplug_done(
void)
132 cpu_hotplug.active_writer =
NULL;
137 static void cpu_hotplug_begin(
void) {}
138 static void cpu_hotplug_done(
void) {}
145 cpu_maps_update_begin();
147 cpu_maps_update_done();
151 static int __cpu_notify(
unsigned long val,
void *
v,
int nr_to_call,
159 return notifier_to_errno(ret);
162 static int cpu_notify(
unsigned long val,
void *
v)
164 return __cpu_notify(val, v, -1,
NULL);
167 #ifdef CONFIG_HOTPLUG_CPU
169 static void cpu_notify_nofail(
unsigned long val,
void *
v)
171 BUG_ON(cpu_notify(val, v));
177 cpu_maps_update_begin();
179 cpu_maps_update_done();
195 void clear_tasks_mm_cpumask(
int cpu)
218 cpumask_clear_cpu(cpu, mm_cpumask(t->
mm));
224 static inline void check_for_tasks(
int cpu)
233 "(state = %ld, flags = %x)\n",
234 p->
comm, task_pid_nr(p), cpu,
240 struct take_cpu_down_param {
246 static int __ref take_cpu_down(
void *_param)
248 struct take_cpu_down_param *
param = _param;
256 cpu_notify(
CPU_DYING | param->mod, param->hcpu);
261 static int __ref _cpu_down(
unsigned int cpu,
int tasks_frozen)
263 int err, nr_calls = 0;
264 void *hcpu = (
void *)(
long)
cpu;
266 struct take_cpu_down_param tcd_param = {
283 printk(
"%s: attempt to take down CPU %u failed\n",
289 err = __stop_machine(take_cpu_down, &tcd_param,
cpumask_of(cpu));
312 cpu_notify_nofail(
CPU_DEAD | mod, hcpu);
314 check_for_tasks(cpu);
323 int __ref cpu_down(
unsigned int cpu)
327 cpu_maps_update_begin();
329 if (cpu_hotplug_disabled) {
334 err = _cpu_down(cpu, 0);
337 cpu_maps_update_done();
344 static int __cpuinit _cpu_up(
unsigned int cpu,
int tasks_frozen)
346 int ret, nr_calls = 0;
347 void *hcpu = (
void *)(
long)
cpu;
356 idle = idle_thread_get(cpu);
399 #ifdef CONFIG_MEMORY_HOTPLUG
406 "configured as may-hotadd at boot time\n", cpu);
407 #if defined(CONFIG_IA64)
414 #ifdef CONFIG_MEMORY_HOTPLUG
425 "Can't online cpu %d due to NULL pgdat\n", cpu);
436 cpu_maps_update_begin();
438 if (cpu_hotplug_disabled) {
443 err = _cpu_up(cpu, 0);
446 cpu_maps_update_done();
451 #ifdef CONFIG_PM_SLEEP_SMP
454 int disable_nonboot_cpus(
void)
458 cpu_maps_update_begin();
459 first_cpu = cpumask_first(cpu_online_mask);
464 cpumask_clear(frozen_cpus);
466 printk(
"Disabling non-boot CPUs ...\n");
468 if (cpu == first_cpu)
470 error = _cpu_down(cpu, 1);
472 cpumask_set_cpu(cpu, frozen_cpus);
483 cpu_hotplug_disabled = 1;
487 cpu_maps_update_done();
499 void __ref enable_nonboot_cpus(
void)
504 cpu_maps_update_begin();
505 cpu_hotplug_disabled = 0;
506 if (cpumask_empty(frozen_cpus))
514 error = _cpu_up(cpu, 1);
524 cpumask_clear(frozen_cpus);
526 cpu_maps_update_done();
529 static int __init alloc_frozen_cpus(
void)
548 void cpu_hotplug_disable_before_freeze(
void)
550 cpu_maps_update_begin();
551 cpu_hotplug_disabled = 1;
552 cpu_maps_update_done();
560 void cpu_hotplug_enable_after_thaw(
void)
562 cpu_maps_update_begin();
563 cpu_hotplug_disabled = 0;
564 cpu_maps_update_done();
586 cpu_hotplug_disable_before_freeze();
591 cpu_hotplug_enable_after_thaw();
602 static int __init cpu_hotplug_pm_sync_init(
void)
619 void __cpuinit notify_cpu_starting(
unsigned int cpu)
623 #ifdef CONFIG_PM_SLEEP_SMP
627 cpu_notify(val, (
void *)(
long)cpu);
641 #define MASK_DECLARE_1(x) [x+1][0] = (1UL << (x))
642 #define MASK_DECLARE_2(x) MASK_DECLARE_1(x), MASK_DECLARE_1(x+1)
643 #define MASK_DECLARE_4(x) MASK_DECLARE_2(x), MASK_DECLARE_2(x+2)
644 #define MASK_DECLARE_8(x) MASK_DECLARE_4(x), MASK_DECLARE_4(x+4)
650 #if BITS_PER_LONG > 32
660 #ifdef CONFIG_INIT_ALL_POSSIBLE
684 cpumask_set_cpu(cpu,
to_cpumask(cpu_possible_bits));
686 cpumask_clear_cpu(cpu,
to_cpumask(cpu_possible_bits));
692 cpumask_set_cpu(cpu,
to_cpumask(cpu_present_bits));
694 cpumask_clear_cpu(cpu,
to_cpumask(cpu_present_bits));
700 cpumask_set_cpu(cpu,
to_cpumask(cpu_online_bits));
702 cpumask_clear_cpu(cpu,
to_cpumask(cpu_online_bits));
708 cpumask_set_cpu(cpu,
to_cpumask(cpu_active_bits));
710 cpumask_clear_cpu(cpu,
to_cpumask(cpu_active_bits));
715 cpumask_copy(
to_cpumask(cpu_present_bits), src);
720 cpumask_copy(
to_cpumask(cpu_possible_bits), src);
725 cpumask_copy(
to_cpumask(cpu_online_bits), src);