Vous êtes sur la page 1sur 4

Name

adjtimex - display or set the kernel time variables


Synopsis
adjtimex [option]...
Description
This program gives you raw access to the kernel time variables. Anyone may print
out the time variables, but only the superuser may change them.
Your computer has two clocks - the "hardware clock" that runs all the time, and
the system clock that runs only while the computer is on. Normally, "hwclock --h
ctosys" should be run at startup to initialize the system clock. The system cloc
k has much better precision (approximately 1 usec), but the hardware clock proba
bly has better long-term stability. There are three basic strategies for managin
g these clocks.
For a machine connected to the Internet, or equipped with a precision oscillator
or radio clock, the best way is to regulate the system clock with ntpd(8). The
kernel will automatically update the hardware clock every eleven minutes.
In addition, hwclock(8) can be used to approximately correct for a constant drif
t in the hardware clock. In this case, "hwclock --adjust" is run occasionally. h
wclock notes how long it has been since the last adjustment, and nudges the hard
ware clock forward or back by the appropriate amount. The user needs to set the
time with "hwclock --set" several times over the course of a few days so hwclock
can estimate the drift rate. During that time, ntpd should not be running, or e
lse hwclock will conclude the hardware clock does not drift at all. After you ha
ve run "hwclock --set" for the last time, it's okay to start ntpd. Then, "hwcloc
k --systohc" should be run when the machine is shut down. (To see why, suppose t
he machine runs for a week with ntpd, is shut down for a day, is restarted, and
"hwclock --adjust" is run by a startup script. It should only correct for one da
y's worth of drift. However, it has no way of knowing that ntpd has been adjusti
ng the hardware clock, so it bases its adjustment on the last time hwclock was r
un.)
For a standalone or intermittently connected machine, where it's not possible to
run ntpd, you may use adjtimex instead to correct the system clock for systemat
ic drift.
There are several ways to estimate the drift rate. If your computer can be conne
cted to the net, you might run ntpd for at least several hours and run "adjtimex
--print" to learn what values of tick and freq it settled on. Alternately, you
could estimate values using as a reference the CMOS clock (see the --compare and
--adjust switches), another host (see --host and --review), or some other sourc
e of time (see --watch and --review). You could then add a line to rc.local invo
king adjtimex, or configure /etc/init.d/adjtimex or /etc/default/adjtimex, to se
t those parameters each time you reboot.
Options
Options may be introduced by either - or --, and unique abbreviations may be use
d. Here is a summary of the options, grouped by type. Explanations follow.
Get/Set Kernel Time Parameters
-p --print -t --tick val -f newfreq --frequency newfreq -o val --offset val
-s adjustment --singleshot adjustment -S status --status status -m val -R --rese
t --maxerror val -e val --esterror val -T val --timeconstant val -a[count] --adj
ust[=count]
Estimate Systematic Drifts

-c[count] --compare[=count] -i tim --interval tim -l file --logfile file -h


timeserver --host timeserver -w --watch -r[file] --review[=file] -u --utc
Informative Output
--help -v --version
-p, --print
Print the current values of the kernel time variables. NOTE: The time is "ra
w", and may be off by up to one timer tick (10 msec). "status" gives the value o
f the time_status variable in the kernel. For Linux 1.0 and 1.2 kernels, the val
ue is as follows:
0
1
2
3
4
5

clock is synchronized (so the kernel should


periodically set the CMOS clock to match the
system clock)
inserting a leap second at midnight
deleting a leap second at midnight
leap second in progress
leap second has occurred
clock not externally synchronized (so the
kernel should leave the CMOS clock alone)

For Linux 2.0 kernels, the value is a sum of these:


1
2
4
8
16
32
64
128
256
512
1024
2048
4096

PLL updates enabled


PPS freq discipline enabled
PPS time discipline enabled
frequency-lock mode enabled
inserting leap second
deleting leap second
clock unsynchronized
holding frequency
PPS signal present
PPS signal jitter exceeded
PPS signal wander exceeded
PPS signal calibration error
clock hardware fault

-t val, --tick val


Set the number of microseconds that should be added to the system time for e
ach kernel tick interrupt. For a kernel with USER_HZ=100, there are supposed to
be 100 ticks per second, so val should be close to 10000. Increasing val by 1 sp
eeds up the system clock by about 100 ppm, or 8.64 sec/day. tick must be in the
range 900000/USER_HZ...1100000/USER_HZ. If val is rejected by the kernel, adjtim
ex will determine the acceptable range through trial and error and print it. (Af
ter completing the search, it will restore the original value.)
-f newfreq, --frequency newfreq
Set the system clock frequency offset to newfreq. newfreq can be negative or
positive, and gives a much finer adjustment than the --tick switch. When USER_H
Z=100, the value is scaled such that newfreq = 65536 speeds up the system clock
by about 1 ppm, or .0864 sec/day. Thus, all of these are about the same:
--tick
--tick
--tick
--tick
--tick

9995
10000
10001
10002
10005

--frequency 32768000
--frequency 6553600
--frequency
0
--frequency -6553600
--frequency -32768000

To see the acceptable range for newfreq, use --print and look at "tolerance"
, or try an illegal value (e.g. --tick 0).
-s adj, --singleshot adj
Slew the system clock by adj usec. (Its rate is changed temporarily by about

1 part in 2000.)
-o adj, --offset adj
Add a time offset of adj usec. The kernel code adjusts the time gradually by
adj, notes how long it has been since the last time offset, and then adjusts th
e frequency offset to correct for the apparent drift. adj must be in the range 512000...512000.
-S status, --status status
Set kernel system clock status register to value status. Look here above at
the --print switch section for the meaning of status, depending on your kernel.
-R, --reset
Reset clock status after setting a clock parameter. For early Linux kernels,
using the adjtimex(2) system call to set any time parameter the kernel think th
e clock is synchronized with an external time source, so it sets the kernel vari
able time_status to TIME_OK. Thereafter, at 11 minute intervals, it will adjust
the CMOS clock to match. We prevent this "eleven minute mode" by setting the clo
ck, because that has the side effect of resetting time_status to TIME_BAD. We tr
y not to actually change the clock setting. Kernel versions 2.0.40 and later app
arently don't need this. If your kernel does require it, use this option with: t -T -t -e -m -f -s -o -c -r.
-m val, --maxerror val
Set maximum error (usec).
-e val, --esterror val
Set estimated error (usec). The maximum and estimated error are not used by
the kernel. They are merely made available to user processes via the adjtimex(2)
system call.
-T val, --timeconstant val
Set phase locked loop (PLL) time constant. val determines the bandwidth or "
stiffness" of the PLL. The effective PLL time constant will be a multiple of (1
<< val). For room-temperature quartz oscillators, David Mills recommends the val
ue 2, which corresponds to a PLL time constant of about 900 sec and a maximum up
date interval of about 64 sec. The maximum update interval scales directly with
the time constant, so that at the maximum time constant of 6, the update interva
l can be as large as 1024 sec.
Values of val between zero and 2 give quick convergence; values between 2 an
d 6 can be used to reduce network load, but at a modest cost in accuracy.
-c[count], --compare[=count]
Periodically compare the system clock with the CMOS clock. After the first t
wo calls, print values for tick and frequency offset that would bring the system
clock into approximate agreement with the CMOS clock. CMOS clock readings are a
djusted for systematic drift using using the correction in /etc/adjtime - see hw
clock(8). The interval between comparisons is 10 seconds, unless changed by the
--interval switch. The optional argument is the number of comparisons. (If the a
rgument is supplied, the "=" is required.)
-a[count], --adjust[=count]
By itself, same as --compare, except the recommended values are actually ins
talled after every third comparison. With --review, the tick and frequency are s
et to the least-squares estimates. (In the latter case, any count value is ignor
ed.)
-i tim, --interval tim
Set the interval in seconds between clock comparisons for the --compare and
--adjust options.
-u, --utc
The CMOS clock is set to UTC (universal time) rather than local time.
-l[file], --log[=file]
Save the current values of the system and CMOS clocks, and optionally a refe
rence time, to file (default /var/log/clocks.log). The reference time is taken f
rom a network timeserver (see the --host switch) or supplied by the user (see th
e --watch switch).
-h timeserver, --host timeserver

Use ntpdate to query the given timeserver for the current time. This will fa
il if timeserver is not running a Network Time Protocol (NTP) server, or if that
server is not synchronized. Implies --log.
-w, --watch
Ask for a keypress when the user knows the time, then ask what that time was
, and its approximate accuracy. Implies --log.
-r[file], --review[=file]
Review the clock log file (default /var/log/clocks.log) and estimate, if pos
sible, the rates of the CMOS and system clocks. Calculate least-squares rates us
ing all suitable log entries. Suggest corrections to adjust for systematic drift
. With --adjust, the frequency and tick are set to the suggested values. (The CM
OS clock correction is not changed.)
-h, --help
Print the program options.
-v, --version
Print the program version.
Examples
If your system clock gained 8 seconds in 24 hours, you could set the tick to 999
9, and then it would lose 0.64 seconds a day (that is, 1 tick unit = 8.64 second
s per day). To correct the rest of the error, you could set the frequency offset
to (2^16)*0.64/.0864 = 485452. Thus, putting the following in rc.local would ap
proximately correct the system clock:
adjtimex --tick 9999 --freq 485452
Notes
adjtimex adjusts only the system clock - the one that runs while the computer is
powered up. To set or regulate the CMOS clock, see hwclock(8).

Vous aimerez peut-être aussi