linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Waiman Long <longman@redhat.com>
Cc: John Stultz <john.stultz@linaro.org>,
	linux-kernel@vger.kernel.org, Stephen Boyd <sboyd@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH] clocksource: Warn if too many missing ticks are detected
Date: Wed, 19 Sep 2018 00:06:51 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.21.1809190004100.1468@nanos.tec.linutronix.de> (raw)
In-Reply-To: <5afd698b-2337-71ef-f118-7395c7991922@redhat.com>

On Tue, 18 Sep 2018, Waiman Long wrote:
> On 09/18/2018 05:07 PM, Thomas Gleixner wrote:
> > On Tue, 18 Sep 2018, Waiman Long wrote:
> >> --- 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)
> >> +#define WATCHDOG_INTERNVAL_NS (NSEC_PER_SEC >> 1)
> >>  #define WATCHDOG_THRESHOLD (NSEC_PER_SEC >> 4)
> >>  
> >>  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,
> >>  					     watchdog->shift);
> >>  
> >> +		/*
> >> +		 * 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);
> > But this is using the watchdog delta to check. If that wrapped the
> > detection is broken.
> >
> > I'd rather use watchdog_timer.expires and check against jiffies. That tells
> > you how late the timer callback actually is and does not suffer any
> > wraparound issues.
> 
> The clocksource_delta() function will deal with wrap-around in the
> counter value. It is only when the counter advances more than 0x80000000
> for 32-bit hpet counter mask that a value of 0 will be returned. That is
> why I have a !wd_nsec check there. There is a small chance when the
> warparound is just within the 1 second window that the test fails. In
> this case, the following kind of warning will certainly be triggered:

Ok.

> [  578.890937] clocksource: timekeeping watchdog on CPU21: Marking
> clocksource 'tsc' as unstable because the skew is too large:
> [  578.890938] clocksource:                       'hpet' wd_now:
> ee332105 wd_last: 544f80e7 mask: ffffffff
> [  578.890939] clocksource:                       'tsc' cs_now:
> 4b6e6ccb5d609 cs_last: 4b679a469d09e mask: ffffffffffffffff
> [  578.890954] tsc: Marking TSC unstable due to clocksource watchdog
> [  578.890963] TSC found unstable after boot, most likely due to broken
> BIOS. Use 'tsc=unstable'.
> [  578.890965] sched_clock: Marking unstable (578920214163,
> -28725675)<-(579047174801, -156217937)
> [  578.891056] clocksource: Switched to clocksource hpet
> 
> Another reason that I used wd_nsec is because the data has already been
> computed.

Sure, but that's hardly a hotpath.

> I am perfectly fine to use the watchdog_timer.expires as suggested, though.

I really prefer that because it's just more robust and obvious. No head
scratching about correctness required.

Thanks,

	tglx

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

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

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=alpine.DEB.2.21.1809190004100.1468@nanos.tec.linutronix.de \
    --to=tglx@linutronix.de \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=peterz@infradead.org \
    --cc=sboyd@kernel.org \
    --subject='Re: [PATCH] clocksource: Warn if too many missing ticks are detected' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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).