hw_nmi.c 2.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/*
 *  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
 *
 */
11
#include <asm/apic.h>
12 13

#include <linux/cpumask.h>
14 15 16
#include <linux/kdebug.h>
#include <linux/notifier.h>
#include <linux/kprobes.h>
17 18
#include <linux/nmi.h>
#include <linux/module.h>
19
#include <linux/delay.h>
20

21
#ifdef CONFIG_HARDLOCKUP_DETECTOR
22
u64 hw_nmi_get_sample_period(int watchdog_thresh)
23
{
24
	return (u64)(cpu_khz) * 1000 * watchdog_thresh;
25
}
26
#endif
27

28
#ifdef arch_trigger_all_cpu_backtrace
29 30 31
/* For reliability, we're prepared to waste bits here. */
static DECLARE_BITMAP(backtrace_mask, NR_CPUS) __read_mostly;

32 33 34
/* "in progress" flag of arch_trigger_all_cpu_backtrace */
static unsigned long backtrace_flag;

35 36 37 38
void arch_trigger_all_cpu_backtrace(void)
{
	int i;

39 40 41 42 43 44 45
	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;

46 47 48 49 50 51 52 53 54 55 56
	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);
	}
57 58 59

	clear_bit(0, &backtrace_flag);
	smp_mb__after_clear_bit();
60
}
61 62

static int __kprobes
63
arch_trigger_all_cpu_backtrace_handler(unsigned int cmd, struct pt_regs *regs)
64
{
65
	int cpu;
66

67
	cpu = smp_processor_id();
68 69 70 71 72 73 74 75 76

	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));
77
		return NMI_HANDLED;
78 79
	}

80
	return NMI_DONE;
81 82 83 84
}

static int __init register_trigger_all_cpu_backtrace(void)
{
85 86
	register_nmi_handler(NMI_LOCAL, arch_trigger_all_cpu_backtrace_handler,
				0, "arch_bt");
87 88 89
	return 0;
}
early_initcall(register_trigger_all_cpu_backtrace);
90
#endif