mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Hilber <peter.hilber@opensynergy.com>
To: John Stultz <jstultz@google.com>
Cc: linux-kernel@vger.kernel.org,
	Thomas Gleixner <tglx@linutronix.de>,
	Stephen Boyd <sboyd@kernel.org>,
	"Christopher S. Hall" <christopher.s.hall@intel.com>
Subject: Re: [RFC PATCH 3/7] timekeeping: Fix cross-timestamp interpolation for non-x86
Date: Thu, 27 Jul 2023 12:21:56 +0200	[thread overview]
Message-ID: <e508b3a4-21b9-e921-a8fc-b7913f5a2d4c@opensynergy.com> (raw)
In-Reply-To: <CANDhNCoi4OrtXdqs4UErhM0ofecdg94-Yew2NETxhpKkDojt4A@mail.gmail.com>

On 08.07.23 01:31, John Stultz wrote:
> On Fri, Jun 30, 2023 at 10:12 AM Peter Hilber
> <peter.hilber@opensynergy.com> wrote:
>>
>> So far, get_device_system_crosststamp() unconditionally passes
>> system_counterval.cycles to timekeeping_cycles_to_ns(). But when
>> interpolating system time (do_interp == true), system_counterval.cycles is
>> before tkr_mono.cycle_last, contrary to the timekeeping_cycles_to_ns()
>> expectations.
>>
>> On x86, CONFIG_CLOCKSOURCE_VALIDATE_LAST_CYCLE will mitigate on
>> interpolating, setting delta to 0. With delta == 0, xtstamp->sys_monoraw
>> and xtstamp->sys_realtime are then set to the last update time, as
>> implicitly expected by adjust_historical_crosststamp(). On other
>> architectures, the resulting nonsense xtstamp->sys_monoraw and
>> xtstamp->sys_realtime corrupt the xtstamp (ts) adjustment in
>> adjust_historical_crosststamp().
>>
>> Fix this by always setting the delta to 0 when interpolating.
>>
>> Fixes: 2c756feb18d9 ("time: Add history to cross timestamp interface supporting slower devices")
>> Signed-off-by: Peter Hilber <peter.hilber@opensynergy.com>
>> ---
>>  kernel/time/timekeeping.c | 13 +++++++++----
>>  1 file changed, 9 insertions(+), 4 deletions(-)
>>
>> diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
>> index 7e86d5cd784d..7ccc2377c319 100644
>> --- a/kernel/time/timekeeping.c
>> +++ b/kernel/time/timekeeping.c
>> @@ -1259,10 +1259,15 @@ int get_device_system_crosststamp(int (*get_time_fn)
>>                                       tk_core.timekeeper.offs_real);
>>                 base_raw = tk->tkr_raw.base;
>>
>> -               nsec_real = timekeeping_cycles_to_ns(&tk->tkr_mono,
>> -                                                    system_counterval.cycles);
>> -               nsec_raw = timekeeping_cycles_to_ns(&tk->tkr_raw,
>> -                                                   system_counterval.cycles);
>> +               if (do_interp) {
>> +                       nsec_real = timekeeping_delta_to_ns(&tk->tkr_mono, 0);
>> +                       nsec_raw = timekeeping_delta_to_ns(&tk->tkr_raw, 0);
>> +               } else {
>> +                       nsec_real = timekeeping_cycles_to_ns(
>> +                               &tk->tkr_mono, system_counterval.cycles);
>> +                       nsec_raw = timekeeping_cycles_to_ns(
>> +                               &tk->tkr_raw, system_counterval.cycles);
>> +               }
> 
> Rather than adding another conditional branch here to go through, why
> not just use "cycles" instead of system_counterval.cycles as it seems
> to be set properly already?

OK. Thanks for the review and suggestion!


  reply	other threads:[~2023-07-27 10:22 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-30 17:10 [RFC PATCH 0/7] Add virtio_rtc module and related changes Peter Hilber
2023-06-30 17:10 ` [RFC PATCH 1/7] timekeeping: Fix cross-timestamp interpolation on counter wrap Peter Hilber
2023-07-07 22:51   ` John Stultz
2023-07-27 10:21     ` Peter Hilber
2023-06-30 17:10 ` [RFC PATCH 2/7] timekeeping: Fix cross-timestamp interpolation corner case decision Peter Hilber
2023-07-07 23:02   ` John Stultz
2023-07-27 10:21     ` Peter Hilber
2023-06-30 17:10 ` [RFC PATCH 3/7] timekeeping: Fix cross-timestamp interpolation for non-x86 Peter Hilber
2023-07-07 23:31   ` John Stultz
2023-07-27 10:21     ` Peter Hilber [this message]
2023-06-30 17:10 ` [RFC PATCH 4/7] clocksource: arm_arch_timer: Export counter type, clocksource Peter Hilber
2023-07-03  8:13   ` Marc Zyngier
2023-07-27 10:22     ` Peter Hilber
2023-07-28  8:11       ` Marc Zyngier
2023-07-31 16:15         ` Peter Hilber
2023-06-30 17:10 ` [RFC PATCH 5/7] virtio_rtc: Add module and driver core Peter Hilber
2023-06-30 17:10 ` [RFC PATCH 6/7] virtio_rtc: Add PTP clocks Peter Hilber
2023-06-30 17:10 ` [RFC PATCH 7/7] virtio_rtc: Add Arm Generic Timer cross-timestamping Peter Hilber

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=e508b3a4-21b9-e921-a8fc-b7913f5a2d4c@opensynergy.com \
    --to=peter.hilber@opensynergy.com \
    --cc=christopher.s.hall@intel.com \
    --cc=jstultz@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sboyd@kernel.org \
    --cc=tglx@linutronix.de \
    /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

all inboxes | Powered by JetHome®