2010-02-06 10:47:04 +08:00
|
|
|
/*
|
|
|
|
* HW NMI watchdog support
|
|
|
|
*
|
|
|
|
* started by Don Zickus, Copyright (C) 2010 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Arch specific calls to support NMI watchdog
|
|
|
|
*
|
|
|
|
* Bits copied from original nmi.c file
|
|
|
|
*
|
|
|
|
*/
|
2010-05-13 15:12:39 +08:00
|
|
|
#include <asm/apic.h>
|
2010-02-06 10:47:04 +08:00
|
|
|
|
|
|
|
#include <linux/cpumask.h>
|
2010-05-08 05:11:48 +08:00
|
|
|
#include <linux/kdebug.h>
|
|
|
|
#include <linux/notifier.h>
|
|
|
|
#include <linux/kprobes.h>
|
2010-02-06 10:47:04 +08:00
|
|
|
#include <linux/nmi.h>
|
|
|
|
#include <linux/module.h>
|
2011-03-25 22:20:14 +08:00
|
|
|
#include <linux/delay.h>
|
2010-02-06 10:47:04 +08:00
|
|
|
|
2010-11-13 00:22:23 +08:00
|
|
|
#ifdef CONFIG_HARDLOCKUP_DETECTOR
|
2011-05-23 13:10:23 +08:00
|
|
|
u64 hw_nmi_get_sample_period(int watchdog_thresh)
|
2010-02-13 06:19:19 +08:00
|
|
|
{
|
2011-05-23 13:10:23 +08:00
|
|
|
return (u64)(cpu_khz) * 1000 * watchdog_thresh;
|
2010-02-13 06:19:19 +08:00
|
|
|
}
|
2010-11-13 00:22:23 +08:00
|
|
|
#endif
|
2010-02-13 06:19:19 +08:00
|
|
|
|
2010-12-09 16:47:34 +08:00
|
|
|
#ifdef arch_trigger_all_cpu_backtrace
|
2010-11-12 22:50:54 +08:00
|
|
|
/* For reliability, we're prepared to waste bits here. */
|
|
|
|
static DECLARE_BITMAP(backtrace_mask, NR_CPUS) __read_mostly;
|
|
|
|
|
2011-01-05 11:38:08 +08:00
|
|
|
/* "in progress" flag of arch_trigger_all_cpu_backtrace */
|
|
|
|
static unsigned long backtrace_flag;
|
|
|
|
|
2010-02-06 10:47:04 +08:00
|
|
|
void arch_trigger_all_cpu_backtrace(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2011-01-05 11:38:08 +08:00
|
|
|
if (test_and_set_bit(0, &backtrace_flag))
|
|
|
|
/*
|
|
|
|
* If there is already a trigger_all_cpu_backtrace() in progress
|
|
|
|
* (backtrace_flag == 1), don't output double cpu dump infos.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
|
2010-02-06 10:47:04 +08:00
|
|
|
cpumask_copy(to_cpumask(backtrace_mask), cpu_online_mask);
|
|
|
|
|
|
|
|
printk(KERN_INFO "sending NMI to all CPUs:\n");
|
|
|
|
apic->send_IPI_all(NMI_VECTOR);
|
|
|
|
|
|
|
|
/* Wait for up to 10 seconds for all CPUs to do the backtrace */
|
|
|
|
for (i = 0; i < 10 * 1000; i++) {
|
|
|
|
if (cpumask_empty(to_cpumask(backtrace_mask)))
|
|
|
|
break;
|
|
|
|
mdelay(1);
|
|
|
|
}
|
2011-01-05 11:38:08 +08:00
|
|
|
|
|
|
|
clear_bit(0, &backtrace_flag);
|
|
|
|
smp_mb__after_clear_bit();
|
2010-02-06 10:47:04 +08:00
|
|
|
}
|
2010-05-08 05:11:48 +08:00
|
|
|
|
|
|
|
static int __kprobes
|
|
|
|
arch_trigger_all_cpu_backtrace_handler(struct notifier_block *self,
|
|
|
|
unsigned long cmd, void *__args)
|
|
|
|
{
|
|
|
|
struct die_args *args = __args;
|
|
|
|
struct pt_regs *regs;
|
2011-01-05 11:38:07 +08:00
|
|
|
int cpu;
|
2010-05-08 05:11:48 +08:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case DIE_NMI:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
regs = args->regs;
|
2011-01-05 11:38:07 +08:00
|
|
|
cpu = smp_processor_id();
|
2010-05-08 05:11:48 +08:00
|
|
|
|
|
|
|
if (cpumask_test_cpu(cpu, to_cpumask(backtrace_mask))) {
|
|
|
|
static arch_spinlock_t lock = __ARCH_SPIN_LOCK_UNLOCKED;
|
|
|
|
|
|
|
|
arch_spin_lock(&lock);
|
|
|
|
printk(KERN_WARNING "NMI backtrace for cpu %d\n", cpu);
|
|
|
|
show_regs(regs);
|
|
|
|
arch_spin_unlock(&lock);
|
|
|
|
cpumask_clear_cpu(cpu, to_cpumask(backtrace_mask));
|
|
|
|
return NOTIFY_STOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __read_mostly struct notifier_block backtrace_notifier = {
|
|
|
|
.notifier_call = arch_trigger_all_cpu_backtrace_handler,
|
|
|
|
.next = NULL,
|
2011-01-07 05:18:49 +08:00
|
|
|
.priority = NMI_LOCAL_LOW_PRIOR,
|
2010-05-08 05:11:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init register_trigger_all_cpu_backtrace(void)
|
|
|
|
{
|
|
|
|
register_die_notifier(&backtrace_notifier);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
early_initcall(register_trigger_all_cpu_backtrace);
|
2010-02-19 10:56:52 +08:00
|
|
|
#endif
|