Linux RTC
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Gabriel Beddingfield <gabe@nestlabs.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Stephen Boyd <sboyd@codeaurora.org>,
	John Stultz <john.stultz@linaro.org>,
	Alessandro Zummo <a.zummo@towertech.it>,
	Alexandre Belloni <alexandre.belloni@free-electrons.com>,
	linux-rtc@vger.kernel.org, Guy Erb <guy@nestlabs.com>,
	Howard Harte <hharte@nestlabs.com>
Subject: Re: Extreme time jitter with suspend/resume cycles
Date: Thu, 5 Oct 2017 20:01:16 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.20.1710051943570.2398@nanos> (raw)
In-Reply-To: <CAOdF7nu9JpG0C=d_2vMka00eEX_wWWv-UUaiUo-YsDcP9-7VdQ@mail.gmail.com>

Gabriel,

On Thu, 5 Oct 2017, Gabriel Beddingfield wrote:
> On Thu, Oct 5, 2017 at 4:01 AM, Thomas Gleixner <tglx@linutronix.de> wrote:
> > i.e. the 32bit rollover of the clocksource. So, if the clocksource->read()
> > function returns a full 64bit counter value, then it must have protection
> > against observing the rollover independent of the clock which feeds that
> > counter. Of course the frequency changes the probablity of observing it,
> > but still the read function must be protected against observing the
> > rollover unconditionally.
> 
> Right, but isn't this what clocksource->mask is supposed to do? When we change
> the back-end frequency, we're still using the same front-end 32-bit register and
> we don't see the same jumps.

Right. That's what the mask should protect. I was assuming that this is one
of the fancy clocksources which expose two 32bit registers of a 64bit
counter and the rollover protection was missing. So that's not the
case. Good, or not so good :)

> > Which SoC/clocksource driver are you talking about?
> 
> NXP i.MX 6SoloX
> drivers/clocksource/timer-imx-gpt.c

So that clocksource driver looks correct. Do you have an idea in which
context this time jump happens? Does it happen when you exercise your high
frequency suspend/resume dance or is that happening just when you let the
machine run forever as well?

The timekeeping_resume() path definitely has an issue:

        cycle_now = tk_clock_read(&tk->tkr_mono);
        if ((clock->flags & CLOCK_SOURCE_SUSPEND_NONSTOP) &&
                cycle_now > tk->tkr_mono.cycle_last) {

This works nice for clocksources which wont wrap across suspend/resume but
not for those which can. That cycle_now -> cycle_last check should take
cs-mask into account ...

Of course for clocksources which can wrap within realistic suspend times,
which 36 hours might be accounted for, this would need an extra sanity
check against a RTC whether wrap time has been exceeded.

I haven't thought it through whether that buggered check fully explains
what you are observing, but it's wrong nevertheless. John?

Thanks,

	tglx

  reply	other threads:[~2017-10-05 18:01 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-04 16:11 Extreme time jitter with suspend/resume cycles Gabriel Beddingfield
2017-10-04 18:22 ` Thomas Gleixner
2017-10-04 23:10   ` Gabriel Beddingfield
2017-10-05  0:20     ` John Stultz
2017-10-05 16:46       ` Gabriel Beddingfield
2017-10-05 11:01     ` Thomas Gleixner
2017-10-05 16:47       ` Gabriel Beddingfield
2017-10-05 18:01         ` Thomas Gleixner [this message]
2017-10-05 20:51           ` Gabriel Beddingfield
2017-10-05 21:04             ` Thomas Gleixner
2017-10-05 21:12               ` Gabriel Beddingfield
2017-10-05 21:33               ` Thomas Gleixner
2017-10-05  0:16 ` John Stultz
2017-10-05 11:05   ` Thomas Gleixner
2017-10-05 14:11     ` Thomas Gleixner
2017-10-05 11:08   ` Miroslav Lichvar
2017-10-05 20:14   ` Gabriel Beddingfield
2017-10-05 21:31     ` Thomas Gleixner
2017-10-15  6:39 ` Introduce clock precision to help time travelers was " Pavel Machek
2017-10-18 20:34   ` Alan Cox
2017-10-18 21:08     ` Pavel Machek
2017-10-18 21:26       ` Alexandre Belloni
2017-10-18 21:56         ` Pavel Machek
2017-11-04 15:34           ` Alexandre Belloni

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.20.1710051943570.2398@nanos \
    --to=tglx@linutronix.de \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=gabe@nestlabs.com \
    --cc=guy@nestlabs.com \
    --cc=hharte@nestlabs.com \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=sboyd@codeaurora.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox