Skip to contentSkip to conversation

generic NMI watchdog for v2.6.34

GIT PULL Ingo Molnar 1 participant 1 message Mar 1, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Linus,

Please consider pulling the perf-nmi-for-linus git tree from:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git perf-nmi-for-linus

This tree adds a generic implementation of the x86 'NMI watchdog', in kernel/nmi_watchdog.c. This is based on struct perf_event and hence will allow the gradual phasing-out of the arch/x86/kernel/cpu/perfctr-watchdog.c code.

We placed it in kernel/ to enable other architectures to make use of it as well in the future. An architecture can enable it by providing the PERF_EVENTS_NMI Kconfig switch.

Thanks,

Ingo

------------------>
Don Zickus (10):
x86: Move notify_die from nmi.c to traps.c
nmi_watchdog: Add new, generic implementation, using perf events
nmi_watchdog: Config option to enable new nmi_watchdog
nmi_watchdog: Use a boolean config flag for compiling
nmi_watchdog: Compile and portability fixes
nmi_watchdog: Fallback to software events when no hardware pmu detected
nmi_watchdog: support for oprofile
nmi_watchdog: Properly configure for software events
nmi_watchdog: Fix undefined 'apic' build bug
nmi_watchdog: Clean up various small details

Ingo Molnar (2):
nmi_watchdog: Only enable on x86 for now
nmi_watchdog: Turn it off by default

 arch/x86/Kconfig              |    1 +
 arch/x86/include/asm/nmi.h    |    2 +
 arch/x86/kernel/apic/Makefile |    7 +-
 arch/x86/kernel/apic/hw_nmi.c |  127 ++++++++++++++++++++
 arch/x86/kernel/apic/nmi.c    |    7 -
 arch/x86/kernel/traps.c       |    7 +
 include/linux/nmi.h           |   13 ++
 init/Kconfig                  |    5 +
 kernel/Makefile               |    1 +
 kernel/nmi_watchdog.c         |  257 +++++++++++++++++++++++++++++++++++++++++
 kernel/sysctl.c               |   15 +++-
 lib/Kconfig.debug             |   12 ++
 12 files changed, 445 insertions(+), 9 deletions(-)
 create mode 100644 arch/x86/kernel/apic/hw_nmi.c
 create mode 100644 kernel/nmi_watchdog.c
arch/x86/Kconfig +1 -0
index cbcbfde..4f9685f 100644
@@ -52,6 +52,7 @@ config X86
 	select HAVE_KERNEL_LZO
 	select HAVE_HW_BREAKPOINT
 	select PERF_EVENTS
+	select PERF_EVENTS_NMI
 	select ANON_INODES
 	select HAVE_ARCH_KMEMCHECK
 	select HAVE_USER_RETURN_NOTIFIER
arch/x86/include/asm/nmi.h +2 -0
index 93da9c3..5b41b0f 100644
@@ -17,7 +17,9 @@ int do_nmi_callback(struct pt_regs *regs, int cpu);
 
 extern void die_nmi(char *str, struct pt_regs *regs, int do_panic);
 extern int check_nmi_watchdog(void);
+#if !defined(CONFIG_NMI_WATCHDOG)
 extern int nmi_watchdog_enabled;
+#endif
 extern int avail_to_resrv_perfctr_nmi_bit(unsigned int);
 extern int reserve_perfctr_nmi(unsigned int);
 extern void release_perfctr_nmi(unsigned int);
arch/x86/kernel/apic/Makefile +6 -1
index 565c1bf..1a4512e 100644
@@ -2,7 +2,12 @@
 # Makefile for local APIC drivers and for the IO-APIC code
 #
 
-obj-$(CONFIG_X86_LOCAL_APIC)	+= apic.o apic_noop.o probe_$(BITS).o ipi.o nmi.o
+obj-$(CONFIG_X86_LOCAL_APIC)	+= apic.o apic_noop.o probe_$(BITS).o ipi.o
+ifneq ($(CONFIG_NMI_WATCHDOG),y)
+obj-$(CONFIG_X86_LOCAL_APIC)	+= nmi.o
+endif
+obj-$(CONFIG_NMI_WATCHDOG)	+= hw_nmi.o
+
 obj-$(CONFIG_X86_IO_APIC)	+= io_apic.o
 obj-$(CONFIG_SMP)		+= ipi.o
 
arch/x86/kernel/apic/hw_nmi.c new file +127 -0

127 lines not on this page · raw message

arch/x86/kernel/apic/nmi.c +0 -7
index 0159a69..5d47682 100644
@@ -400,13 +400,6 @@ nmi_watchdog_tick(struct pt_regs *regs, unsigned reason)
 	int cpu = smp_processor_id();
 	int rc = 0;
 
-	/* check for other users first */
-	if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT)
-			== NOTIFY_STOP) {
-		rc = 1;
-		touched = 1;
-	}
-
 	sum = get_timer_irqs(cpu);
 
 	if (__get_cpu_var(nmi_touch)) {
arch/x86/kernel/traps.c +7 -0
index 1168e44..bdc7fab 100644
@@ -400,7 +400,13 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
 		if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT)
 								== NOTIFY_STOP)
 			return;
+
 #ifdef CONFIG_X86_LOCAL_APIC
+		if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT)
+							== NOTIFY_STOP)
+			return;
+
+#ifndef CONFIG_NMI_WATCHDOG
 		/*
 		 * Ok, so this is none of the documented NMI sources,
 		 * so it must be the NMI watchdog.
@@ -408,6 +414,7 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
 		if (nmi_watchdog_tick(regs, reason))
 			return;
 		if (!do_nmi_callback(regs, cpu))
+#endif /* !CONFIG_NMI_WATCHDOG */
 			unknown_nmi_error(reason, regs);
 #else
 		unknown_nmi_error(reason, regs);
include/linux/nmi.h +13 -0
index b752e80..22cc796 100644
@@ -20,10 +20,14 @@ extern void touch_nmi_watchdog(void);
 extern void acpi_nmi_disable(void);
 extern void acpi_nmi_enable(void);
 #else
+#ifndef CONFIG_NMI_WATCHDOG
 static inline void touch_nmi_watchdog(void)
 {
 	touch_softlockup_watchdog();
 }
+#else
+extern void touch_nmi_watchdog(void);
+#endif
 static inline void acpi_nmi_disable(void) { }
 static inline void acpi_nmi_enable(void) { }
 #endif
@@ -47,4 +51,13 @@ static inline bool trigger_all_cpu_backtrace(void)
 }
 #endif
 
+#ifdef CONFIG_NMI_WATCHDOG
+int hw_nmi_is_cpu_stuck(struct pt_regs *);
+u64 hw_nmi_get_sample_period(void);
+extern int nmi_watchdog_enabled;
+struct ctl_table;
+extern int proc_nmi_enabled(struct ctl_table *, int ,
+			void __user *, size_t *, loff_t *);
+#endif
+
 #endif
init/Kconfig +5 -0
index ada4844..7331a16 100644
@@ -946,6 +946,11 @@ config PERF_USE_VMALLOC
 	help
 	  See tools/perf/design.txt for details
 
+config PERF_EVENTS_NMI
+	bool
+	help
+	  Arch has support for nmi_watchdog
+
 menu "Kernel Performance Events And Counters"
 
 config PERF_EVENTS
kernel/Makefile +1 -0
index 864ff75..8a5abe5 100644
@@ -76,6 +76,7 @@ obj-$(CONFIG_AUDIT_TREE) += audit_tree.o
 obj-$(CONFIG_KPROBES) += kprobes.o
 obj-$(CONFIG_KGDB) += kgdb.o
 obj-$(CONFIG_DETECT_SOFTLOCKUP) += softlockup.o
+obj-$(CONFIG_NMI_WATCHDOG) += nmi_watchdog.o
 obj-$(CONFIG_DETECT_HUNG_TASK) += hung_task.o
 obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
 obj-$(CONFIG_SECCOMP) += seccomp.o
kernel/nmi_watchdog.c new file +257 -0

257 lines not on this page · raw message

kernel/sysctl.c +14 -1
index 8a68b24..ac72c9e 100644
@@ -60,6 +60,10 @@
 #include <asm/io.h>
 #endif
 
+#ifdef CONFIG_NMI_WATCHDOG
+#include <linux/nmi.h>
+#endif
+
 
 #if defined(CONFIG_SYSCTL)
 
@@ -692,7 +696,16 @@ static struct ctl_table kern_table[] = {
 		.mode		= 0444,
 		.proc_handler	= proc_dointvec,
 	},
-#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
+#if defined(CONFIG_NMI_WATCHDOG)
+	{
+		.procname       = "nmi_watchdog",
+		.data           = &nmi_watchdog_enabled,
+		.maxlen         = sizeof (int),
+		.mode           = 0644,
+		.proc_handler   = proc_nmi_enabled,
+	},
+#endif
+#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_NMI_WATCHDOG)
 	{
 		.procname       = "unknown_nmi_panic",
 		.data           = &unknown_nmi_panic,
lib/Kconfig.debug +12 -0
index 25c3ed5..e2e73cc 100644
@@ -170,6 +170,18 @@ config DETECT_SOFTLOCKUP
 	   can be detected via the NMI-watchdog, on platforms that
 	   support it.)
 
+config NMI_WATCHDOG
+	bool "Detect Hard Lockups with an NMI Watchdog"
+	depends on DEBUG_KERNEL && PERF_EVENTS && PERF_EVENTS_NMI
+	help
+	  Say Y here to enable the kernel to use the NMI as a watchdog
+	  to detect hard lockups.  This is useful when a cpu hangs for no
+	  reason but can still respond to NMIs.  A backtrace is displayed
+	  for reviewing and reporting.
+
+	  The overhead should be minimal, just an extra NMI every few
+	  seconds.
+
 config BOOTPARAM_SOFTLOCKUP_PANIC
 	bool "Panic (Reboot) On Soft Lockups"
 	depends on DETECT_SOFTLOCKUP