From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D310439BFE6 for ; Wed, 20 May 2026 13:52:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779285148; cv=none; b=e6dM13NQP82rpip8SFt4Zpo7YsU/2J9XbUifd13gmEhy6HEC4iQQabathtdM6lX6rPPTGOlATzfkhrXMNyTUA5J8TOohuoWEn8m4VgzAtBcwwA6OcyYfnCUQo9NRk/+b4QgHXZI9A7o6QgIIZz9+RGT39QDikB1/7lpd2fuAEpY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779285148; c=relaxed/simple; bh=x2EDSdakPJhC6So/XLDvqzuzR3btxiKD/OiQ/5RL+Fo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MDYOWsEo/TAZBxZzWxSnoLvr/CUkCdvqxKeX3F+u4IZCy/FG3FB/n9M7/jNQyt7DZ5UvfhBxdFY8o12l9Mt7VPE1A/wgn7E2xyItTzGpJQO1tB1Ve+fpaYcUVc3uBidt+8PK0mRcDegoPXEMBpZIiyZT1QoSnfo2qpuI/E86OY4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=casper.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=k1vmDGCn; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=casper.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="k1vmDGCn" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description; bh=Oa47mKK9GRk5UqeFd7JbZkXnPSyG8Wc01sGke8jD9tU=; b=k1vmDGCn/QLQFBwJy7kcF67Gq8 DlyNBkvmZBOIRC3t4A7M/nnurKydThvKzFsXTv0ctYU9uWBKui377G7qemCzN9zpr03ior8xt8mJ8 +ChwImng3VT8/4VLjhVbHksDNtJ9kELTYPfsgNAWU1GQBd2pEP8V696Ih6Fkb1IOd2mPT/aopy+9e v72dN/oEnZcEKUmNCu1SV/hFJSzQ8G2OfNaudMD25u+nLTlcG197bNj3gx4BwQhM440hRRdKVqvuu lqrnaYpzUS8a0go0CBMeaZUKC5LpCJECfaqrTeQjSVEMMSA7vYzAqsbzAOig/ows8VMjlGBjwMZPO ZFi9nkWA==; Received: from i7.infradead.org ([2001:8b0:10b:1:21e:67ff:fecb:7a92]) by casper.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1wPhLG-00000007DRp-0VqL; Wed, 20 May 2026 13:52:10 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.99.2 #2 (Red Hat Linux)) id 1wPhLF-000000009tN-2Hbd; Wed, 20 May 2026 14:52:09 +0100 From: David Woodhouse To: Richard Cochran , Wen Gu , David Woodhouse , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , John Stultz , Thomas Gleixner , Stephen Boyd , Anna-Maria Behnsen , Frederic Weisbecker , Shuah Khan , Peter Zijlstra , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Arnd Bergmann , Miroslav Lichvar , Julien Ridoux , Ryan Luu , linux-kernel@vger.kernel.org Cc: David Woodhouse Subject: [RFC PATCH v3 03/10] timekeeping: Account for monotonicity adjustment in ntp_error Date: Wed, 20 May 2026 14:33:42 +0100 Message-ID: <20260520135207.37826-4-dwmw2@infradead.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260520135207.37826-1-dwmw2@infradead.org> References: <20260520135207.37826-1-dwmw2@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html From: David Woodhouse timekeeping_apply_adjustment() modifies xtime_nsec to maintain vDSO monotonicity when mult changes: xtime_nsec -= offset This ensures that the time reported to userspace does not jump when the multiplier is adjusted from one tick to the next. However, the ntp_error accumulator which tracks the difference between intended and actual clock position was not being updated updated to reflect this additional discrepancy. An earlier attempt at this compensation existed as: ntp_error -= (interval - offset) << ntp_error_shift but was removed in commit c2cda2a5bda9 ("timekeeping/ntp: Don't align NTP frequency adjustments to ticks") because it was a major source of NTP error. That's because (interval - offset) was wrong: the subtraction of "interval" prematurely accounted for the changed xtime_interval of the next tick, which would be correctly accounted in the next accumulation anyway — a double subtraction. What is actually needed is just the "offset" part: ntp_error must be told that xtime_nsec moved by "offset" without a corresponding change in the intended position. For the normal ±1 mult dithering this is negligible (the adjustments cancel over time), but for larger mult changes — such as when an external reference clock sets a new frequency — the one-time uncompensated offset is significant. Fix by adjusting ntp_error by the correct amount: ntp_error += offset << ntp_error_shift This keeps ntp_error consistent with the actual xtime_nsec position after the adjustment. Fixes: c2cda2a5bda9 ("timekeeping/ntp: Don't align NTP frequency adjustments to ticks") Signed-off-by: David Woodhouse Assisted-by: Kiro:claude-opus-4.6-1m --- kernel/time/timekeeping.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index b84b05f9d460..95973e45d456 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -2317,6 +2317,7 @@ static __always_inline void timekeeping_apply_adjustment(struct timekeeper *tk, tk->tkr_mono.mult += mult_adj; tk->xtime_interval += interval; tk->tkr_mono.xtime_nsec -= offset; + tk->ntp_error += offset << tk->ntp_error_shift; } /* -- 2.54.0