PROBLEM: Linux updates RTC secretly when clock synchronizes

From: Ian Maclaine-cross (
Date: Tue Oct 30 2001 - 19:33:12 EST

PROBLEM: Linux updates RTC secretly when clock synchronizes.

Please CC replies etc to Ian Maclaine-cross <>.

When /usr/sbin/ntpd synchronizes the Linux kernel (or system) clock
using the Network Time Protocol the kernel time is accurate to a few
milliseconds. Linux then sets the Real Time (or Hardware or CMOS)
Clock to this time at approximately 11 minute intervals. Typical RTCs
drift less than 10 s/day so rebooting causes only millisecond errors.

Linux currently does not record the 11 minute updates to a log file.
Clock programs (like hwclock) cannot correct RTC drift at boot without
knowing when the RTC was last set. If NTP service is available after a
long shutdown, ntpd may step the time. Worse after a longer shutdown
ntpd may drop out or even synchronize to the wrong time zone. The
workarounds are clumsy.

Please find following my small patch for linux/arch/i386/kernel/time.c
which adds a KERN_NOTICE of each 11 minute update to the RTC. This is
just for i386 machines at present. A script can search the logs for
the last set time of the RTC and update /etc/adjtime. Hwclock can
then correct the RTC for drift and set the kernel clock.

I patched Linux 2.2.19 and 2.4.12 then compiled, installed and
rebooted on Pentium MMX and AMD K6-III machines respectively. When the
kernel clock synchronized "...: Real Time Clock set at xxx s" appeared
in the kernel log every 661 s where "xxx" was the current system
time. Messages ceased whenever the clock was unsynchronized. Ntpd
produces typically four log lines in 661 s so the increase in log
volume is small for ntpd users and nothing for nonusers. The patch
added 11 bytes to the size of my compressed kernel.

diff -u --recursive linux.old/arch/i386/kernel/time.c linux/arch/i386/kernel/time.c
--- linux.old/arch/i386/kernel/time.c Mon Oct 29 16:37:19 2001
+++ linux/arch/i386/kernel/time.c Mon Oct 29 16:42:03 2001
@@ -28,6 +28,9 @@
  * 1998-12-24 Copyright (C) 1998 Andrea Arcangeli
  * Fixed a xtime SMP race (we need the xtime_lock rw spinlock to
  * serialize accesses to xtime/lost_ticks).
+ * 2001-10-28 Ian Maclaine-cross
+ * Added KERN_NOTICE of each ~11 minute update to RTC. If no time source
+ * on boot hwclock etc can correct RTC drift error with last logged time.
 #include <linux/errno.h>
@@ -435,8 +438,12 @@
             xtime.tv_sec > last_rtc_update + 660 &&
             xtime.tv_usec >= 500000 - ((unsigned) tick) / 2 &&
             xtime.tv_usec <= 500000 + ((unsigned) tick) / 2) {
- if (set_rtc_mmss(xtime.tv_sec) == 0)
+ if (set_rtc_mmss(xtime.tv_sec) == 0) {
                         last_rtc_update = xtime.tv_sec;
+ printk(KERN_NOTICE
+ "Real Time Clock set at %d s\n",
+ last_rtc_update);
+ }
                         last_rtc_update = xtime.tv_sec - 600; /* do it again in 60 s */

Ian Maclaine-cross (
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

This archive was generated by hypermail 2b29 : Wed Oct 31 2001 - 21:00:42 EST