powerpc/watchdog: Use hrtimers for per-CPU heartbeat
Nicholas Piggin
reviewerPATCH 1/1 powerpc/watchdog: Use hrtimers for per-CPU heartbeat
Using a jiffies timer creates a dependency on the tick_do_timer_cpu incrementing jiffies. If that CPU has locked up and jiffies is not incrementing, the watchdog heartbeat timer for all CPUs stops and creates false positives and confusing warnings on local CPUs, and also causes the SMP detector to stop, so the root cause is never detected.
Fix this by using hrtimer based timers for the watchdog heartbeat, like the generic kernel hardlockup detector.
--- arch/powerpc/kernel/watchdog.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-)
arch/powerpc/kernel/watchdog.c +18 -16
@@ -77,7 +77,7 @@ static u64 wd_smp_panic_timeout_tb __read_mostly; /* panic other CPUs */static u64 wd_timer_period_ms__read_mostly ;/* interval between heartbeat */ -static DEFINE_PER_CPU(struct timer_list, wd_timer); +static DEFINE_PER_CPU(struct hrtimer, wd_hrtimer); static DEFINE_PER_CPU(u64, wd_timer_tb);/* SMP checker bits */
@@ -293,21 +293,21 @@ void soft_nmi_interrupt(struct pt_regs *regs)nmi_exit (); } -static void wd_timer_reset (unsigned int cpu,struct timer_list *t) -{ - t->expires = jiffies +msecs_to_jiffies (wd_timer_period_ms); -if (wd_timer_period_ms >1000 ) - t->expires =__round_jiffies_up (t->expires, cpu); -add_timer_on (t, cpu); -} - -static void wd_timer_fn (struct timer_list *t) +static enum hrtimer_restart watchdog_timer_fn (struct hrtimer *hrtimer) {int cpu =smp_processor_id (); +if (!(watchdog_enabled &NMI_WATCHDOG_ENABLED )) +return HRTIMER_NORESTART ; + +if (!cpumask_test_cpu (cpu, &watchdog_cpumask)) +return HRTIMER_NORESTART ; +watchdog_timer_interrupt (cpu); -wd_timer_reset (cpu, t); +hrtimer_forward_now (hrtimer,ms_to_ktime (wd_timer_period_ms)); + +return HRTIMER_RESTART ; }void arch_touch_nmi_watchdog (void )
@@ -325,19 +325,21 @@ EXPORT_SYMBOL(arch_touch_nmi_watchdog);static void start_watchdog_timer_on (unsigned int cpu) { -struct timer_list *t =per_cpu_ptr (&wd_timer, cpu); +struct hrtimer *hrtimer =this_cpu_ptr (&wd_hrtimer);per_cpu (wd_timer_tb, cpu) =get_tb (); -timer_setup (t, wd_timer_fn,TIMER_PINNED ); -wd_timer_reset (cpu, t); +hrtimer_init (hrtimer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); + hrtimer->function = watchdog_timer_fn; +hrtimer_start (hrtimer,ms_to_ktime (wd_timer_period_ms), +HRTIMER_MODE_REL_PINNED ); }static void stop_watchdog_timer_on (unsigned int cpu) { -struct timer_list *t =per_cpu_ptr (&wd_timer, cpu); +struct hrtimer *hrtimer =this_cpu_ptr (&wd_hrtimer); -del_timer_sync (t); +hrtimer_cancel (hrtimer); }static int start_wd_on_cpu (unsigned int cpu)
Signature · 1 line
2.20.1
Quoted 11 lines · Nicholas Piggin
Using a jiffies timer creates a dependency on the
tick_do_timer_cpuincrementing jiffies. If that CPU has locked up and jiffies is not incrementing, the watchdog heartbeat timer for all CPUs stops and creates false positives and confusing warnings on local CPUs, and also causes the SMP detector to stop, so the root cause is never detected.Fix this by using hrtimer based timers for the watchdog heartbeat, like the generic kernel hardlockup detector.
Reported-by Ravikumar Bangoria <[email protected]>
Thanks,
Ravi
Hello Nicholas,
Quoted 13 lines · Nicholas Piggin
Using a jiffies timer creates a dependency on the
tick_do_timer_cpuincrementing jiffies. If that CPU has locked up and jiffies is not incrementing, the watchdog heartbeat timer for all CPUs stops and creates false positives and confusing warnings on local CPUs, and also causes the SMP detector to stop, so the root cause is never detected.Fix this by using hrtimer based timers for the watchdog heartbeat, like the generic kernel hardlockup detector.
Reported-by Ravikumar Bangoria <[email protected]>Signed-off-by Nicholas Piggin <[email protected]>
[..snip..]
arch/powerpc/kernel/watchdog.c EXPORT_SYMBOL(arch_touch_nmi_watchdog); · line 328
Quoted 6 lines
arch/powerpc/kernel/watchdog.c +1
-1@@ -325,19 +325,21 @@ EXPORT_SYMBOL(arch_touch_nmi_watchdog);static void start_watchdog_timer_on (unsigned int cpu) { -struct timer_list *t =per_cpu_ptr (&wd_timer, cpu); +struct hrtimer *hrtimer =this_cpu_ptr (&wd_hrtimer);
This function can be called during the initialization via
watchdog_nmi_start -->
for_each_online_cpu(cpu)
start_wd_on_cpu(cpu) -->
start_watchdog_timer_on(cpu)Thus, it is not guarateed that we are always calling start_watchdog_timer_on() from the CPU where we want to start the watchdog timer.
Thus, should we be calling this function from start_wd_on_cpu() via an smp_call_function_single() ?
Quoted 24 lines
arch/powerpc/kernel/watchdog.c +6
-5per_cpu (wd_timer_tb, cpu) =get_tb (); -timer_setup (t, wd_timer_fn,TIMER_PINNED ); -wd_timer_reset (cpu, t); +hrtimer_init (hrtimer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); + hrtimer->function = watchdog_timer_fn; +hrtimer_start (hrtimer,ms_to_ktime (wd_timer_period_ms), +HRTIMER_MODE_REL_PINNED ); }static void stop_watchdog_timer_on (unsigned int cpu) { -struct timer_list *t =per_cpu_ptr (&wd_timer, cpu); +struct hrtimer *hrtimer =this_cpu_ptr (&wd_hrtimer); -del_timer_sync (t); +hrtimer_cancel (hrtimer); }static int start_wd_on_cpu (unsigned int cpu) --2.20.1
Signature · 2 lines
Thanks and Regards gautham.
Nicholas Piggin
reviewerGautham R Shenoy's on April 4, 2019 9:19 pm:
Quoted 33 lines
Hello Nicholas,
Quoted 13 lines · Nicholas Piggin
Using a jiffies timer creates a dependency on the
tick_do_timer_cpuincrementing jiffies. If that CPU has locked up and jiffies is not incrementing, the watchdog heartbeat timer for all CPUs stops and creates false positives and confusing warnings on local CPUs, and also causes the SMP detector to stop, so the root cause is never detected.Fix this by using hrtimer based timers for the watchdog heartbeat, like the generic kernel hardlockup detector.
Reported-by Ravikumar Bangoria <[email protected]>Signed-off-by Nicholas Piggin <[email protected]>[..snip..]
arch/powerpc/kernel/watchdog.c EXPORT_SYMBOL(arch_touch_nmi_watchdog); · line 328
Quoted 6 lines
arch/powerpc/kernel/watchdog.c +1
-1@@ -325,19 +325,21 @@ EXPORT_SYMBOL(arch_touch_nmi_watchdog);static void start_watchdog_timer_on (unsigned int cpu) { -struct timer_list *t =per_cpu_ptr (&wd_timer, cpu); +struct hrtimer *hrtimer =this_cpu_ptr (&wd_hrtimer);This function can be called during the initialization via
watchdog_nmi_start-->for_each_online_cpu(cpu) start_wd_on_cpu(cpu) --> start_watchdog_timer_on(cpu)
Quoted 6 lines
Thus, it is not guarateed that we are always calling
start_watchdog_timer_on()from the CPU where we want to start the watchdog timer.Thus, should we be calling this function from
start_wd_on_cpu()via ansmp_call_function_single()?
Good catch, yes I think we need that change (like kernel/watchdog.c).
I'll resend.
Thanks,
Nick