aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cpu.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/cpu.c')
-rw-r--r--kernel/cpu.c113
1 files changed, 92 insertions, 21 deletions
diff --git a/kernel/cpu.c b/kernel/cpu.c
index cfb1d43ab80..86d49045dae 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -64,6 +64,8 @@ void __init cpu_hotplug_init(void)
64 cpu_hotplug.refcount = 0; 64 cpu_hotplug.refcount = 0;
65} 65}
66 66
67cpumask_t cpu_active_map;
68
67#ifdef CONFIG_HOTPLUG_CPU 69#ifdef CONFIG_HOTPLUG_CPU
68 70
69void get_online_cpus(void) 71void get_online_cpus(void)
@@ -197,13 +199,14 @@ static int __ref take_cpu_down(void *_param)
197 struct take_cpu_down_param *param = _param; 199 struct take_cpu_down_param *param = _param;
198 int err; 200 int err;
199 201
200 raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod,
201 param->hcpu);
202 /* Ensure this CPU doesn't handle any more interrupts. */ 202 /* Ensure this CPU doesn't handle any more interrupts. */
203 err = __cpu_disable(); 203 err = __cpu_disable();
204 if (err < 0) 204 if (err < 0)
205 return err; 205 return err;
206 206
207 raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod,
208 param->hcpu);
209
207 /* 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
208 immediately notice cpu is offline and die quickly. */ 211 immediately notice cpu is offline and die quickly. */
209 sched_idle_next(); 212 sched_idle_next();
@@ -214,7 +217,6 @@ static int __ref take_cpu_down(void *_param)
214static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) 217static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
215{ 218{
216 int err, nr_calls = 0; 219 int err, nr_calls = 0;
217 struct task_struct *p;
218 cpumask_t old_allowed, tmp; 220 cpumask_t old_allowed, tmp;
219 void *hcpu = (void *)(long)cpu; 221 void *hcpu = (void *)(long)cpu;
220 unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0; 222 unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0;
@@ -247,21 +249,18 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
247 cpus_setall(tmp); 249 cpus_setall(tmp);
248 cpu_clear(cpu, tmp); 250 cpu_clear(cpu, tmp);
249 set_cpus_allowed_ptr(current, &tmp); 251 set_cpus_allowed_ptr(current, &tmp);
252 tmp = cpumask_of_cpu(cpu);
250 253
251 p = __stop_machine_run(take_cpu_down, &tcd_param, cpu); 254 err = __stop_machine(take_cpu_down, &tcd_param, &tmp);
252 255 if (err) {
253 if (IS_ERR(p) || cpu_online(cpu)) {
254 /* CPU didn't die: tell everyone. Can't complain. */ 256 /* CPU didn't die: tell everyone. Can't complain. */
255 if (raw_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED | mod, 257 if (raw_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED | mod,
256 hcpu) == NOTIFY_BAD) 258 hcpu) == NOTIFY_BAD)
257 BUG(); 259 BUG();
258 260
259 if (IS_ERR(p)) { 261 goto out_allowed;
260 err = PTR_ERR(p);
261 goto out_allowed;
262 }
263 goto out_thread;
264 } 262 }
263 BUG_ON(cpu_online(cpu));
265 264
266 /* Wait for it to sleep (leaving idle task). */ 265 /* Wait for it to sleep (leaving idle task). */
267 while (!idle_cpu(cpu)) 266 while (!idle_cpu(cpu))
@@ -277,12 +276,15 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
277 276
278 check_for_tasks(cpu); 277 check_for_tasks(cpu);
279 278
280out_thread:
281 err = kthread_stop(p);
282out_allowed: 279out_allowed:
283 set_cpus_allowed_ptr(current, &old_allowed); 280 set_cpus_allowed_ptr(current, &old_allowed);
284out_release: 281out_release:
285 cpu_hotplug_done(); 282 cpu_hotplug_done();
283 if (!err) {
284 if (raw_notifier_call_chain(&cpu_chain, CPU_POST_DEAD | mod,
285 hcpu) == NOTIFY_BAD)
286 BUG();
287 }
286 return err; 288 return err;
287} 289}
288 290
@@ -291,11 +293,30 @@ int __ref cpu_down(unsigned int cpu)
291 int err = 0; 293 int err = 0;
292 294
293 cpu_maps_update_begin(); 295 cpu_maps_update_begin();
294 if (cpu_hotplug_disabled) 296
297 if (cpu_hotplug_disabled) {
295 err = -EBUSY; 298 err = -EBUSY;
296 else 299 goto out;
297 err = _cpu_down(cpu, 0); 300 }
298 301
302 cpu_clear(cpu, cpu_active_map);
303
304 /*
305 * Make sure the all cpus did the reschedule and are not
306 * using stale version of the cpu_active_map.
307 * This is not strictly necessary becuase stop_machine()
308 * that we run down the line already provides the required
309 * synchronization. But it's really a side effect and we do not
310 * want to depend on the innards of the stop_machine here.
311 */
312 synchronize_sched();
313
314 err = _cpu_down(cpu, 0);
315
316 if (cpu_online(cpu))
317 cpu_set(cpu, cpu_active_map);
318
319out:
299 cpu_maps_update_done(); 320 cpu_maps_update_done();
300 return err; 321 return err;
301} 322}
@@ -329,6 +350,8 @@ static int __cpuinit _cpu_up(unsigned int cpu, int tasks_frozen)
329 goto out_notify; 350 goto out_notify;
330 BUG_ON(!cpu_online(cpu)); 351 BUG_ON(!cpu_online(cpu));
331 352
353 cpu_set(cpu, cpu_active_map);
354
332 /* Now call notifier in preparation. */ 355 /* Now call notifier in preparation. */
333 raw_notifier_call_chain(&cpu_chain, CPU_ONLINE | mod, hcpu); 356 raw_notifier_call_chain(&cpu_chain, CPU_ONLINE | mod, hcpu);
334 357
@@ -347,7 +370,7 @@ int __cpuinit cpu_up(unsigned int cpu)
347 if (!cpu_isset(cpu, cpu_possible_map)) { 370 if (!cpu_isset(cpu, cpu_possible_map)) {
348 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 "
349 "configured as may-hotadd at boot time\n", cpu); 372 "configured as may-hotadd at boot time\n", cpu);
350#if defined(CONFIG_IA64) || defined(CONFIG_X86_64) || defined(CONFIG_S390) 373#if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
351 printk(KERN_ERR "please check additional_cpus= boot " 374 printk(KERN_ERR "please check additional_cpus= boot "
352 "parameter\n"); 375 "parameter\n");
353#endif 376#endif
@@ -355,11 +378,15 @@ int __cpuinit cpu_up(unsigned int cpu)
355 } 378 }
356 379
357 cpu_maps_update_begin(); 380 cpu_maps_update_begin();
358 if (cpu_hotplug_disabled) 381
382 if (cpu_hotplug_disabled) {
359 err = -EBUSY; 383 err = -EBUSY;
360 else 384 goto out;
361 err = _cpu_up(cpu, 0); 385 }
362 386
387 err = _cpu_up(cpu, 0);
388
389out:
363 cpu_maps_update_done(); 390 cpu_maps_update_done();
364 return err; 391 return err;
365} 392}
@@ -413,7 +440,7 @@ void __ref enable_nonboot_cpus(void)
413 goto out; 440 goto out;
414 441
415 printk("Enabling non-boot CPUs ...\n"); 442 printk("Enabling non-boot CPUs ...\n");
416 for_each_cpu_mask(cpu, frozen_cpus) { 443 for_each_cpu_mask_nr(cpu, frozen_cpus) {
417 error = _cpu_up(cpu, 1); 444 error = _cpu_up(cpu, 1);
418 if (!error) { 445 if (!error) {
419 printk("CPU%d is up\n", cpu); 446 printk("CPU%d is up\n", cpu);
@@ -427,4 +454,48 @@ out:
427} 454}
428#endif /* CONFIG_PM_SLEEP_SMP */ 455#endif /* CONFIG_PM_SLEEP_SMP */
429 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
430#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);