Hardware clock is not SYNC'ed with kernel clock by ntpdate?

Andre Albsmeier andre at albsmeier.net
Thu Mar 19 08:21:03 PDT 2009


On Sat, 14-Feb-2009 at 19:38:58 +0100, Oliver Fromme wrote:
> Won De Erick <won.derick at yahoo.com> wrote:
>
> ...
> 
>  > However, how should I make this automatic, something that will update
>  > the CMOS clock everytime the kernel clock is syncronized with a NTP
>  > server? Do I need to make changes on the variables below?
> 
> You seem to misunderstand.  The CMOS clock _is_ always
> updated when you run ntpd.  You do not have to change
> anything.

Hmm, my experience is different here. I have 17 FreeBSD machines
which are all running ntpd (btw, no /etc/wall_cmos_clock). When
being rebooted, they sync the time with ntpdate before starting
ntpd. Somtimes I noticed the time being stepped by several seconds
(up to 50). I observed that the higher the previous uptime had been,
the bigger the stepping during the following reboot was.
While ntpd keeps the kernel time perfectly in sync with our
stratum-1 server the CMOS clocks slowly drift away. The higher
the uptime, the bigger the drift.

I am now using this ugly hack to sync the kernel time to the
CMOS clock (settimeofday() sets both) before reboot and
the problem never appeared again:

#include <sys/time.h>
#include <stdlib.h>
#include <err.h>
#include <sysexits.h>

int main( void )
{
  struct timeval tv;

  if( gettimeofday( &tv, NULL ) != 0 )
    err( EX_DATAERR, "gettimeofday" );

  if( settimeofday( &tv, NULL ) != 0 )
    err( EX_DATAERR, "settimeofday" );

  return 0;
}


A cleaner way might be to call resettodr() in subr_clock.c
just before rebooting.

If there are easier/cleaner ways to keep CMOS time in sync,
I will be happy about any suggestions.

	-Andre


More information about the freebsd-hardware mailing list