See HowToCalibrateSystemClockUsingNTPDev for discussion of this topic.
How to calibrate the system clock using NTP
If you have a NTP daemon running and configured for a reliable time server, NTP will discipline your system clock. If you do not want to run NTP continuously, but rather calibrate your system clock once, NTP can help you to find the frequency offset of your system clock.
Linux / Unix
There are several methods to measure your system clock's frequency offset using
NTP. These include David's recipes from his
posting.
Plan A: let NTP daemon determine the clock skew.
Run the NTP daemon using a reliable time server. The daemon will then measure and record the intrinsic clock frequency offset in the so called
frequency file ntp.drift. Depending on the computer clock oscillator's frequency error this may take some hours (or even days) to stabilize. When the value has converged, the
frequency file contains the frequency offset measured in parts-per-million (PPM).
David's recipe:
- Run
ntptime -f 0 to remove any leftover kernel bias.
- Configure for a reliable server over a quiet network link.
- Remove the frequency file
ntp.drift.
- Start the daemon and wait for at least 15 minutes until
ntpq -c rv shows state=4. Record the frequency offset (the value after frequency=). It should be within 1 PPM of the actual frequency offset. For enhanced confidence, wait until the first frequency file update after one hour or so.
Plan B: calculate skew as first derivative of offset against time
You can also measure the time offset to a reliable time server.
The offset plotted against time should give a straight line; the slope is the time offset per second.
David's recipe:
- Run
ntptime -f 0 to remove any leftover kernel bias.
- Delete the frequency file
ntp.drift otherwise NTP daemon will sets clock adjustment parameters and you end up measuring the residual error.
- Configure for a reliable server over a quiet network link.
- Start the daemon with
disable ntp in the configuration file (see misc. configuration options).
- Find the assID of your peer using
ntpq -c assoc and write it down.
- Using
ntpq -c 'rv assId', record the offset (the value after offset=) over a period of hours.
- Do a least-squares fit; the regression line slope is the frequency.
Plan C: same as B but from remote.
If you want to remotely measure the time offset, resort to
ntpdate.
Run the NTP daemon configured for the pseudo-reference
local clock (127.127.1.0) as server. Execute
ntpdate -q on a synchronized system against the system you want to measure.
ntpdate will output the time offset in seconds. If you record the offset (and time) periodically, you can fit a straight line to the data points. The slope times 86400 will give the estimated offset in seconds per day. This can be converted into PPM. Measuring for one hour will be enough to get a reasonably accurate value.
Hint: The official distribution will be
DeprecatingNtpdate soon.
Instead of
ntpdate, you can also use the
sntp program distributed with the NTP software.
ntptime
Linux uses David L. Mills' clock adjustment algorithm. The system call
adjtimex reads and optionally sets adjustment parameters (e.g. frequency offset) for this algorithm. To read or set the current kernel parameters use the
ntptime utility program included in the NTP distribution.
ntpq
The
ntpq utility program is used to monitor NTP daemon ntpd operations and determine performance.
ntpdate
ntpdate sets the local date and time by polling the Network Time Protocol (NTP) server(s) given as the server arguments to determine the correct time.
Units
100 PPM = 8.64 seconds / day
Documentation
Recommended readings:
--
DanielKabs - 6 Mar 2006
Please use
HowToCalibrateSystemClockUsingNTPDev for comments about
HowToCalibrateSystemClockUsingNTP.