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>
21 #include <linux/nmi.h>
22 #include <linux/module.h>
24 /* For reliability, we're prepared to waste bits here. */
25 static DECLARE_BITMAP(backtrace_mask, NR_CPUS) __read_mostly;
27 static DEFINE_PER_CPU(unsigned, last_irq_sum);
30 * Take the local apic timer and PIT/HPET into account. We don't
31 * know which one is active, when we have highres/dyntick on
33 static inline unsigned int get_timer_irqs(int cpu)
35 unsigned int irqs = per_cpu(irq_stat, cpu).irq0_irqs;
37 #if defined(CONFIG_X86_LOCAL_APIC)
38 irqs += per_cpu(irq_stat, cpu).apic_timer_irqs;
44 static inline int mce_in_progress(void)
46 #if defined(CONFIG_X86_MCE)
47 return atomic_read(&mce_entry) > 0;
52 int hw_nmi_is_cpu_stuck(struct pt_regs *regs)
55 int cpu = smp_processor_id();
57 /* FIXME: cheap hack for this check, probably should get its own
58 * die_notifier handler
60 if (cpumask_test_cpu(cpu, to_cpumask(backtrace_mask))) {
61 static DEFINE_SPINLOCK(lock); /* Serialise the printks */
64 printk(KERN_WARNING "NMI backtrace for cpu %d\n", cpu);
68 cpumask_clear_cpu(cpu, to_cpumask(backtrace_mask));
71 /* if we are doing an mce, just assume the cpu is not stuck */
72 /* Could check oops_in_progress here too, but it's safer not to */
73 if (mce_in_progress())
76 /* We determine if the cpu is stuck by checking whether any
77 * interrupts have happened since we last checked. Of course
78 * an nmi storm could create false positives, but the higher
79 * level logic should account for that
81 sum = get_timer_irqs(cpu);
82 if (__get_cpu_var(last_irq_sum) == sum) {
85 __get_cpu_var(last_irq_sum) = sum;
90 u64 hw_nmi_get_sample_period(void)
92 return (u64)(cpu_khz) * 1000 * 60;
95 #ifdef ARCH_HAS_NMI_WATCHDOG
96 void arch_trigger_all_cpu_backtrace(void)
100 cpumask_copy(to_cpumask(backtrace_mask), cpu_online_mask);
102 printk(KERN_INFO "sending NMI to all CPUs:\n");
103 apic->send_IPI_all(NMI_VECTOR);
105 /* Wait for up to 10 seconds for all CPUs to do the backtrace */
106 for (i = 0; i < 10 * 1000; i++) {
107 if (cpumask_empty(to_cpumask(backtrace_mask)))
114 /* STUB calls to mimic old nmi_watchdog behaviour */
115 #if defined(CONFIG_X86_LOCAL_APIC)
116 unsigned int nmi_watchdog = NMI_NONE;
117 EXPORT_SYMBOL(nmi_watchdog);
118 void acpi_nmi_enable(void) { return; }
119 void acpi_nmi_disable(void) { return; }
121 atomic_t nmi_active = ATOMIC_INIT(0); /* oprofile uses this */
122 EXPORT_SYMBOL(nmi_active);
123 int unknown_nmi_panic;
124 void cpu_nmi_set_wd_enabled(void) { return; }
125 void stop_apic_nmi_watchdog(void *unused) { return; }
126 void setup_apic_nmi_watchdog(void *unused) { return; }
127 int __init check_nmi_watchdog(void) { return 0; }