aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cpu.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/cpu.c')
-rw-r--r--kernel/cpu.c89
1 files changed, 70 insertions, 19 deletions
diff --git a/kernel/cpu.c b/kernel/cpu.c
index cfb1d43ab801..f17e9854c246 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)
@@ -214,7 +216,6 @@ static int __ref take_cpu_down(void *_param)
214static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) 216static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
215{ 217{
216 int err, nr_calls = 0; 218 int err, nr_calls = 0;
217 struct task_struct *p;
218 cpumask_t old_allowed, tmp; 219 cpumask_t old_allowed, tmp;
219 void *hcpu = (void *)(long)cpu; 220 void *hcpu = (void *)(long)cpu;
220 unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0; 221 unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0;
@@ -247,21 +248,18 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
247 cpus_setall(tmp); 248 cpus_setall(tmp);
248 cpu_clear(cpu, tmp); 249 cpu_clear(cpu, tmp);
249 set_cpus_allowed_ptr(current, &tmp); 250 set_cpus_allowed_ptr(current, &tmp);
251 tmp = cpumask_of_cpu(cpu);
250 252
251 p = __stop_machine_run(take_cpu_down, &tcd_param, cpu); 253 err = __stop_machine(take_cpu_down, &tcd_param, &tmp);
252 254 if (err) {
253 if (IS_ERR(p) || cpu_online(cpu)) {
254 /* CPU didn't die: tell everyone. Can't complain. */ 255 /* CPU didn't die: tell everyone. Can't complain. */
255 if (raw_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED | mod, 256 if (raw_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED | mod,
256 hcpu) == NOTIFY_BAD) 257 hcpu) == NOTIFY_BAD)
257 BUG(); 258 BUG();
258 259
259 if (IS_ERR(p)) { 260 goto out_allowed;
260 err = PTR_ERR(p);
261 goto out_allowed;
262 }
263 goto out_thread;
264 } 261 }
262 BUG_ON(cpu_online(cpu));
265 263
266 /* Wait for it to sleep (leaving idle task). */ 264 /* Wait for it to sleep (leaving idle task). */
267 while (!idle_cpu(cpu)) 265 while (!idle_cpu(cpu))
@@ -277,12 +275,15 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
277 275
278 check_for_tasks(cpu); 276 check_for_tasks(cpu);
279 277
280out_thread:
281 err = kthread_stop(p);
282out_allowed: 278out_allowed:
283 set_cpus_allowed_ptr(current, &old_allowed); 279 set_cpus_allowed_ptr(current, &old_allowed);
284out_release: 280out_release:
285 cpu_hotplug_done(); 281 cpu_hotplug_done();
282 if (!err) {
283 if (raw_notifier_call_chain(&cpu_chain, CPU_POST_DEAD | mod,
284 hcpu) == NOTIFY_BAD)
285 BUG();
286 }
286 return err; 287 return err;
287} 288}
288 289
@@ -291,11 +292,30 @@ int __ref cpu_down(unsigned int cpu)
291 int err = 0; 292 int err = 0;
292 293
293 cpu_maps_update_begin(); 294 cpu_maps_update_begin();
294 if (cpu_hotplug_disabled) 295
296 if (cpu_hotplug_disabled) {
295 err = -EBUSY; 297 err = -EBUSY;
296 else 298 goto out;
297 err = _cpu_down(cpu, 0); 299 }
300
301 cpu_clear(cpu, cpu_active_map);
302
303 /*
304 * Make sure the all cpus did the reschedule and are not
305 * using stale version of the cpu_active_map.
306 * This is not strictly necessary becuase stop_machine()
307 * that we run down the line already provides the required
308 * synchronization. But it's really a side effect and we do not
309 * want to depend on the innards of the stop_machine here.
310 */
311 synchronize_sched();
312
313 err = _cpu_down(cpu, 0);
314
315 if (cpu_online(cpu))
316 cpu_set(cpu, cpu_active_map);
298 317
318out:
299 cpu_maps_update_done(); 319 cpu_maps_update_done();
300 return err; 320 return err;
301} 321}
@@ -329,6 +349,8 @@ static int __cpuinit _cpu_up(unsigned int cpu, int tasks_frozen)
329 goto out_notify; 349 goto out_notify;
330 BUG_ON(!cpu_online(cpu)); 350 BUG_ON(!cpu_online(cpu));
331 351
352 cpu_set(cpu, cpu_active_map);
353
332 /* Now call notifier in preparation. */ 354 /* Now call notifier in preparation. */
333 raw_notifier_call_chain(&cpu_chain, CPU_ONLINE | mod, hcpu); 355 raw_notifier_call_chain(&cpu_chain, CPU_ONLINE | mod, hcpu);
334 356
@@ -347,7 +369,7 @@ int __cpuinit cpu_up(unsigned int cpu)
347 if (!cpu_isset(cpu, cpu_possible_map)) { 369 if (!cpu_isset(cpu, cpu_possible_map)) {
348 printk(KERN_ERR "can't online cpu %d because it is not " 370 printk(KERN_ERR "can't online cpu %d because it is not "
349 "configured as may-hotadd at boot time\n", cpu); 371 "configured as may-hotadd at boot time\n", cpu);
350#if defined(CONFIG_IA64) || defined(CONFIG_X86_64) || defined(CONFIG_S390) 372#if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
351 printk(KERN_ERR "please check additional_cpus= boot " 373 printk(KERN_ERR "please check additional_cpus= boot "
352 "parameter\n"); 374 "parameter\n");
353#endif 375#endif
@@ -355,11 +377,15 @@ int __cpuinit cpu_up(unsigned int cpu)
355 } 377 }
356 378
357 cpu_maps_update_begin(); 379 cpu_maps_update_begin();
358 if (cpu_hotplug_disabled) 380
381 if (cpu_hotplug_disabled) {
359 err = -EBUSY; 382 err = -EBUSY;
360 else 383 goto out;
361 err = _cpu_up(cpu, 0); 384 }
385
386 err = _cpu_up(cpu, 0);
362 387
388out:
363 cpu_maps_update_done(); 389 cpu_maps_update_done();
364 return err; 390 return err;
365} 391}
@@ -413,7 +439,7 @@ void __ref enable_nonboot_cpus(void)
413 goto out; 439 goto out;
414 440
415 printk("Enabling non-boot CPUs ...\n"); 441 printk("Enabling non-boot CPUs ...\n");
416 for_each_cpu_mask(cpu, frozen_cpus) { 442 for_each_cpu_mask_nr(cpu, frozen_cpus) {
417 error = _cpu_up(cpu, 1); 443 error = _cpu_up(cpu, 1);
418 if (!error) { 444 if (!error) {
419 printk("CPU%d is up\n", cpu); 445 printk("CPU%d is up\n", cpu);
@@ -428,3 +454,28 @@ out:
428#endif /* CONFIG_PM_SLEEP_SMP */ 454#endif /* CONFIG_PM_SLEEP_SMP */
429 455
430#endif /* CONFIG_SMP */ 456#endif /* CONFIG_SMP */
457
458/*
459 * cpu_bit_bitmap[] is a special, "compressed" data structure that
460 * represents all NR_CPUS bits binary values of 1<<nr.
461 *
462 * It is used by cpumask_of_cpu() to get a constant address to a CPU
463 * mask value that has a single bit set only.
464 */
465
466/* cpu_bit_bitmap[0] is empty - so we can back into it */
467#define MASK_DECLARE_1(x) [x+1][0] = 1UL << (x)
468#define MASK_DECLARE_2(x) MASK_DECLARE_1(x), MASK_DECLARE_1(x+1)
469#define MASK_DECLARE_4(x) MASK_DECLARE_2(x), MASK_DECLARE_2(x+2)
470#define MASK_DECLARE_8(x) MASK_DECLARE_4(x), MASK_DECLARE_4(x+4)
471
472const unsigned long cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)] = {
473
474 MASK_DECLARE_8(0), MASK_DECLARE_8(8),
475 MASK_DECLARE_8(16), MASK_DECLARE_8(24),
476#if BITS_PER_LONG > 32
477 MASK_DECLARE_8(32), MASK_DECLARE_8(40),
478 MASK_DECLARE_8(48), MASK_DECLARE_8(56),
479#endif
480};
481EXPORT_SYMBOL_GPL(cpu_bit_bitmap);