Re: PROBLEM: Linux updates RTC secretly when clock synchronizes

Kurt Roeckx (Q@ping.be)
Sat, 3 Nov 2001 22:04:35 +0100


On Sat, Nov 03, 2001 at 06:35:44PM +0000, Riley Williams wrote:
> server 127.127.1.0 # local clock
> fudge 127.127.1.0 stratum 10
>
> The second server line specifies 127.127.1.0 which is the address that
> ntp associates with the local RTC clock.

* This is a hack to allow a machine to use its own system clock as a
* reference clock

This just calls gettimeofday() indirectly.

It's the system clock, not the RTC. Afaik, there is no support
for the RTC clock.

> >> 2. My experience with the xntpd driver suggests that if no better
> >> reference is available and the RTC is one of the listed clocks,
> >> then it ALWAYS adjusts the time to match the RTC, irrespective
> >> of the time difference between them.
>
> > ... you are assuming that the RTC doesn't get adjusted first (to
> > match the system clock)!
>
> If it does, what adjusts it?

ntpd asks the kernel to write the time to the RTC. I think it
does that from the moment it's sycnhed. If it would be reading
and writing to the RTC, you could have a problem.

> >> 3. AFAICT, if xntpd writes to the RTC, then it has achieved true
> >> synchronisation to a reference clock other than the RTC.
>
> > I thought the original poster was claiming that the /kernel/
> > wrote to the RTC, which would explain the behaviour I'm seeing.
>
> The kernel itself never writes to the RTC, and that is one of Linus's
> decisions with which I am in 100% agreeance (and one thing I hate about
> Windows). In fact, the kernel itself also doesn't read from the RTC
> either, but leaves that to userspace.

The kernel does write to the RTC if told to do so, every 11
minutes. This is broken because it doesn't even know what hour
it should be writing, so it doesn't write it.

In arch/i386/kernel/time.c/do_timer_interrupt():

/*
* If we have an externally synchronized Linux clock, then update
* CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
* called as close as possible to 500 ms before the new second starts.
*/
if ((time_status & STA_UNSYNC) == 0 &&
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)
last_rtc_update = xtime.tv_sec;
else
last_rtc_update = xtime.tv_sec - 600; /* do it again in
60 s */
}

Kurt

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/