[PLUG] automatic running of ntpdate

Mike Connors mconnors1 at gmail.com
Thu Dec 3 08:59:44 UTC 2009


Denis Heidtmann wrote:
> Data:  ntpdate runs during boot and logs an offset of something from
> .3 to .9 seconds.  A short time after boot runing ntpdate from the
> command line reports an offset of .00##--something close to zero.
> Shutdown and reboot shortly later, ntpdate runs during boot and logs
> an offset of something from .3 to .9 seconds. Repeat as desired.
>
> I take this to mean that 1) the hardware clock was not synchronized
> better than 1 second on shutdown, or 2) the hardware clock gets bumped
> during the shutdown/reboot cycle, or 3) the hardware clock is unstable
> in the extreme, or 4) the system clock gets set to the rtc to within 1
> second on boot.  1) and 4) seem to me to be effectively the same
> thing.
>
> I vote for 4), because I find in the logs:
> Dec  2 17:58:46 R2D4 kernel: [    3.906800] rtc_cmos 00:08: setting
> system clock to 2009-12-03 01:58:34 UTC (1259805514)
>
> If it were set more accurately than the nearest second why would it
> not show in the log?
Why wouldn't the output from the NTPDATE command be close to zero shortly 
after ntpdate just adjusted the system clock to an ntp server? It's a 
highly accurate clock source and the system clock doesn't drift as much as 
the hwclock.

If you don't believe the hwclock is unstable, just run the "hwclock"
command a few times in a row and you'll see the drift:

root at mc-goose:/var/log# hwclock
Wed 02 Dec 2009 11:22:27 PM PST  -0.859939 seconds
root at mc-goose:/var/log# hwclock
Wed 02 Dec 2009 11:22:28 PM PST  -0.094328 seconds
root at mc-goose:/var/log# hwclock
Wed 02 Dec 2009 11:22:30 PM PST  -0.719333 seconds
root at mc-goose:/var/log# hwclock
Wed 02 Dec 2009 11:22:31 PM PST  -0.281826 seconds
root at mc-goose:/var/log# hwclock
Wed 02 Dec 2009 11:22:33 PM PST  -0.625572 seconds


The  System  Time  is the time that matters. The hwclock's purpose 
is to keep time when Linux is not running. The System Time is initialized by
the time from the hwclock when Linux starts up, and then never use the hwclock again. 


Here's some debug output that shows hwclock after 
reboot:

root at mc-goose:~# hwclock -D
hwclock from util-linux-ng 2.16.1
Using /dev interface to clock.
Last drift adjustment done at 1259827578 seconds after 1969
Last calibration done at 1259827578 seconds after 1969
Hardware clock is on local time
Assuming hardware clock is kept in local time.
Waiting for clock tick...
...got clock tick
Time read from Hardware Clock: 2009/12/03 00:08:18
Hw clock time : 2009/12/03 00:08:18 = 1259827698 seconds since 1969
Thu 03 Dec 2009 12:08:18 AM PST  -0.666495 seconds

I did find some info that the hwclock doesn't make adjustments for 
drift < 1 sec. 

"A  small  amount of error creeps in any time hwclock sets the clock, so
it refrains from making an adjustment that would be less than 1 second.
Later  on,  when you request an adjustment again, the accumulated drift
will be more than a second and hwclock will do the adjustment then.

It is good to do a hwclock --adjust just before the  hwclock  --hctosys
at system startup time, and maybe periodically while the system is run-
ning via cron.

The adjtime file, while named for its historical purpose of controlling
adjustments  only,  actually  contains  other  information  for  use by
hwclock in remembering information from one invocation to the next."



 













More information about the PLUG mailing list