linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ian Maclaine-cross <iml@ilm.mech.unsw.edu.au>
To: linux-kernel@vger.kernel.org
Cc: Ian Maclaine-cross <iml@debian.org>
Subject: PROBLEM: Linux updates RTC secretly when clock synchronizes
Date: Wed, 31 Oct 2001 11:33:12 +1100	[thread overview]
Message-ID: <20011031113312.A8738@ilm.mech.unsw.edu.au> (raw)


PROBLEM: Linux updates RTC secretly when clock synchronizes.

Please CC replies etc to Ian Maclaine-cross <iml@debian.org>.

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);
+		}
 		else
 			last_rtc_update = xtime.tv_sec - 600; /* do it again in 60 s */
 	}

-- 
Regards,
Ian Maclaine-cross (iml@debian.org)

             reply	other threads:[~2001-10-31  0:33 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-31  0:33 Ian Maclaine-cross [this message]
2001-10-31  1:05 ` PROBLEM: Linux updates RTC secretly when clock synchronizes Kurt Roeckx
2001-10-31  2:55   ` Ian Maclaine-cross
2001-10-31 11:52     ` Kurt Roeckx
2001-11-01  0:52       ` Riley Williams
2001-11-01  1:26         ` Kurt Roeckx
2001-11-01 13:57         ` Alex Bligh - linux-kernel
2001-11-02  9:50           ` Riley Williams
2001-11-03 11:41             ` Alex Bligh - linux-kernel
2001-11-03 18:35               ` Riley Williams
2001-11-03 19:19                 ` Alex Bligh - linux-kernel
2001-11-03 21:04                 ` Kurt Roeckx
2001-11-06 10:01                 ` Pavel Machek
2001-11-06  9:57             ` Pavel Machek
2001-11-02 12:16 ` Pavel Machek
2001-11-05 23:08   ` Riley Williams
2001-11-06 10:17     ` Pavel Machek
2001-11-07  0:00       ` Riley Williams
2001-11-07  0:44         ` Alex Bligh - linux-kernel
2001-11-07  1:01           ` Kurt Roeckx
2001-11-07  1:15             ` Alex Bligh - linux-kernel
2001-11-07  9:24             ` Russell King
2001-11-08 12:26         ` Pavel Machek
2001-11-08 23:00           ` Riley Williams
2001-11-09  9:32             ` Pavel Machek
2001-11-09 21:11               ` Riley Williams
2001-11-09 21:30                 ` Pavel Machek
2001-11-09 22:54                   ` Riley Williams
2001-11-09 23:10                     ` Mark Zealey
2001-11-10 20:04                     ` Pavel Machek
2001-11-10 20:35                       ` Riley Williams
2001-11-10 20:43                         ` Pavel Machek
2001-11-10 20:49                         ` Doug McNaught
2001-11-06  0:20   ` Ian Maclaine-cross
2001-11-06 10:18     ` Pavel Machek
2001-11-08  5:09       ` Ian Maclaine-cross

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=20011031113312.A8738@ilm.mech.unsw.edu.au \
    --to=iml@ilm.mech.unsw.edu.au \
    --cc=iml@debian.org \
    --cc=linux-kernel@vger.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;
as well as URLs for NNTP newsgroup(s).