x86: nmi - unify die_nmi() interface
[cascardo/linux.git] / arch / x86 / kernel / nmi_32.c
index 6a0aa70..bd04a28 100644 (file)
 #include <linux/cpumask.h>
 #include <linux/kernel_stat.h>
 #include <linux/kdebug.h>
+#include <linux/slab.h>
 
 #include <asm/smp.h>
 #include <asm/nmi.h>
+#include <asm/timer.h>
 
 #include "mach_traps.h"
 
@@ -67,7 +69,7 @@ static __init void nmi_cpu_busy(void *data)
 }
 #endif
 
-static int __init check_nmi_watchdog(void)
+int __init check_nmi_watchdog(void)
 {
        unsigned int *prev_nmi_count;
        int cpu;
@@ -80,7 +82,7 @@ static int __init check_nmi_watchdog(void)
 
        prev_nmi_count = kmalloc(NR_CPUS * sizeof(int), GFP_KERNEL);
        if (!prev_nmi_count)
-               return -1;
+               goto error;
 
        printk(KERN_INFO "Testing NMI watchdog ... ");
 
@@ -117,7 +119,7 @@ static int __init check_nmi_watchdog(void)
        if (!atomic_read(&nmi_active)) {
                kfree(prev_nmi_count);
                atomic_set(&nmi_active, -1);
-               return -1;
+               goto error;
        }
        printk("OK.\n");
 
@@ -128,9 +130,11 @@ static int __init check_nmi_watchdog(void)
 
        kfree(prev_nmi_count);
        return 0;
+error:
+       timer_ack = !cpu_has_tsc;
+
+       return -1;
 }
-/* This needs to happen later in boot so counters are working */
-late_initcall(check_nmi_watchdog);
 
 static int __init setup_nmi_watchdog(char *str)
 {
@@ -289,9 +293,9 @@ void stop_apic_nmi_watchdog(void *unused)
  *  here too!]
  */
 
-static unsigned int
-       last_irq_sums [NR_CPUS],
-       alert_counter [NR_CPUS];
+static DEFINE_PER_CPU(unsigned, last_irq_sum);
+static DEFINE_PER_CPU(local_t, alert_counter);
+static DEFINE_PER_CPU(int, nmi_touch);
 
 void touch_nmi_watchdog(void)
 {
@@ -299,12 +303,13 @@ void touch_nmi_watchdog(void)
                unsigned cpu;
 
                /*
-                * Just reset the alert counters, (other CPUs might be
-                * spinning on locks we hold):
+                * Tell other CPUs to reset their alert counters. We cannot
+                * do it ourselves because the alert count increase is not
+                * atomic.
                 */
                for_each_present_cpu(cpu) {
-                       if (alert_counter[cpu])
-                               alert_counter[cpu] = 0;
+                       if (per_cpu(nmi_touch, cpu) != 1)
+                               per_cpu(nmi_touch, cpu) = 1;
                }
        }
 
@@ -315,9 +320,8 @@ void touch_nmi_watchdog(void)
 }
 EXPORT_SYMBOL(touch_nmi_watchdog);
 
-extern void die_nmi(struct pt_regs *, const char *msg);
-
-__kprobes int nmi_watchdog_tick(struct pt_regs * regs, unsigned reason)
+notrace __kprobes int
+nmi_watchdog_tick(struct pt_regs *regs, unsigned reason)
 {
 
        /*
@@ -353,22 +357,27 @@ __kprobes int nmi_watchdog_tick(struct pt_regs * regs, unsigned reason)
         */
        sum = per_cpu(irq_stat, cpu).apic_timer_irqs +
                per_cpu(irq_stat, cpu).irq0_irqs;
+       if (__get_cpu_var(nmi_touch)) {
+               __get_cpu_var(nmi_touch) = 0;
+               touched = 1;
+       }
 
        /* if the none of the timers isn't firing, this cpu isn't doing much */
-       if (!touched && last_irq_sums[cpu] == sum) {
+       if (!touched && __get_cpu_var(last_irq_sum) == sum) {
                /*
                 * Ayiee, looks like this CPU is stuck ...
                 * wait a few IRQs (5 seconds) before doing the oops ...
                 */
-               alert_counter[cpu]++;
-               if (alert_counter[cpu] == 5*nmi_hz)
+               local_inc(&__get_cpu_var(alert_counter));
+               if (local_read(&__get_cpu_var(alert_counter)) == 5*nmi_hz)
                        /*
                         * die_nmi will return ONLY if NOTIFY_STOP happens..
                         */
-                       die_nmi(regs, "BUG: NMI Watchdog detected LOCKUP");
+                       die_nmi("BUG: NMI Watchdog detected LOCKUP",
+                               regs, 0);
        } else {
-               last_irq_sums[cpu] = sum;
-               alert_counter[cpu] = 0;
+               __get_cpu_var(last_irq_sum) = sum;
+               local_set(&__get_cpu_var(alert_counter), 0);
        }
        /* see if the nmi watchdog went off */
        if (!__get_cpu_var(wd_enabled))
@@ -396,7 +405,7 @@ static int unknown_nmi_panic_callback(struct pt_regs *regs, int cpu)
        char buf[64];
 
        sprintf(buf, "NMI received for unknown reason %02x\n", reason);
-       die_nmi(regs, buf);
+       die_nmi(buf, regs, 0);
        return 0;
 }