aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/kernel/smp.c
diff options
context:
space:
mode:
authorRussell King <rmk+kernel@arm.linux.org.uk>2011-01-06 17:32:52 -0500
committerRussell King <rmk+kernel@arm.linux.org.uk>2011-01-06 17:32:52 -0500
commit4073723acb9cdcdbe4df9c0e0c376c65d1697e43 (patch)
treef41c17eac157b1223ce104845cf9b1e5a9e6a83d /arch/arm/kernel/smp.c
parent58daf18cdcab550262a5f4681e1f1e073e21965a (diff)
parent4ec3eb13634529c0bc7466658d84d0bbe3244aea (diff)
Merge branch 'misc' into devel
Conflicts: arch/arm/Kconfig arch/arm/common/Makefile arch/arm/kernel/Makefile arch/arm/kernel/smp.c
Diffstat (limited to 'arch/arm/kernel/smp.c')
-rw-r--r--arch/arm/kernel/smp.c409
1 files changed, 157 insertions, 252 deletions
diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
index b6b78b22031b..5ec79b4ff950 100644
--- a/arch/arm/kernel/smp.c
+++ b/arch/arm/kernel/smp.c
@@ -25,6 +25,7 @@
25#include <linux/irq.h> 25#include <linux/irq.h>
26#include <linux/percpu.h> 26#include <linux/percpu.h>
27#include <linux/clockchips.h> 27#include <linux/clockchips.h>
28#include <linux/completion.h>
28 29
29#include <asm/atomic.h> 30#include <asm/atomic.h>
30#include <asm/cacheflush.h> 31#include <asm/cacheflush.h>
@@ -38,7 +39,6 @@
38#include <asm/tlbflush.h> 39#include <asm/tlbflush.h>
39#include <asm/ptrace.h> 40#include <asm/ptrace.h>
40#include <asm/localtimer.h> 41#include <asm/localtimer.h>
41#include <asm/smp_plat.h>
42 42
43/* 43/*
44 * as from 2.5, kernels no longer have an init_tasks structure 44 * as from 2.5, kernels no longer have an init_tasks structure
@@ -47,22 +47,8 @@
47 */ 47 */
48struct secondary_data secondary_data; 48struct secondary_data secondary_data;
49 49
50/*
51 * structures for inter-processor calls
52 * - A collection of single bit ipi messages.
53 */
54struct ipi_data {
55 spinlock_t lock;
56 unsigned long ipi_count;
57 unsigned long bits;
58};
59
60static DEFINE_PER_CPU(struct ipi_data, ipi_data) = {
61 .lock = SPIN_LOCK_UNLOCKED,
62};
63
64enum ipi_msg_type { 50enum ipi_msg_type {
65 IPI_TIMER, 51 IPI_TIMER = 2,
66 IPI_RESCHEDULE, 52 IPI_RESCHEDULE,
67 IPI_CALL_FUNC, 53 IPI_CALL_FUNC,
68 IPI_CALL_FUNC_SINGLE, 54 IPI_CALL_FUNC_SINGLE,
@@ -178,8 +164,12 @@ int __cpuinit __cpu_up(unsigned int cpu)
178 barrier(); 164 barrier();
179 } 165 }
180 166
181 if (!cpu_online(cpu)) 167 if (!cpu_online(cpu)) {
168 pr_crit("CPU%u: failed to come online\n", cpu);
182 ret = -EIO; 169 ret = -EIO;
170 }
171 } else {
172 pr_err("CPU%u: failed to boot: %d\n", cpu, ret);
183 } 173 }
184 174
185 secondary_data.stack = NULL; 175 secondary_data.stack = NULL;
@@ -195,18 +185,12 @@ int __cpuinit __cpu_up(unsigned int cpu)
195 185
196 pgd_free(&init_mm, pgd); 186 pgd_free(&init_mm, pgd);
197 187
198 if (ret) {
199 printk(KERN_CRIT "CPU%u: processor failed to boot\n", cpu);
200
201 /*
202 * FIXME: We need to clean up the new idle thread. --rmk
203 */
204 }
205
206 return ret; 188 return ret;
207} 189}
208 190
209#ifdef CONFIG_HOTPLUG_CPU 191#ifdef CONFIG_HOTPLUG_CPU
192static void percpu_timer_stop(void);
193
210/* 194/*
211 * __cpu_disable runs on the processor to be shutdown. 195 * __cpu_disable runs on the processor to be shutdown.
212 */ 196 */
@@ -234,7 +218,7 @@ int __cpu_disable(void)
234 /* 218 /*
235 * Stop the local timer for this CPU. 219 * Stop the local timer for this CPU.
236 */ 220 */
237 local_timer_stop(); 221 percpu_timer_stop();
238 222
239 /* 223 /*
240 * Flush user cache and TLB mappings, and then remove this CPU 224 * Flush user cache and TLB mappings, and then remove this CPU
@@ -253,12 +237,20 @@ int __cpu_disable(void)
253 return 0; 237 return 0;
254} 238}
255 239
240static DECLARE_COMPLETION(cpu_died);
241
256/* 242/*
257 * called on the thread which is asking for a CPU to be shutdown - 243 * called on the thread which is asking for a CPU to be shutdown -
258 * waits until shutdown has completed, or it is timed out. 244 * waits until shutdown has completed, or it is timed out.
259 */ 245 */
260void __cpu_die(unsigned int cpu) 246void __cpu_die(unsigned int cpu)
261{ 247{
248 if (!wait_for_completion_timeout(&cpu_died, msecs_to_jiffies(5000))) {
249 pr_err("CPU%u: cpu didn't die\n", cpu);
250 return;
251 }
252 printk(KERN_NOTICE "CPU%u: shutdown\n", cpu);
253
262 if (!platform_cpu_kill(cpu)) 254 if (!platform_cpu_kill(cpu))
263 printk("CPU%u: unable to kill\n", cpu); 255 printk("CPU%u: unable to kill\n", cpu);
264} 256}
@@ -275,12 +267,17 @@ void __ref cpu_die(void)
275{ 267{
276 unsigned int cpu = smp_processor_id(); 268 unsigned int cpu = smp_processor_id();
277 269
278 local_irq_disable();
279 idle_task_exit(); 270 idle_task_exit();
280 271
272 local_irq_disable();
273 mb();
274
275 /* Tell __cpu_die() that this CPU is now safe to dispose of */
276 complete(&cpu_died);
277
281 /* 278 /*
282 * actual CPU shutdown procedure is at least platform (if not 279 * actual CPU shutdown procedure is at least platform (if not
283 * CPU) specific 280 * CPU) specific.
284 */ 281 */
285 platform_cpu_die(cpu); 282 platform_cpu_die(cpu);
286 283
@@ -290,6 +287,7 @@ void __ref cpu_die(void)
290 * to be repeated to undo the effects of taking the CPU offline. 287 * to be repeated to undo the effects of taking the CPU offline.
291 */ 288 */
292 __asm__("mov sp, %0\n" 289 __asm__("mov sp, %0\n"
290 " mov fp, #0\n"
293 " b secondary_start_kernel" 291 " b secondary_start_kernel"
294 : 292 :
295 : "r" (task_stack_page(current) + THREAD_SIZE - 8)); 293 : "r" (task_stack_page(current) + THREAD_SIZE - 8));
@@ -297,6 +295,17 @@ void __ref cpu_die(void)
297#endif /* CONFIG_HOTPLUG_CPU */ 295#endif /* CONFIG_HOTPLUG_CPU */
298 296
299/* 297/*
298 * Called by both boot and secondaries to move global data into
299 * per-processor storage.
300 */
301static void __cpuinit smp_store_cpu_info(unsigned int cpuid)
302{
303 struct cpuinfo_arm *cpu_info = &per_cpu(cpu_data, cpuid);
304
305 cpu_info->loops_per_jiffy = loops_per_jiffy;
306}
307
308/*
300 * This is the secondary CPU boot entry. We're using this CPUs 309 * This is the secondary CPU boot entry. We're using this CPUs
301 * idle thread stack, but a set of temporary page tables. 310 * idle thread stack, but a set of temporary page tables.
302 */ 311 */
@@ -320,6 +329,7 @@ asmlinkage void __cpuinit secondary_start_kernel(void)
320 329
321 cpu_init(); 330 cpu_init();
322 preempt_disable(); 331 preempt_disable();
332 trace_hardirqs_off();
323 333
324 /* 334 /*
325 * Give the platform a chance to do its own initialisation. 335 * Give the platform a chance to do its own initialisation.
@@ -353,17 +363,6 @@ asmlinkage void __cpuinit secondary_start_kernel(void)
353 cpu_idle(); 363 cpu_idle();
354} 364}
355 365
356/*
357 * Called by both boot and secondaries to move global data into
358 * per-processor storage.
359 */
360void __cpuinit smp_store_cpu_info(unsigned int cpuid)
361{
362 struct cpuinfo_arm *cpu_info = &per_cpu(cpu_data, cpuid);
363
364 cpu_info->loops_per_jiffy = loops_per_jiffy;
365}
366
367void __init smp_cpus_done(unsigned int max_cpus) 366void __init smp_cpus_done(unsigned int max_cpus)
368{ 367{
369 int cpu; 368 int cpu;
@@ -386,61 +385,80 @@ void __init smp_prepare_boot_cpu(void)
386 per_cpu(cpu_data, cpu).idle = current; 385 per_cpu(cpu_data, cpu).idle = current;
387} 386}
388 387
389static void send_ipi_message(const struct cpumask *mask, enum ipi_msg_type msg) 388void __init smp_prepare_cpus(unsigned int max_cpus)
390{ 389{
391 unsigned long flags; 390 unsigned int ncores = num_possible_cpus();
392 unsigned int cpu;
393
394 local_irq_save(flags);
395 391
396 for_each_cpu(cpu, mask) { 392 smp_store_cpu_info(smp_processor_id());
397 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
398
399 spin_lock(&ipi->lock);
400 ipi->bits |= 1 << msg;
401 spin_unlock(&ipi->lock);
402 }
403 393
404 /* 394 /*
405 * Call the platform specific cross-CPU call function. 395 * are we trying to boot more cores than exist?
406 */ 396 */
407 smp_cross_call(mask); 397 if (max_cpus > ncores)
398 max_cpus = ncores;
399
400 if (max_cpus > 1) {
401 /*
402 * Enable the local timer or broadcast device for the
403 * boot CPU, but only if we have more than one CPU.
404 */
405 percpu_timer_setup();
408 406
409 local_irq_restore(flags); 407 /*
408 * Initialise the SCU if there are more than one CPU
409 * and let them know where to start.
410 */
411 platform_smp_prepare_cpus(max_cpus);
412 }
410} 413}
411 414
412void arch_send_call_function_ipi_mask(const struct cpumask *mask) 415void arch_send_call_function_ipi_mask(const struct cpumask *mask)
413{ 416{
414 send_ipi_message(mask, IPI_CALL_FUNC); 417 smp_cross_call(mask, IPI_CALL_FUNC);
415} 418}
416 419
417void arch_send_call_function_single_ipi(int cpu) 420void arch_send_call_function_single_ipi(int cpu)
418{ 421{
419 send_ipi_message(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE); 422 smp_cross_call(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE);
420} 423}
421 424
422void show_ipi_list(struct seq_file *p) 425static const char *ipi_types[NR_IPI] = {
426#define S(x,s) [x - IPI_TIMER] = s
427 S(IPI_TIMER, "Timer broadcast interrupts"),
428 S(IPI_RESCHEDULE, "Rescheduling interrupts"),
429 S(IPI_CALL_FUNC, "Function call interrupts"),
430 S(IPI_CALL_FUNC_SINGLE, "Single function call interrupts"),
431 S(IPI_CPU_STOP, "CPU stop interrupts"),
432};
433
434void show_ipi_list(struct seq_file *p, int prec)
423{ 435{
424 unsigned int cpu; 436 unsigned int cpu, i;
425 437
426 seq_puts(p, "IPI:"); 438 for (i = 0; i < NR_IPI; i++) {
439 seq_printf(p, "%*s%u: ", prec - 1, "IPI", i);
427 440
428 for_each_present_cpu(cpu) 441 for_each_present_cpu(cpu)
429 seq_printf(p, " %10lu", per_cpu(ipi_data, cpu).ipi_count); 442 seq_printf(p, "%10u ",
443 __get_irq_stat(cpu, ipi_irqs[i]));
430 444
431 seq_putc(p, '\n'); 445 seq_printf(p, " %s\n", ipi_types[i]);
446 }
432} 447}
433 448
434void show_local_irqs(struct seq_file *p) 449u64 smp_irq_stat_cpu(unsigned int cpu)
435{ 450{
436 unsigned int cpu; 451 u64 sum = 0;
452 int i;
437 453
438 seq_printf(p, "LOC: "); 454 for (i = 0; i < NR_IPI; i++)
455 sum += __get_irq_stat(cpu, ipi_irqs[i]);
439 456
440 for_each_present_cpu(cpu) 457#ifdef CONFIG_LOCAL_TIMERS
441 seq_printf(p, "%10u ", irq_stat[cpu].local_timer_irqs); 458 sum += __get_irq_stat(cpu, local_timer_irqs);
459#endif
442 460
443 seq_putc(p, '\n'); 461 return sum;
444} 462}
445 463
446/* 464/*
@@ -463,18 +481,30 @@ asmlinkage void __exception_irq_entry do_local_timer(struct pt_regs *regs)
463 int cpu = smp_processor_id(); 481 int cpu = smp_processor_id();
464 482
465 if (local_timer_ack()) { 483 if (local_timer_ack()) {
466 irq_stat[cpu].local_timer_irqs++; 484 __inc_irq_stat(cpu, local_timer_irqs);
467 ipi_timer(); 485 ipi_timer();
468 } 486 }
469 487
470 set_irq_regs(old_regs); 488 set_irq_regs(old_regs);
471} 489}
490
491void show_local_irqs(struct seq_file *p, int prec)
492{
493 unsigned int cpu;
494
495 seq_printf(p, "%*s: ", prec, "LOC");
496
497 for_each_present_cpu(cpu)
498 seq_printf(p, "%10u ", __get_irq_stat(cpu, local_timer_irqs));
499
500 seq_printf(p, " Local timer interrupts\n");
501}
472#endif 502#endif
473 503
474#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST 504#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
475static void smp_timer_broadcast(const struct cpumask *mask) 505static void smp_timer_broadcast(const struct cpumask *mask)
476{ 506{
477 send_ipi_message(mask, IPI_TIMER); 507 smp_cross_call(mask, IPI_TIMER);
478} 508}
479#else 509#else
480#define smp_timer_broadcast NULL 510#define smp_timer_broadcast NULL
@@ -511,6 +541,21 @@ void __cpuinit percpu_timer_setup(void)
511 local_timer_setup(evt); 541 local_timer_setup(evt);
512} 542}
513 543
544#ifdef CONFIG_HOTPLUG_CPU
545/*
546 * The generic clock events code purposely does not stop the local timer
547 * on CPU_DEAD/CPU_DEAD_FROZEN hotplug events, so we have to do it
548 * manually here.
549 */
550static void percpu_timer_stop(void)
551{
552 unsigned int cpu = smp_processor_id();
553 struct clock_event_device *evt = &per_cpu(percpu_clockevent, cpu);
554
555 evt->set_mode(CLOCK_EVT_MODE_UNUSED, evt);
556}
557#endif
558
514static DEFINE_SPINLOCK(stop_lock); 559static DEFINE_SPINLOCK(stop_lock);
515 560
516/* 561/*
@@ -537,216 +582,76 @@ static void ipi_cpu_stop(unsigned int cpu)
537 582
538/* 583/*
539 * Main handler for inter-processor interrupts 584 * Main handler for inter-processor interrupts
540 *
541 * For ARM, the ipimask now only identifies a single
542 * category of IPI (Bit 1 IPIs have been replaced by a
543 * different mechanism):
544 *
545 * Bit 0 - Inter-processor function call
546 */ 585 */
547asmlinkage void __exception_irq_entry do_IPI(struct pt_regs *regs) 586asmlinkage void __exception_irq_entry do_IPI(int ipinr, struct pt_regs *regs)
548{ 587{
549 unsigned int cpu = smp_processor_id(); 588 unsigned int cpu = smp_processor_id();
550 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
551 struct pt_regs *old_regs = set_irq_regs(regs); 589 struct pt_regs *old_regs = set_irq_regs(regs);
552 590
553 ipi->ipi_count++; 591 if (ipinr >= IPI_TIMER && ipinr < IPI_TIMER + NR_IPI)
554 592 __inc_irq_stat(cpu, ipi_irqs[ipinr - IPI_TIMER]);
555 for (;;) {
556 unsigned long msgs;
557 593
558 spin_lock(&ipi->lock); 594 switch (ipinr) {
559 msgs = ipi->bits; 595 case IPI_TIMER:
560 ipi->bits = 0; 596 ipi_timer();
561 spin_unlock(&ipi->lock); 597 break;
562
563 if (!msgs)
564 break;
565
566 do {
567 unsigned nextmsg;
568
569 nextmsg = msgs & -msgs;
570 msgs &= ~nextmsg;
571 nextmsg = ffz(~nextmsg);
572
573 switch (nextmsg) {
574 case IPI_TIMER:
575 ipi_timer();
576 break;
577 598
578 case IPI_RESCHEDULE: 599 case IPI_RESCHEDULE:
579 /* 600 /*
580 * nothing more to do - eveything is 601 * nothing more to do - eveything is
581 * done on the interrupt return path 602 * done on the interrupt return path
582 */ 603 */
583 break; 604 break;
584 605
585 case IPI_CALL_FUNC: 606 case IPI_CALL_FUNC:
586 generic_smp_call_function_interrupt(); 607 generic_smp_call_function_interrupt();
587 break; 608 break;
588 609
589 case IPI_CALL_FUNC_SINGLE: 610 case IPI_CALL_FUNC_SINGLE:
590 generic_smp_call_function_single_interrupt(); 611 generic_smp_call_function_single_interrupt();
591 break; 612 break;
592 613
593 case IPI_CPU_STOP: 614 case IPI_CPU_STOP:
594 ipi_cpu_stop(cpu); 615 ipi_cpu_stop(cpu);
595 break; 616 break;
596 617
597 default: 618 default:
598 printk(KERN_CRIT "CPU%u: Unknown IPI message 0x%x\n", 619 printk(KERN_CRIT "CPU%u: Unknown IPI message 0x%x\n",
599 cpu, nextmsg); 620 cpu, ipinr);
600 break; 621 break;
601 }
602 } while (msgs);
603 } 622 }
604
605 set_irq_regs(old_regs); 623 set_irq_regs(old_regs);
606} 624}
607 625
608void smp_send_reschedule(int cpu) 626void smp_send_reschedule(int cpu)
609{ 627{
610 send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE); 628 smp_cross_call(cpumask_of(cpu), IPI_RESCHEDULE);
611} 629}
612 630
613void smp_send_stop(void) 631void smp_send_stop(void)
614{ 632{
615 cpumask_t mask = cpu_online_map; 633 unsigned long timeout;
616 cpu_clear(smp_processor_id(), mask);
617 if (!cpus_empty(mask))
618 send_ipi_message(&mask, IPI_CPU_STOP);
619}
620 634
621/* 635 if (num_online_cpus() > 1) {
622 * not supported here 636 cpumask_t mask = cpu_online_map;
623 */ 637 cpu_clear(smp_processor_id(), mask);
624int setup_profiling_timer(unsigned int multiplier)
625{
626 return -EINVAL;
627}
628 638
629static void 639 smp_cross_call(&mask, IPI_CPU_STOP);
630on_each_cpu_mask(void (*func)(void *), void *info, int wait, 640 }
631 const struct cpumask *mask)
632{
633 preempt_disable();
634 641
635 smp_call_function_many(mask, func, info, wait); 642 /* Wait up to one second for other CPUs to stop */
636 if (cpumask_test_cpu(smp_processor_id(), mask)) 643 timeout = USEC_PER_SEC;
637 func(info); 644 while (num_online_cpus() > 1 && timeout--)
645 udelay(1);
638 646
639 preempt_enable(); 647 if (num_online_cpus() > 1)
648 pr_warning("SMP: failed to stop secondary CPUs\n");
640} 649}
641 650
642/**********************************************************************/
643
644/* 651/*
645 * TLB operations 652 * not supported here
646 */ 653 */
647struct tlb_args { 654int setup_profiling_timer(unsigned int multiplier)
648 struct vm_area_struct *ta_vma;
649 unsigned long ta_start;
650 unsigned long ta_end;
651};
652
653static inline void ipi_flush_tlb_all(void *ignored)
654{
655 local_flush_tlb_all();
656}
657
658static inline void ipi_flush_tlb_mm(void *arg)
659{
660 struct mm_struct *mm = (struct mm_struct *)arg;
661
662 local_flush_tlb_mm(mm);
663}
664
665static inline void ipi_flush_tlb_page(void *arg)
666{
667 struct tlb_args *ta = (struct tlb_args *)arg;
668
669 local_flush_tlb_page(ta->ta_vma, ta->ta_start);
670}
671
672static inline void ipi_flush_tlb_kernel_page(void *arg)
673{
674 struct tlb_args *ta = (struct tlb_args *)arg;
675
676 local_flush_tlb_kernel_page(ta->ta_start);
677}
678
679static inline void ipi_flush_tlb_range(void *arg)
680{
681 struct tlb_args *ta = (struct tlb_args *)arg;
682
683 local_flush_tlb_range(ta->ta_vma, ta->ta_start, ta->ta_end);
684}
685
686static inline void ipi_flush_tlb_kernel_range(void *arg)
687{
688 struct tlb_args *ta = (struct tlb_args *)arg;
689
690 local_flush_tlb_kernel_range(ta->ta_start, ta->ta_end);
691}
692
693void flush_tlb_all(void)
694{
695 if (tlb_ops_need_broadcast())
696 on_each_cpu(ipi_flush_tlb_all, NULL, 1);
697 else
698 local_flush_tlb_all();
699}
700
701void flush_tlb_mm(struct mm_struct *mm)
702{
703 if (tlb_ops_need_broadcast())
704 on_each_cpu_mask(ipi_flush_tlb_mm, mm, 1, mm_cpumask(mm));
705 else
706 local_flush_tlb_mm(mm);
707}
708
709void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
710{
711 if (tlb_ops_need_broadcast()) {
712 struct tlb_args ta;
713 ta.ta_vma = vma;
714 ta.ta_start = uaddr;
715 on_each_cpu_mask(ipi_flush_tlb_page, &ta, 1, mm_cpumask(vma->vm_mm));
716 } else
717 local_flush_tlb_page(vma, uaddr);
718}
719
720void flush_tlb_kernel_page(unsigned long kaddr)
721{
722 if (tlb_ops_need_broadcast()) {
723 struct tlb_args ta;
724 ta.ta_start = kaddr;
725 on_each_cpu(ipi_flush_tlb_kernel_page, &ta, 1);
726 } else
727 local_flush_tlb_kernel_page(kaddr);
728}
729
730void flush_tlb_range(struct vm_area_struct *vma,
731 unsigned long start, unsigned long end)
732{
733 if (tlb_ops_need_broadcast()) {
734 struct tlb_args ta;
735 ta.ta_vma = vma;
736 ta.ta_start = start;
737 ta.ta_end = end;
738 on_each_cpu_mask(ipi_flush_tlb_range, &ta, 1, mm_cpumask(vma->vm_mm));
739 } else
740 local_flush_tlb_range(vma, start, end);
741}
742
743void flush_tlb_kernel_range(unsigned long start, unsigned long end)
744{ 655{
745 if (tlb_ops_need_broadcast()) { 656 return -EINVAL;
746 struct tlb_args ta;
747 ta.ta_start = start;
748 ta.ta_end = end;
749 on_each_cpu(ipi_flush_tlb_kernel_range, &ta, 1);
750 } else
751 local_flush_tlb_kernel_range(start, end);
752} 657}