Clean up watchdog handlers
v2 cover Clean up watchdog handlers
This is an attempt to cleanup watchdog handlers. Right now, kernel/watchdog.c implements both softlockup and hardlockup detectors. Softlockup code is generic. Hardlockup code is arch specific. Some architectures don't use hardlockup detectors. They use their own watchdog detectors. To make both these combination work, we have numerous #ifdefs in kernel/watchdog.c.
We are trying here to make these handlers independent of each other. Also provide an interface for architectures to implement their own handlers. watchdog_nmi_enable and watchdog_nmi_disable will be defined as weak such that architectures can override its definitions.
Thanks to Don Zickus for his suggestions.
Here are our previous discussions
http://www.spinics.net/lists/sparclinux/msg16543.html
http://www.spinics.net/lists/sparclinux/msg16441.html
v2:
Addressed few comments from Don Zickus.
1. Took care of bisectability issue. Previous patch2 is patch1 now. Combined patch 1 and 3. Patch 4 is now patch 3.
2. Added pr_fmt back in watchdog_hld.c
3. Tweaked the file headers for watchdog.c and watchdog_hld.c.
4. Took care of couple of config compile issues.
drivers/edac/edac_device.o:(.discard+0x0): multiple definition of `__pcpu_unique_hrtimer_interrupts' drivers/edac/edac_mc.o:(.discard+0x0): first defined here
This was a problem with uni processor config. Moved the definition of hrtimer_interrupts and is_hardlockup into watchdog.c as softlockup code does most of the work here. is_hardlockup kind of generic most part.
kernel/built-in.o: In function `watchdog_overflow_callback':
watchdog_hld.c:(.text+0x56940): undefined reference to `sysctl_hardlockup_all_cpu_backtrace' Moved this definition to nmi.h.
v1:
Initial version
Babu Moger (3):
watchdog: Move shared definitions to nmi.h
watchdog: Move hardlockup detector to separate file
sparc: Implement watchdog_nmi_enable and watchdog_nmi_disable
arch/sparc/kernel/nmi.c | 44 ++++++++- include/linux/nmi.h | 24 ++++ kernel/Makefile | 1 + kernel/watchdog.c | 270 +++-------------------------------------------- kernel/watchdog_hld.c | 227 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 310 insertions(+), 256 deletions(-) create mode 100644 kernel/watchdog_hld.c
PATCH v2 1/3 watchdog: Move shared definitions to nmi.h
Move shared macros and definitions to nmi.h so that watchdog.c, new file watchdog_hld.c or any other architecture specific handler can use those definitions.
--- include/linux/nmi.h | 24 ++++++++++++++++++++++++ kernel/watchdog.c | 28 ++++------------------------ 2 files changed, 28 insertions(+), 24 deletions(-)
include/linux/nmi.h +24 -0
@@ -7,6 +7,23 @@#include <linux/sched.h> #include <asm/irq.h> +/* +* The run state of the lockup detectors is controlled by the content of the +* 'watchdog_enabled' variable. Each lockup detector has its dedicated bit - +* bit 0 for the hard lockup detector and bit 1 for the soft lockup detector. +* +* 'watchdog_user_enabled', 'nmi_watchdog_enabled' and 'soft_watchdog_enabled' +* are variables that are only used as an 'interface' between the parameters +* in /proc/sys/kernel and the internal state bits in 'watchdog_enabled'. The +* 'watchdog_thresh' variable is handled differently because its value is not +* boolean, and the lockup detectors are 'suspended' while 'watchdog_thresh' +* is equal zero. +*/ +#define NMI_WATCHDOG_ENABLED_BIT 0 +#define SOFT_WATCHDOG_ENABLED_BIT 1 +#define NMI_WATCHDOG_ENABLED (1 << NMI_WATCHDOG_ENABLED_BIT) +#define SOFT_WATCHDOG_ENABLED (1 << SOFT_WATCHDOG_ENABLED_BIT) +/** * touch_nmi_watchdog - restart NMI watchdog timeout. *
@@ -91,9 +108,16 @@ static inline bool trigger_single_cpu_backtrace(int cpu)extern int soft_watchdog_enabled;extern int watchdog_user_enabled;extern int watchdog_thresh; +extern unsigned long watchdog_enabled;extern unsigned long *watchdog_cpumask_bits; +#ifdef CONFIG_SMP extern int sysctl_softlockup_all_cpu_backtrace;extern int sysctl_hardlockup_all_cpu_backtrace; +#else +#define sysctl_softlockup_all_cpu_backtrace 0 +#define sysctl_hardlockup_all_cpu_backtrace 0 +#endif +extern bool is_hardlockup (void );struct ctl_table ;extern int proc_watchdog (struct ctl_table *,int ,void __user *,size_t *,loff_t *);
kernel/watchdog.c +4 -24
@@ -27,29 +27,12 @@#include <linux/perf_event.h> #include <linux/kthread.h> -/* -* The run state of the lockup detectors is controlled by the content of the -* 'watchdog_enabled' variable. Each lockup detector has its dedicated bit - -* bit 0 for the hard lockup detector and bit 1 for the soft lockup detector. -* -* 'watchdog_user_enabled', 'nmi_watchdog_enabled' and 'soft_watchdog_enabled' -* are variables that are only used as an 'interface' between the parameters -* in /proc/sys/kernel and the internal state bits in 'watchdog_enabled'. The -* 'watchdog_thresh' variable is handled differently because its value is not -* boolean, and the lockup detectors are 'suspended' while 'watchdog_thresh' -* is equal zero. -*/ -#define NMI_WATCHDOG_ENABLED_BIT 0 -#define SOFT_WATCHDOG_ENABLED_BIT 1 -#define NMI_WATCHDOG_ENABLED (1 << NMI_WATCHDOG_ENABLED_BIT) -#define SOFT_WATCHDOG_ENABLED (1 << SOFT_WATCHDOG_ENABLED_BIT) -static DEFINE_MUTEX (watchdog_proc_mutex); -#ifdef CONFIG_HARDLOCKUP_DETECTOR -static unsigned long __read_mostly watchdog_enabled =SOFT_WATCHDOG_ENABLED |NMI_WATCHDOG_ENABLED ; +#if defined(CONFIG_HAVE_NMI_WATCHDOG ) || defined(CONFIG_HARDLOCKUP_DETECTOR ) +unsigned long __read_mostly watchdog_enabled =SOFT_WATCHDOG_ENABLED |NMI_WATCHDOG_ENABLED ;#else -static unsigned long __read_mostly watchdog_enabled =SOFT_WATCHDOG_ENABLED ; +unsigned long __read_mostly watchdog_enabled =SOFT_WATCHDOG_ENABLED ;#endif int __read_mostly nmi_watchdog_enabled;int __read_mostly soft_watchdog_enabled;
@@ -59,9 +42,6 @@#ifdef CONFIG_SMP int __read_mostly sysctl_softlockup_all_cpu_backtrace;int __read_mostly sysctl_hardlockup_all_cpu_backtrace; -#else -#define sysctl_softlockup_all_cpu_backtrace 0 -#define sysctl_hardlockup_all_cpu_backtrace 0#endif static struct cpumask watchdog_cpumask__read_mostly ;unsigned long *watchdog_cpumask_bits =cpumask_bits (&watchdog_cpumask);
@@ -289,7 +269,7 @@ void touch_softlockup_watchdog_sync(void)#ifdef CONFIG_HARDLOCKUP_DETECTOR /* watchdog detector functions */ -static bool is_hardlockup (void ) +bool is_hardlockup (void ) {unsigned long hrint =__this_cpu_read (hrtimer_interrupts);
Signature · 1 line
1.7.1
PATCH v2 2/3 watchdog: Move hardlockup detector to separate file
In reply to Babu MogerSeparate hardlockup code from watchdog.c and move it to watchdog_hld.c. It is mostly straight forward. Remove everything inside CONFIG_HARDLOCKUP_DETECTORS. This code will go to file watchdog_hld.c. Also update the makefile accordigly.
--- kernel/Makefile | 1 + kernel/watchdog.c | 242 ++---------------------------------------------- kernel/watchdog_hld.c | 227 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 239 insertions(+), 231 deletions(-) create mode 100644 kernel/watchdog_hld.c
kernel/Makefile +1 -0
@@ -84,6 +84,7 @@ obj-$(CONFIG_KPROBES) += kprobes.o obj-$(CONFIG_KGDB) += debug/ obj-$(CONFIG_DETECT_HUNG_TASK) += hung_task.o obj-$(CONFIG_LOCKUP_DETECTOR) += watchdog.o +obj-$(CONFIG_HARDLOCKUP_DETECTOR) += watchdog_hld.o obj-$(CONFIG_SECCOMP) += seccomp.o obj-$(CONFIG_RELAY) += relay.o obj-$(CONFIG_SYSCTL) += utsname_sysctl.o
kernel/watchdog.c +11 -230
290 lines not on this page · raw message
kernel/watchdog_hld.c new file +226 -0
226 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v2 3/3 sparc: Implement watchdog_nmi_enable and watchdog_nmi_disable
In reply to Babu MogerImplement functions watchdog_nmi_enable and watchdog_nmi_disable to enable/disable nmi watchdog. Sparc uses arch specific nmi watchdog handler. Currently, we do not have a way to enable/disable nmi watchdog dynamically. With these patches we can enable or disable arch specific nmi watchdogs using proc or sysctl interface.
Example commands.
To enable: echo 1 > /proc/sys/kernel/nmi_watchdog To disable: echo 0 > /proc/sys/kernel/nmi_watchdog
It can also achieved using the sysctl parameter kernel.nmi_watchdog
--- arch/sparc/kernel/nmi.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 43 insertions(+), 1 deletions(-)
arch/sparc/kernel/nmi.c +43 -1
@@ -42,7 +42,7 @@*/ atomic_t nmi_active =ATOMIC_INIT (0 );/* oprofile uses this */ EXPORT_SYMBOL (nmi_active); - +static int nmi_init_done;static unsigned int nmi_hz =HZ ; static DEFINE_PER_CPU(short, wd_enabled);static int endflag__initdata ;
@@ -153,6 +153,8 @@ static void report_broken_nmi(int cpu, int *prev_nmi_count)void stop_nmi_watchdog (void *unused) { +if (!__this_cpu_read (wd_enabled)) +return ; pcr_ops->write_pcr (0 , pcr_ops->pcr_nmi_disable);__this_cpu_write (wd_enabled,0 );atomic_dec (&nmi_active);
@@ -207,6 +209,9 @@ static int __init check_nmi_watchdog(void)void start_nmi_watchdog (void *unused) { +if (__this_cpu_read (wd_enabled)) +return ; +__this_cpu_write (wd_enabled,1 );atomic_inc (&nmi_active);
@@ -259,6 +264,8 @@ int __init nmi_init(void) } } + nmi_init_done =1 ; +return err; }
@@ -270,3 +277,38 @@ static int __init setup_nmi_watchdog(char *str)return 0 ; }__setup ("nmi_watchdog=" , setup_nmi_watchdog); + +/* +* sparc specific NMI watchdog enable function. +* Enables watchdog if it is not enabled already. +*/ +int watchdog_nmi_enable (unsigned int cpu) +{ +if (atomic_read (&nmi_active) =-1 ) { +pr_warn ("NMI watchdog cannot be enabled or disabled\n" ); +return -1 ; + } + +/* +* watchdog thread could start even before nmi_init is called. +* Just Return in that case. Let nmi_init finish the init +* process first. +*/ +if (!nmi_init_done) +return 0 ; + +smp_call_function_single (cpu, start_nmi_watchdog,NULL ,1 ); + +return 0 ; +} +/* +* sparc specific NMI watchdog disable function. +* Disables watchdog if it is not disabled already. +*/ +void watchdog_nmi_disable (unsigned int cpu) +{ +if (atomic_read (&nmi_active) =-1 ) +pr_warn_once ("NMI watchdog cannot be enabled or disabled\n" ); +else +smp_call_function_single (cpu, stop_nmi_watchdog,NULL ,1 ); +}
Signature · 1 line
1.7.1
Quoted 12 lines · Babu Moger
This is an attempt to cleanup watchdog handlers. Right now,
kernel/watchdog.cimplements both softlockup and hardlockup detectors. Softlockup code is generic. Hardlockup code is arch specific. Some architectures don't use hardlockup detectors. They use their own watchdog detectors. To make both these combination work, we have numerous #ifdefs inkernel/watchdog.c.We are trying here to make these handlers independent of each other. Also provide an interface for architectures to implement their own handlers.
watchdog_nmi_enableandwatchdog_nmi_disablewill be defined as weak such that architectures can override its definitions.
Quoted 5 lines
Thanks to Don Zickus for his suggestions.
Here are our previous discussions
http://www.spinics.net/lists/sparclinux/msg16543.html
http://www.spinics.net/lists/sparclinux/msg16441.html
Hi Babu,
Thanks for the patches. It passes my panic/reboot testing. The patches look good for now. Though this change has me thinking about other cleanup changes I can make on top of this. But I am going to hold off for now until we are sure nothing really broke. As this should be a straight forward split.
The only odd thing for me is I am having trouble disabling CONFIG_HARDLOCKUP_DETECTOR. For some reason def_bool y, is forcing the option on despite my repeated attempts to disable it. I had to rename the option to do some test compiling and verify it doesn't regress when disabled. Probably my environment..
Thanks for the work Babu!
Quoted 34 lines
v2:
Addressed few comments from Don Zickus.
1. Took care of bisectability issue. Previous patch2 is patch1 now. Combined patch 1 and 3. Patch 4 is now patch 3.
2. Addedpr_fmtback inwatchdog_hld.c
3. Tweaked the file headers forwatchdog.candwatchdog_hld.c.4. Took care of couple of config compile issues.
drivers/edac/edac_device.o:(.discard+0x0): multiple definition of `__pcpu_unique_hrtimer_interrupts' drivers/edac/edac_mc.o:(.discard+0x0): first defined here
This was a problem with uni processor config. Moved the definition ofhrtimer_interruptsandis_hardlockupintowatchdog.cas softlockup code does most of the work here.is_hardlockupkind of generic most part.
kernel/built-in.o: In function `watchdog_overflow_callback':
watchdog_hld.c:(.text+0x56940): undefined reference to `sysctl_hardlockup_all_cpu_backtrace' Moved this definition tonmi.h.v1:
Initial version
Babu Moger (3):
watchdog: Move shared definitions tonmi.h
watchdog: Move hardlockup detector to separate file
sparc: Implementwatchdog_nmi_enableandwatchdog_nmi_disablearch/sparc/kernel/nmi.c | 44 ++++++++- include/linux/nmi.h | 24 ++++ kernel/Makefile | 1 + kernel/watchdog.c | 270 +++-------------------------------------------- kernel/watchdog_hld.c | 227 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 310 insertions(+), 256 deletions(-) create mode 100644 kernel/watchdog_hld.c
Quoted 26 lines · Don Zickus
Quoted 12 lines · Babu Moger
This is an attempt to cleanup watchdog handlers. Right now,
kernel/watchdog.cimplements both softlockup and hardlockup detectors. Softlockup code is generic. Hardlockup code is arch specific. Some architectures don't use hardlockup detectors. They use their own watchdog detectors. To make both these combination work, we have numerous #ifdefs inkernel/watchdog.c.We are trying here to make these handlers independent of each other. Also provide an interface for architectures to implement their own handlers.
watchdog_nmi_enableandwatchdog_nmi_disablewill be defined as weak such that architectures can override its definitions.Quoted 5 lines
Thanks to Don Zickus for his suggestions.
Here are our previous discussions
http://www.spinics.net/lists/sparclinux/msg16543.html
http://www.spinics.net/lists/sparclinux/msg16441.htmlHi Babu,
Thanks for the patches. It passes my panic/reboot testing. The patches look good for now. Though this change has me thinking about other cleanup changes I can make on top of this. But I am going to hold off for now until we are sure nothing really broke. As this should be a straight forward split.
Quoted 5 lines
The only odd thing for me is I am having trouble disabling
CONFIG_HARDLOCKUP_DETECTOR. For some reasondef_booly, is forcing the option on despite my repeated attempts to disable it. I had to rename the option to do some test compiling and verify it doesn't regress when disabled. Probably my environment..
Don, You are welcome. Thanks for your feedback to resolve this.
Quoted 40 lines
Thanks for the work Babu!
Acked-by Don Zickus <[email protected]>Quoted 34 lines
v2:
Addressed few comments from Don Zickus.
1. Took care of bisectability issue. Previous patch2 is patch1 now. Combined patch 1 and 3. Patch 4 is now patch 3.
2. Addedpr_fmtback inwatchdog_hld.c
3. Tweaked the file headers forwatchdog.candwatchdog_hld.c.4. Took care of couple of config compile issues.
drivers/edac/edac_device.o:(.discard+0x0): multiple definition of `__pcpu_unique_hrtimer_interrupts' drivers/edac/edac_mc.o:(.discard+0x0): first defined here
This was a problem with uni processor config. Moved the definition ofhrtimer_interruptsandis_hardlockupintowatchdog.cas softlockup code does most of the work here.is_hardlockupkind of generic most part.
kernel/built-in.o: In function `watchdog_overflow_callback':
watchdog_hld.c:(.text+0x56940): undefined reference to `sysctl_hardlockup_all_cpu_backtrace' Moved this definition tonmi.h.v1:
Initial version
Babu Moger (3):
watchdog: Move shared definitions tonmi.h
watchdog: Move hardlockup detector to separate file
sparc: Implementwatchdog_nmi_enableandwatchdog_nmi_disablearch/sparc/kernel/nmi.c | 44 ++++++++- include/linux/nmi.h | 24 ++++ kernel/Makefile | 1 + kernel/watchdog.c | 270 +++-------------------------------------------- kernel/watchdog_hld.c | 227 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 310 insertions(+), 256 deletions(-)create mode 100644
kernel/watchdog_hld.c
David Miller
maintainerFrom: Babu Moger <[email protected]>
Date: Tue, 1 Nov 2016 14:13:43 -0700
Quoted 12 lines
This is an attempt to cleanup watchdog handlers. Right now,
kernel/watchdog.cimplements both softlockup and hardlockup detectors. Softlockup code is generic. Hardlockup code is arch specific. Some architectures don't use hardlockup detectors. They use their own watchdog detectors. To make both these combination work, we have numerous #ifdefs inkernel/watchdog.c.We are trying here to make these handlers independent of each other. Also provide an interface for architectures to implement their own handlers.
watchdog_nmi_enableandwatchdog_nmi_disablewill be defined as weak such that architectures can override its definitions.
Quoted 4 lines
Thanks to Don Zickus for his suggestions.
Here are our previous discussions
http://www.spinics.net/lists/sparclinux/msg16543.html
http://www.spinics.net/lists/sparclinux/msg16441.html
This touches a bunch of generic code, only the third patch is sparc specific.
Anyways have any plans to merge this via another tree or should I take it via sparc? If I take it via sparc I want some ACKs.
Thanks.
A message that is not in the archive (sent off-list or not yet received): [email protected]
David Miller
maintainerFrom: Babu Moger <[email protected]>
Date: Mon, 21 Nov 2016 14:25:50 -0600
Quoted 24 lines
Hi Dave,
Quoted 21 lines · David Miller
From: Babu Moger <[email protected]>
Date: Tue, 1 Nov 2016 14:13:43 -0700Quoted 18 lines
This is an attempt to cleanup watchdog handlers. Right now,
kernel/watchdog.cimplements both softlockup and hardlockup detectors. Softlockup code is generic. Hardlockup code is arch specific. Some architectures don't use hardlockup detectors. They use their own watchdog
detectors. To make both these combination work, we have numerous #ifdefs
inkernel/watchdog.c.We are trying here to make these handlers independent of each other. Also provide an interface for architectures to implement their own handlers.
watchdog_nmi_enableandwatchdog_nmi_disablewill be defined as weak such that architectures can override its definitions.Thanks to Don Zickus for his suggestions.
Here are our previous discussions
http://www.spinics.net/lists/sparclinux/msg16543.html
http://www.spinics.net/lists/sparclinux/msg16441.html
Quoted 8 lines
Quoted 5 lines
This touches a bunch of generic code, only the third patch is sparc specific.
Anyways have any plans to merge this via another tree or should I take it via sparc? If I take it via sparc I want some ACKs.
Not sure how these things work. I have got following responses from Andrew Morton earlier.
Ok, if Andrew put it in his tree I'll just assume these changes will take that path.