hardlockup: detect hard lockups without NMIs using secondary cpus
PATCH 1/1 hardlockup: detect hard lockups without NMIs using secondary cpus
Emulate NMIs on systems where they are not available by using timer interrupts on other cpus. Each cpu will use its softlockup hrtimer to check that the next cpu is processing hrtimer interrupts by verifying that a counter is increasing.
This patch is useful on systems where the hardlockup detector is not available due to a lack of NMIs, for example most ARM SoCs. Without this patch any cpu stuck with interrupts disabled can cause a hardware watchdog reset with no debugging information, but with this patch the kernel can detect the lockup and panic, which can result in useful debugging info.
--- include/linux/nmi.h | 5 ++- kernel/watchdog.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++--- lib/Kconfig.debug | 14 +++++++- 3 files changed, 110 insertions(+), 7 deletions(-)
include/linux/nmi.h +4 -1
@@ -14,8 +14,11 @@* may be used to reset the timeout - for code which intentionally * disables interrupts for a long time. This call is stateless. */ -#if defined(CONFIG_HAVE_NMI_WATCHDOG ) || defined(CONFIG_HARDLOCKUP_DETECTOR ) +#if defined(CONFIG_HAVE_NMI_WATCHDOG ) || defined(CONFIG_HARDLOCKUP_DETECTOR_NMI )#include <asm/nmi.h> +#endif + +#if defined(CONFIG_HAVE_NMI_WATCHDOG ) || defined(CONFIG_HARDLOCKUP_DETECTOR )extern void touch_nmi_watchdog (void );#else static inline void touch_nmi_watchdog (void )
kernel/watchdog.c +93 -5
148 lines not on this page · raw message
lib/Kconfig.debug +13 -1
@@ -191,15 +191,27 @@ config LOCKUP_DETECTOR The overhead should be minimal. A periodic hrtimer runs to generate interrupts and kick the watchdog task every 4 seconds. An NMI is generated every 10 seconds or so to check for hardlockups. + If NMIs are not available on the platform, every 12 seconds the + hrtimer interrupt on one cpu will be used to check for hardlockups + on the next cpu. The frequency of hrtimer and NMI events and the soft and hard lockup thresholds can be controlled through the sysctl watchdog_thresh. -config HARDLOCKUP_DETECTOR +config HARDLOCKUP_DETECTOR_NMI def_bool y depends on LOCKUP_DETECTOR && !HAVE_NMI_WATCHDOG depends on PERF_EVENTS && HAVE_PERF_EVENTS_NMI +config HARDLOCKUP_DETECTOR_OTHER_CPU + def_bool y + depends on LOCKUP_DETECTOR && SMP + depends on !HARDLOCKUP_DETECTOR_NMI && !HAVE_NMI_WATCHDOG + +config HARDLOCKUP_DETECTOR + def_bool y + depends on HARDLOCKUP_DETECTOR_NMI || HARDLOCKUP_DETECTOR_OTHER_CPU + config BOOTPARAM_HARDLOCKUP_PANIC bool "Panic (Reboot) On Hard Lockups" depends on HARDLOCKUP_DETECTOR
Signature · 1 line
1.7.7.3
Quoted 7 lines · Colin Cross
Emulate NMIs on systems where they are not available by using timer interrupts on other cpus. Each cpu will use its softlockup hrtimer to check that the next cpu is processing hrtimer interrupts by verifying that a counter is increasing.
This patch is useful on systems where the hardlockup detector is not available due to a lack of NMIs, for example most ARM SoCs.
I have seen other cpus, like Sparc I think, create a 'virtual NMI' by reserving an IRQ line as 'special' (can not be masked). Not sure if that is something worth looking at here (or even possible).
Quoted 4 lines
Without this patch any cpu stuck with interrupts disabled can cause a hardware watchdog reset with no debugging information, but with this patch the kernel can detect the lockup and panic, which can result in useful debugging info.
<SNIP>
kernel/watchdog.c static int is_hardlockup(void) · line 210
Quoted 10 lines
kernel/watchdog.c +10
-0+#ifdef CONFIG_HARDLOCKUP_DETECTOR_OTHER_CPU +static int is_hardlockup_other_cpu (int cpu) +{ +unsigned long hrint =per_cpu (hrtimer_interrupts, cpu); + +if (per_cpu (hrtimer_interrupts_saved, cpu) == hrint) +return 1 ; + +per_cpu (hrtimer_interrupts_saved, cpu) = hrint; +return 0 ;
Will this race with the other cpu you are checking? For example if cpuA just updated its hrtimer_interrupts_saved and cpuB goes to check cpuA's hrtimer_interrupts_saved, it seems possible that cpuB could falsely assume cpuA is stuck?
Quoted 18 lines
kernel/watchdog.c +18
-0+} + +static void watchdog_check_hardlockup_other_cpu (void ) +{ +int cpu; +cpumask_t cpus = watchdog_cpus; + +/* +* Test for hardlockups every 3 samples. The sample period is +* watchdog_thresh * 2 / 5, so 3 samples gets us back to slightly over +* watchdog_thresh (over by 20%). +*/ +if (__this_cpu_read (hrtimer_interrupts) %3 !=0 ) +return ; + +/* check for a hardlockup on the next cpu */ + cpu =cpumask_next (smp_processor_id (), &cpus); +if (cpu >= nr_cpu_ids)
kernel/watchdog.c static int is_hardlockup(void) · line 238
Quoted 10 lines
kernel/watchdog.c +10
-0+ cpu =cpumask_first (&cpus); +if (cpu ==smp_processor_id ()) +return ; + +smp_rmb (); + +if (per_cpu (watchdog_nmi_touch, cpu) == true) { +per_cpu (watchdog_nmi_touch, cpu) = false; +return ; + }
Same race here. Usually touch_nmi_watchdog is reserved for those functions that plan on disabling interrupts for a while. cpuB could set cpuA's watchdog_nmi_touch to false here expecting not to revisit this variable for another couple of seconds. While cpuA could read this variable milliseconds later after cpuB sets it and falsely assume there is a lockup?
Perhaps I am misreading the code?
If not, I don't have a good idea on how to solve those races off the top of my head unfortunately.
Cheers,
Don
Quoted 6 lines · Don Zickus
Quoted 5 lines · Colin Cross
Emulate NMIs on systems where they are not available by using timer interrupts on other cpus. Each cpu will use its softlockup hrtimer to check that the next cpu is processing hrtimer interrupts by verifying that a counter is increasing.
Quoted 6 lines
Quoted 2 lines
This patch is useful on systems where the hardlockup detector is not available due to a lack of NMIs, for example most ARM SoCs.
I have seen other cpus, like Sparc I think, create a 'virtual NMI' by reserving an IRQ line as 'special' (can not be masked). Not sure if that is something worth looking at here (or even possible).
No it isn't, because that assumes that things like spin_lock_irqsave() won't mask that interrupt. We don't have the facility to do that.
2013/1/10 Russell King - ARM Linux <[email protected]>:
Quoted 10 lines · Don Zickus
Quoted 9 lines · Colin Cross
Quoted 7 lines
Emulate NMIs on systems where they are not available by using timer interrupts on other cpus. Each cpu will use its softlockup hrtimer to check that the next cpu is processing hrtimer interrupts by verifying that a counter is increasing.
This patch is useful on systems where the hardlockup detector is not available due to a lack of NMIs, for example most ARM SoCs.
Quoted 6 lines
Quoted 3 lines
I have seen other cpus, like Sparc I think, create a 'virtual NMI' by reserving an IRQ line as 'special' (can not be masked). Not sure if that is something worth looking at here (or even possible).
No it isn't, because that assumes that things like
spin_lock_irqsave()won't mask that interrupt. We don't have the facility to do that.
I believe sparc is doing something like this though. Look at arch/sparc/include/asm/irqflags_64.h, it seems NMIs are implemented there using an irq number that is not masked by this function.
Not all archs can do that so easily I guess.
Quoted 15 lines · Frederic Weisbecker
2013/1/10 Russell King - ARM Linux <[email protected]>:
Quoted 14 lines · Don Zickus
Quoted 12 lines · Colin Cross
Quoted 7 lines
Emulate NMIs on systems where they are not available by using timer interrupts on other cpus. Each cpu will use its softlockup hrtimer to check that the next cpu is processing hrtimer interrupts by verifying that a counter is increasing.
This patch is useful on systems where the hardlockup detector is not available due to a lack of NMIs, for example most ARM SoCs.
I have seen other cpus, like Sparc I think, create a 'virtual NMI' by reserving an IRQ line as 'special' (can not be masked). Not sure if that is something worth looking at here (or even possible).
Quoted 6 lines
Quoted 2 lines
No it isn't, because that assumes that things like
spin_lock_irqsave()won't mask that interrupt. We don't have the facility to do that.I believe sparc is doing something like this though. Look at
arch/sparc/include/asm/irqflags_64.h, it seems NMIs are implemented there using an irq number that is not masked by this function.
As I said, we don't have a facility to do that.
The CPU doesn't know about interrupt levels. It's either all-IRQs-masked or no-IRQs-masked. If you want anything inbetween, you have to go outside the CPU and fiddle with the IRQ controller, which may be one of _many_ different types, and some platforms even have a shadow IRQ controller. Plus, doing such manipulation may in itself also require locking.
Quoted 19 lines · Don Zickus
Quoted 7 lines · Colin Cross
Emulate NMIs on systems where they are not available by using timer interrupts on other cpus. Each cpu will use its softlockup hrtimer to check that the next cpu is processing hrtimer interrupts by verifying that a counter is increasing.
This patch is useful on systems where the hardlockup detector is not available due to a lack of NMIs, for example most ARM SoCs.
I have seen other cpus, like Sparc I think, create a 'virtual NMI' by reserving an IRQ line as 'special' (can not be masked). Not sure if that is something worth looking at here (or even possible).
Quoted 4 lines
Without this patch any cpu stuck with interrupts disabled can cause a hardware watchdog reset with no debugging information, but with this patch the kernel can detect the lockup and panic, which can result in useful debugging info.
<SNIP>
Quoted 15 lines
kernel/watchdog.c static int is_hardlockup(void) · line 210
Quoted 10 lines
kernel/watchdog.c +10
-0+#ifdef CONFIG_HARDLOCKUP_DETECTOR_OTHER_CPU +static int is_hardlockup_other_cpu (int cpu) +{ +unsigned long hrint =per_cpu (hrtimer_interrupts, cpu); + +if (per_cpu (hrtimer_interrupts_saved, cpu) == hrint) +return 1 ; + +per_cpu (hrtimer_interrupts_saved, cpu) = hrint; +return 0 ;Will this race with the other cpu you are checking? For example if cpuA just updated its
hrtimer_interrupts_savedand cpuB goes to check cpuA'shrtimer_interrupts_saved, it seems possible that cpuB could falsely assume cpuA is stuck?
cpuA doesn't update its own hrtimer_interrupts_saved, cpuB does. However, there may be a similar race condition during hotplug if cpuB updates hrtimer_interrupts_saved for cpuA, then goes offline, then cpuC may try to check cpuA and see that hrtimer_interrupts_saved == hrtimer_interrupts. I think this can be solved by setting watchdog_nmi_touch for the next cpu when a cpu goes online or offline.
Quoted 36 lines
Quoted 18 lines
kernel/watchdog.c +18
-0+} + +static void watchdog_check_hardlockup_other_cpu (void ) +{ +int cpu; +cpumask_t cpus = watchdog_cpus; + +/* +* Test for hardlockups every 3 samples. The sample period is +* watchdog_thresh * 2 / 5, so 3 samples gets us back to slightly over +* watchdog_thresh (over by 20%). +*/ +if (__this_cpu_read (hrtimer_interrupts) %3 !=0 ) +return ; + +/* check for a hardlockup on the next cpu */ + cpu =cpumask_next (smp_processor_id (), &cpus); +if (cpu >= nr_cpu_ids)kernel/watchdog.c static int is_hardlockup(void) · line 238
Quoted 10 lines
kernel/watchdog.c +10
-0+ cpu =cpumask_first (&cpus); +if (cpu ==smp_processor_id ()) +return ; + +smp_rmb (); + +if (per_cpu (watchdog_nmi_touch, cpu) == true) { +per_cpu (watchdog_nmi_touch, cpu) = false; +return ; + }Same race here. Usually
touch_nmi_watchdogis reserved for those functions that plan on disabling interrupts for a while. cpuB could set cpuA'swatchdog_nmi_touchto false here expecting not to revisit this variable for another couple of seconds. While cpuA could read this variable milliseconds later after cpuB sets it and falsely assume there is a lockup?
Quoted 1 line
Perhaps I am misreading the code?
Again, cpuA won't ever read its own watchdog_nmi_touch variable, only cpuB will. The only variables cpuA updates for itself is hrtimer_interrupts or setting watchdog_nmi_touch to true. hrtimer_interrupts_saved and setting watchdog_nmi_touch to false are done by the cpu watching over cpuA, so the only races here are when a cpu goes offline and a different cpu starts watching over cpuA.
Quoted 5 lines
If not, I don't have a good idea on how to solve those races off the top of my head unfortunately.
Cheers,
Don
Quoted 36 lines · Colin Cross
Quoted 19 lines · Don Zickus
Quoted 7 lines · Colin Cross
Emulate NMIs on systems where they are not available by using timer interrupts on other cpus. Each cpu will use its softlockup hrtimer to check that the next cpu is processing hrtimer interrupts by verifying that a counter is increasing.
This patch is useful on systems where the hardlockup detector is not available due to a lack of NMIs, for example most ARM SoCs.
I have seen other cpus, like Sparc I think, create a 'virtual NMI' by reserving an IRQ line as 'special' (can not be masked). Not sure if that is something worth looking at here (or even possible).
Quoted 4 lines
Without this patch any cpu stuck with interrupts disabled can cause a hardware watchdog reset with no debugging information, but with this patch the kernel can detect the lockup and panic, which can result in useful debugging info.
<SNIP>
Quoted 15 lines
kernel/watchdog.c static int is_hardlockup(void) · line 210
Quoted 10 lines
kernel/watchdog.c +10
-0+#ifdef CONFIG_HARDLOCKUP_DETECTOR_OTHER_CPU +static int is_hardlockup_other_cpu (int cpu) +{ +unsigned long hrint =per_cpu (hrtimer_interrupts, cpu); + +if (per_cpu (hrtimer_interrupts_saved, cpu) == hrint) +return 1 ; + +per_cpu (hrtimer_interrupts_saved, cpu) = hrint; +return 0 ;Will this race with the other cpu you are checking? For example if cpuA just updated its
hrtimer_interrupts_savedand cpuB goes to check cpuA'shrtimer_interrupts_saved, it seems possible that cpuB could falsely assume cpuA is stuck?
Quoted 6 lines
cpuA doesn't update its own
hrtimer_interrupts_saved, cpuB does. However, there may be a similar race condition during hotplug if cpuB updateshrtimer_interrupts_savedfor cpuA, then goes offline, then cpuC may try to check cpuA and see thathrtimer_interrupts_saved==hrtimer_interrupts. I think this can be solved by settingwatchdog_nmi_touchfor the next cpu when a cpu goes online or offline.
Ah, that is where my misunderstanding was. I overlooked the fact that it was only updated by the other cpu. Sorry about that.
I'll re-review it again with that in mind.
Cheers,
Don
Quoted 5 lines · Colin Cross
kernel/watchdog.c +5
-0+static void watchdog_check_hardlockup_other_cpu (void ) +{ +int cpu; +cpumask_t cpus = watchdog_cpus; +
kernel/watchdog.c static int is_hardlockup(void) · line 227
Quoted 10 lines
kernel/watchdog.c +10
-0+/* +* Test for hardlockups every 3 samples. The sample period is +* watchdog_thresh * 2 / 5, so 3 samples gets us back to slightly over +* watchdog_thresh (over by 20%). +*/ +if (__this_cpu_read (hrtimer_interrupts) %3 !=0 ) +return ; + +/* check for a hardlockup on the next cpu */ + cpu =cpumask_next (smp_processor_id (), &cpus);
Hmm don't you want to check cpu_oneline_mask here and return if the other CPU is offline?
kernel/watchdog.c static int is_hardlockup(void) · line 231
Quoted 4 lines
kernel/watchdog.c +4
-0+if (cpu >= nr_cpu_ids) + cpu =cpumask_first (&cpus); +if (cpu ==smp_processor_id ()) +return ;
Regards,
Tony
Quoted 12 lines · Tony Lindgren
Quoted 10 lines · Colin Cross
kernel/watchdog.c +10
-0+static void watchdog_check_hardlockup_other_cpu (void ) +{ +int cpu; +cpumask_t cpus = watchdog_cpus; + +/* +* Test for hardlockups every 3 samples. The sample period is +* watchdog_thresh * 2 / 5, so 3 samples gets us back to slightly over +* watchdog_thresh (over by 20%). +*/
Quoted 8 lines
kernel/watchdog.c static int is_hardlockup(void) · line 227
Quoted 5 lines
kernel/watchdog.c +5
-0+if (__this_cpu_read (hrtimer_interrupts) %3 !=0 ) +return ; + +/* check for a hardlockup on the next cpu */ + cpu =cpumask_next (smp_processor_id (), &cpus);Hmm don't you want to check
cpu_oneline_maskhere and return if the other CPU is offline?
watchdog_cpus is effectively a local copy of cpu_online_mask, but updated after the watchdog_nmi_touch in watchdog_nmi_enable. This avoids a false positive after hotplugging in a cpu when cpu_online_mask is true but that cpu hasn't yet run it's first hrtimer.
Quoted 8 lines
kernel/watchdog.c static int is_hardlockup(void) · line 231
Quoted 4 lines
kernel/watchdog.c +4
-0+if (cpu >= nr_cpu_ids) + cpu =cpumask_first (&cpus); +if (cpu ==smp_processor_id ()) +return ;Regards,
Tony
Quoted 22 lines · Colin Cross
Quoted 12 lines · Tony Lindgren
Quoted 10 lines · Colin Cross
kernel/watchdog.c +10
-0+static void watchdog_check_hardlockup_other_cpu (void ) +{ +int cpu; +cpumask_t cpus = watchdog_cpus; + +/* +* Test for hardlockups every 3 samples. The sample period is +* watchdog_thresh * 2 / 5, so 3 samples gets us back to slightly over +* watchdog_thresh (over by 20%). +*/ Quoted 8 lines
kernel/watchdog.c static int is_hardlockup(void) · line 227
Quoted 5 lines
kernel/watchdog.c +5
-0+if (__this_cpu_read (hrtimer_interrupts) %3 !=0 ) +return ; + +/* check for a hardlockup on the next cpu */ + cpu =cpumask_next (smp_processor_id (), &cpus);Hmm don't you want to check
cpu_oneline_maskhere and return if the other CPU is offline?
Quoted 5 lines
watchdog_cpusis effectively a local copy ofcpu_online_mask, but updated after thewatchdog_nmi_touchinwatchdog_nmi_enable. This avoids a false positive after hotplugging in a cpu whencpu_online_maskis true but that cpu hasn't yet run it's first hrtimer.
OK thanks for clarifying that.
Tony
Quoted 43 lines
-----Original Message-----
From: Colin Cross [mailto:ccross at android.com]
Sent: Thursday, January 10, 2013 9:58 AM
To: linux-kernel at vger.kernel.org
Cc: Andrew Morton; Don Zickus; Ingo Molnar; Thomas Gleixner; Liu, Chuansheng; linux-arm-kernel at lists.infradead.org; Colin Cross
Subject: [PATCH] hardlockup: detect hard lockups without NMIs using secondary cpusEmulate NMIs on systems where they are not available by using timer interrupts on other cpus. Each cpu will use its softlockup hrtimer to check that the next cpu is processing hrtimer interrupts by verifying that a counter is increasing.
This patch is useful on systems where the hardlockup detector is not available due to a lack of NMIs, for example most ARM SoCs. Without this patch any cpu stuck with interrupts disabled can cause a hardware watchdog reset with no debugging information, but with this patch the kernel can detect the lockup and panic, which can result in useful debugging info.
Signed-off-by Colin Cross <[email protected]>kernel/watchdog.c +19
-0+static void watchdog_check_hardlockup_other_cpu (void ) +{ +int cpu; +cpumask_t cpus = watchdog_cpus; + +/* +* Test for hardlockups every 3 samples. The sample period is +* watchdog_thresh * 2 / 5, so 3 samples gets us back to slightly over +* watchdog_thresh (over by 20%). +*/ +if (__this_cpu_read (hrtimer_interrupts) %3 !=0 ) +return ; + +/* check for a hardlockup on the next cpu */ + cpu =cpumask_next (smp_processor_id (), &cpus); +if (cpu >= nr_cpu_ids) + cpu =cpumask_first (&cpus); +if (cpu ==smp_processor_id ()) +return ;
kernel/watchdog.c static int is_hardlockup(void) · line 241
Quoted 10 lines
kernel/watchdog.c +10
-0+ +smp_rmb (); + +if (per_cpu (watchdog_nmi_touch, cpu) == true) { +per_cpu (watchdog_nmi_touch, cpu) = false; +return ; + } + +if (is_hardlockup_other_cpu (cpu)) { +/* only warn once */
One possible case for new hotplug CPU that false hardlockup case. 1/ Assume CPU1, CPU2 are online, CPU3 is being hotplug:
CPU3: CPU2:watchdog_nmi_enable()
per_cpu(watchdog_nmi_touch, cpu) = true;
cpumask_set_cpu(cpu, &watchdog_cpus);
watchdog_check_hardlockup_other_cpu()
per_cpu(watchdog_nmi_touch, cpu) = false; == > Here cpu is CPU32/ Before CPU3's first hrtimer interrupt coming, CPU2 is been offlined.
Then CPU1's next CPU is CPU3. But we can not use CPU3's watchdog_nmi_touch to defense false CPU3 hardlock more. When CPU1's hrtimer interrupt coming, it is possible report CPU3 false hard lockup.
Is it the case?
Quoted 62 lines · Chuansheng
Quoted 43 lines
-----Original Message-----
From: Colin Cross [mailto:ccross at android.com]
Sent: Thursday, January 10, 2013 9:58 AM
To: linux-kernel at vger.kernel.org
Cc: Andrew Morton; Don Zickus; Ingo Molnar; Thomas Gleixner; Liu, Chuansheng; linux-arm-kernel at lists.infradead.org; Colin Cross
Subject: [PATCH] hardlockup: detect hard lockups without NMIs using secondary cpusEmulate NMIs on systems where they are not available by using timer interrupts on other cpus. Each cpu will use its softlockup hrtimer to check that the next cpu is processing hrtimer interrupts by verifying that a counter is increasing.
This patch is useful on systems where the hardlockup detector is not available due to a lack of NMIs, for example most ARM SoCs. Without this patch any cpu stuck with interrupts disabled can cause a hardware watchdog reset with no debugging information, but with this patch the kernel can detect the lockup and panic, which can result in useful debugging info.
Signed-off-by Colin Cross <[email protected]>kernel/watchdog.c +19
-0+static void watchdog_check_hardlockup_other_cpu (void ) +{ +int cpu; +cpumask_t cpus = watchdog_cpus; + +/* +* Test for hardlockups every 3 samples. The sample period is +* watchdog_thresh * 2 / 5, so 3 samples gets us back to slightly over +* watchdog_thresh (over by 20%). +*/ +if (__this_cpu_read (hrtimer_interrupts) %3 !=0 ) +return ; + +/* check for a hardlockup on the next cpu */ + cpu =cpumask_next (smp_processor_id (), &cpus); +if (cpu >= nr_cpu_ids) + cpu =cpumask_first (&cpus); +if (cpu ==smp_processor_id ()) +return ;kernel/watchdog.c static int is_hardlockup(void) · line 241
Quoted 10 lines
kernel/watchdog.c +10
-0+ +smp_rmb (); + +if (per_cpu (watchdog_nmi_touch, cpu) == true) { +per_cpu (watchdog_nmi_touch, cpu) = false; +return ; + } + +if (is_hardlockup_other_cpu (cpu)) { +/* only warn once */ One possible case for new hotplug CPU that false hardlockup case. 1/ Assume CPU1, CPU2 are online, CPU3 is being hotplug:
CPU3: CPU2:watchdog_nmi_enable()
per_cpu(watchdog_nmi_touch, cpu)= true;cpumask_set_cpu(cpu, &watchdog_cpus); watchdog_check_hardlockup_other_cpu() per_cpu(watchdog_nmi_touch, cpu) = false; == > Here cpu is CPU3
Quoted 6 lines
2/ Before CPU3's first hrtimer interrupt coming, CPU2 is been offlined.
Then CPU1's next CPU is CPU3. But we can not use CPU3'swatchdog_nmi_touchto defense false CPU3 hardlock more. When CPU1's hrtimer interrupt coming, it is possible report CPU3 false hard lockup.Is it the case?
Yes, this is the same race condition I pointed out in reply to Don Zickus earlier in the thread. I think the easiest solution is to set per_cpu(watchdog_nmi_touch, next_cpu) = true during cpu offlining.
Quoted 37 lines
-----Original Message-----
From: ccross at google.com [mailto:ccross at google.com] On Behalf Of Colin Cross
Sent: Friday, January 11, 2013 1:34 PM
To: Liu, Chuansheng
Cc: linux-kernel at vger.kernel.org; Andrew Morton; Don Zickus; Ingo Molnar; Thomas Gleixner; linux-arm-kernel at lists.infradead.org
Subject: Re: [PATCH] hardlockup: detect hard lockups without NMIs using secondary cpusQuoted 23 lines · Chuansheng
Quoted 23 lines
-----Original Message-----
From: Colin Cross [mailto:ccross at android.com]
Sent: Thursday, January 10, 2013 9:58 AM
To: linux-kernel at vger.kernel.org
Cc: Andrew Morton; Don Zickus; Ingo Molnar; Thomas Gleixner; Liu, Chuansheng; linux-arm-kernel at lists.infradead.org; Colin Cross
Subject: [PATCH] hardlockup: detect hard lockups without NMIs using secondary cpusEmulate NMIs on systems where they are not available by using timer interrupts on other cpus. Each cpu will use its softlockup hrtimer to check that the next cpu is processing hrtimer interrupts by verifying that a counter is increasing.
This patch is useful on systems where the hardlockup detector is not available due to a lack of NMIs, for example most ARM SoCs. Without this patch any cpu stuck with interrupts disabled can cause a hardware watchdog reset with no debugging information, but with this patch the kernel can detect the lockup and panic, which can result in useful debugging info.
Quoted 15 lines
Quoted 9 lines
kernel/watchdog.c static int is_hardlockup(void)
Quoted 9 lines
Signed-off-by Colin Cross <[email protected]>kernel/watchdog.c +8
-0+static void watchdog_check_hardlockup_other_cpu (void ) +{ +int cpu; +cpumask_t cpus = watchdog_cpus; + +/* +* Test for hardlockups every 3 samples. The sample period is +* watchdog_thresh * 2 / 5, so 3 samples gets us back to slightly over
Quoted 5 lines
Quoted 5 lines
kernel/watchdog.c +5
-0+* watchdog_thresh (over by 20%). +*/ +if (__this_cpu_read (hrtimer_interrupts) %3 !=0 ) +return ; +
Another feeling is about __this_cpu_read(hrtimer_interrupts) % 3 != 0,
It will cause the actual timeout value for hard lockup detection is not very fix, or even very short.
Sometimes using 3 samples can detect the lockup case, but sometimes 1 sample. Is it the case?
And in NMI case, the NMI interrupt is coming at least every watchdog_thresh.
Quoted 52 lines · Chuansheng
Quoted 37 lines
-----Original Message-----
From: ccross at google.com [mailto:ccross at google.com] On Behalf Of Colin Cross
Sent: Friday, January 11, 2013 1:34 PM
To: Liu, Chuansheng
Cc: linux-kernel at vger.kernel.org; Andrew Morton; Don Zickus; Ingo Molnar; Thomas Gleixner; linux-arm-kernel at lists.infradead.org
Subject: Re: [PATCH] hardlockup: detect hard lockups without NMIs using secondary cpusQuoted 23 lines · Chuansheng
Quoted 23 lines
-----Original Message-----
From: Colin Cross [mailto:ccross at android.com]
Sent: Thursday, January 10, 2013 9:58 AM
To: linux-kernel at vger.kernel.org
Cc: Andrew Morton; Don Zickus; Ingo Molnar; Thomas Gleixner; Liu, Chuansheng; linux-arm-kernel at lists.infradead.org; Colin Cross
Subject: [PATCH] hardlockup: detect hard lockups without NMIs using secondary cpusEmulate NMIs on systems where they are not available by using timer interrupts on other cpus. Each cpu will use its softlockup hrtimer to check that the next cpu is processing hrtimer interrupts by verifying that a counter is increasing.
This patch is useful on systems where the hardlockup detector is not available due to a lack of NMIs, for example most ARM SoCs. Without this patch any cpu stuck with interrupts disabled can cause a hardware watchdog reset with no debugging information, but with this patch the kernel can detect the lockup and panic, which can result in useful debugging info.
Quoted 15 lines
Quoted 9 lines
kernel/watchdog.c static int is_hardlockup(void)
Quoted 9 lines
Signed-off-by Colin Cross <[email protected]>kernel/watchdog.c +8
-0+static void watchdog_check_hardlockup_other_cpu (void ) +{ +int cpu; +cpumask_t cpus = watchdog_cpus; + +/* +* Test for hardlockups every 3 samples. The sample period is +* watchdog_thresh * 2 / 5, so 3 samples gets us back to slightly over
Quoted 5 lines
Quoted 5 lines
kernel/watchdog.c +5
-0+* watchdog_thresh (over by 20%). +*/ +if (__this_cpu_read (hrtimer_interrupts) %3 !=0 ) +return ; +
Quoted 5 lines
Another feeling is about
__this_cpu_read(hrtimer_interrupts)% 3 != 0,
It will cause the actual timeout value for hard lockup detection is not very fix, or even very short.
Sometimes using 3 samples can detect the lockup case, but sometimes 1 sample. Is it the case?
I'm not sure what you mean. The mod 3 will cause every 3rd timer (12 seconds, assuming watchdog_thresh = 10) to check hrtimer_interrupts vs. hrtimer_interrupts_saved, and then update it. The sampling should be fixed and very accurate. It will cause a panic/warning between 12 and 24 seconds after a cpu stops processing timer interrupts, depending on the alignment of the hrtimers between the two cpus.
Quoted 1 line
And in NMI case, the NMI interrupt is coming at least every
watchdog_thresh.
NMI interrupt will happen every 10 seconds instead of 12, meaning the panic/warning will occur between 10 and 20 seconds after a cpu stops processing timer interrupts, depending on the alignment of the NMI with the hrtimer, but otherwise my patch should be very similar.
Quoted 73 lines
-----Original Message-----
From: ccross at google.com [mailto:ccross at google.com] On Behalf Of Colin Cross
Sent: Friday, January 11, 2013 2:18 PM
To: Liu, Chuansheng
Cc: linux-kernel at vger.kernel.org; Andrew Morton; Don Zickus; Ingo Molnar; Thomas Gleixner; linux-arm-kernel at lists.infradead.org
Subject: Re: [PATCH] hardlockup: detect hard lockups without NMIs using secondary cpusQuoted 37 lines · Chuansheng
Quoted 37 lines
-----Original Message-----
From: ccross at google.com [mailto:ccross at google.com] On Behalf Of Colin Cross
Sent: Friday, January 11, 2013 1:34 PM
To: Liu, Chuansheng
Cc: linux-kernel at vger.kernel.org; Andrew Morton; Don Zickus; Ingo Molnar; Thomas Gleixner; linux-arm-kernel at lists.infradead.org
Subject: Re: [PATCH] hardlockup: detect hard lockups without NMIs using secondary cpusQuoted 23 lines · Chuansheng
Quoted 23 lines
-----Original Message-----
From: Colin Cross [mailto:ccross at android.com]
Sent: Thursday, January 10, 2013 9:58 AM
To: linux-kernel at vger.kernel.org
Cc: Andrew Morton; Don Zickus; Ingo Molnar; Thomas Gleixner; Liu, Chuansheng; linux-arm-kernel at lists.infradead.org; Colin Cross
Subject: [PATCH] hardlockup: detect hard lockups without NMIs using secondary cpusEmulate NMIs on systems where they are not available by using timer interrupts on other cpus. Each cpu will use its softlockup hrtimer to check that the next cpu is processing hrtimer interrupts by verifying that a counter is increasing.
This patch is useful on systems where the hardlockup detector is not available due to a lack of NMIs, for example most ARM SoCs. Without this patch any cpu stuck with interrupts disabled can cause a hardware watchdog reset with no debugging information, but with this patch the kernel can detect the lockup and panic, which can result in useful debugging info.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
kernel/watchdog.c static int is_hardlockup(void)
Quoted 9 lines
Signed-off-by Colin Cross <[email protected]>kernel/watchdog.c +8
-0+static void watchdog_check_hardlockup_other_cpu (void ) +{ +int cpu; +cpumask_t cpus = watchdog_cpus; + +/* +* Test for hardlockups every 3 samples. The sample period is +* watchdog_thresh * 2 / 5, so 3 samples gets us back to slightly
Quoted 8 lines
Quoted 6 lines
over
Quoted 5 lines
Quoted 5 lines
kernel/watchdog.c +5
-0+* watchdog_thresh (over by 20%). +*/ +if (__this_cpu_read (hrtimer_interrupts) %3 !=0 ) +return ; +Another feeling is about
__this_cpu_read(hrtimer_interrupts)% 3 != 0, It will cause the actual timeout value for hard lockup detection is not very fix,or even
Quoted 2 lines
very short.
Sometimes using 3 samples can detect the lockup case, but sometimes 1sample.
Quoted 9 lines
Quoted 1 line
Is it the case?
I'm not sure what you mean. The mod 3 will cause every 3rd timer (12 seconds, assuming
watchdog_thresh= 10) to checkhrtimer_interruptsvs.hrtimer_interrupts_saved, and then update it. The sampling should be fixed and very accurate. It will cause a panic/warning between 12 and 24 seconds after a cpu stops processing timer interrupts, depending on the alignment of the hrtimers between the two cpus.
You are right, thanks.