2 * HW NMI watchdog support
4 * started by Don Zickus, Copyright (C) 2010 Red Hat, Inc.
6 * Arch specific calls to support NMI watchdog
8 * Bits copied from original nmi.c file
13 #include <linux/smp.h>
14 #include <linux/cpumask.h>
15 #include <linux/sched.h>
16 #include <linux/percpu.h>
17 #include <linux/cpumask.h>
18 #include <linux/kernel_stat.h>
20 #include <linux/kdebug.h>
21 #include <linux/notifier.h>
22 #include <linux/kprobes.h>
25 #include <linux/nmi.h>
26 #include <linux/module.h>
28 /* For reliability, we're prepared to waste bits here. */
29 static DECLARE_BITMAP(backtrace_mask
, NR_CPUS
) __read_mostly
;
31 static DEFINE_PER_CPU(unsigned, last_irq_sum
);
34 * Take the local apic timer and PIT/HPET into account. We don't
35 * know which one is active, when we have highres/dyntick on
37 static inline unsigned int get_timer_irqs(int cpu
)
39 unsigned int irqs
= per_cpu(irq_stat
, cpu
).irq0_irqs
;
41 #if defined(CONFIG_X86_LOCAL_APIC)
42 irqs
+= per_cpu(irq_stat
, cpu
).apic_timer_irqs
;
48 static inline int mce_in_progress(void)
50 #if defined(CONFIG_X86_MCE)
51 return atomic_read(&mce_entry
) > 0;
56 int hw_nmi_is_cpu_stuck(struct pt_regs
*regs
)
59 int cpu
= smp_processor_id();
61 /* if we are doing an mce, just assume the cpu is not stuck */
62 /* Could check oops_in_progress here too, but it's safer not to */
63 if (mce_in_progress())
66 /* We determine if the cpu is stuck by checking whether any
67 * interrupts have happened since we last checked. Of course
68 * an nmi storm could create false positives, but the higher
69 * level logic should account for that
71 sum
= get_timer_irqs(cpu
);
72 if (__get_cpu_var(last_irq_sum
) == sum
) {
75 __get_cpu_var(last_irq_sum
) = sum
;
80 u64
hw_nmi_get_sample_period(void)
82 return (u64
)(cpu_khz
) * 1000 * 60;
85 #ifdef ARCH_HAS_NMI_WATCHDOG
86 void arch_trigger_all_cpu_backtrace(void)
90 cpumask_copy(to_cpumask(backtrace_mask
), cpu_online_mask
);
92 printk(KERN_INFO
"sending NMI to all CPUs:\n");
93 apic
->send_IPI_all(NMI_VECTOR
);
95 /* Wait for up to 10 seconds for all CPUs to do the backtrace */
96 for (i
= 0; i
< 10 * 1000; i
++) {
97 if (cpumask_empty(to_cpumask(backtrace_mask
)))
104 arch_trigger_all_cpu_backtrace_handler(struct notifier_block
*self
,
105 unsigned long cmd
, void *__args
)
107 struct die_args
*args
= __args
;
108 struct pt_regs
*regs
;
109 int cpu
= smp_processor_id();
122 if (cpumask_test_cpu(cpu
, to_cpumask(backtrace_mask
))) {
123 static arch_spinlock_t lock
= __ARCH_SPIN_LOCK_UNLOCKED
;
125 arch_spin_lock(&lock
);
126 printk(KERN_WARNING
"NMI backtrace for cpu %d\n", cpu
);
129 arch_spin_unlock(&lock
);
130 cpumask_clear_cpu(cpu
, to_cpumask(backtrace_mask
));
137 static __read_mostly
struct notifier_block backtrace_notifier
= {
138 .notifier_call
= arch_trigger_all_cpu_backtrace_handler
,
143 static int __init
register_trigger_all_cpu_backtrace(void)
145 register_die_notifier(&backtrace_notifier
);
148 early_initcall(register_trigger_all_cpu_backtrace
);
151 /* STUB calls to mimic old nmi_watchdog behaviour */
152 #if defined(CONFIG_X86_LOCAL_APIC)
153 unsigned int nmi_watchdog
= NMI_NONE
;
154 EXPORT_SYMBOL(nmi_watchdog
);
155 void acpi_nmi_enable(void) { return; }
156 void acpi_nmi_disable(void) { return; }
158 atomic_t nmi_active
= ATOMIC_INIT(0); /* oprofile uses this */
159 EXPORT_SYMBOL(nmi_active
);
160 int unknown_nmi_panic
;
161 void cpu_nmi_set_wd_enabled(void) { return; }
162 void stop_apic_nmi_watchdog(void *unused
) { return; }
163 void setup_apic_nmi_watchdog(void *unused
) { return; }
164 int __init
check_nmi_watchdog(void) { return 0; }