public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Hilber <peter.hilber@opensynergy.com>
To: linux-kernel@vger.kernel.org
Cc: Peter Hilber <peter.hilber@opensynergy.com>,
	John Stultz <jstultz@google.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Stephen Boyd <sboyd@kernel.org>,
	"Christopher S. Hall" <christopher.s.hall@intel.com>
Subject: [RFC PATCH v2 1/6] timekeeping: Fix cross-timestamp interpolation on counter wrap
Date: Fri, 18 Aug 2023 03:20:07 +0200	[thread overview]
Message-ID: <20230818012014.212155-2-peter.hilber@opensynergy.com> (raw)
In-Reply-To: <20230818012014.212155-1-peter.hilber@opensynergy.com>

cycle_between() decides whether get_device_system_crosststamp() will
interpolate for older counter readings.

cycle_between() yields wrong results for a counter wrap-around where after
< before < test, and for the case after < test < before.

Fix the comparison logic.

Fixes: 2c756feb18d9 ("time: Add history to cross timestamp interface supporting slower devices")
Signed-off-by: Peter Hilber <peter.hilber@opensynergy.com>
Acked-by: John Stultz <jstultz@google.com>
---
 kernel/time/timekeeping.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 56428eadf4c1..cd5c83473bab 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1186,7 +1186,7 @@ static bool cycle_between(u64 before, u64 test, u64 after)
 {
 	if (test > before && test < after)
 		return true;
-	if (test < before && before > after)
+	if (before > after && (test > before || test < after))
 		return true;
 	return false;
 }
-- 
2.39.2


  reply	other threads:[~2023-08-18  1:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-18  1:20 [RFC PATCH v2 0/6] Add virtio_rtc module and related changes Peter Hilber
2023-08-18  1:20 ` Peter Hilber [this message]
2023-08-18  1:20 ` [RFC PATCH v2 2/6] timekeeping: Fix cross-timestamp interpolation corner case decision Peter Hilber
2023-08-25  4:02   ` John Stultz
2023-09-15 16:10   ` Thomas Gleixner
2023-09-15 17:30     ` Peter Hilber
2023-09-15 19:02       ` Thomas Gleixner
2023-08-18  1:20 ` [RFC PATCH v2 3/6] timekeeping: Fix cross-timestamp interpolation for non-x86 Peter Hilber
2023-08-25  4:04   ` John Stultz
2023-09-13  9:11     ` Peter Hilber
2023-08-18  1:20 ` [RFC PATCH v2 4/6] virtio_rtc: Add module and driver core Peter Hilber
2023-08-18  1:20 ` [RFC PATCH v2 5/6] virtio_rtc: Add PTP clocks Peter Hilber
2023-08-18  1:20 ` [RFC PATCH v2 6/6] 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=20230818012014.212155-2-peter.hilber@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