1ADJTIMEX(8)                 System Manager's Manual                ADJTIMEX(8)
2
3
4

NAME

6       adjtimex - display or set the kernel time variables
7

SYNOPSIS

9       adjtimex option]...
10

DESCRIPTION

12       This program gives you raw access to the kernel time variables.  Anyone
13       may print out the time variables, but only the superuser may change
14       them.
15
16       Your computer has two clocks - the "hardware clock" that runs all the
17       time, and the system clock that runs only while the computer is on.
18       Normally, "hwclock --hctosys" should be run at startup to initialize
19       the system clock.  The system clock has much better precision (approxi‐
20       mately 1 usec), but the hardware clock probably has better long-term
21       stability.  There are three basic strategies for managing these clocks.
22
23       For a machine connected to the Internet, or equipped with a precision
24       oscillator or radio clock, the best way is to regulate the system clock
25       with ntpd(8).  The kernel will automatically update the hardware clock
26       every eleven minutes.
27
28       In addition, hwclock(8) can be used to approximately correct for a con‐
29       stant drift in the hardware clock.  In this case, "hwclock --adjust" is
30       run occasionally. hwclock notes how long it has been since the last
31       adjustment, and nudges the hardware clock forward or back by the appro‐
32       priate amount.  The user needs to set the time with "hwclock --set"
33       several times over the course of a few days so hwclock can estimate the
34       drift rate.  During that time, ntpd should not be running, or else
35       hwclock will conclude the hardware clock does not drift at all.  After
36       you have run "hwclock --set" for the last time, it's okay to start
37       ntpd.  Then, "hwclock --systohc" should be run when the machine is shut
38       down.  (To see why, suppose the machine runs for a week with ntpd, is
39       shut down for a day, is restarted, and "hwclock --adjust" is run by a
40       startup script.  It should only correct for one day's worth of drift.
41       However, it has no way of knowing that ntpd has been adjusting the
42       hardware clock, so it bases its adjustment on the last time hwclock was
43       run.)
44
45       For a standalone or intermittently connected machine, where it's not
46       possible to run ntpd, you may use adjtimex instead to correct the sys‐
47       tem clock for systematic drift.
48
49       There are several ways to estimate the drift rate.  If your computer
50       can be connected to the net, you might run ntpd for at least several
51       hours and run "adjtimex --print" to learn what values of tick and freq
52       it settled on.  Alternately, you could estimate values using as a ref‐
53       erence the CMOS clock (see the --compare and --adjust switches),
54       another host (see --host and --review), or some other source of time
55       (see --watch and --review).  You could then add a line to rc.local
56       invoking adjtimex, or configure /etc/init.d/adjtimex or
57       /etc/default/adjtimex, to set those parameters each time you reboot.
58

OPTIONS

60       Options may be introduced by either - or --, and unique abbreviations
61       may be used.  Here is a summary of the options, grouped by type.
62       Explanations follow.
63
64       Get/Set Kernel Time Parameters
65              -p --print -t --tick val -f newfreq --frequency newfreq -o val
66              --offset val -s adjustment --singleshot adjustment -S status
67              --status status -m val -R --reset --maxerror val -e val
68              --esterror val -T val --timeconstant val -a[count]
69              --adjust[=count]
70
71       Estimate Systematic Drifts
72              -c[count] --compare[=count] -i tim --interval tim -l file
73              --logfile file -h timeserver --host timeserver -w --watch
74              -r[file] --review[=file] -u --utc
75
76       Informative Output
77              --help -v --version -V --verbose
78
79       -p, --print
80              Print the current values of the kernel time variables.  NOTE:
81              The time is "raw", and may be off by up to one timer tick (10
82              msec).  "status" gives the value of the time_status variable in
83              the kernel.  For Linux 1.0 and 1.2 kernels, the value is as
84              follows:
85                    0   clock is synchronized (so the kernel should
86                        periodically set the CMOS clock to match the
87                        system clock)
88                    1   inserting a leap second at midnight
89                    2   deleting a leap second at midnight
90                    3   leap second in progress
91                    4   leap second has occurred
92                    5   clock not externally synchronized (so the
93                        kernel should leave the CMOS clock alone)
94              For Linux 2.0 kernels, the value is a sum of these:
95                    1   PLL updates enabled
96                    2   PPS freq discipline enabled
97                    4   PPS time discipline enabled
98                    8   frequency-lock mode enabled
99                   16   inserting leap second
100                   32   deleting leap second
101                   64   clock unsynchronized
102                  128   holding frequency
103                  256   PPS signal present
104                  512   PPS signal jitter exceeded
105                 1024   PPS signal wander exceeded
106                 2048   PPS signal calibration error
107                 4096   clock hardware fault
108
109       -t val, --tick val
110              Set the number of microseconds that should be added to the
111              system time for each kernel tick interrupt.  For a kernel with
112              USER_HZ=100, there are supposed to be 100 ticks per second, so
113              val should be close to 10000.  Increasing val by 1 speeds up the
114              system clock by about 100 ppm, or 8.64 sec/day.  tick must be in
115              the range 900000/USER_HZ...1100000/USER_HZ.  If val is rejected
116              by the kernel, adjtimex will determine the acceptable range
117              through trial and error and print it.  (After completing the
118              search, it will restore the original value.)
119
120       -f newfreq, --frequency newfreq
121              Set the system clock frequency offset to newfreq.  newfreq can
122              be negative or positive, and gives a much finer adjustment than
123              the --tick switch.  When USER_HZ=100, the value is scaled such
124              that newfreq = 65536 speeds up the system clock by about 1 ppm,
125              or .0864 sec/day.  Thus, all of these are about the same:
126                   --tick  9995 --frequency  32768000
127                   --tick 10000 --frequency   6553600
128                   --tick 10001 --frequency         0
129                   --tick 10002 --frequency  -6553600
130                   --tick 10005 --frequency -32768000
131              To see the acceptable range for newfreq, use --print and look at
132              "tolerance", or try an illegal value (e.g. --tick 0).
133
134       -s adj, --singleshot adj
135              Slew the system clock by adj usec.  (Its rate is changed
136              temporarily by about 1 part in 2000.)
137
138       -o adj, --offset adj
139              Add a time offset of adj usec.  The kernel code adjusts the time
140              gradually by adj, notes how long it has been since the last time
141              offset, and then adjusts the frequency offset to correct for the
142              apparent drift.  adj must be in the range -512000...512000.
143
144       -S status, --status status
145              Set kernel system clock status register to value status. Look
146              here above at the --print switch section for the meaning of
147              status, depending on your kernel.
148
149       -R, --reset
150              Reset clock status after setting a clock parameter.  For early
151              Linux kernels, using the adjtimex(2) system call to set any time
152              parameter the kernel think the clock is synchronized with an
153              external time source, so it sets the kernel variable time_status
154              to TIME_OK.  Thereafter, at 11 minute intervals, it will adjust
155              the CMOS clock to match.  We prevent this "eleven minute mode"
156              by setting the clock, because that has the side effect of
157              resetting time_status to TIME_BAD.  We try not to actually
158              change the clock setting.  Kernel versions 2.0.40 and later
159              apparently don't need this.  If your kernel does require it, use
160              this option with: -t -T -t -e -m -f -s -o -c -r.
161
162       -m val, --maxerror val
163              Set maximum error (usec).
164
165       -e val, --esterror val
166              Set estimated error (usec).  The maximum and estimated error are
167              not used by the kernel.  They are merely made available to user
168              processes via the adjtimex(2) system call.
169
170       -T val, --timeconstant val
171              Set phase locked loop (PLL) time constant.  val determines the
172              bandwidth or "stiffness" of the PLL.  The effective PLL time
173              constant will be a multiple of (2^val).  For room-temperature
174              quartz oscillators, David Mills recommends the value 2, which
175              corresponds to a PLL time constant of about 900 sec and a
176              maximum update interval of about 64 sec.  The maximum update
177              interval scales directly with the time constant, so that at the
178              maximum time constant of 6, the update interval can be as large
179              as 1024 sec.
180
181              Values of val between zero and 2 give quick convergence; values
182              between 2 and 6 can be used to reduce network load, but at a
183              modest cost in accuracy.
184
185       -ccount], --compare=count
186              Periodically compare the system clock with the CMOS clock.
187              After the first two calls, print values for tick and frequency
188              offset that would bring the system clock into approximate
189              agreement with the CMOS clock.  CMOS clock readings are adjusted
190              for systematic drift using using the correction in /etc/adjtime
191              — see hwclock(8).  The interval between comparisons is 10
192              seconds, unless changed by the --interval switch.  The optional
193              argument is the number of comparisons.  (If the argument is
194              supplied, the "=" is required.)  If the CMOS clock and the
195              system clock differ by more than six minutes, adjtimex will try
196              shifting the time from the CMOS clock by some multiple of one
197              hour, up to plus or minus 13 hours in all.  This should allow
198              correct operation, including logging, if the --utc switch was
199              used when the CMOS clock is set to local time (or vice-versa),
200              or if summer time has started or stopped since the CMOS clock
201              was last set.
202
203       -acount], --adjust[=count]
204              By itself, same as --compare, except the recommended values are
205              actually installed after every third comparison.  With --review,
206              the tick and frequency are set to the least-squares estimates.
207              (In the latter case, any count value is ignored.)
208
209       -i tim, --interval tim
210              Set the interval in seconds between clock comparisons for the
211              --compare and --adjust options.
212
213       -u, --utc
214              The CMOS clock is set to UTC (universal time) rather than local
215              time.
216
217       -lfile], --log=file
218              Save the current values of the system and CMOS clocks, and
219              optionally a reference time, to file (default
220              /var/log/clocks.log).  The reference time is taken from a
221              network timeserver (see the --host switch) or supplied by the
222              user (see the --watch switch).
223
224       -h timeserver, --host timeserver
225              Use ntpdate to query the given timeserver for the current time.
226              This will fail if timeserver is not running a Network Time
227              Protocol (NTP) server, or if that server is not synchronized.
228              Implies --log.
229
230       -w, --watch
231              Ask for a keypress when the user knows the time, then ask what
232              that time was, and its approximate accuracy.  Implies --log.
233
234       -rfile], --review=file
235              Review the clock log file (default /var/log/clocks.log) and
236              estimate, if possible, the rates of the CMOS and system clocks.
237              Calculate least-squares rates using all suitable log entries.
238              Suggest corrections to adjust for systematic drift.  With
239              --adjust, the frequency and tick are set to the suggested
240              values.  (The CMOS clock correction is not changed.)
241
242       -V, --verbose
243              Increase verbosity.
244
245       --help Print the program options.
246
247       -v, --version
248              Print the program version.
249

EXAMPLES

251       If your system clock gained 8 seconds in 24 hours, you could set the
252       tick to 9999, and then it would lose 0.64 seconds a day (that is, 1
253       tick unit = 8.64 seconds per day).  To correct the rest of the error,
254       you could set the frequency offset to (2^16)*0.64/.0864 = 485452.
255       Thus, putting the following in rc.local would approximately correct the
256       system clock:
257
258            adjtimex  --tick 9999  --freq 485452
259

NOTES

261       adjtimex adjusts only the system clock — the one that runs while the
262       computer is powered up.  To set or regulate the CMOS clock, see
263       hwclock(8).
264

AUTHORS

266       Steven S. Dick <ssd at nevets.oau.org>, Jim Van Zandt <jrv at
267       comcast.net>.
268

SEE ALSO

270       date(1L), gettimeofday(2), settimeofday(2), hwclock(8), ntpdate(8),
271       ntpd(8), /usr/src/linux/include/linux/timex.h,
272       /usr/src/linux/include/linux/sched.h, /usr/src/linux/kernel/time.c,
273       /usr/src/linux/kernel/sched.c
274
275
276
277                                 May 23, 2006                      ADJTIMEX(8)
Impressum