Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-2.6
[pandora-kernel.git] / arch / x86 / kernel / apic / hw_nmi.c
1 /*
2  *  HW NMI watchdog support
3  *
4  *  started by Don Zickus, Copyright (C) 2010 Red Hat, Inc.
5  *
6  *  Arch specific calls to support NMI watchdog
7  *
8  *  Bits copied from original nmi.c file
9  *
10  */
11 #include <asm/apic.h>
12
13 #include <linux/cpumask.h>
14 #include <linux/kdebug.h>
15 #include <linux/notifier.h>
16 #include <linux/kprobes.h>
17 #include <linux/nmi.h>
18 #include <linux/module.h>
19
20 u64 hw_nmi_get_sample_period(void)
21 {
22         return (u64)(cpu_khz) * 1000 * 60;
23 }
24
25 #ifdef ARCH_HAS_NMI_WATCHDOG
26
27 /* For reliability, we're prepared to waste bits here. */
28 static DECLARE_BITMAP(backtrace_mask, NR_CPUS) __read_mostly;
29
30 void arch_trigger_all_cpu_backtrace(void)
31 {
32         int i;
33
34         cpumask_copy(to_cpumask(backtrace_mask), cpu_online_mask);
35
36         printk(KERN_INFO "sending NMI to all CPUs:\n");
37         apic->send_IPI_all(NMI_VECTOR);
38
39         /* Wait for up to 10 seconds for all CPUs to do the backtrace */
40         for (i = 0; i < 10 * 1000; i++) {
41                 if (cpumask_empty(to_cpumask(backtrace_mask)))
42                         break;
43                 mdelay(1);
44         }
45 }
46
47 static int __kprobes
48 arch_trigger_all_cpu_backtrace_handler(struct notifier_block *self,
49                          unsigned long cmd, void *__args)
50 {
51         struct die_args *args = __args;
52         struct pt_regs *regs;
53         int cpu = smp_processor_id();
54
55         switch (cmd) {
56         case DIE_NMI:
57         case DIE_NMI_IPI:
58                 break;
59
60         default:
61                 return NOTIFY_DONE;
62         }
63
64         regs = args->regs;
65
66         if (cpumask_test_cpu(cpu, to_cpumask(backtrace_mask))) {
67                 static arch_spinlock_t lock = __ARCH_SPIN_LOCK_UNLOCKED;
68
69                 arch_spin_lock(&lock);
70                 printk(KERN_WARNING "NMI backtrace for cpu %d\n", cpu);
71                 show_regs(regs);
72                 dump_stack();
73                 arch_spin_unlock(&lock);
74                 cpumask_clear_cpu(cpu, to_cpumask(backtrace_mask));
75                 return NOTIFY_STOP;
76         }
77
78         return NOTIFY_DONE;
79 }
80
81 static __read_mostly struct notifier_block backtrace_notifier = {
82         .notifier_call          = arch_trigger_all_cpu_backtrace_handler,
83         .next                   = NULL,
84         .priority               = 1
85 };
86
87 static int __init register_trigger_all_cpu_backtrace(void)
88 {
89         register_die_notifier(&backtrace_notifier);
90         return 0;
91 }
92 early_initcall(register_trigger_all_cpu_backtrace);
93 #endif
94
95 /* STUB calls to mimic old nmi_watchdog behaviour */
96 #if defined(CONFIG_X86_LOCAL_APIC)
97 unsigned int nmi_watchdog = NMI_NONE;
98 EXPORT_SYMBOL(nmi_watchdog);
99 void acpi_nmi_enable(void) { return; }
100 void acpi_nmi_disable(void) { return; }
101 #endif
102 atomic_t nmi_active = ATOMIC_INIT(0);           /* oprofile uses this */
103 EXPORT_SYMBOL(nmi_active);
104 int unknown_nmi_panic;
105 void cpu_nmi_set_wd_enabled(void) { return; }
106 void stop_apic_nmi_watchdog(void *unused) { return; }
107 void setup_apic_nmi_watchdog(void *unused) { return; }
108 int __init check_nmi_watchdog(void) { return 0; }