on 19/03/2009 17:09 Andre Albsmeier said the following:
> On Sat, 14-Feb-2009 at 19:38:58 +0100, Oliver Fromme wrote:
>> Won De Erick <won.der...@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.

Oliver, if this is not misquoted then you are not correct.
Sorry, I noticed this thread too late, so I have to follow up in this fashion.
RTC ("CMOS clock") is updated via resettodr function and you can search kernel
sources yourself to see how many times and where it called.
I reported the problem myself once upon a time:
http://lists.freebsd.org/pipermail/freebsd-hackers/2005-August/013383.html

> 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.

I think that ideally RTC time should be updated when discrepancy between it and
kernel time exceeds certain threshold.
Also, we can could have a kernel self-rescheduling callout that would update
hardware clock every half an hour (or whatever, configurable).
Periodic - because we not always have a graceful shutdown (crashes, power loss, 
etc).

For time beng I am using this hack:
#save OS clock value to time-of-day register (x86 CMOS)
10      0-2,4-23        *       *       *       /usr/local/sbin/resettodr.sh

$ cat /usr/local/sbin/resettodr.sh
#!/bin/sh

# ATTENTION: run this script only at time when you are sure that no
# timezone change (daylight savings time) could possibly occur.
# Otherwise you risk race with adjkerntz -e run from /etc/crontab.
# Time between 06:00 and 23:59 should be safe.


trigger_sysctl_name="machdep.adjkerntz"
sysctl_command="/sbin/sysctl"

$sysctl_command `$sysctl_command -e $trigger_sysctl_name` > /dev/null

Calling this at shutdown would be a bonus.

-- 
Andriy Gapon
_______________________________________________
freebsd-hardware@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hardware
To unsubscribe, send any mail to "freebsd-hardware-unsubscr...@freebsd.org"

Reply via email to