Skip to contentSkip to conversation

watchdog: Handle comma separated nmi_watchdog command line

PATCH Applied Song Liu 1 participant 2 messages Apr 30, 2024 Documentation

lore
Share & tools
lore

Song Liu

author
#0 lore raw

PATCH v5 1/2 watchdog: Handle comma separated nmi_watchdog command line

Per the document, the kernel can accept comma separated command line like nmi_watchdog=nopanic,0. However, the code doesn't really handle it. Fix the kernel to handle it properly.

Cc Andrew Morton <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 kernel/watchdog.c | 7 +++++++
 1 file changed, 7 insertions(+)
kernel/watchdog.c +7 -0
index d7b2125503af..7f54484de16f 100644
@@ -71,6 +71,7 @@ void __init hardlockup_detector_disable(void)
 
 static int __init hardlockup_panic_setup(char *str)
 {
+next:
 	if (!strncmp(str, "panic", 5))
 		hardlockup_panic = 1;
 	else if (!strncmp(str, "nopanic", 7))
@@ -79,6 +80,12 @@ static int __init hardlockup_panic_setup(char *str)
 		watchdog_hardlockup_user_enabled = 0;
 	else if (!strncmp(str, "1", 1))
 		watchdog_hardlockup_user_enabled = 1;
+	while (*(str++)) {
+		if (*str == ',') {
+			str++;
+			goto next;
+		}
+	}
 	return 1;
 }
 __setup("nmi_watchdog=", hardlockup_panic_setup);
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v5 2/2 watchdog: Allow nmi watchdog to use raw perf event

NMI watchdog permanently consumes one hardware counters per CPU on the system. For systems that use many hardware counters, this causes more aggressive time multiplexing of perf events.

OTOH, some CPUs (mostly Intel) support "ref-cycles" event, which is rarely used. Add kernel cmdline arg nmi_watchdog=rNNN to configure the watchdog to use raw event. For example, on Intel CPUs, we can use "r300" to configure the watchdog to use ref-cycles event.

If the raw event does not work, fall back to use "cycles".

Cc Andrew Morton <[email protected]>
Cc Peter Zijlstra <[email protected]>

---
Changes in v5:
Change the design so that we can configure the watchdog with any raw event.
Add fall back mechanism that use "cycles" if the raw event doesn't work.

v4: https://lore.kernel.org/lkml/[email protected]/

Changes in v4:
Fix compile error for !CONFIG_HARDLOCKUP_DETECTOR_PERF. (kernel test bot)

Changes in v3:

Pivot the design to use kernel arg nmi_watchdog=ref-cycles (Peter)

---
 .../admin-guide/kernel-parameters.txt         |  5 ++-
 include/linux/nmi.h                           |  2 +
 kernel/watchdog.c                             |  2 +
 kernel/watchdog_perf.c                        | 44 +++++++++++++++++++
 4 files changed, 51 insertions(+), 2 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +3 -2
index 213d0719e2b7..7445738f45b3 100644
@@ -3776,10 +3776,12 @@
 			Format: [state][,regs][,debounce][,die]
 
 	nmi_watchdog=	[KNL,BUGS=X86] Debugging features for SMP kernels
-			Format: [panic,][nopanic,][num]
+			Format: [panic,][nopanic,][rNNN,][num]
 			Valid num: 0 or 1
 			0 - turn hardlockup detector in nmi_watchdog off
 			1 - turn hardlockup detector in nmi_watchdog on
+			rNNN - configure the watchdog with raw perf event 0xNNN
+
 			When panic is specified, panic when an NMI watchdog
 			timeout occurs (or 'nopanic' to not panic on an NMI
 			watchdog, if CONFIG_BOOTPARAM_HARDLOCKUP_PANIC is set)
@@ -7467,4 +7469,3 @@
 				memory, and other data can't be written using
 				xmon commands.
 			off	xmon is disabled.
-
include/linux/nmi.h +2 -0
index f53438eae815..a8dfb38c9bb6 100644
@@ -105,10 +105,12 @@ void watchdog_hardlockup_check(unsigned int cpu, struct pt_regs *regs);
 extern void hardlockup_detector_perf_stop(void);
 extern void hardlockup_detector_perf_restart(void);
 extern void hardlockup_detector_perf_cleanup(void);
+extern void hardlockup_config_perf_event(const char *str);
 #else
 static inline void hardlockup_detector_perf_stop(void) { }
 static inline void hardlockup_detector_perf_restart(void) { }
 static inline void hardlockup_detector_perf_cleanup(void) { }
+static inline void hardlockup_config_perf_event(const char *str) { }
 #endif
 
 void watchdog_hardlockup_stop(void);
kernel/watchdog.c +2 -0
index 7f54484de16f..ab0129b15f25 100644
@@ -80,6 +80,8 @@ static int __init hardlockup_panic_setup(char *str)
 		watchdog_hardlockup_user_enabled = 0;
 	else if (!strncmp(str, "1", 1))
 		watchdog_hardlockup_user_enabled = 1;
+	else if (!strncmp(str, "r", 1))
+		hardlockup_config_perf_event(str + 1);
 	while (*(str++)) {
 		if (*str == ',') {
 			str++;
kernel/watchdog_perf.c +44 -0

59 lines not on this page · raw message

Signature · 1 line
2.43.0