From: Thomas Gleixner <tglx@linutronix.de>
To: John Stultz <jstultz@google.com>
Cc: Miroslav Lichvar <mlichvar@redhat.com>,
LKML <linux-kernel@vger.kernel.org>,
Stephen Boyd <sboyd@kernel.org>,
Anna-Maria Behnsen <anna-maria@linutronix.de>,
Frederic Weisbecker <frederic@kernel.org>,
Shuah Khan <shuah@kernel.org>,
linux-kselftest@vger.kernel.org, kernel-team@android.com,
Lei Chen <lei.chen@smartx.com>
Subject: Re: [PATCH] timekeeping: Prevent coarse clocks going backwards
Date: Fri, 18 Apr 2025 08:37:36 +0200 [thread overview]
Message-ID: <87tt6mq8jz.ffs@tglx> (raw)
In-Reply-To: <CANDhNCrUhZktW=_h9YTZndmyHwe9YbUMG6uVYaEuQyuKsG4AEg@mail.gmail.com>
On Thu, Apr 17 2025 at 17:46, John Stultz wrote:
> On Sat, Apr 5, 2025 at 2:40 PM Thomas Gleixner <tglx@linutronix.de> wrote:
>> @@ -1831,6 +1847,8 @@ void timekeeping_resume(void)
>> /* Re-base the last cycle value */
>> tks->tkr_mono.cycle_last = cycle_now;
>> tks->tkr_raw.cycle_last = cycle_now;
>> + /* Reset the offset for the coarse time getters */
>> + tks->coarse_nsec = 0;
>>
>> tks->ntp_error = 0;
>> timekeeping_suspended = 0;
>
>
> So using the clocksource-switch test in kselftest, I can pretty easily
> hit inconsistencies with this.
>
> The reason is since we use the coarse_nsec as the nanosecond portion
> of the coarse clockids, I don't think we ever want to set it to zero,
> as whenever we do so, we lose the previous contents and cause the
> coarse time to jump back.
Bah. Obviously. What was I thinking?
> It seems more likely that we'd want to do something similar to
> tk_update_coarse_nsecs() filling it in with the shifted down
> tk->tkr_mono.xtime_nsec.
Indeed. The earlier approach of handing the offset to
timekeeping_update_from_shadow() was exactly doing that. I dropped that
because of the uglyness vs. the TAI update case in adjtimex().
>> +static inline void tk_update_coarse_nsecs(struct timekeeper *tk, u64 offset)
>> +{
>> + offset *= tk->tkr_mono.mult;
>> + tk->coarse_nsec = (tk->tkr_mono.xtime_nsec + offset) >> tk->tkr_mono.shift;
>> +}
>
> Thinking more on this, I get that you're providing the offset to save
> the "at the point" time into the coarse value, but I think this ends
> up complicating things.
>
> Instead it seems like we should just do:
> tk->coarse_nsec = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift;
You end up with the same problem again because xtime_nsec can move
backwards when the multiplier is updated, no?
Thanks,
tglx
next prev parent reply other threads:[~2025-04-18 6:37 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-20 20:03 [PATCH v2 1/2] time/timekeeping: Fix possible inconsistencies in _COARSE clockids John Stultz
2025-03-20 20:03 ` [PATCH v2 2/2] selftests/timers: Improve skew_consistency by testing with other clockids John Stultz
2025-03-21 18:35 ` [tip: timers/core] " tip-bot2 for John Stultz
2025-03-21 18:35 ` [tip: timers/core] timekeeping: Fix possible inconsistencies in _COARSE clockids tip-bot2 for John Stultz
2025-03-25 11:32 ` [PATCH v2 1/2] time/timekeeping: " Miroslav Lichvar
2025-03-27 9:22 ` Thomas Gleixner
2025-03-27 15:42 ` Miroslav Lichvar
2025-03-27 17:32 ` Thomas Gleixner
2025-03-31 7:53 ` Miroslav Lichvar
2025-04-17 2:55 ` John Stultz
2025-03-31 14:53 ` Miroslav Lichvar
2025-04-01 6:34 ` Thomas Gleixner
2025-04-01 11:19 ` Miroslav Lichvar
2025-04-01 18:29 ` Thomas Gleixner
2025-04-03 8:32 ` Miroslav Lichvar
2025-04-03 11:29 ` Thomas Gleixner
2025-04-05 21:40 ` [PATCH] timekeeping: Prevent coarse clocks going backwards Thomas Gleixner
2025-04-17 5:29 ` John Stultz
2025-04-17 12:36 ` Thomas Gleixner
2025-04-18 0:46 ` John Stultz
2025-04-18 6:37 ` Thomas Gleixner [this message]
2025-04-18 7:00 ` Thomas Gleixner
2025-04-19 5:55 ` John Stultz
2025-04-18 18:40 ` John Stultz
2025-04-19 5:46 ` [PATCH v3] " John Stultz
2025-04-24 16:02 ` [tip: timers/urgent] " tip-bot2 for Thomas Gleixner
2025-04-28 9:28 ` tip-bot2 for Thomas Gleixner
2025-04-04 17:22 ` [tip: timers/urgent] Revert "timekeeping: Fix possible inconsistencies in _COARSE clockids" tip-bot2 for 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:
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=87tt6mq8jz.ffs@tglx \
--to=tglx@linutronix.de \
--cc=anna-maria@linutronix.de \
--cc=frederic@kernel.org \
--cc=jstultz@google.com \
--cc=kernel-team@android.com \
--cc=lei.chen@smartx.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mlichvar@redhat.com \
--cc=sboyd@kernel.org \
--cc=shuah@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.