From owner-freebsd-hardware@FreeBSD.ORG Fri Mar 20 00:44:29 2009 Return-Path: Delivered-To: freebsd-hardware@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DA7DE106564A for ; Fri, 20 Mar 2009 00:44:29 +0000 (UTC) (envelope-from won.derick@yahoo.com) Received: from n23.bullet.mail.mud.yahoo.com (n23.bullet.mail.mud.yahoo.com [68.142.206.162]) by mx1.freebsd.org (Postfix) with SMTP id 9F7CE8FC17 for ; Fri, 20 Mar 2009 00:44:29 +0000 (UTC) (envelope-from won.derick@yahoo.com) Received: from [68.142.194.244] by n23.bullet.mail.mud.yahoo.com with NNFMP; 20 Mar 2009 00:44:29 -0000 Received: from [68.142.201.243] by t2.bullet.mud.yahoo.com with NNFMP; 20 Mar 2009 00:44:29 -0000 Received: from [127.0.0.1] by omp404.mail.mud.yahoo.com with NNFMP; 20 Mar 2009 00:44:29 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 19559.75695.bm@omp404.mail.mud.yahoo.com Received: (qmail 2753 invoked by uid 60001); 20 Mar 2009 00:44:28 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1237509868; bh=qsoOlcyCyzlsxDpDikXAO7K5XF94tu5M/ZkG32knvi0=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:Cc:MIME-Version:Content-Type; b=WOWsFPiiB0tno/AOGAt/9sKt4rLlZqmuSjcE0FPkqzfCU/UMxVfm79IIjKDG8CGdWwweT5uqH/tklgSYfPkhILhtDv3+fRo6/GyefXRBuRC0/BEKAdBNVIzCe8YyFdJDUFeTdeesoNRMe5mtAVEw2XjDxDtT49ENUvbNqtV9EJ0= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:Cc:MIME-Version:Content-Type; b=UpnOpFpQgriqCcKlRQUNnbXCBXQZrhyEFOTNwe0H5YHEZEtB5yHrOlkG0hYUkkt2CTKzwfQwLcdHATPYVifE19b6ER4tn7WgnPde4Fx9YP0R6YtB9OMAztjjH8a6yP/AMHS6HtI7KMZscERdrUuZ43YGse5lZPmMw28cRo/G8gA=; Message-ID: <402443.1503.qm@web45812.mail.sp1.yahoo.com> X-YMail-OSG: zvlR2M4VM1mKf0MfExh3r_2GgmcvT6.qKf7q_DLD9E_v2Yj7E9VGnaMkX1yen2BO.Fjh6bGdcIzCHEzkNIZ_NK.J8xxekvQa.GCMMDAglq8GyteppE1vPtj2rkn_iFlIydUfo97uotHxfjMDfUb0mcNRbf8UVlC7jIKaLriwjUGf2PY6H6X9aZkSPbXpAqtqC8wvQrdQsmcAZbqT_Oo3eGXWsospeZtC8rBsjrNHKa.I8JSZohthY_.sfwsi7fRKstQXdt2RFomT1QCUOGgJY3J.fXPSKtw- Received: from [58.71.34.137] by web45812.mail.sp1.yahoo.com via HTTP; Thu, 19 Mar 2009 17:44:27 PDT X-Mailer: YahooMailClassic/5.1.20 YahooMailWebService/0.7.289.1 Date: Thu, 19 Mar 2009 17:44:27 -0700 (PDT) From: Won De Erick To: Andre Albsmeier , Oliver Fromme , Andriy Gapon MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: freebsd-hardware@freebsd.org Subject: Re: Hardware clock is not SYNC'ed with kernel clock by ntpdate? X-BeenThere: freebsd-hardware@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General discussion of FreeBSD hardware List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Mar 2009 00:44:30 -0000 --- On Thu, 3/19/09, Andriy Gapon wrote: > 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 > >> 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 > > #include > > #include > > #include > > > > 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 > Cool!