archive mirror
 help / color / mirror / Atom feed
From: Waiman Long <>
To: John Stultz <>,
	Thomas Gleixner <>
Cc:, Stephen Boyd <>,
	Peter Zijlstra <>,
	Waiman Long <>
Subject: [PATCH] clocksource: Warn if too many missing ticks are detected
Date: Tue, 18 Sep 2018 14:36:14 -0400	[thread overview]
Message-ID: <> (raw)

The clocksource watchdog, when running, is scheduled on all the CPUs in
the system sequentially on a round-robin fashion with a period of 0.5s.
A bug in the 4.18 kernel is causing missing ticks when nohz_full
is specified. Under some circumstances, this causes the watchdog to
incorrectly state that the TSC is unstable because of counter overflow
in the hpet watchdog clock source after a few minutes delay.

That particular bug is fixed by the 4.19 commit 7059b36636beab ("sched:
idle: Avoid retaining the tick when it has been stopped"). To make it
easier to catch this kind of bug in the future, a check is added to see
if there is too much delay in the watchdog invocation and print a
warning once if it happens.

Signed-off-by: Waiman Long <>
 kernel/time/clocksource.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index 0e6e97a..2ea5db0 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -140,6 +140,7 @@ static void inline clocksource_watchdog_unlock(unsigned long *flags)
  * Interval: 0.5sec Threshold: 0.0625s
 #define WATCHDOG_INTERVAL (HZ >> 1)
 static void clocksource_watchdog_work(struct work_struct *work)
@@ -242,6 +243,18 @@ static void clocksource_watchdog(struct timer_list *unused)
 		wd_nsec = clocksource_cyc2ns(delta, watchdog->mult,
+		/*
+		 * When the timer tick is incorrectly stopped on a CPU with
+		 * pending events, for example, it is possible that the
+		 * clocksource watchdog will stop running for a sufficiently
+		 * long enough time to cause overflow in the delta
+		 * computation leading to incorrect report of unstable clock
+		 * source. So print a warning if there is unusually large
+		 * delay (> 0.5s) in the invocation of the watchdog. That
+		 * can indicate a hidden bug in the timer tick code.
+		 */
+		WARN_ON_ONCE(!wd_nsec || wd_nsec > 2*WATCHDOG_INTERNVAL_NS);
 		delta = clocksource_delta(csnow, cs->cs_last, cs->mask);
 		cs_nsec = clocksource_cyc2ns(delta, cs->mult, cs->shift);
 		wdlast = cs->wd_last; /* save these in case we print them */

             reply	other threads:[~2018-09-18 18:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-18 18:36 Waiman Long [this message]
2018-09-18 21:07 ` Thomas Gleixner
2018-09-18 21:54   ` Waiman Long
2018-09-18 22:06     ` Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \
    --subject='Re: [PATCH] clocksource: Warn if too many missing ticks are detected' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).