Subject: Re: todr changes to improve clock accuracy across sleeps & reboots
To: Perry E. Metzger <>
From: Daniel Carosone <>
List: tech-kern
Date: 09/08/2006 13:37:38
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Sep 08, 2006 at 11:39:18AM +1000, Daniel Carosone wrote:
> Which really just leaves the question of how to align with second
> transition at startup. =20

Garrett's comments about overengineering, and whether/when to bother
doing these things, are well made.  My major point was to show that
each of the three steps could be tackled separately based on their own

For the sake of posterity, or if someone wants to make the effort
anyway, here's an idea for the startup case:

Assuming the todr is accurate, but truncated to the current second,
set the kernel clock to what is read from the todr at
startup. Schedule a callout that runs several times a second (even if
callout processing doesn't start until a little later).

Each time the callout runs, read the todr and the kernel clock. If the
todr has advanced to the next second (ie, is ahead of the kernel
clock) then set the kernel clock forward to that second.  If the todr
hasn't (is behind the kernel clock), do nothing.

After a few seconds of doing this, the kernel clock will have caught
up to the second transition in the internal todr counter. There's no
benefit in doing this further, stop the callout.  If the kernel clock
is set some other way, say from the root filesystem or from a userland
call, or if adjtime stuff is called indicating that ntp has started
already, stop the callout.=20

Or maybe just stop it unconditionally at some convenient point, like
when init starts, to avoid checks in those syscall paths.  If init
starts less than a second after todr attaches, lucky you.

Content-Type: application/pgp-signature
Content-Disposition: inline

Version: GnuPG v1.4.5 (NetBSD)