public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Guenter Roeck <linux@roeck-us.net>, John Stultz <jstultz@google.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Anna-Maria Behnsen <anna-maria@linutronix.de>,
	Frederic Weisbecker <frederic@kernel.org>,
	Stephen Boyd <sboyd@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [patch 2/2] timekeeping: Always check for negative motion
Date: Thu, 28 Nov 2024 15:51:40 +0100	[thread overview]
Message-ID: <87cyifxvgj.ffs@tglx> (raw)
In-Reply-To: <65b412ef-fc57-4988-bf92-3c924a1c74a5@roeck-us.net>

On Wed, Nov 27 2024 at 15:02, Guenter Roeck wrote:
> On 11/27/24 14:08, John Stultz wrote:
> An example log is at [1]. It says
>
> clocksource: npcm7xx-timer1: mask: 0xffffff max_cycles: 0xffffff, max_idle_ns: 597268854 ns

That's a 24bit counter. So negative motion happens when the readouts are
more than (1 << 23) apart. AFAICT the counter runs with about 14MHz, but
I'd like to have that confirmed.

> clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
> ...
> clocksource: Switched to clocksource npcm7xx-timer1
>
> I don't know where exactly it stalls; sometime after handover to userspace.
> I'll be happy to do some more debugging, but you'll nee to let me know what
> to look for.

On that platform max_idle_ns should correspond to 50% of the counter
width. So if both CPUs go deep idle for max_idle_ns, then the next timer
interrupt doing the timeeeping advancement sees a delta of > (1 << 23)
and timekeeping stalls.

If my ssumption is correct, then the below should fix it.

Thanks,

        tglx
---
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -2221,7 +2221,7 @@ static bool timekeeping_advance(enum tim
 	struct timekeeper *real_tk = &tk_core.timekeeper;
 	unsigned int clock_set = 0;
 	int shift = 0, maxshift;
-	u64 offset;
+	u64 offset, maxcyc;
 
 	guard(raw_spinlock_irqsave)(&tk_core.lock);
 
@@ -2229,8 +2229,13 @@ static bool timekeeping_advance(enum tim
 	if (unlikely(timekeeping_suspended))
 		return false;
 
-	offset = clocksource_delta(tk_clock_read(&tk->tkr_mono),
-				   tk->tkr_mono.cycle_last, tk->tkr_mono.mask);
+	offset = tk_clock_read(&tk->tkr_mono) - tk->tkr_mono.cycle_last;
+	offset &= tk->tkr_mono.mask;
+
+	maxcyc = tk->tkr_mono.mask >>= 1;
+	maxcyc += tk->tkr_mono.mask >>= 2;
+	if (offset > maxcyc)
+		offset = 0;
 
 	/* Check if there's really nothing to do */
 	if (offset < real_tk->cycle_interval && mode == TK_ADV_TICK)

  reply	other threads:[~2024-11-28 14:51 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-31 12:04 [patch 0/2] timekeeping: Fall cleaning Thomas Gleixner
2024-10-31 12:04 ` [patch 1/2] timekeeping: Remove CONFIG_DEBUG_TIMEKEEPING Thomas Gleixner
2024-11-02  4:14   ` John Stultz
2024-11-02  9:24   ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2024-10-31 12:04 ` [patch 2/2] timekeeping: Always check for negative motion Thomas Gleixner
2024-11-02  4:15   ` John Stultz
2024-11-02  9:24   ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2024-11-25  0:48   ` [patch 2/2] " Guenter Roeck
2024-11-27 22:08     ` John Stultz
2024-11-27 23:02       ` Guenter Roeck
2024-11-28 14:51         ` Thomas Gleixner [this message]
2024-11-28 15:30           ` Guenter Roeck
2024-11-29 12:16             ` Thomas Gleixner
2024-11-29 16:09               ` Guenter Roeck
2024-11-30 11:09                 ` Thomas Gleixner
2024-11-30 18:21                   ` Guenter Roeck
2024-12-03 10:16                     ` [patch] clocksource: Make negative motion detection more robust Thomas Gleixner
2024-12-05 15:11                       ` [tip: timers/urgent] " tip-bot2 for Thomas Gleixner
2024-11-28 15:57           ` [patch 2/2] timekeeping: Always check for negative motion Guenter Roeck
2024-11-28 17:13             ` Guenter Roeck
2024-11-28 17:47               ` Guenter Roeck

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=87cyifxvgj.ffs@tglx \
    --to=tglx@linutronix.de \
    --cc=anna-maria@linutronix.de \
    --cc=frederic@kernel.org \
    --cc=jstultz@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=peterz@infradead.org \
    --cc=sboyd@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox