aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cpu.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/cpu.c')
-rw-r--r--kernel/cpu.c72
1 files changed, 55 insertions, 17 deletions
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 10ba5f1004a5..86d49045daed 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -199,13 +199,14 @@ static int __ref take_cpu_down(void *_param)
199 struct take_cpu_down_param *param = _param; 199 struct take_cpu_down_param *param = _param;
200 int err; 200 int err;
201 201
202 raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod,
203 param->hcpu);
204 /* Ensure this CPU doesn't handle any more interrupts. */ 202 /* Ensure this CPU doesn't handle any more interrupts. */
205 err = __cpu_disable(); 203 err = __cpu_disable();
206 if (err < 0) 204 if (err < 0)
207 return err; 205 return err;
208 206
207 raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod,
208 param->hcpu);
209
209 /* Force idle task to run as soon as we yield: it should 210 /* Force idle task to run as soon as we yield: it should
210 immediately notice cpu is offline and die quickly. */ 211 immediately notice cpu is offline and die quickly. */
211 sched_idle_next(); 212 sched_idle_next();
@@ -216,7 +217,6 @@ static int __ref take_cpu_down(void *_param)
216static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) 217static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
217{ 218{
218 int err, nr_calls = 0; 219 int err, nr_calls = 0;
219 struct task_struct *p;
220 cpumask_t old_allowed, tmp; 220 cpumask_t old_allowed, tmp;
221 void *hcpu = (void *)(long)cpu; 221 void *hcpu = (void *)(long)cpu;
222 unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0; 222 unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0;
@@ -249,21 +249,18 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
249 cpus_setall(tmp); 249 cpus_setall(tmp);
250 cpu_clear(cpu, tmp); 250 cpu_clear(cpu, tmp);
251 set_cpus_allowed_ptr(current, &tmp); 251 set_cpus_allowed_ptr(current, &tmp);
252 tmp = cpumask_of_cpu(cpu);
252 253
253 p = __stop_machine_run(take_cpu_down, &tcd_param, cpu); 254 err = __stop_machine(take_cpu_down, &tcd_param, &tmp);
254 255 if (err) {
255 if (IS_ERR(p) || cpu_online(cpu)) {
256 /* CPU didn't die: tell everyone. Can't complain. */ 256 /* CPU didn't die: tell everyone. Can't complain. */
257 if (raw_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED | mod, 257 if (raw_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED | mod,
258 hcpu) == NOTIFY_BAD) 258 hcpu) == NOTIFY_BAD)
259 BUG(); 259 BUG();
260 260
261 if (IS_ERR(p)) { 261 goto out_allowed;
262 err = PTR_ERR(p);
263 goto out_allowed;
264 }
265 goto out_thread;
266 } 262 }
263 BUG_ON(cpu_online(cpu));
267 264
268 /* Wait for it to sleep (leaving idle task). */ 265 /* Wait for it to sleep (leaving idle task). */
269 while (!idle_cpu(cpu)) 266 while (!idle_cpu(cpu))
@@ -279,8 +276,6 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
279 276
280 check_for_tasks(cpu); 277 check_for_tasks(cpu);
281 278
282out_thread:
283 err = kthread_stop(p);
284out_allowed: 279out_allowed:
285 set_cpus_allowed_ptr(current, &old_allowed); 280 set_cpus_allowed_ptr(current, &old_allowed);
286out_release: 281out_release:
@@ -355,6 +350,8 @@ static int __cpuinit _cpu_up(unsigned int cpu, int tasks_frozen)
355 goto out_notify; 350 goto out_notify;
356 BUG_ON(!cpu_online(cpu)); 351 BUG_ON(!cpu_online(cpu));
357 352
353 cpu_set(cpu, cpu_active_map);
354
358 /* Now call notifier in preparation. */ 355 /* Now call notifier in preparation. */
359 raw_notifier_call_chain(&cpu_chain, CPU_ONLINE | mod, hcpu); 356 raw_notifier_call_chain(&cpu_chain, CPU_ONLINE | mod, hcpu);
360 357
@@ -373,7 +370,7 @@ int __cpuinit cpu_up(unsigned int cpu)
373 if (!cpu_isset(cpu, cpu_possible_map)) { 370 if (!cpu_isset(cpu, cpu_possible_map)) {
374 printk(KERN_ERR "can't online cpu %d because it is not " 371 printk(KERN_ERR "can't online cpu %d because it is not "
375 "configured as may-hotadd at boot time\n", cpu); 372 "configured as may-hotadd at boot time\n", cpu);
376#if defined(CONFIG_IA64) || defined(CONFIG_X86_64) || defined(CONFIG_S390) 373#if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
377 printk(KERN_ERR "please check additional_cpus= boot " 374 printk(KERN_ERR "please check additional_cpus= boot "
378 "parameter\n"); 375 "parameter\n");
379#endif 376#endif
@@ -389,9 +386,6 @@ int __cpuinit cpu_up(unsigned int cpu)
389 386
390 err = _cpu_up(cpu, 0); 387 err = _cpu_up(cpu, 0);
391 388
392 if (cpu_online(cpu))
393 cpu_set(cpu, cpu_active_map);
394
395out: 389out:
396 cpu_maps_update_done(); 390 cpu_maps_update_done();
397 return err; 391 return err;
@@ -460,4 +454,48 @@ out:
460} 454}
461#endif /* CONFIG_PM_SLEEP_SMP */ 455#endif /* CONFIG_PM_SLEEP_SMP */
462 456
457/**
458 * notify_cpu_starting(cpu) - call the CPU_STARTING notifiers
459 * @cpu: cpu that just started
460 *
461 * This function calls the cpu_chain notifiers with CPU_STARTING.
462 * It must be called by the arch code on the new cpu, before the new cpu
463 * enables interrupts and before the "boot" cpu returns from __cpu_up().
464 */
465void notify_cpu_starting(unsigned int cpu)
466{
467 unsigned long val = CPU_STARTING;
468
469#ifdef CONFIG_PM_SLEEP_SMP
470 if (cpu_isset(cpu, frozen_cpus))
471 val = CPU_STARTING_FROZEN;
472#endif /* CONFIG_PM_SLEEP_SMP */
473 raw_notifier_call_chain(&cpu_chain, val, (void *)(long)cpu);
474}
475
463#endif /* CONFIG_SMP */ 476#endif /* CONFIG_SMP */
477
478/*
479 * cpu_bit_bitmap[] is a special, "compressed" data structure that
480 * represents all NR_CPUS bits binary values of 1<<nr.
481 *
482 * It is used by cpumask_of_cpu() to get a constant address to a CPU
483 * mask value that has a single bit set only.
484 */
485
486/* cpu_bit_bitmap[0] is empty - so we can back into it */
487#define MASK_DECLARE_1(x) [x+1][0] = 1UL << (x)
488#define MASK_DECLARE_2(x) MASK_DECLARE_1(x), MASK_DECLARE_1(x+1)
489#define MASK_DECLARE_4(x) MASK_DECLARE_2(x), MASK_DECLARE_2(x+2)
490#define MASK_DECLARE_8(x) MASK_DECLARE_4(x), MASK_DECLARE_4(x+4)
491
492const unsigned long cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)] = {
493
494 MASK_DECLARE_8(0), MASK_DECLARE_8(8),
495 MASK_DECLARE_8(16), MASK_DECLARE_8(24),
496#if BITS_PER_LONG > 32
497 MASK_DECLARE_8(32), MASK_DECLARE_8(40),
498 MASK_DECLARE_8(48), MASK_DECLARE_8(56),
499#endif
500};
501EXPORT_SYMBOL_GPL(cpu_bit_bitmap);