lockup detector: Compile fixes from removing the old x86 nmi watchdog
[cascardo/linux.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 #ifdef CONFIG_HARDLOCKUP_DETECTOR
21 u64 hw_nmi_get_sample_period(void)
22 {
23         return (u64)(cpu_khz) * 1000 * 60;
24 }
25 #endif
26
27 #ifndef CONFIG_HARDLOCKUP_DETECTOR
28 void touch_nmi_watchdog(void)
29 {
30         touch_softlockup_watchdog();
31 }
32 EXPORT_SYMBOL(touch_nmi_watchdog);
33 #endif
34 #ifdef arch_trigger_all_cpu_backtrace
35 /* For reliability, we're prepared to waste bits here. */
36 static DECLARE_BITMAP(backtrace_mask, NR_CPUS) __read_mostly;
37
38 void arch_trigger_all_cpu_backtrace(void)
39 {
40         int i;
41
42         cpumask_copy(to_cpumask(backtrace_mask), cpu_online_mask);
43
44         printk(KERN_INFO "sending NMI to all CPUs:\n");
45         apic->send_IPI_all(NMI_VECTOR);
46
47         /* Wait for up to 10 seconds for all CPUs to do the backtrace */
48         for (i = 0; i < 10 * 1000; i++) {
49                 if (cpumask_empty(to_cpumask(backtrace_mask)))
50                         break;
51                 mdelay(1);
52         }
53 }
54
55 static int __kprobes
56 arch_trigger_all_cpu_backtrace_handler(struct notifier_block *self,
57                          unsigned long cmd, void *__args)
58 {
59         struct die_args *args = __args;
60         struct pt_regs *regs;
61         int cpu = smp_processor_id();
62
63         switch (cmd) {
64         case DIE_NMI:
65         case DIE_NMI_IPI:
66                 break;
67
68         default:
69                 return NOTIFY_DONE;
70         }
71
72         regs = args->regs;
73
74         if (cpumask_test_cpu(cpu, to_cpumask(backtrace_mask))) {
75                 static arch_spinlock_t lock = __ARCH_SPIN_LOCK_UNLOCKED;
76
77                 arch_spin_lock(&lock);
78                 printk(KERN_WARNING "NMI backtrace for cpu %d\n", cpu);
79                 show_regs(regs);
80                 dump_stack();
81                 arch_spin_unlock(&lock);
82                 cpumask_clear_cpu(cpu, to_cpumask(backtrace_mask));
83                 return NOTIFY_STOP;
84         }
85
86         return NOTIFY_DONE;
87 }
88
89 static __read_mostly struct notifier_block backtrace_notifier = {
90         .notifier_call          = arch_trigger_all_cpu_backtrace_handler,
91         .next                   = NULL,
92         .priority               = 1
93 };
94
95 static int __init register_trigger_all_cpu_backtrace(void)
96 {
97         register_die_notifier(&backtrace_notifier);
98         return 0;
99 }
100 early_initcall(register_trigger_all_cpu_backtrace);
101 #endif
102
103 /* STUB calls to mimic old nmi_watchdog behaviour */
104 int unknown_nmi_panic;