Subject: Re: why times are often off by up to a second
To: None <perry@piermont.com>
From: Bill Sommerfeld <sommerfeld@orchard.arlington.ma.us>
List: tech-kern
Date: 02/24/1999 10:48:01
I'm pretty sure that this isn't worth it, but in abstract terms,
here's how to get ~1/hz accuracy without buzzlooping:

You need 32 bits of stable storage for a sub-seconds offset across
reboot.  I'll call it clock_offset.  (Implementing this is left as an
exercise for the reader.  A spare field in the superblock might work
for this; you just have to *not* call resettodr() after the final
sync()).

I assume the TODR clock ticks once per second.  Generalizing it to
other tick frequencies is left as an exercise for the reader.

At resettodr time, you store time.tv_usec (time.tv_nsec if we ever get
around to converting time to be a timespec) into clock_offset.  .

At inittodr time, you set time0 = time, and set up a periodic task
(e.g., using timeout(), running every 1/hz seconds) to poll the RTC
waiting for it to tick.

When you notice the flip, you compute the time we waited for the clock
to tick:

    delta = time - time0

At this point, we now want to adjust the clock backwards by 1-delta
seconds, and forward by the fractional second stored in clock_offset.

Presumably doing an in-kernel adjtime call would be the way to go for
this..

Again, I think this is severe overkill.

						- Bill