Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 19 Mar 2009 16:09:32 +0100
From:      Andre Albsmeier <andre@albsmeier.net>
To:        freebsd-hardware@freebsd.org, won.derick@yahoo.com
Subject:   Re: Hardware clock is not SYNC'ed with kernel clock by ntpdate?
Message-ID:  <20090319150932.GA2174@schlappy.albsmeier.net>
In-Reply-To: <200902141838.n1EIcwQX009259@lurza.secnetix.de>
References:  <800496.48763.qm@web45816.mail.sp1.yahoo.com> <200902141838.n1EIcwQX009259@lurza.secnetix.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 14-Feb-2009 at 19:38:58 +0100, Oliver Fromme wrote:
> Won De Erick <won.derick@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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090319150932.GA2174>