lockup detector changes
Subsystems (15)
cover lockup detector changes
This patch series covers mostly the changes necessary for combining the nmi_watchdog and softlockup code. Also added are the cleanups associated with the change, like removing the old files.
The changelogs in each patch are more specific to what the changes are.
Don Zickus (5):
[watchdog] combine nmi_watchdog and softlockup
[watchdog] convert touch_softlockup_watchdog to touch_watchdog [watchdog] remove old softlockup code
[watchdog] remove nmi_watchdog.c file
[x86] watchdog: move trigger_all_cpu_backtrace to its own die_notifier [x86] watchdog: cleanup hw_nmi.c cruft
Documentation/kernel-parameters.txt | 2 + arch/ia64/kernel/time.c | 2 +- arch/ia64/kernel/uncached.c | 2 +- arch/ia64/xen/time.c | 2 +- arch/mn10300/kernel/gdb-stub.c | 2 +- arch/powerpc/kernel/swsusp_64.c | 2 +- arch/sparc/kernel/nmi.c | 2 +- arch/x86/include/asm/nmi.h | 2 +- arch/x86/kernel/apic/Makefile | 4 +- arch/x86/kernel/apic/hw_nmi.c | 113 +++----- arch/x86/kernel/apic/nmi.c | 2 +- arch/x86/kernel/traps.c | 4 +- arch/x86/xen/smp.c | 2 +- drivers/ide/ide-iops.c | 2 +- drivers/ide/ide-taskfile.c | 2 +- drivers/mtd/nand/nand_base.c | 4 +- drivers/video/nvidia/nv_accel.c | 2 +- include/linux/nmi.h | 13 +- include/linux/sched.h | 20 +- init/Kconfig | 5 +- kernel/Makefile | 3 +- kernel/kgdb.c | 6 +- kernel/nmi_watchdog.c | 259 ---------------- kernel/panic.c | 2 +- kernel/power/hibernate.c | 2 +- kernel/sched.c | 2 +- kernel/sched_clock.c | 2 +- kernel/softlockup.c | 278 ------------------ kernel/sysctl.c | 52 ++-- kernel/time/tick-sched.c | 8 +- kernel/time/timekeeping.c | 2 +- kernel/timer.c | 1 - kernel/watchdog.c | 552 +++++++++++++++++++++++++++++++++++ lib/Kconfig.debug | 30 ++- 34 files changed, 692 insertions(+), 696 deletions(-) delete mode 100644 kernel/nmi_watchdog.c delete mode 100644 kernel/softlockup.c create mode 100644 kernel/watchdog.c
PATCH 1/6 combine nmi_watchdog and softlockup
The new nmi_watchdog (which uses the perf event subsystem) is very similar in structure to the softlockup detector. Using Ingo's suggestion, I combined the two functionalities into one file, kernel/watchdog.c.
Now both the nmi_watchdog (or hardlockup detector) and softlockup detector sit on top of the perf event subsystem, which is run every 60 seconds or so to see if there are any lockups.
To detect hardlockups, cpus not responding to interrupts, I implemented an hrtimer that runs 5 times for every perf event overflow event. If that stops counting on a cpu, then the cpu is most likely in trouble.
To detect softlockups, tasks not yielding to the scheduler, I used the previous kthread idea that now gets kicked every time the hrtimer fires. If the kthread isn't being scheduled neither is anyone else and the warning is printed to the console.
I tested this on x86_64 and both the softlockup and hardlockup paths work.
V2:
- cleaned up the Kconfig and softlockup combination
- surrounded hardlockup cases with #ifdef CONFIG_PERF_EVENTS_NMI
- seperated out the softlockup case from perf event subsystem
- re-arranged the enabling/disabling nmi watchdog from proc space
- added cpumasks for hardlockup failure cases
- removed fallback to soft events if no PMU exists for hard events
V3:
- comment cleanups
- drop support for older softlockup code
- per_cpu cleanups
- completely remove software clock base hardlockup detector
- use per_cpu masking on hard/soft lockup detection
- #ifdef cleanups
- rename config option NMI_WATCHDOG to LOCKUP_DETECTOR
- documentation additions
TODO:
- figure out how to make an arch-agnostic clock2cycles call (if possible) to feed into perf events as a sample period
--- Documentation/kernel-parameters.txt | 2 + arch/x86/include/asm/nmi.h | 2 +- arch/x86/kernel/apic/Makefile | 4 +- arch/x86/kernel/apic/hw_nmi.c | 2 +- arch/x86/kernel/traps.c | 4 +- include/linux/nmi.h | 8 +- include/linux/sched.h | 6 + init/Kconfig | 5 +- kernel/Makefile | 3 +- kernel/sysctl.c | 21 +- kernel/watchdog.c | 580 +++++++++++++++++++++++++++++++++++ lib/Kconfig.debug | 30 ++- 12 files changed, 638 insertions(+), 29 deletions(-) create mode 100644 kernel/watchdog.c
Documentation/kernel-parameters.txt +2 -0
@@ -1764,6 +1764,8 @@ and is between 256 and 4096 characters. It is defined in the file nousb [USB] Disable the USB subsystem + nowatchdog [KNL] Disable the lockup detector. + nowb [ARM] nox2apic [X86-64,APIC] Do not enable x2APIC mode.
arch/x86/include/asm/nmi.h +1 -1
@@ -17,7 +17,7 @@ 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 ) +#if !defined(CONFIG_LOCKUP_DETECTOR )extern int nmi_watchdog_enabled;#endif extern int avail_to_resrv_perfctr_nmi_bit (unsigned int );
arch/x86/kernel/apic/Makefile +2 -2
@@ -3,10 +3,10 @@ # obj-$(CONFIG_X86_LOCAL_APIC) += apic.o apic_noop.o probe_$(BITS).o ipi.o -ifneq ($(CONFIG_NMI_WATCHDOG),y) +ifneq ($(CONFIG_LOCKUP_DETECTOR),y) obj-$(CONFIG_X86_LOCAL_APIC) += nmi.o endif -obj-$(CONFIG_NMI_WATCHDOG) += hw_nmi.o +obj-$(CONFIG_LOCKUP_DETECTOR) += hw_nmi.o obj-$(CONFIG_X86_IO_APIC) += io_apic.o obj-$(CONFIG_SMP) += ipi.o
arch/x86/kernel/apic/hw_nmi.c +1 -1
@@ -89,7 +89,7 @@ int hw_nmi_is_cpu_stuck(struct pt_regs *regs)u64 hw_nmi_get_sample_period (void ) { -return cpu_khz *1000 ; +return (u64)(cpu_khz) *1000 *60 ; }#ifdef ARCH_HAS_NMI_WATCHDOG
arch/x86/kernel/traps.c +2 -2
@@ -406,7 +406,7 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs) == NOTIFY_STOP)return ; -#ifndef CONFIG_NMI_WATCHDOG +#ifndef CONFIG_LOCKUP_DETECTOR /* * Ok, so this is none of the documented NMI sources, * so it must be the NMI watchdog.
@@ -414,7 +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 */ +#endif /* !CONFIG_LOCKUP_DETECTOR */ unknown_nmi_error (reason, regs);#else unknown_nmi_error (reason, regs);
include/linux/nmi.h +4 -4
@@ -20,7 +20,7 @@ extern void touch_nmi_watchdog(void); extern void acpi_nmi_disable(void); extern void acpi_nmi_enable(void); #else -#ifndef CONFIG_NMI_WATCHDOG +#ifndef CONFIG_LOCKUP_DETECTOR static inline void touch_nmi_watchdog(void) { touch_softlockup_watchdog();
@@ -51,12 +51,12 @@ static inline bool trigger_all_cpu_backtrace(void) }#endif -#ifdef CONFIG_NMI_WATCHDOG +#ifdef CONFIG_LOCKUP_DETECTOR int hw_nmi_is_cpu_stuck (struct pt_regs *);u64 hw_nmi_get_sample_period (void ); -extern int nmi_watchdog_enabled; +extern int watchdog_enabled;struct ctl_table ; -extern int proc_nmi_enabled (struct ctl_table *,int , +extern int proc_dowatchdog_enabled (struct ctl_table *,int ,void __user *,size_t *,loff_t *);#endif
include/linux/sched.h +6 -0
@@ -338,6 +338,12 @@ extern int proc_dohung_task_timeout_secs(struct ctl_table *table, int write, size_t *lenp, loff_t *ppos);#endif +#ifdef CONFIG_LOCKUP_DETECTOR +extern int proc_dowatchdog_thresh (struct ctl_table *table,int write, +void __user *buffer, +size_t *lenp,loff_t *ppos); +#endif +/* Attach to any functions which should be ignored in wchan output. */ #define __sched __attribute__((__section__(".sched.text")))
init/Kconfig +4 -1
@@ -948,8 +948,11 @@ config PERF_USE_VMALLOC config PERF_EVENTS_NMI bool + depends on PERF_EVENTS help - Arch has support for nmi_watchdog + Arch can generate an NMI using the perf event subsystem + Also has support for calculating cpu cycle events to + determine how many clock cycles in a given period menu "Kernel Performance Events And Counters"
kernel/Makefile +1 -2
@@ -75,9 +75,8 @@ obj-$(CONFIG_GCOV_KERNEL) += gcov/ 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_LOCKUP_DETECTOR) += watchdog.o obj-$(CONFIG_GENERIC_HARDIRQS) += irq/ obj-$(CONFIG_SECCOMP) += seccomp.o obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o
kernel/sysctl.c +15 -6
@@ -60,7 +60,7 @@#include <asm/io.h> #endif -#ifdef CONFIG_NMI_WATCHDOG +#ifdef CONFIG_LOCKUP_DETECTOR #include <linux/nmi.h> #endif
@@ -696,16 +696,25 @@ static struct ctl_table kern_table[] = { .mode = 0444, .proc_handler = proc_dointvec, }, -#if defined(CONFIG_NMI_WATCHDOG) +#if defined(CONFIG_LOCKUP_DETECTOR) { - .procname = "nmi_watchdog", - .data = &nmi_watchdog_enabled, + .procname = "watchdog", + .data = &watchdog_enabled, .maxlen = sizeof (int), .mode = 0644, - .proc_handler = proc_nmi_enabled, + .proc_handler = proc_dowatchdog_enabled, + }, + { + .procname = "watchdog_thresh", + .data = &softlockup_thresh, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dowatchdog_thresh, + .extra1 = &neg_one, + .extra2 = &sixty, }, #endif -#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_NMI_WATCHDOG) +#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_LOCKUP_DETECTOR) { .procname = "unknown_nmi_panic", .data = &unknown_nmi_panic,
kernel/watchdog.c new file +580 -0
580 lines not on this page · raw message
lib/Kconfig.debug +20 -10
@@ -152,7 +152,7 @@ config DEBUG_SHIRQ points; some don't and need to be caught. config DETECT_SOFTLOCKUP - bool "Detect Soft Lockups" + bool depends on DEBUG_KERNEL && !S390 default y help
@@ -170,17 +170,27 @@ 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 +config LOCKUP_DETECTOR + bool "Detect Hard and Soft Lockups" + depends on DEBUG_KERNEL + default DETECT_SOFTLOCKUP 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. + Say Y here to enable the kernel to act as a watchdog to detect + hard and soft lockups. + + Softlockups are bugs that cause the kernel to loop in kernel + mode for more than 60 seconds, without giving other tasks a + chance to run. The current stack trace is displayed upon + detection and the system will stay locked up. + + Hardlockups are bugs that cause the CPU to loop in kernel mode + for more than 60 seconds, without letting other interrupts have a + chance to run. The current stack trace is displayed upon detection + and the system will stay locked up. - The overhead should be minimal, just an extra NMI every few - seconds. + The overhead should be minimal. A periodic hrtimer runs to + generate interrupts and kick the watchdog task every 10-12 seconds. + An NMI is generated every 60 seconds or so to check for hardlockups. config BOOTPARAM_SOFTLOCKUP_PANIC bool "Panic (Reboot) On Soft Lockups"
Signature · 1 line
1.6.5.2
Re: [PATCH 1/6] [watchdog] combine nmi_watchdog and softlockup
init/Kconfig config PERF_USE_VMALLOC · line 953
Quoted 12 lines · On Tue, 20 Apr 2010 11:23:58 -0400 Don Zickus wrote:
init/Kconfig +2
-1@@ -948,8 +948,11 @@ config PERF_USE_VMALLOC config PERF_EVENTS_NMI bool + depends on PERF_EVENTS help - Arch has support for nmi_watchdog + Arch can generate an NMI using the perf event subsystem
Hi Don,
I realize that you didn't introduce Arch in this help text, but can we eliminate him, please? E.g.:
Platform can generate an NMI using the perf event subsystem.
or
System hardware can generate an NMI using the perf event subsystem.
init/Kconfig config PERF_USE_VMALLOC · line 954
Quoted 1 line
init/Kconfig +1
-0+ Also has support for calculating cpu cycle events to
CPU
init/Kconfig config PERF_USE_VMALLOC · line 955
Quoted 1 line
init/Kconfig +1
-0+ determine how many clock cycles in a given period
period.
init/Kconfig config PERF_USE_VMALLOC · line 957
Quoted 2 lines
init/Kconfig +0
-0menu "Kernel Performance Events And Counters"
---
~Randy
Re: [PATCH 1/6] [watchdog] combine nmi_watchdog and softlockup
Quoted 17 lines · Randy Dunlap
init/Kconfig config PERF_USE_VMALLOC · line 953
Quoted 12 lines · On Tue, 20 Apr 2010 11:23:58 -0400 Don Zickus wrote:
init/Kconfig +2
-1@@ -948,8 +948,11 @@ config PERF_USE_VMALLOC config PERF_EVENTS_NMI bool + depends on PERF_EVENTS help - Arch has support for nmi_watchdog + Arch can generate an NMI using the perf event subsystemHi Don,
Quoted 2 lines
I realize that you didn't introduce Arch in this help text, but can we eliminate him, please? E.g.:
yup.
Thanks,
Don
Re: [PATCH 1/6] [watchdog] combine nmi_watchdog and softlockup
In reply to Don ZickusSome minor things:
kernel/watchdog.c line 210
Quoted 8 lines · Don Zickus
kernel/watchdog.c new file +8
-0+#ifdef CONFIG_PERF_EVENTS_NMI +struct perf_event_attr wd_hw_attr = { + .type =PERF_TYPE_HARDWARE , + .config =PERF_COUNT_HW_CPU_CYCLES , + .size =sizeof (struct perf_event_attr ), + .pinned =1 , + .disabled =1 , +};
Shouldn't it be static?
kernel/watchdog.c line 219
Quoted 9 lines
kernel/watchdog.c new file +9
-0+ +/* Callback function for perf event subsystem */ +void watchdog_overflow_callback (struct perf_event *event,int nmi, +struct perf_sample_data *data, +struct pt_regs *regs) +{ +int this_cpu =smp_processor_id (); +unsigned long touch_ts =per_cpu (watchdog_touch_ts, this_cpu); +char warn =per_cpu (watchdog_warn, this_cpu);
You can use __get_cpu_var() here
Quoted 13 lines
kernel/watchdog.c new file +13
-0+ +if (touch_ts ==0 ) { +__touch_watchdog (); +return ; + } + +/* check for a hardlockup +* This is done by making sure our timer interrupt +* is incrementing. The timer interrupt should have +* fired multiple times before we overflow'd. If it hasn't +* then this is a good indication the cpu is stuck +*/ +if (is_hardlockup (this_cpu)) {
kernel/watchdog.c line 242
Quoted 10 lines
kernel/watchdog.c new file +10
-0+/* only print hardlockups once */ +if (warn &HARDLOCKUP ) +return ; + +if (hardlockup_panic) +panic ("Watchdog detected hard LOCKUP on cpu %d" , this_cpu); +else +WARN (1 ,"Watchdog detected hard LOCKUP on cpu %d" , this_cpu); + +per_cpu (watchdog_warn, this_cpu) = warn |HARDLOCKUP ;
and here.
kernel/watchdog.c line 254
Quoted 12 lines
kernel/watchdog.c new file +12
-0+ return; + } + +per_cpu (watchdog_warn, this_cpu) = warn & ~HARDLOCKUP ; +return ; +} +static void watchdog_interrupt_count (void ) +{ +__get_cpu_var (hrtimer_interrupts)++; +} +#else +static void watchdog_interrupt_count (void ) {return ; }
Off case should be inline (although gcc will probably inline it by itself)
kernel/watchdog.c line 261
Quoted 7 lines
kernel/watchdog.c new file +7
-0+#endif /* CONFIG_PERF_EVENTS_NMI */ + +/* watchdog kicker functions */ +static enum hrtimer_restart watchdog_timer_fn (struct hrtimer *hrtimer) +{ +int this_cpu =smp_processor_id (); +unsigned long touch_ts =per_cpu (watchdog_touch_ts, this_cpu);
__get_cpu_var
Re: [PATCH 1/6] [watchdog] combine nmi_watchdog and softlockup
Quoted 4 lines · Frederic Weisbecker
Some minor things:
On Tue, Apr 20, 2010 at 11:23:58AM -0400, Don Zickus wrote:
Quoted 12 lines
kernel/watchdog.c line 210
Quoted 8 lines
kernel/watchdog.c new file +8
-0+#ifdef CONFIG_PERF_EVENTS_NMI +struct perf_event_attr wd_hw_attr = { + .type =PERF_TYPE_HARDWARE , + .config =PERF_COUNT_HW_CPU_CYCLES , + .size =sizeof (struct perf_event_attr ), + .pinned =1 , + .disabled =1 , +};Shouldn't it be static?
yes. thanks.
Quoted 15 lines
kernel/watchdog.c line 219
Quoted 11 lines
kernel/watchdog.c new file +9
-0+ +/* Callback function for perf event subsystem */ +void watchdog_overflow_callback (struct perf_event *event,int nmi, +struct perf_sample_data *data, +struct pt_regs *regs) +{ +int this_cpu =smp_processor_id (); +unsigned long touch_ts =per_cpu (watchdog_touch_ts, this_cpu); +char warn =per_cpu (watchdog_warn, this_cpu);You can use
__get_cpu_var()here
well, I already have this_cpu and need it later, I figured I would just use it with per_cpu and save _get_cpu_var the work of re-running smp_processor_id().
Quoted 22 lines
Quoted 22 lines
kernel/watchdog.c new file +19
-0+ +if (touch_ts ==0 ) { +__touch_watchdog (); +return ; + } + +/* check for a hardlockup +* This is done by making sure our timer interrupt +* is incrementing. The timer interrupt should have +* fired multiple times before we overflow'd. If it hasn't +* then this is a good indication the cpu is stuck +*/ +if (is_hardlockup (this_cpu)) { +/* only print hardlockups once */ +if (warn &HARDLOCKUP ) +return ; + +if (hardlockup_panic) +panic ("Watchdog detected hard LOCKUP on cpu %d" , this_cpu);
Quoted 8 lines
kernel/watchdog.c line 242
Quoted 4 lines
kernel/watchdog.c new file +4
-0+else +WARN (1 ,"Watchdog detected hard LOCKUP on cpu %d" , this_cpu); + +per_cpu (watchdog_warn, this_cpu) = warn |HARDLOCKUP ;and here.
same arguement as above.
Quoted 19 lines
Quoted 5 lines
kernel/watchdog.c new file +2
-0+return ; + }kernel/watchdog.c line 254
Quoted 10 lines
kernel/watchdog.c new file +10
-0+ +per_cpu (watchdog_warn, this_cpu) = warn & ~HARDLOCKUP ; + return; +} +static void watchdog_interrupt_count (void ) +{ +__get_cpu_var (hrtimer_interrupts)++; +} +#else +static void watchdog_interrupt_count (void ) {return ; }Off case should be inline (although gcc will probably inline it by itself)
yup. thanks.
Quoted 14 lines
kernel/watchdog.c line 261
Quoted 10 lines
kernel/watchdog.c new file +7
-0+#endif /* CONFIG_PERF_EVENTS_NMI */ + +/* watchdog kicker functions */ +static enum hrtimer_restart watchdog_timer_fn (struct hrtimer *hrtimer) +{ +int this_cpu =smp_processor_id (); +unsigned long touch_ts =per_cpu (watchdog_touch_ts, this_cpu);
__get_cpu_var
again same as above.
Thanks for the review.
Cheers,
Don
Re: [PATCH 1/6] [watchdog] combine nmi_watchdog and softlockup
Quoted 36 lines · Don Zickus
Quoted 4 lines · Frederic Weisbecker
Some minor things:
On Tue, Apr 20, 2010 at 11:23:58AM -0400, Don Zickus wrote:
Quoted 12 lines
kernel/watchdog.c line 210
Quoted 8 lines
kernel/watchdog.c new file +8
-0+#ifdef CONFIG_PERF_EVENTS_NMI +struct perf_event_attr wd_hw_attr = { + .type =PERF_TYPE_HARDWARE , + .config =PERF_COUNT_HW_CPU_CYCLES , + .size =sizeof (struct perf_event_attr ), + .pinned =1 , + .disabled =1 , +};Shouldn't it be static?
yes. thanks.
Quoted 15 lines
kernel/watchdog.c line 219
Quoted 11 lines
kernel/watchdog.c new file +9
-0+ +/* Callback function for perf event subsystem */ +void watchdog_overflow_callback (struct perf_event *event,int nmi, +struct perf_sample_data *data, +struct pt_regs *regs) +{ +int this_cpu =smp_processor_id (); +unsigned long touch_ts =per_cpu (watchdog_touch_ts, this_cpu); +char warn =per_cpu (watchdog_warn, this_cpu);You can use
__get_cpu_var()here
Quoted 3 lines
well, I already have
this_cpuand need it later, I figured I would just use it withper_cpuand save_get_cpu_varthe work of re-runningsmp_processor_id().
This is more about code clarity in fact. per_cpu() suggests we are fetching something from another cpu.
This is a very minor issue though.
Re: [PATCH 1/6] [watchdog] combine nmi_watchdog and softlockup
Quoted 37 lines · Frederic Weisbecker
Quoted 36 lines · Don Zickus
Quoted 4 lines · Frederic Weisbecker
Some minor things:
On Tue, Apr 20, 2010 at 11:23:58AM -0400, Don Zickus wrote:
Quoted 12 lines
kernel/watchdog.c line 210
Quoted 8 lines
kernel/watchdog.c new file +8
-0+#ifdef CONFIG_PERF_EVENTS_NMI +struct perf_event_attr wd_hw_attr = { + .type =PERF_TYPE_HARDWARE , + .config =PERF_COUNT_HW_CPU_CYCLES , + .size =sizeof (struct perf_event_attr ), + .pinned =1 , + .disabled =1 , +};Shouldn't it be static?
yes. thanks.
Quoted 15 lines
kernel/watchdog.c line 219
Quoted 11 lines
kernel/watchdog.c new file +9
-0+ +/* Callback function for perf event subsystem */ +void watchdog_overflow_callback (struct perf_event *event,int nmi, +struct perf_sample_data *data, +struct pt_regs *regs) +{ +int this_cpu =smp_processor_id (); +unsigned long touch_ts =per_cpu (watchdog_touch_ts, this_cpu); +char warn =per_cpu (watchdog_warn, this_cpu);You can use
__get_cpu_var()here
Quoted 8 lines
Quoted 3 lines
well, I already have
this_cpuand need it later, I figured I would just use it withper_cpuand save_get_cpu_varthe work of re-runningsmp_processor_id().This is more about code clarity in fact.
per_cpu()suggests we are fetching something from another cpu.
ah gotcha.
Quoted 2 lines
This is a very minor issue though.
I have no problem changing it.
Cheers,
Don
PATCH 2/6 convert touch_softlockup_watchdog to touch_watchdog
In reply to Don ZickusJust a scripted conversion to remove touch_softlockup_watchdog.
Also converts the once case of touch_all_softlockup_watchdogs to touch_all_watchdogs.
This is done as part of the removal of the old softlockup code and transition to the new softlockup code.
--- arch/ia64/kernel/time.c | 2 +- arch/ia64/kernel/uncached.c | 2 +- arch/ia64/xen/time.c | 2 +- arch/mn10300/kernel/gdb-stub.c | 2 +- arch/powerpc/kernel/swsusp_64.c | 2 +- arch/sparc/kernel/nmi.c | 2 +- arch/x86/kernel/apic/nmi.c | 2 +- arch/x86/xen/smp.c | 2 +- drivers/ide/ide-iops.c | 2 +- drivers/ide/ide-taskfile.c | 2 +- drivers/mtd/nand/nand_base.c | 4 ++-- drivers/video/nvidia/nv_accel.c | 2 +- include/linux/nmi.h | 7 +------ include/linux/sched.h | 26 ++++++++------------------ kernel/kgdb.c | 6 +++--- kernel/panic.c | 2 +- kernel/power/hibernate.c | 2 +- kernel/sched.c | 2 +- kernel/sched_clock.c | 2 +- kernel/sysctl.c | 9 --------- kernel/time/tick-sched.c | 8 ++++---- kernel/time/timekeeping.c | 2 +- kernel/timer.c | 1 - kernel/watchdog.c | 30 +----------------------------- 24 files changed, 35 insertions(+), 88 deletions(-)
arch/ia64/kernel/time.c +1 -1
@@ -368,7 +368,7 @@ ia64_init_itm (void)paravirt_init_missing_ticks_accounting (smp_processor_id ());/* avoid softlock up message when cpu is unplug and plugged again. */ -touch_softlockup_watchdog (); +touch_watchdog ();/* Setup the CPU local timer tick */ ia64_cpu_local_tick ();
arch/ia64/kernel/uncached.c +1 -1
@@ -256,7 +256,7 @@ static int __init uncached_build_memmap(u64 uc_start, u64 uc_end, void *arg)struct gen_pool *pool = uncached_pools[nid].pool;size_t size = uc_end - uc_start; -touch_softlockup_watchdog (); +touch_watchdog ();if (pool !=NULL ) {memset ((char *)uc_start,0 , size);
arch/ia64/xen/time.c +1 -1
@@ -233,7 +233,7 @@ static void xen_local_tick_resume(void) {/* Just trigger a tick. */ ia64_cpu_local_tick (); -touch_softlockup_watchdog (); +touch_watchdog (); }void
arch/mn10300/kernel/gdb-stub.c +1 -1
@@ -1668,7 +1668,7 @@ done:if (excep ==EXCEP_NMI )NMICR =NMICR_NMIF ; -touch_softlockup_watchdog (); +touch_watchdog ();local_irq_restore (epsw);return 1 ;
arch/powerpc/kernel/swsusp_64.c +1 -1
@@ -14,7 +14,7 @@void do_after_copyback (void ) {iommu_restore (); -touch_softlockup_watchdog (); +touch_watchdog ();mb (); }
arch/sparc/kernel/nmi.c +1 -1
@@ -61,7 +61,7 @@ void touch_nmi_watchdog(void) } } -touch_softlockup_watchdog (); +touch_watchdog (); }EXPORT_SYMBOL (touch_nmi_watchdog);
arch/x86/kernel/apic/nmi.c +1 -1
@@ -383,7 +383,7 @@ void touch_nmi_watchdog(void)/* * Tickle the softlockup detector too: */ -touch_softlockup_watchdog (); +touch_watchdog (); }EXPORT_SYMBOL (touch_nmi_watchdog);
arch/x86/xen/smp.c +1 -1
@@ -60,7 +60,7 @@ static __cpuinit void cpu_bringup(void)int cpu =smp_processor_id ();cpu_init (); -touch_softlockup_watchdog (); +touch_watchdog ();preempt_disable ();xen_enable_sysenter ();
drivers/ide/ide-iops.c +1 -1
@@ -524,7 +524,7 @@ int ide_wait_not_busy(ide_hwif_t *hwif, unsigned long timeout)*/ if (stat ==0xff )return -ENODEV ; -touch_softlockup_watchdog (); +touch_watchdog ();touch_nmi_watchdog (); }return -EBUSY ;
drivers/ide/ide-taskfile.c +1 -1
@@ -291,7 +291,7 @@ static void ide_pio_datablock(ide_drive_t *drive, struct ide_cmd *cmd,if (cmd->tf_flags &IDE_TFLAG_IO_16BIT ) drive->io_32bit =0 ; -touch_softlockup_watchdog (); +touch_watchdog ();if (cmd->tf_flags &IDE_TFLAG_MULTI_PIO ) nr_bytes =min_t (unsigned, cmd->nleft, drive->mult_count <<9 );
drivers/mtd/nand/nand_base.c +2 -2
@@ -445,7 +445,7 @@ static void panic_nand_wait_ready(struct mtd_info *mtd, unsigned long timeo)for (i =0 ; i < timeo; i++) {if (chip->dev_ready (mtd))break ; -touch_softlockup_watchdog (); +touch_watchdog ();mdelay (1 ); } }
@@ -468,7 +468,7 @@ void nand_wait_ready(struct mtd_info *mtd)do {if (chip->dev_ready (mtd))break ; -touch_softlockup_watchdog (); +touch_watchdog (); }while (time_before (jiffies, timeo));led_trigger_event (nand_led_trigger,LED_OFF ); }
drivers/video/nvidia/nv_accel.c +1 -1
@@ -73,7 +73,7 @@ static inline void nvidiafb_safe_mode(struct fb_info *info) {struct nvidia_par *par = info->par; -touch_softlockup_watchdog (); +touch_watchdog (); info->pixmap.scan_align =1 ; par->lockup =1 ; }
include/linux/nmi.h +1 -6
@@ -20,14 +20,10 @@ extern void touch_nmi_watchdog(void);extern void acpi_nmi_disable (void );extern void acpi_nmi_enable (void );#else -#ifndef CONFIG_LOCKUP_DETECTOR static inline void touch_nmi_watchdog (void ) { -touch_softlockup_watchdog (); +touch_watchdog (); } -#else -extern void touch_nmi_watchdog (void ); -#endif static inline void acpi_nmi_disable (void ) { }static inline void acpi_nmi_enable (void ) { }#endif
@@ -52,7 +48,6 @@ static inline bool trigger_all_cpu_backtrace(void)#endif #ifdef CONFIG_LOCKUP_DETECTOR -int hw_nmi_is_cpu_stuck (struct pt_regs *);u64 hw_nmi_get_sample_period (void );extern int watchdog_enabled;struct ctl_table ;
include/linux/sched.h +8 -18
@@ -307,23 +307,19 @@ extern void scheduler_tick(void);extern void sched_show_task (struct task_struct *p); -#ifdef CONFIG_DETECT_SOFTLOCKUP -extern void softlockup_tick (void ); -extern void touch_softlockup_watchdog (void ); -extern void touch_all_softlockup_watchdogs (void ); -extern int proc_dosoftlockup_thresh (struct ctl_table *table,int write, -void __user *buffer, -size_t *lenp,loff_t *ppos); +#ifdef CONFIG_LOCKUP_DETECTOR +extern void touch_watchdog (void ); +extern void touch_all_watchdogs (void );extern unsigned int softlockup_panic;extern int softlockup_thresh; +extern int proc_dowatchdog_thresh (struct ctl_table *table,int write, +void __user *buffer, +size_t *lenp,loff_t *ppos);#else -static inline void softlockup_tick (void ) -{ -} -static inline void touch_softlockup_watchdog (void ) +static inline void touch_watchdog (void ) { } -static inline void touch_all_softlockup_watchdogs (void ) +static inline void touch_all_watchdogs (void ) { }#endif
@@ -338,12 +334,6 @@ extern int proc_dohung_task_timeout_secs(struct ctl_table *table, int write, size_t *lenp, loff_t *ppos);#endif -#ifdef CONFIG_LOCKUP_DETECTOR -extern int proc_dowatchdog_thresh (struct ctl_table *table,int write, -void __user *buffer, -size_t *lenp,loff_t *ppos); -#endif -/* Attach to any functions which should be ignored in wchan output. */ #define __sched __attribute__((__section__(".sched.text")))
kernel/kgdb.c +3 -3
@@ -596,7 +596,7 @@ static void kgdb_wait(struct pt_regs *regs)/* Signal the primary CPU that we are done: */ atomic_set (&cpu_in_kgdb[cpu],0 ); -touch_softlockup_watchdog (); +touch_watchdog ();clocksource_touch_watchdog ();local_irq_restore (flags); }
@@ -1450,7 +1450,7 @@ acquirelock: (kgdb_info[cpu].task && kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {atomic_set (&kgdb_active,-1 ); -touch_softlockup_watchdog (); +touch_watchdog ();clocksource_touch_watchdog ();local_irq_restore (flags);
@@ -1550,7 +1550,7 @@ kgdb_restore: }/* Free kgdb_active */ atomic_set (&kgdb_active,-1 ); -touch_softlockup_watchdog (); +touch_watchdog ();clocksource_touch_watchdog ();local_irq_restore (flags);
kernel/panic.c +1 -1
@@ -136,7 +136,7 @@ NORET_TYPE void panic(const char * fmt, ...)#endif local_irq_enable ();for (i =0 ; ; ) { -touch_softlockup_watchdog (); +touch_watchdog (); i +=panic_blink (i);mdelay (1 ); i++;
kernel/power/hibernate.c +1 -1
@@ -415,7 +415,7 @@ static int resume_target_kernel(bool platform_mode)*/ swsusp_free ();restore_processor_state (); -touch_softlockup_watchdog (); +touch_watchdog ();sysdev_resume ();
kernel/sched.c +1 -1
@@ -6991,7 +6991,7 @@ void show_state_filter(unsigned long state_filter)sched_show_task (p); }while_each_thread (g, p); -touch_all_softlockup_watchdogs (); +touch_all_watchdogs ();#ifdef CONFIG_SCHED_DEBUG sysrq_sched_debug_show ();
kernel/sched_clock.c +1 -1
@@ -232,7 +232,7 @@ void sched_clock_idle_wakeup_event(u64 delta_ns)return ;sched_clock_tick (); -touch_softlockup_watchdog (); +touch_watchdog (); }EXPORT_SYMBOL_GPL (sched_clock_idle_wakeup_event);
kernel/sysctl.c +0 -9
@@ -827,15 +827,6 @@ static struct ctl_table kern_table[] = { .extra1 = &zero, .extra2 = &one, }, - { - .procname = "softlockup_thresh", - .data = &softlockup_thresh, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dosoftlockup_thresh, - .extra1 = &neg_one, - .extra2 = &sixty, - },#endif #ifdef CONFIG_DETECT_HUNG_TASK {
kernel/time/tick-sched.c +4 -4
@@ -147,7 +147,7 @@ static void tick_nohz_update_jiffies(ktime_t now)tick_do_update_jiffies64 (now);local_irq_restore (flags); -touch_softlockup_watchdog (); +touch_watchdog (); }static void tick_nohz_stop_idle (int cpu,ktime_t now)
@@ -494,7 +494,7 @@ void tick_nohz_restart_sched_tick(void)account_idle_ticks (ticks);#endif -touch_softlockup_watchdog (); +touch_watchdog ();/* * Cancel the scheduled timer and restore the tick */
@@ -547,7 +547,7 @@ static void tick_nohz_handler(struct clock_event_device *dev)* do when we go busy again does not account too much ticks. */ if (ts->tick_stopped) { -touch_softlockup_watchdog (); +touch_watchdog (); ts->idle_jiffies++; }
@@ -708,7 +708,7 @@ static enum hrtimer_restart tick_sched_timer(struct hrtimer *timer)* when we go busy again does not account too much ticks. */ if (ts->tick_stopped) { -touch_softlockup_watchdog (); +touch_watchdog (); ts->idle_jiffies++; }update_process_times (user_mode (regs));
kernel/time/timekeeping.c +1 -1
@@ -600,7 +600,7 @@ static int timekeeping_resume(struct sys_device *dev) timekeeping_suspended =0 ;write_sequnlock_irqrestore (&xtime_lock, flags); -touch_softlockup_watchdog (); +touch_watchdog ();clockevents_notify (CLOCK_EVT_NOTIFY_RESUME ,NULL );
kernel/timer.c +0 -1
@@ -1223,7 +1223,6 @@ void run_local_timers(void) {hrtimer_run_queues ();raise_softirq (TIMER_SOFTIRQ ); -softlockup_tick (); }/*
kernel/watchdog.c +1 -29
@@ -125,7 +125,7 @@ void touch_watchdog(void) }EXPORT_SYMBOL (touch_watchdog); -void touch_all_watchdog (void ) +void touch_all_watchdogs (void ) {int cpu;
@@ -144,25 +144,6 @@ void touch_nmi_watchdog(void) }EXPORT_SYMBOL (touch_nmi_watchdog); -void touch_all_nmi_watchdog (void ) -{ -touch_all_watchdog (); -} - -void touch_softlockup_watchdog (void ) -{ -touch_watchdog (); -} - -void touch_all_softlockup_watchdogs (void ) -{ -touch_all_watchdog (); -} - -void softlockup_tick (void ) -{ -} -#ifdef CONFIG_PERF_EVENTS_NMI /* watchdog detector functions */ static int is_hardlockup (int cpu)
@@ -510,15 +491,6 @@ int proc_dowatchdog_thresh(struct ctl_table *table, int write, {return proc_dointvec_minmax (table, write, buffer, lenp, ppos); } - -/* stub functions */ -int proc_dosoftlockup_thresh (struct ctl_table *table,int write, -void __user *buffer, -size_t *lenp,loff_t *ppos) -{ -return proc_dowatchdog_thresh (table, write, buffer, lenp, ppos); -} -/* end of stub functions */ #endif /* CONFIG_SYSCTL */
Signature · 1 line
1.6.5.2
Re: [PATCH 2/6] [watchdog] convert touch_softlockup_watchdog to touch_watchdog
Quoted 9 lines · Don Zickus
Just a scripted conversion to remove
touch_softlockup_watchdog.Also converts the once case of
touch_all_softlockup_watchdogstotouch_all_watchdogs.This is done as part of the removal of the old softlockup code and transition to the new softlockup code.
Signed-off-by Don Zickus <[email protected]>
In fact I worry a bit about this unification of watchdog touching. When we touch the softlockup watchdog, do we also want to touch the nmi watchdog?
Most of the time, I think we don't want to. We usually touch the softlockup detector because we know we are abnormally delaying the softlockup kthread from being scheduled, and if we are in such situation, it means we are doing something in a sensitive context:
typically the kind of context favorable to create hardlockups...
But the opposite is right: if we touch the nmi watchdog: it means we are abnormally delaying irqs, which means we also are abnormally delaying the softlockup kthread from being scheduled, so if we touch the nmi watchdog, we also want to touch the softlockup detector.
Hence I guess we want to keep the current state:
- touch_nmi_watchdog() = touch softlockup and nmi watchdogs
- touch_softlockup_watchdog() = only touch softlockup watchdog
Re: [PATCH 2/6] [watchdog] convert touch_softlockup_watchdog to touch_watchdog
Quoted 28 lines · Frederic Weisbecker
Quoted 9 lines · Don Zickus
Just a scripted conversion to remove
touch_softlockup_watchdog.Also converts the once case of
touch_all_softlockup_watchdogstotouch_all_watchdogs.This is done as part of the removal of the old softlockup code and transition to the new softlockup code.
Signed-off-by Don Zickus <[email protected]>In fact I worry a bit about this unification of watchdog touching. When we touch the softlockup watchdog, do we also want to touch the nmi watchdog?
Most of the time, I think we don't want to. We usually touch the softlockup detector because we know we are abnormally delaying the softlockup kthread from being scheduled, and if we are in such situation, it means we are doing something in a sensitive context:
typically the kind of context favorable to create hardlockups...But the opposite is right: if we touch the nmi watchdog: it means we are abnormally delaying irqs, which means we also are abnormally delaying the softlockup kthread from being scheduled, so if we touch the nmi watchdog, we also want to touch the softlockup detector.
Quoted 4 lines
Hence I guess we want to keep the current state:
-
touch_nmi_watchdog()= touch softlockup and nmi watchdogs
-touch_softlockup_watchdog()= only touch softlockup watchdog
Hmm ok I see what you are saying. A little tweak and I have this compiled-tested only patch that I think satisifies you.
I didn't really touch the touch_nmi_watchdog() code in the kernel, so it still calls a stub function in kernel/watchdog.c. Add a boolean to that path and I think it accomplishes the logic you are looking for.
Cheers,
Don
kernel/watchdog.c +4 -3
@@ -31,6 +31,7 @@ int watchdog_enabled;int __read_mostly softlockup_thresh =60 ; static DEFINE_PER_CPU(unsigned long, watchdog_touch_ts); +static DEFINE_PER_CPU(bool, watchdog_nmi_touch); static DEFINE_PER_CPU(struct task_struct *, softlockup_watchdog); static DEFINE_PER_CPU(struct hrtimer, watchdog_hrtimer); static DEFINE_PER_CPU(bool, watchdog_touch_sync);
@@ -147,6 +148,7 @@ void touch_watchdog_sync(void)void touch_nmi_watchdog (void ) { +__get_cpu_var (watchdog_nmi_touch) = true;touch_watchdog (); }EXPORT_SYMBOL (touch_nmi_watchdog);
@@ -203,11 +205,10 @@ void watchdog_overflow_callback(struct perf_event *event, int nmi, struct pt_regs *regs) {int this_cpu =smp_processor_id (); -unsigned long touch_ts =per_cpu (watchdog_touch_ts, this_cpu);char warn =per_cpu (watchdog_warn, this_cpu); -if (touch_ts ==0 ) { -__touch_watchdog (); +if (__get_cpu_var (watchdog_nmi_touch) == true) { +__get_cpu_var (watchdog_nmi_touch) = false;return ; }
Re: [PATCH 2/6] [watchdog] convert touch_softlockup_watchdog to touch_watchdog
Quoted 37 lines · Don Zickus
Quoted 28 lines · Frederic Weisbecker
Quoted 9 lines · Don Zickus
Just a scripted conversion to remove
touch_softlockup_watchdog.Also converts the once case of
touch_all_softlockup_watchdogstotouch_all_watchdogs.This is done as part of the removal of the old softlockup code and transition to the new softlockup code.
Signed-off-by Don Zickus <[email protected]>In fact I worry a bit about this unification of watchdog touching. When we touch the softlockup watchdog, do we also want to touch the nmi watchdog?
Most of the time, I think we don't want to. We usually touch the softlockup detector because we know we are abnormally delaying the softlockup kthread from being scheduled, and if we are in such situation, it means we are doing something in a sensitive context:
typically the kind of context favorable to create hardlockups...But the opposite is right: if we touch the nmi watchdog: it means we are abnormally delaying irqs, which means we also are abnormally delaying the softlockup kthread from being scheduled, so if we touch the nmi watchdog, we also want to touch the softlockup detector.
Quoted 4 lines
Hence I guess we want to keep the current state:
-
touch_nmi_watchdog()= touch softlockup and nmi watchdogs
-touch_softlockup_watchdog()= only touch softlockup watchdogHmm ok I see what you are saying. A little tweak and I have this compiled-tested only patch that I think satisifies you.
Quoted 6 lines
I didn't really touch the
touch_nmi_watchdog()code in the kernel, so it still calls a stub function inkernel/watchdog.c. Add a boolean to that path and I think it accomplishes the logic you are looking for.Cheers,
Don
Yeah looks good.
Could you send this patch with a changelog and your sign-off?
Thanks!
Quoted 36 lines
kernel/watchdog.c +4
-3@@ -31,6 +31,7 @@ int watchdog_enabled;int __read_mostly softlockup_thresh =60 ; static DEFINE_PER_CPU(unsigned long, watchdog_touch_ts); +static DEFINE_PER_CPU(bool, watchdog_nmi_touch); static DEFINE_PER_CPU(struct task_struct *, softlockup_watchdog); static DEFINE_PER_CPU(struct hrtimer, watchdog_hrtimer); static DEFINE_PER_CPU(bool, watchdog_touch_sync);@@ -147,6 +148,7 @@ void touch_watchdog_sync(void)void touch_nmi_watchdog (void ) { +__get_cpu_var (watchdog_nmi_touch) = true;touch_watchdog (); }EXPORT_SYMBOL (touch_nmi_watchdog);@@ -203,11 +205,10 @@ void watchdog_overflow_callback(struct perf_event *event, int nmi, struct pt_regs *regs) {int this_cpu =smp_processor_id (); -unsigned long touch_ts =per_cpu (watchdog_touch_ts, this_cpu);char warn =per_cpu (watchdog_warn, this_cpu); -if (touch_ts ==0 ) { -__touch_watchdog (); +if (__get_cpu_var (watchdog_nmi_touch) == true) { +__get_cpu_var (watchdog_nmi_touch) = false;return ; }
Re: [PATCH 2/6] [watchdog] convert touch_softlockup_watchdog to touch_watchdog
Quoted 12 lines · Frederic Weisbecker
Quoted 12 lines
Quoted 4 lines
Hence I guess we want to keep the current state:
-
touch_nmi_watchdog()= touch softlockup and nmi watchdogs
-touch_softlockup_watchdog()= only touch softlockup watchdogHmm ok I see what you are saying. A little tweak and I have this compiled-tested only patch that I think satisifies you.
I didn't really touch the
touch_nmi_watchdog()code in the kernel, so it still calls a stub function inkernel/watchdog.c. Add a boolean to that path and I think it accomplishes the logic you are looking for.
Quoted 7 lines
Quoted 2 lines
Cheers,
DonYeah looks good.
Could you send this patch with a changelog and your sign-off?
I thought about including it when I refresh the patch series with the other changes you suggested. Do you prefer it to be separate?
Cheers,
Don
Re: [PATCH 2/6] [watchdog] convert touch_softlockup_watchdog to touch_watchdog
Quoted 17 lines · Don Zickus
Quoted 16 lines · Frederic Weisbecker
Quoted 14 lines
Quoted 4 lines
Hence I guess we want to keep the current state:
-
touch_nmi_watchdog()= touch softlockup and nmi watchdogs
-touch_softlockup_watchdog()= only touch softlockup watchdogHmm ok I see what you are saying. A little tweak and I have this compiled-tested only patch that I think satisifies you.
I didn't really touch the
touch_nmi_watchdog()code in the kernel, so it still calls a stub function inkernel/watchdog.c. Add a boolean to that path and I think it accomplishes the logic you are looking for.Cheers,
Don
Quoted 6 lines
Quoted 3 lines
Yeah looks good.
Could you send this patch with a changelog and your sign-off?
I thought about including it when I refresh the patch series with the other changes you suggested. Do you prefer it to be separate?
I was about to apply the series because there were mostly minor things to fix.
But I would indeed prefer you repost a new series with the reviews addressed, whatever this patch is a delta or a fixed existing one. I will more likely forget things in the middle than you will.
Thanks.
PATCH 3/6 remove old softlockup code
In reply to Don ZickusNow that is no longer compiled or used, just remove it.
Also moves some of the code wrapped with DETECT_SOFTLOCKUP to the LOCKUP_DETECTOR wrappers because that is the code that uses it now.
--- kernel/softlockup.c | 278 --------------------------------------------------- kernel/sysctl.c | 22 ++-- 2 files changed, 10 insertions(+), 290 deletions(-) delete mode 100644 kernel/softlockup.c
kernel/softlockup.c deleted +0 -278
@@ -1,278 +0,0 @@ -/* -* Detect Soft Lockups -* -* started by Ingo Molnar, Copyright (C) 2005, 2006 Red Hat, Inc. -* -* this code detects soft lockups: incidents in where on a CPU -* the kernel does not reschedule for 10 seconds or more. -*/ -#include <linux/mm.h> -#include <linux/cpu.h> -#include <linux/nmi.h> -#include <linux/init.h> -#include <linux/delay.h> -#include <linux/freezer.h> -#include <linux/kthread.h> -#include <linux/lockdep.h> -#include <linux/notifier.h> -#include <linux/module.h> -#include <linux/sysctl.h> - -#include <asm/irq_regs.h> - -static DEFINE_SPINLOCK (print_lock); - -static DEFINE_PER_CPU(unsigned long, softlockup_touch_ts); /* touch timestamp */ -static DEFINE_PER_CPU(unsigned long, softlockup_print_ts); /* print timestamp */ -static DEFINE_PER_CPU(struct task_struct *, softlockup_watchdog); - -static int __read_mostly did_panic; -int __read_mostly softlockup_thresh =60 ; - -/* -* Should we panic (and reboot, if panic_timeout= is set) when a -* soft-lockup occurs: -*/ -unsigned int __read_mostly softlockup_panic = -CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE ; - -static int __init softlockup_panic_setup (char *str) -{ - softlockup_panic =simple_strtoul (str,NULL ,0 ); - -return 1 ; -} -__setup ("softlockup_panic=" , softlockup_panic_setup); - -static int -softlock_panic (struct notifier_block *this,unsigned long event,void *ptr) -{ - did_panic =1 ; - -return NOTIFY_DONE ; -} - -static struct notifier_block panic_block = { - .notifier_call = softlock_panic, -}; - -/* -* Returns seconds, approximately. We don't need nanosecond -* resolution, and we don't need to waste time with a big divide when -* 2^30ns == 1.074s. -*/ -static unsigned long get_timestamp (int this_cpu) -{ -return cpu_clock (this_cpu) >>30LL ;/* 2^30 ~= 10^9 */ -} - -static void __touch_softlockup_watchdog (void ) -{ -int this_cpu =raw_smp_processor_id (); - -__raw_get_cpu_var (softlockup_touch_ts) =get_timestamp (this_cpu); -} - -void touch_softlockup_watchdog (void ) -{ -__raw_get_cpu_var (softlockup_touch_ts) =0 ; -} -EXPORT_SYMBOL (touch_softlockup_watchdog); - -void touch_all_softlockup_watchdogs (void ) -{ -int cpu; - -/* Cause each CPU to re-update its timestamp rather than complain */ -for_each_online_cpu (cpu) -per_cpu (softlockup_touch_ts, cpu) =0 ; -} -EXPORT_SYMBOL (touch_all_softlockup_watchdogs); - -int proc_dosoftlockup_thresh (struct ctl_table *table,int write, -void __user *buffer, -size_t *lenp,loff_t *ppos) -{ -touch_all_softlockup_watchdogs (); -return proc_dointvec_minmax (table, write, buffer, lenp, ppos); -} - -/* -* This callback runs from the timer interrupt, and checks -* whether the watchdog thread has hung or not: -*/ -void softlockup_tick (void ) -{ -int this_cpu =smp_processor_id (); -unsigned long touch_ts =per_cpu (softlockup_touch_ts, this_cpu); -unsigned long print_ts; -struct pt_regs *regs =get_irq_regs (); -unsigned long now; - -/* Is detection switched off? */ -if (!per_cpu (softlockup_watchdog, this_cpu) || softlockup_thresh <=0 ) { -/* Be sure we don't false trigger if switched back on */ -if (touch_ts) -per_cpu (softlockup_touch_ts, this_cpu) =0 ; -return ; - } - -if (touch_ts ==0 ) { -__touch_softlockup_watchdog (); -return ; - } - - print_ts =per_cpu (softlockup_print_ts, this_cpu); - -/* report at most once a second */ -if (print_ts == touch_ts || did_panic) -return ; - -/* do not print during early bootup: */ -if (unlikely (system_state !=SYSTEM_RUNNING )) { -__touch_softlockup_watchdog (); -return ; - } - - now =get_timestamp (this_cpu); - -/* -* Wake up the high-prio watchdog task twice per -* threshold timespan. -*/ -if (now > touch_ts + softlockup_thresh/2 ) -wake_up_process (per_cpu (softlockup_watchdog, this_cpu)); - -/* Warn about unreasonable delays: */ -if (now <= (touch_ts + softlockup_thresh)) -return ; - -per_cpu (softlockup_print_ts, this_cpu) = touch_ts; - -spin_lock (&print_lock); -printk (KERN_ERR "BUG: soft lockup - CPU#%d stuck for %lus! [%s:%d]\n" , - this_cpu, now - touch_ts, - current->comm,task_pid_nr (current)); -print_modules (); -print_irqtrace_events (current); -if (regs) -show_regs (regs); -else -dump_stack (); -spin_unlock (&print_lock); - -if (softlockup_panic) -panic ("softlockup: hung tasks" ); -} - -/* -* The watchdog thread - runs every second and touches the timestamp. -*/ -static int watchdog (void *__bind_cpu) -{ -struct sched_param param = { .sched_priority =MAX_RT_PRIO -1 }; - -sched_setscheduler (current,SCHED_FIFO , ¶m); - -/* initialize timestamp */ -__touch_softlockup_watchdog (); - -set_current_state (TASK_INTERRUPTIBLE ); -/* -* Run briefly once per second to reset the softlockup timestamp. -* If this gets delayed for more than 60 seconds then the -* debug-printout triggers in softlockup_tick(). -*/ -while (!kthread_should_stop ()) { -__touch_softlockup_watchdog (); -schedule (); - -if (kthread_should_stop ()) -break ; - -set_current_state (TASK_INTERRUPTIBLE ); - } -__set_current_state (TASK_RUNNING ); - -return 0 ; -} - -/* -* Create/destroy watchdog threads as CPUs come and go: -*/ -static int __cpuinit -cpu_callback (struct notifier_block *nfb,unsigned long action,void *hcpu) -{ -int hotcpu = (unsigned long )hcpu; -struct task_struct *p; - -switch (action) { -case CPU_UP_PREPARE : -case CPU_UP_PREPARE_FROZEN : -BUG_ON (per_cpu (softlockup_watchdog, hotcpu)); - p =kthread_create (watchdog, hcpu,"watchdog/%d" , hotcpu); -if (IS_ERR (p)) { -printk (KERN_ERR "watchdog for %i failed\n" , hotcpu); -return NOTIFY_BAD ; - } -per_cpu (softlockup_touch_ts, hotcpu) =0 ; -per_cpu (softlockup_watchdog, hotcpu) = p; -kthread_bind (p, hotcpu); -break ; -case CPU_ONLINE : -case CPU_ONLINE_FROZEN : -wake_up_process (per_cpu (softlockup_watchdog, hotcpu)); -break ; -#ifdef CONFIG_HOTPLUG_CPU -case CPU_UP_CANCELED : -case CPU_UP_CANCELED_FROZEN : -if (!per_cpu (softlockup_watchdog, hotcpu)) -break ; -/* Unbind so it can run. Fall thru. */ -kthread_bind (per_cpu (softlockup_watchdog, hotcpu), -cpumask_any (cpu_online_mask)); -case CPU_DEAD : -case CPU_DEAD_FROZEN : - p =per_cpu (softlockup_watchdog, hotcpu); -per_cpu (softlockup_watchdog, hotcpu) =NULL ; -kthread_stop (p); -break ; -#endif /* CONFIG_HOTPLUG_CPU */ - } -return NOTIFY_OK ; -} - -static struct notifier_block __cpuinitdata cpu_nfb = { - .notifier_call = cpu_callback -}; - -static int __initdata nosoftlockup; - -static int __init nosoftlockup_setup (char *str) -{ - nosoftlockup =1 ; -return 1 ; -} -__setup ("nosoftlockup" , nosoftlockup_setup); - -static int __init spawn_softlockup_task (void ) -{ -void *cpu = (void *)(long )smp_processor_id (); -int err; - -if (nosoftlockup) -return 0 ; - - err =cpu_callback (&cpu_nfb,CPU_UP_PREPARE , cpu); -if (err ==NOTIFY_BAD ) { -BUG (); -return 1 ; - } -cpu_callback (&cpu_nfb,CPU_ONLINE , cpu); -register_cpu_notifier (&cpu_nfb); - -atomic_notifier_chain_register (&panic_notifier_list, &panic_block); - -return 0 ; -} -early_initcall (spawn_softlockup_task);
kernel/sysctl.c +10 -12
@@ -99,7 +99,7 @@ extern int blk_iopoll_enabled;#endif /* Constants used for minimum and maximum */ -#ifdef CONFIG_DETECT_SOFTLOCKUP +#ifdef CONFIG_LOCKUP_DETECTOR static int sixty =60 ;static int neg_one =-1 ;#endif
@@ -713,6 +713,15 @@ static struct ctl_table kern_table[] = { .extra1 = &neg_one, .extra2 = &sixty, }, + { + .procname = "softlockup_panic", + .data = &softlockup_panic, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &one, + },#endif #if defined(CONFIG_X86_LOCAL_APIC ) && defined(CONFIG_X86 ) && !defined(CONFIG_LOCKUP_DETECTOR ) {
@@ -817,17 +826,6 @@ static struct ctl_table kern_table[] = { .proc_handler = proc_dointvec, },#endif -#ifdef CONFIG_DETECT_SOFTLOCKUP - { - .procname = "softlockup_panic", - .data = &softlockup_panic, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec_minmax, - .extra1 = &zero, - .extra2 = &one, - }, -#endif#ifdef CONFIG_DETECT_HUNG_TASK { .procname = "hung_task_panic",
Signature · 1 line
1.6.5.2
PATCH 4/6 remove nmi_watchdog.c file
In reply to Don ZickusThis file migrated to kernel/watchdog.c and then combined with kernel/softlockup.c. As a result kernel/nmi_watchdog.c is no longer needed. Just remove it.
--- kernel/nmi_watchdog.c | 259 ------------------------------------------------- 1 files changed, 0 insertions(+), 259 deletions(-) delete mode 100644 kernel/nmi_watchdog.c
kernel/nmi_watchdog.c deleted +0 -259
@@ -1,259 +0,0 @@ -/* -* Detect Hard Lockups using the NMI -* -* started by Don Zickus, Copyright (C) 2010 Red Hat, Inc. -* -* this code detects hard lockups: incidents in where on a CPU -* the kernel does not respond to anything except NMI. -* -* Note: Most of this code is borrowed heavily from softlockup.c, -* so thanks to Ingo for the initial implementation. -* Some chunks also taken from arch/x86/kernel/apic/nmi.c, thanks -* to those contributors as well. -*/ - -#include <linux/mm.h> -#include <linux/cpu.h> -#include <linux/nmi.h> -#include <linux/init.h> -#include <linux/delay.h> -#include <linux/freezer.h> -#include <linux/lockdep.h> -#include <linux/notifier.h> -#include <linux/module.h> -#include <linux/sysctl.h> - -#include <asm/irq_regs.h> -#include <linux/perf_event.h> - -static DEFINE_PER_CPU(struct perf_event *, nmi_watchdog_ev); -static DEFINE_PER_CPU(int, nmi_watchdog_touch); -static DEFINE_PER_CPU(long, alert_counter); - -static int panic_on_timeout; - -void touch_nmi_watchdog (void ) -{ -__raw_get_cpu_var (nmi_watchdog_touch) =1 ; -touch_softlockup_watchdog (); -} -EXPORT_SYMBOL (touch_nmi_watchdog); - -void touch_all_nmi_watchdog (void ) -{ -int cpu; - -for_each_online_cpu (cpu) -per_cpu (nmi_watchdog_touch, cpu) =1 ; -touch_softlockup_watchdog (); -} - -static int __init setup_nmi_watchdog (char *str) -{ -if (!strncmp (str,"panic" ,5 )) { - panic_on_timeout =1 ; - str =strchr (str,',' ); -if (!str) -return 1 ; - ++str; - } -return 1 ; -} -__setup ("nmi_watchdog=" , setup_nmi_watchdog); - -struct perf_event_attr wd_hw_attr = { - .type =PERF_TYPE_HARDWARE , - .config =PERF_COUNT_HW_CPU_CYCLES , - .size =sizeof (struct perf_event_attr ), - .pinned =1 , - .disabled =1 , -}; - -struct perf_event_attr wd_sw_attr = { - .type =PERF_TYPE_SOFTWARE , - .config =PERF_COUNT_SW_CPU_CLOCK , - .size =sizeof (struct perf_event_attr ), - .pinned =1 , - .disabled =1 , -}; - -void wd_overflow (struct perf_event *event,int nmi, -struct perf_sample_data *data, -struct pt_regs *regs) -{ -int cpu =smp_processor_id (); -int touched =0 ; - -if (__get_cpu_var (nmi_watchdog_touch)) { -per_cpu (nmi_watchdog_touch, cpu) =0 ; - touched =1 ; - } - -/* check to see if the cpu is doing anything */ -if (!touched &&hw_nmi_is_cpu_stuck (regs)) { -/* -* Ayiee, looks like this CPU is stuck ... -* wait a few IRQs (5 seconds) before doing the oops ... -*/ -per_cpu (alert_counter, cpu) +=1 ; -if (per_cpu (alert_counter, cpu) ==5 ) { -if (panic_on_timeout) -panic ("NMI Watchdog detected LOCKUP on cpu %d" , cpu); -else -WARN (1 ,"NMI Watchdog detected LOCKUP on cpu %d" , cpu); - } - }else { -per_cpu (alert_counter, cpu) =0 ; - } - -return ; -} - -static int enable_nmi_watchdog (int cpu) -{ -struct perf_event *event; -struct perf_event_attr *wd_attr; - - event =per_cpu (nmi_watchdog_ev, cpu); -if (event && event->state >PERF_EVENT_STATE_OFF ) -return 0 ; - -if (event ==NULL ) { -/* Try to register using hardware perf events first */ - wd_attr = &wd_hw_attr; - wd_attr->sample_period =hw_nmi_get_sample_period (); - event =perf_event_create_kernel_counter (wd_attr, cpu,-1 , wd_overflow); -if (IS_ERR (event)) { -/* hardware doesn't exist or not supported, fallback to software events */ -printk (KERN_INFO "nmi_watchdog: hardware not available, trying software events\n" ); - wd_attr = &wd_sw_attr; - wd_attr->sample_period =NSEC_PER_SEC ; - event =perf_event_create_kernel_counter (wd_attr, cpu,-1 , wd_overflow); -if (IS_ERR (event)) { -printk (KERN_ERR "nmi watchdog failed to create perf event on %i: %p\n" , cpu, event); -return -1 ; - } - } -per_cpu (nmi_watchdog_ev, cpu) = event; - } -perf_event_enable (per_cpu (nmi_watchdog_ev, cpu)); -return 0 ; -} - -static void disable_nmi_watchdog (int cpu) -{ -struct perf_event *event; - - event =per_cpu (nmi_watchdog_ev, cpu); -if (event) { -perf_event_disable (per_cpu (nmi_watchdog_ev, cpu)); -per_cpu (nmi_watchdog_ev, cpu) =NULL ; -perf_event_release_kernel (event); - } -} - -#ifdef CONFIG_SYSCTL -/* -* proc handler for /proc/sys/kernel/nmi_watchdog -*/ -int nmi_watchdog_enabled; - -int proc_nmi_enabled (struct ctl_table *table,int write, -void __user *buffer,size_t *length,loff_t *ppos) -{ -int cpu; - -if (!write) { -struct perf_event *event; -for_each_online_cpu (cpu) { - event =per_cpu (nmi_watchdog_ev, cpu); -if (event && event->state >PERF_EVENT_STATE_OFF ) { - nmi_watchdog_enabled =1 ; -break ; - } - } -proc_dointvec (table, write, buffer, length, ppos); -return 0 ; - } - -touch_all_nmi_watchdog (); -proc_dointvec (table, write, buffer, length, ppos); -if (nmi_watchdog_enabled) { -for_each_online_cpu (cpu) -if (enable_nmi_watchdog (cpu)) { -printk (KERN_ERR "NMI watchdog failed configuration, " -" can not be enabled\n" ); - } - }else { -for_each_online_cpu (cpu) -disable_nmi_watchdog (cpu); - } -return 0 ; -} - -#endif /* CONFIG_SYSCTL */ - -/* -* Create/destroy watchdog threads as CPUs come and go: -*/ -static int __cpuinit -cpu_callback (struct notifier_block *nfb,unsigned long action,void *hcpu) -{ -int hotcpu = (unsigned long )hcpu; - -switch (action) { -case CPU_UP_PREPARE : -case CPU_UP_PREPARE_FROZEN : -per_cpu (nmi_watchdog_touch, hotcpu) =0 ; -break ; -case CPU_ONLINE : -case CPU_ONLINE_FROZEN : -if (enable_nmi_watchdog (hotcpu)) -return NOTIFY_BAD ; -break ; -#ifdef CONFIG_HOTPLUG_CPU -case CPU_UP_CANCELED : -case CPU_UP_CANCELED_FROZEN : -disable_nmi_watchdog (hotcpu); -case CPU_DEAD : -case CPU_DEAD_FROZEN : -break ; -#endif /* CONFIG_HOTPLUG_CPU */ - } -return NOTIFY_OK ; -} - -static struct notifier_block __cpuinitdata cpu_nfb = { - .notifier_call = cpu_callback -}; - -static int __initdata nonmi_watchdog; - -static int __init nonmi_watchdog_setup (char *str) -{ - nonmi_watchdog =1 ; -return 1 ; -} -__setup ("nonmi_watchdog" , nonmi_watchdog_setup); - -static int __init spawn_nmi_watchdog_task (void ) -{ -void *cpu = (void *)(long )smp_processor_id (); -int err; - -if (nonmi_watchdog) -return 0 ; - -printk (KERN_INFO "NMI watchdog enabled, takes one hw-pmu counter.\n" ); - - err =cpu_callback (&cpu_nfb,CPU_UP_PREPARE , cpu); -if (err ==NOTIFY_BAD ) { -BUG (); -return 1 ; - } -cpu_callback (&cpu_nfb,CPU_ONLINE , cpu); -register_cpu_notifier (&cpu_nfb); - -return 0 ; -} -early_initcall (spawn_nmi_watchdog_task);
Signature · 1 line
1.6.5.2
PATCH 5/6 watchdog: move trigger_all_cpu_backtrace to its own die_notifier
In reply to Don ZickusAs part of the transition of the nmi watchdog to something more generic, the trigger_all_cpu_backtrace code is getting left behind. Put it in its own die_notifier so it can still be used.
--- arch/x86/kernel/apic/hw_nmi.c | 65 ++++++++++++++++++++++++++++++++--------- 1 files changed, 51 insertions(+), 14 deletions(-)
arch/x86/kernel/apic/hw_nmi.c +51 -14
@@ -17,6 +17,10 @@#include <linux/cpumask.h> #include <linux/kernel_stat.h> #include <asm/mce.h> +#include <linux/kdebug.h> +#include <linux/notifier.h> +#include <linux/kprobes.h> +#include <linux/nmi.h> #include <linux/module.h>
@@ -54,20 +58,6 @@ int hw_nmi_is_cpu_stuck(struct pt_regs *regs)unsigned int sum;int cpu =smp_processor_id (); -/* FIXME: cheap hack for this check, probably should get its own -* die_notifier handler -*/ -if (cpumask_test_cpu (cpu,to_cpumask (backtrace_mask))) { -static DEFINE_SPINLOCK (lock);/* Serialise the printks */ - -spin_lock (&lock); -printk (KERN_WARNING "NMI backtrace for cpu %d\n" , cpu); -show_regs (regs); -dump_stack (); -spin_unlock (&lock); -cpumask_clear_cpu (cpu,to_cpumask (backtrace_mask)); - } -/* if we are doing an mce, just assume the cpu is not stuck */ /* Could check oops_in_progress here too, but it's safer not to */ if (mce_in_progress ())
@@ -109,6 +99,53 @@ void arch_trigger_all_cpu_backtrace(void) mdelay(1); } } + +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; +int cpu =smp_processor_id (); + +switch (cmd) { +case DIE_NMI : +case DIE_NMI_IPI : +break ; + +default : +return NOTIFY_DONE ; + } + + regs = args->regs; + +if (cpumask_test_cpu (cpu,to_cpumask (backtrace_mask))) { +static DEFINE_SPINLOCK (lock);/* Serialise the printks */ + +spin_lock (&lock); +printk (KERN_WARNING "NMI backtrace for cpu %d\n" , cpu); +show_regs (regs); +dump_stack (); +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 , + .priority =1 +}; + +static int __init register_trigger_all_cpu_backtrace (void ) +{ +register_die_notifier (&backtrace_notifier); +return 0 ; +} +early_initcall (register_trigger_all_cpu_backtrace);#endif /* STUB calls to mimic old nmi_watchdog behaviour */
Signature · 1 line
1.6.5.2
Re: [PATCH 5/6] [x86] watchdog: move trigger_all_cpu_backtrace to its own die_notifier
Quoted 63 lines · Don Zickus
As part of the transition of the nmi watchdog to something more generic, the
trigger_all_cpu_backtracecode is getting left behind. Put it in its owndie_notifierso it can still be used.Signed-off-by Don Zickus <[email protected]>--- arch/x86/kernel/apic/hw_nmi.c | 65 ++++++++++++++++++++++++++++++++--------- 1 files changed, 51 insertions(+), 14 deletions(-)arch/x86/kernel/apic/hw_nmi.c +18
-14@@ -17,6 +17,10 @@#include <linux/cpumask.h> #include <linux/kernel_stat.h> #include <asm/mce.h> +#include <linux/kdebug.h> +#include <linux/notifier.h> +#include <linux/kprobes.h> +#include <linux/nmi.h> #include <linux/module.h> @@ -54,20 +58,6 @@ int hw_nmi_is_cpu_stuck(struct pt_regs *regs)unsigned int sum;int cpu =smp_processor_id (); -/* FIXME: cheap hack for this check, probably should get its own -* die_notifier handler -*/ -if (cpumask_test_cpu (cpu,to_cpumask (backtrace_mask))) { -static DEFINE_SPINLOCK (lock);/* Serialise the printks */ - -spin_lock (&lock); -printk (KERN_WARNING "NMI backtrace for cpu %d\n" , cpu); -show_regs (regs); -dump_stack (); -spin_unlock (&lock); -cpumask_clear_cpu (cpu,to_cpumask (backtrace_mask)); - } -/* if we are doing an mce, just assume the cpu is not stuck */ /* Could check oops_in_progress here too, but it's safer not to */ if (mce_in_progress ())@@ -109,6 +99,53 @@ void arch_trigger_all_cpu_backtrace(void)mdelay (1 ); } } + +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; +int cpu =smp_processor_id (); + +switch (cmd) { +case DIE_NMI : +case DIE_NMI_IPI : +break ; +
arch/x86/kernel/apic/hw_nmi.c void arch_trigger_all_cpu_backtrace(void) · line 125
Quoted 10 lines
arch/x86/kernel/apic/hw_nmi.c +10
-0+default : +return NOTIFY_DONE ; + } + + regs = args->regs; + +if (cpumask_test_cpu (cpu,to_cpumask (backtrace_mask))) { +static DEFINE_SPINLOCK (lock);/* Serialise the printks */ + +spin_lock (&lock);
This should be an arch_spin_lock(), so that it won't sleep with rt mutex.
In fact this whole function can be moved to generic code, right?
Quoted 29 lines
arch/x86/kernel/apic/hw_nmi.c +23
-0+printk (KERN_WARNING "NMI backtrace for cpu %d\n" , cpu); +show_regs (regs); +dump_stack (); +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 , + .priority =1 +}; + +static int __init register_trigger_all_cpu_backtrace (void ) +{ +register_die_notifier (&backtrace_notifier); +return 0 ; +} +early_initcall (register_trigger_all_cpu_backtrace);#endif /* STUB calls to mimic old nmi_watchdog behaviour */ Signature · 1 line
1.6.5.2
Re: [PATCH 5/6] [x86] watchdog: move trigger_all_cpu_backtrace to its own die_notifier
Quoted 70 lines · Frederic Weisbecker
Quoted 69 lines · Don Zickus
As part of the transition of the nmi watchdog to something more generic, the
trigger_all_cpu_backtracecode is getting left behind. Put it in its owndie_notifierso it can still be used.Signed-off-by Don Zickus <[email protected]>--- arch/x86/kernel/apic/hw_nmi.c | 65 ++++++++++++++++++++++++++++++++--------- 1 files changed, 51 insertions(+), 14 deletions(-)arch/x86/kernel/apic/hw_nmi.c +24
-14@@ -17,6 +17,10 @@#include <linux/cpumask.h> #include <linux/kernel_stat.h> #include <asm/mce.h> +#include <linux/kdebug.h> +#include <linux/notifier.h> +#include <linux/kprobes.h> +#include <linux/nmi.h> #include <linux/module.h> @@ -54,20 +58,6 @@ int hw_nmi_is_cpu_stuck(struct pt_regs *regs)unsigned int sum;int cpu =smp_processor_id (); -/* FIXME: cheap hack for this check, probably should get its own -* die_notifier handler -*/ -if (cpumask_test_cpu (cpu,to_cpumask (backtrace_mask))) { -static DEFINE_SPINLOCK (lock);/* Serialise the printks */ - -spin_lock (&lock); -printk (KERN_WARNING "NMI backtrace for cpu %d\n" , cpu); -show_regs (regs); -dump_stack (); -spin_unlock (&lock); -cpumask_clear_cpu (cpu,to_cpumask (backtrace_mask)); - } -/* if we are doing an mce, just assume the cpu is not stuck */ /* Could check oops_in_progress here too, but it's safer not to */ if (mce_in_progress ())@@ -109,6 +99,53 @@ void arch_trigger_all_cpu_backtrace(void)mdelay (1 ); } } + +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; +int cpu =smp_processor_id (); + +switch (cmd) { +case DIE_NMI : +case DIE_NMI_IPI : +break ; + +default : +return NOTIFY_DONE ; + } + + regs = args->regs; +
Quoted 8 lines
arch/x86/kernel/apic/hw_nmi.c void arch_trigger_all_cpu_backtrace(void) · line 125
Quoted 4 lines
arch/x86/kernel/apic/hw_nmi.c +4
-0+if (cpumask_test_cpu (cpu,to_cpumask (backtrace_mask))) { +static DEFINE_SPINLOCK (lock);/* Serialise the printks */ + +spin_lock (&lock);This should be an
arch_spin_lock(), so that it won't sleep with rt mutex.
ok, I just copied and pasted what was there currently.
Quoted 3 lines
In fact this whole function can be moved to generic code, right?
generic for x86, yes. Ingo stuck in the nmi.c code awhile ago. This code just needs a home somewhere. I really don't care where.
Cheers,
Don
Re: [PATCH 5/6] [x86] watchdog: move trigger_all_cpu_backtrace to its own die_notifier
Quoted 80 lines · Don Zickus
Quoted 70 lines · Frederic Weisbecker
Quoted 69 lines · Don Zickus
As part of the transition of the nmi watchdog to something more generic, the
trigger_all_cpu_backtracecode is getting left behind. Put it in its owndie_notifierso it can still be used.Signed-off-by Don Zickus <[email protected]>--- arch/x86/kernel/apic/hw_nmi.c | 65 ++++++++++++++++++++++++++++++++--------- 1 files changed, 51 insertions(+), 14 deletions(-)arch/x86/kernel/apic/hw_nmi.c +24
-14@@ -17,6 +17,10 @@#include <linux/cpumask.h> #include <linux/kernel_stat.h> #include <asm/mce.h> +#include <linux/kdebug.h> +#include <linux/notifier.h> +#include <linux/kprobes.h> +#include <linux/nmi.h> #include <linux/module.h> @@ -54,20 +58,6 @@ int hw_nmi_is_cpu_stuck(struct pt_regs *regs)unsigned int sum;int cpu =smp_processor_id (); -/* FIXME: cheap hack for this check, probably should get its own -* die_notifier handler -*/ -if (cpumask_test_cpu (cpu,to_cpumask (backtrace_mask))) { -static DEFINE_SPINLOCK (lock);/* Serialise the printks */ - -spin_lock (&lock); -printk (KERN_WARNING "NMI backtrace for cpu %d\n" , cpu); -show_regs (regs); -dump_stack (); -spin_unlock (&lock); -cpumask_clear_cpu (cpu,to_cpumask (backtrace_mask)); - } -/* if we are doing an mce, just assume the cpu is not stuck */ /* Could check oops_in_progress here too, but it's safer not to */ if (mce_in_progress ())@@ -109,6 +99,53 @@ void arch_trigger_all_cpu_backtrace(void)mdelay (1 ); } } + +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; +int cpu =smp_processor_id (); + +switch (cmd) { +case DIE_NMI : +case DIE_NMI_IPI : +break ; + +default : +return NOTIFY_DONE ; + } + + regs = args->regs; +Quoted 8 lines
arch/x86/kernel/apic/hw_nmi.c void arch_trigger_all_cpu_backtrace(void) · line 125
Quoted 4 lines
arch/x86/kernel/apic/hw_nmi.c +4
-0+if (cpumask_test_cpu (cpu,to_cpumask (backtrace_mask))) { +static DEFINE_SPINLOCK (lock);/* Serialise the printks */ + +spin_lock (&lock);This should be an
arch_spin_lock(), so that it won't sleep with rt mutex.
Quoted 8 lines
ok, I just copied and pasted what was there currently.
Quoted 3 lines
In fact this whole function can be moved to generic code, right?
generic for x86, yes. Ingo stuck in the
nmi.ccode awhile ago. This code just needs a home somewhere. I really don't care where.
Ah right, this is x86 only, sorry.
PATCH 6/6 watchdog: cleanup hw_nmi.c cruft
In reply to Don ZickusThe design of the hardlockup watchdog has changed and cruft was left behind in the hw_nmi.c file. Just remove the code that isn't used anymore.
--- arch/x86/kernel/apic/hw_nmi.c | 58 ----------------------------------------- 1 files changed, 0 insertions(+), 58 deletions(-)
arch/x86/kernel/apic/hw_nmi.c +0 -58
@@ -9,74 +9,16 @@* */ -#include <asm/apic.h> -#include <linux/smp.h> #include <linux/cpumask.h> -#include <linux/sched.h> -#include <linux/percpu.h> -#include <linux/cpumask.h> -#include <linux/kernel_stat.h> -#include <asm/mce.h> #include <linux/kdebug.h> #include <linux/notifier.h> #include <linux/kprobes.h> - -#include <linux/nmi.h> #include <linux/module.h> /* For reliability, we're prepared to waste bits here. */ static DECLARE_BITMAP(backtrace_mask, NR_CPUS) __read_mostly; -static DEFINE_PER_CPU(unsigned, last_irq_sum); - -/* -* Take the local apic timer and PIT/HPET into account. We don't -* know which one is active, when we have highres/dyntick on -*/ -static inline unsigned int get_timer_irqs (int cpu) -{ -unsigned int irqs =per_cpu (irq_stat, cpu).irq0_irqs; - -#if defined(CONFIG_X86_LOCAL_APIC ) - irqs +=per_cpu (irq_stat, cpu).apic_timer_irqs; -#endif - -return irqs; -} - -static inline int mce_in_progress (void ) -{ -#if defined(CONFIG_X86_MCE ) -return atomic_read (&mce_entry) >0 ; -#endif -return 0 ; -} - -int hw_nmi_is_cpu_stuck (struct pt_regs *regs) -{ -unsigned int sum; -int cpu =smp_processor_id (); - -/* if we are doing an mce, just assume the cpu is not stuck */ -/* Could check oops_in_progress here too, but it's safer not to */ -if (mce_in_progress ()) -return 0 ; - -/* We determine if the cpu is stuck by checking whether any -* interrupts have happened since we last checked. Of course -* an nmi storm could create false positives, but the higher -* level logic should account for that -*/ - sum =get_timer_irqs (cpu); -if (__get_cpu_var (last_irq_sum) == sum) { -return 1 ; - }else { -__get_cpu_var (last_irq_sum) = sum; -return 0 ; - } -} -u64 hw_nmi_get_sample_period (void ) {return (u64)(cpu_khz) *1000 *60 ;
Signature · 1 line
1.6.5.2
[PATCH 7/6] [watchdog] resolve softlockup.c conflicts
In reply to Don ZickusMy changes with the softlockup code uses an older version of softlockup.c. A couple of commits have been committed that were not on the branch I am using. This patch resolves those conflicts.
Commit 8c2eb4 softlockup: Stop spurious softlockup messages due to overflow
d6ad3e softlockup: Add sched_clock_tick() to avoid kernel warning on kgdb resume
Conflicts:
include/linux/sched.h
kernel/kgdb.c
kernel/softlockup.c
--
Hi Ingo,
If there is a better way to deal with these conflicts please let me know.
--- include/linux/sched.h | 4 ++++ kernel/kgdb.c | 6 +++--- kernel/watchdog.c | 17 ++++++++++++++++- 3 files changed, 23 insertions(+), 4 deletions(-)
include/linux/sched.h +4 -0
@@ -310,6 +310,7 @@ extern void sched_show_task(struct task_struct *p);#ifdef CONFIG_LOCKUP_DETECTOR extern void touch_watchdog (void );extern void touch_all_watchdogs (void ); +extern void touch_watchdog_sync (void );extern unsigned int softlockup_panic;extern int softlockup_thresh; extern int proc_dowatchdog_thresh(struct ctl_table *table, int write,
@@ -322,6 +323,9 @@ static inline void touch_watchdog(void)static inline void touch_all_watchdogs (void ) { } +static inline void touch_watchdog_sync (void ) +{ +}#endif #ifdef CONFIG_DETECT_HUNG_TASK
kernel/kgdb.c +3 -3
@@ -596,7 +596,7 @@ static void kgdb_wait(struct pt_regs *regs)/* Signal the primary CPU that we are done: */ atomic_set (&cpu_in_kgdb[cpu],0 ); -touch_watchdog (); +touch_watchdog_sync ();clocksource_touch_watchdog ();local_irq_restore (flags); }
@@ -1450,7 +1450,7 @@ acquirelock: (kgdb_info[cpu].task && kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {atomic_set (&kgdb_active,-1 ); -touch_watchdog (); +touch_watchdog_sync ();clocksource_touch_watchdog ();local_irq_restore (flags);
@@ -1550,7 +1550,7 @@ kgdb_restore: }/* Free kgdb_active */ atomic_set (&kgdb_active,-1 ); -touch_watchdog (); +touch_watchdog_sync ();clocksource_touch_watchdog ();local_irq_restore (flags);
kernel/watchdog.c +16 -1
@@ -33,6 +33,7 @@ int __read_mostly softlockup_thresh = 60; static DEFINE_PER_CPU(unsigned long, watchdog_touch_ts); static DEFINE_PER_CPU(struct task_struct *, softlockup_watchdog); static DEFINE_PER_CPU(struct hrtimer, watchdog_hrtimer); +static DEFINE_PER_CPU(bool, watchdog_touch_sync);#define HARDLOCKUP 1#define SOFTLOCKUP 2 static DEFINE_PER_CPU(char, watchdog_warn);
@@ -138,6 +139,12 @@ void touch_all_watchdogs(void)per_cpu (watchdog_touch_ts, cpu) =0 ; } +void touch_watchdog_sync (void ) +{ +__raw_get_cpu_var (watchdog_touch_sync) = true; +__raw_get_cpu_var (watchdog_touch_ts) =0 ; +} +void touch_nmi_watchdog (void ) {touch_watchdog ();
@@ -163,7 +170,7 @@ static int is_softlockup(unsigned long touch_ts, int cpu)unsigned long now =get_timestamp (cpu);/* Warn about unreasonable delays: */ -if (now > (touch_ts + softlockup_thresh)) +if (time_after (now, touch_ts + softlockup_thresh))return now - touch_ts;return 0 ;
@@ -254,6 +261,14 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer)hrtimer_forward_now (hrtimer,ns_to_ktime (get_sample_period ()));if (touch_ts ==0 ) { +if (unlikely (per_cpu (watchdog_touch_sync, this_cpu))) { +/* +* If the time stamp was touched atomically +* make sure the scheduler tick is up to date. +*/ +per_cpu (watchdog_touch_sync, this_cpu) = false; +sched_clock_tick (); + }__touch_watchdog ();return HRTIMER_RESTART ; }
Signature · 1 line
1.6.5.2