From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 16A0E24676D for ; Sun, 17 May 2026 22:03:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779055428; cv=none; b=SYzFEb7IT/EhFqa/SDM7bd6fDN2MbhGWoVeUEiWoCKBjpRmsQhJDumyB55UI+ca7fIeduM5eM22UfY8Rxkflu3a2kU96RcBTwMmEoP4MHAUMDxaiJe2t5W1xDZdf2EbQ/z3lZk6KrNHfJVQQTKDbLzYxiLI1To5WRIZzwGJmoI8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779055428; c=relaxed/simple; bh=QbGs1t2DXBSSC4qGqPdRqDkvS613OjqvdAFzpjqNwos=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X7IwKSthrABlYgSkIbE4VXkazqXvytnNyEkWnQlhYeqDYHNdBPBB7LJeBeDCFNtIrWp4qRjDMhnLn8BDu4igBRx9WP45iiWB3urnu6oWNh1tSEZ3Phv8cAX10iby02y+ec0G9T6hGq8u1dEXtQpSNsDJKzOwNveWiB0sCh/2fmM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=desiato.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=YJYbb05g; arc=none smtp.client-ip=90.155.92.199 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=desiato.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="YJYbb05g" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=I7YiC/kMMyNyDPvJ1bBdoG3jBZi2TppZYv8DAMXHJrI=; b=YJYbb05gKV/sAWne4S+1mslkRc Tr54tKKu+0sVUIgECDX1icOOomsaFE1Ulxv3OqvjhR9yWDO8f6Omt9cQTFZBPrDI2ij8ZB4D6jbsC eeHaTpc/KfY18KcQpC0mzOqxjv8J5Dmn+UBekTxJulmzi+gMkrfOwwMKxeMYq//lGErx9EgAXGqNp KC1Qqm11td6lBnjdgLV9ERgF2vPbiMynEu6hOdasMhrZBDoBWeUrBCqo8KJZ8dIQHgQYja60IUsW6 aZC6eymdf3Fxvu0hRHE8BPHvsAmAH5wRyYgeUuFLju9rhc0RVIvBJ5NYHu0wfBC/uEnJ6MAn/VqAI LKXXUFZQ==; Received: from i7.infradead.org ([2001:8b0:10b:1:21e:67ff:fecb:7a92]) by desiato.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1wOja4-00000009PFo-2euh; Sun, 17 May 2026 22:03:29 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.98.2 #2 (Red Hat Linux)) id 1wOja4-000000001FZ-2SeD; Sun, 17 May 2026 23:03:28 +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 v2 1/8] timekeeping: Remove xtime_remainder from ntp_error accumulation Date: Sun, 17 May 2026 22:25:38 +0100 Message-ID: <20260517220326.4625-2-dwmw2@infradead.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260517220326.4625-1-dwmw2@infradead.org> References: <20260517220326.4625-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-Transfer-Encoding: 8bit Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by desiato.infradead.org. See http://www.infradead.org/rpr.html From: David Woodhouse The ntp_error accumulator tracks the difference between intended and actual clock advance. Each tick it adds ntp_tick (the intended advance) and subtracts what the clock actually advanced. The subtraction was (xtime_interval + xtime_remainder), but only xtime_interval is actually added to xtime_nsec each tick. xtime_remainder was a boot-time constant representing the rounding error from converting the tick period to an integer number of counter cycles. It was never added to xtime_nsec, so subtracting it from ntp_error created a phantom credit that biased the dithering ratio. The effect is a systematic drift whose magnitude depends on the value of xtime_remainder and the NTP frequency correction. NTP masks this by continuously adjusting the frequency to compensate, but with a fixed frequency (or an external reference clock like vmclock), the drift is exposed. Also remove xtime_remainder from the mult computation in timekeeping_adjust(), which used it to offset the division for the same (incorrect) reason. Fixes: a386b5af8edd ("time: Compensate for rounding on odd-frequency clocksources") Signed-off-by: David Woodhouse --- include/linux/timekeeper_internal.h | 2 -- kernel/time/timekeeping.c | 7 +++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/include/linux/timekeeper_internal.h b/include/linux/timekeeper_internal.h index e36d11e33e0c..2f4cfcfcaac0 100644 --- a/include/linux/timekeeper_internal.h +++ b/include/linux/timekeeper_internal.h @@ -84,7 +84,6 @@ struct tk_read_base { * @cycle_interval: Number of clock cycles in one NTP interval * @xtime_interval: Number of clock shifted nano seconds in one NTP * interval. - * @xtime_remainder: Shifted nano seconds left over when rounding * @cycle_interval * @raw_interval: Shifted raw nano seconds accumulated per NTP interval. * @next_leap_ktime: CLOCK_MONOTONIC time value of a pending leap-second @@ -178,7 +177,6 @@ struct timekeeper { u64 cycle_interval; u64 xtime_interval; - s64 xtime_remainder; u64 raw_interval; ktime_t next_leap_ktime; diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index c493a4010305..3da7167ceb0d 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -360,7 +360,6 @@ static void tk_setup_internals(struct timekeeper *tk, struct clocksource *clock) /* Go back from cycles -> shifted ns */ tk->xtime_interval = interval * clock->mult; - tk->xtime_remainder = ntpinterval - tk->xtime_interval; tk->raw_interval = interval * clock->mult; /* if changing clocks, convert xtime_nsec shift units */ @@ -2337,8 +2336,8 @@ static void timekeeping_adjust(struct timekeeper *tk, s64 offset) mult = tk->tkr_mono.mult - tk->ntp_err_mult; } else { tk->ntp_tick = ntp_tl; - mult = div64_u64((tk->ntp_tick >> tk->ntp_error_shift) - - tk->xtime_remainder, tk->cycle_interval); + mult = div64_u64(tk->ntp_tick >> tk->ntp_error_shift, + tk->cycle_interval); } /* @@ -2463,7 +2462,7 @@ static u64 logarithmic_accumulation(struct timekeeper *tk, u64 offset, /* Accumulate error between NTP and clock interval */ tk->ntp_error += tk->ntp_tick << shift; - tk->ntp_error -= (tk->xtime_interval + tk->xtime_remainder) << + tk->ntp_error -= tk->xtime_interval << (tk->ntp_error_shift + shift); return offset; -- 2.51.0