]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/adjtimex.2
sock_diag.7: Tweaks to Dmitry Levin's page
[thirdparty/man-pages.git] / man2 / adjtimex.2
CommitLineData
fea681da 1.\" Copyright (c) 1995 Michael Chastain (mec@shell.portal.com), 15 April 1995.
55b82822 2.\" and Copyright (C) 2014, 2016 Michael Kerrisk <mtk.manpages@gmail.com>
fea681da 3.\"
1dd72f9c 4.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
fea681da
MK
5.\" This is free documentation; you can redistribute it and/or
6.\" modify it under the terms of the GNU General Public License as
7.\" published by the Free Software Foundation; either version 2 of
8.\" the License, or (at your option) any later version.
9.\"
10.\" The GNU General Public License's references to "object code"
11.\" and "executables" are to be interpreted as the output of any
12.\" document formatting or typesetting system, including
13.\" intermediate and printed output.
14.\"
15.\" This manual is distributed in the hope that it will be useful,
16.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
17.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18.\" GNU General Public License for more details.
19.\"
20.\" You should have received a copy of the GNU General Public
c715f741
MK
21.\" License along with this manual; if not, see
22.\" <http://www.gnu.org/licenses/>.
6a8d8745 23.\" %%%LICENSE_END
fea681da
MK
24.\"
25.\" Modified 1997-01-31 by Eric S. Raymond <esr@thyrsus.com>
26.\" Modified 1997-07-30 by Paul Slootman <paul@wurtel.demon.nl>
c11b1abf 27.\" Modified 2004-05-27 by Michael Kerrisk <mtk.manpages@gmail.com>
fea681da 28.\"
b8efb414 29.TH ADJTIMEX 2 2016-10-08 "Linux" "Linux Programmer's Manual"
fea681da 30.SH NAME
b346e7a0 31adjtimex, ntp_adjtime \- tune kernel clock
fea681da 32.SH SYNOPSIS
5918743b 33.nf
fea681da 34.B #include <sys/timex.h>
5918743b 35
fea681da 36.BI "int adjtimex(struct timex *" "buf" );
b346e7a0
MK
37
38.BI "int ntp_adjtime(struct timex *" buf );
5918743b 39.fi
fea681da 40.SH DESCRIPTION
d94ed228 41Linux uses David L. Mills' clock adjustment algorithm (see RFC\ 5905).
fea681da 42The system call
e511ffb6 43.BR adjtimex ()
fea681da
MK
44reads and optionally sets adjustment parameters for this algorithm.
45It takes a pointer to a
c13182ef 46.I timex
46c75010
MK
47structure, updates kernel parameters from (selected) field values,
48and returns the same structure updated with the current kernel values.
fea681da
MK
49This structure is declared as follows:
50.PP
bd191423 51.in +4n
fea681da
MK
52.nf
53struct timex {
4dfc98f2
MK
54 int modes; /* Mode selector */
55 long offset; /* Time offset; nanoseconds, if STA_NANO
4ed5a32d
MK
56 status flag is set, otherwise
57 microseconds */
58 long freq; /* Frequency offset; see NOTES for units */
4dfc98f2
MK
59 long maxerror; /* Maximum error (microseconds) */
60 long esterror; /* Estimated error (microseconds) */
61 int status; /* Clock command/status */
62 long constant; /* PLL (phase-locked loop) time constant */
4ed5a32d
MK
63 long precision; /* Clock precision
64 (microseconds, read-only) */
65 long tolerance; /* Clock frequency tolerance (read-only);
66 see NOTES for units */
95547282 67 struct timeval time;
4dfc98f2
MK
68 /* Current time (read-only, except for
69 ADJ_SETOFFSET); upon return, time.tv_usec
70 contains nanoseconds, if STA_NANO status
71 flag is set, otherwise microseconds */
72 long tick; /* Microseconds between clock ticks */
4ed5a32d
MK
73 long ppsfreq; /* PPS (pulse per second) frequency
74 (read-only); see NOTES for units */
4dfc98f2
MK
75 long jitter; /* PPS jitter (read-only); nanoseconds, if
76 STA_NANO status flag is set, otherwise
77 microseconds */
4ed5a32d
MK
78 int shift; /* PPS interval duration
79 (seconds, read-only) */
80 long stabil; /* PPS stability (read-only);
81 see NOTES for units */
e837b41c
MK
82 long jitcnt; /* PPS count of jitter limit exceeded
83 events (read-only) */
84 long calcnt; /* PPS count of calibration intervals
85 (read-only) */
86 long errcnt; /* PPS count of calibration errors
87 (read-only) */
88 long stbcnt; /* PPS count of stability limit exceeded
89 events (read-only) */
4dfc98f2
MK
90 int tai; /* TAI offset, as set by previous ADJ_TAI
91 operation (seconds, read-only,
92 since Linux 2.6.26) */
7b69c78c 93 /* Further padding bytes to allow for future expansion */
fea681da
MK
94};
95.fi
bd191423 96.in
fea681da
MK
97.PP
98The
99.I modes
100field determines which parameters, if any, to set.
b346e7a0
MK
101(As described later in this page,
102the constants used for
103.BR ntp_adjtime ()
104are equivalent but differently named.)
7431d790 105It is a bit mask containing a
fea681da
MK
106.RI bitwise- or
107combination of zero or more of the following bits:
4f773948 108.TP
7431d790 109.BR ADJ_OFFSET
abe87b0c
MK
110Set time offset from
111.IR buf.offset .
88ec900f
MK
112Since Linux 2.6.26,
113.\" commit 074b3b87941c99bc0ce35385b5817924b1ed0c23
114the supplied value is clamped to the range (\-0.5s, +0.5s).
115In older kernels, an
1a96e4f2 116.B EINVAL
88ec900f 117error occurs if the supplied value is out of range.
7431d790
MK
118.TP
119.BR ADJ_FREQUENCY
abe87b0c
MK
120Set frequency offset from
121.IR buf.freq .
f4d9c97d
MK
122Since Linux 2.6.26,
123.\" commit 074b3b87941c99bc0ce35385b5817924b1ed0c23
124the supplied value is clamped to the range (\-32768000, +32768000).
125In older kernels, an
1a96e4f2 126.B EINVAL
f4d9c97d 127error occurs if the supplied value is out of range.
7431d790
MK
128.TP
129.BR ADJ_MAXERROR
abe87b0c
MK
130Set maximum time error from
131.IR buf.maxerror .
7431d790
MK
132.TP
133.BR ADJ_ESTERROR
abe87b0c
MK
134Set estimated time error from
135.IR buf.esterror .
7431d790
MK
136.TP
137.BR ADJ_STATUS
94148126 138Set clock status bits from
abe87b0c 139.IR buf.status .
94148126 140A description of these bits is provided below.
7431d790
MK
141.TP
142.BR ADJ_TIMECONST
abe87b0c
MK
143Set PLL time constant from
144.IR buf.constant .
373bd098
MK
145If the
146.B STA_NANO
147status flag (see below) is clear, the kernel adds 4 to this value.
7431d790 148.TP
85976da3 149.BR ADJ_SETOFFSET " (since Linux 2.6.39)"
f7a78a2d
MK
150.\" commit 094aa1881fdc1b8889b442eb3511b31f3ec2b762
151.\" Author: Richard Cochran <richardcochran@gmail.com>
152Add
153.I buf.time
154to the current time.
784f5985
MK
155If
156.I buf.status
157includes the
158.B ADJ_NANO
159flag, then
160.I buf.time.tv_usec
161is interpreted as a nanosecond value;
162otherwise it is interpreted as microseconds.
f7a78a2d 163.TP
85976da3 164.BR ADJ_MICRO " (since Linux 2.6.26)"
078f99d7
MK
165.\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
166.\" Author: Roman Zippel <zippel@linux-m68k.org>
167Select microsecond resolution.
168.TP
85976da3 169.BR ADJ_NANO " (since Linux 2.6.26)"
078f99d7
MK
170.\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
171.\" Author: Roman Zippel <zippel@linux-m68k.org>
172Select nanosecond resolution.
173Only one of
174.BR ADJ_MICRO
175and
176.BR ADJ_NANO
177should be specified.
178.TP
7431d790 179.BR ADJ_TAI " (since Linux 2.6.26)"
872feab5
MK
180.\" commit 153b5d054ac2d98ea0d86504884326b6777f683d
181Set TAI (Atomic International Time) offset from
2f016202 182.IR buf.constant .
872feab5
MK
183
184.BR ADJ_TAI
185should not be used in conjunction with
186.BR ADJ_TIMECONST ,
187since the latter mode also employs the
2f016202 188.IR buf.constant
872feab5
MK
189field.
190
191For a complete explanation of TAI
192and the difference between TAI and UTC, see
193.UR http://www.bipm.org/en/bipm/tai/tai.html
194.I BIPM
86e1503e 195.UE
7431d790
MK
196.TP
197.BR ADJ_TICK
abe87b0c
MK
198Set tick value from
199.IR buf.tick .
31d07b1e
MK
200.PP
201Alternatively,
202.I modes
cef8628b
MK
203can be specified as either of the following (multibit mask) values,
204in which case other bits should not be specified in
205.IR modes :
206.\" In general, the other bits are ignored, but ADJ_OFFSET_SINGLESHOT 0x8001
207.\" ORed with ADJ_NANO (0x2000) gives 0xa0001 == ADJ_OFFSET_SS_READ!!
7431d790
MK
208.TP
209.BR ADJ_OFFSET_SINGLESHOT
002d27fb
MK
210.\" In user space, ADJ_OFFSET_SINGLESHOT is 0x8001
211.\" In kernel space it is 0x0001, and must be ANDed with ADJ_ADJTIME (0x8000)
7431d790 212Old-fashioned
002d27fb
MK
213.BR adjtime ():
214(gradually) adjust time by value specified in
005239ca
MK
215.IR buf.offset ,
216which specifies an adjustment in microseconds.
6eaec6b1
MK
217.TP
218.BR ADJ_OFFSET_SS_READ " (functional since Linux 2.6.28)"
219.\" In user space, ADJ_OFFSET_SS_READ is 0xa001
220.\" In kernel space there is ADJ_OFFSET_READONLY (0x2000) anded with
221.\" ADJ_ADJTIME (0x8000) and ADJ_OFFSET_SINGLESHOT (0x0001) to give 0xa001)
222Return (in
69256b80 223.IR buf.offset )
6eaec6b1
MK
224the remaining amount of time to be adjusted after an earlier
225.BR ADJ_OFFSET_SINGLESHOT
226operation.
227This feature was added in Linux 2.6.24,
228.\" commit 52bfb36050c8529d9031d2c2513b281a360922ec
229but did not work correctly
230.\" commit 916c7a855174e3b53d182b97a26b2e27a29726a1
231until Linux 2.6.28.
fea681da 232.PP
6eaec6b1
MK
233Ordinary users are restricted to a value of either 0 or
234.B ADJ_OFFSET_SS_READ
235for
2b375744 236.IR modes .
fea681da 237Only the superuser may set any parameters.
6c9b2fe0 238
b84ba686
MK
239The
240.I buf.status
241field is a bit mask that is used to set and/or retrieve status
242bits associated with the NTP implementation.
243Some bits in the mask are both readable and settable,
244while others are read-only.
245.TP
2f016202
MK
246.BR STA_PLL " (read-write)"
247Enable phase-locked loop (PLL) updates via
b84ba686
MK
248.BR ADJ_OFFSET .
249.TP
2f016202
MK
250.BR STA_PPSFREQ " (read-write)"
251Enable PPS (pulse-per-second) frequency discipline.
252.TP
253.BR STA_PPSTIME " (read-write)"
254Enable PPS time discipline.
255.TP
256.BR STA_FLL " (read-write)"
257Select frequency-locked loop (FLL) mode.
258.TP
259.BR STA_INS " (read-write)"
260Insert a leap second after the last second of the UTC day,
261thus extending the last minute of the day by one second.
262Leap-second insertion will occur each day, so long as this flag remains set.
263.\" John Stultz;
264.\" Usually this is written as extending the day by one second,
265.\" which is represented as:
266.\" 23:59:59
267.\" 23:59:60
268.\" 00:00:00
2c767761 269.\"
2f016202
MK
270.\" But since posix cannot represent 23:59:60, we repeat the last second:
271.\" 23:59:59 + TIME_INS
272.\" 23:59:59 + TIME_OOP
273.\" 00:00:00 + TIME_WAIT
274.\"
275.TP
276.BR STA_DEL " (read-write)"
de69c712 277Delete a leap second at the last second of the UTC day.
2f016202
MK
278.\" John Stultz:
279.\" Similarly the progression here is:
280.\" 23:59:57 + TIME_DEL
281.\" 23:59:58 + TIME_DEL
282.\" 00:00:00 + TIME_WAIT
283Leap second deletion will occur each day, so long as this flag
284remains set.
e3548e1d 285.\" FIXME Does there need to be a statement that it is nonsensical to set
badba3f6 286.\" to set both STA_INS and STA_DEL?
b84ba686 287.TP
2f016202
MK
288.BR STA_UNSYNC " (read-write)"
289Clock unsynchronized.
290.TP
291.BR STA_FREQHOLD " (read-write)"
292Hold frequency.
293.\" Following text from John Stultz:
294Normally adjustments made via
295.B ADJ_OFFSET
296result in dampened frequency adjustments also being made.
297So a single call corrects the current offset,
298but as offsets in the same direction are made repeatedly,
299the small frequency adjustments will accumulate to fix the long-term skew.
2c767761 300
2f016202
MK
301This flag prevents the small frequency adjustment from being made
302when correcting for an
303.B ADJ_OFFSET
304value.
305.\" According to the Kernel Application Program Interface document,
306.\" STA_FREQHOLD is not used by the NTP version 4 daemon
307.TP
308.BR STA_PPSSIGNAL " (read-only)"
309A valid PPS (pulse-per-second) signal is present.
310.TP
311.BR STA_PPSJITTER " (read-only)"
312PPS signal jitter exceeded.
313.TP
314.BR STA_PPSWANDER " (read-only)"
315PPS signal wander exceeded.
316.TP
317.BR STA_PPSERROR " (read-only)"
318PPS signal calibration error.
319.TP
320.BR STA_CLOCKERR " (read-only)"
321Clock hardware fault.
322.\" Not set in current kernel (4.5), but checked in a few places
323.TP
324.BR STA_NANO " (read-only; since Linux 2.6.26)"
b84ba686
MK
325.\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
326.\" Author: Roman Zippel <zippel@linux-m68k.org>
2f016202 327Resolution (0 = microsecond, 1 = nanoseconds).
6848ba03 328Set via
373bd098
MK
329.BR ADJ_NANO ,
330cleared via
331.BR ADJ_MICRO .
b84ba686
MK
332.TP
333.BR STA_MODE " (since Linux 2.6.26)"
334.\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
335.\" Author: Roman Zippel <zippel@linux-m68k.org>
2f016202 336Mode (0 = Phase Locked Loop, 1 = Frequency Locked Loop).
b84ba686 337.TP
2f016202 338.BR STA_CLK " (read-only; since Linux 2.6.26)"
b84ba686
MK
339.\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
340.\" Author: Roman Zippel <zippel@linux-m68k.org>
2f016202 341Clock source (0 = A, 1 = B); currently unused.
b84ba686
MK
342.PP
343Attempts to set read-only
344.I status
345bits are silently ignored.
b346e7a0
MK
346.\"
347.SS ntp_adjtime ()
348The
349.BR ntp_adjtime ()
350library function
351(described in the NTP "Kernel Application Program API", KAPI)
352is a more portable interface for performing the same task as
353.BR adjtimex ().
354Other than the following points, it is identical to
355.BR adjtime ():
356.IP * 3
357The constants used in
358.I modes
359are prefixed with "MOD_" rather than "ADJ_", and have the same suffixes (thus,
360.BR MOD_OFFSET ,
361.BR MOD_FREQUENCY ,
362and so on), other than the exceptions noted in the following points.
363.IP *
364.BR MOD_CLKA
365is the synonym for
366.BR ADJ_OFFSET_SINGLESHOT .
367.IP *
368.BR MOD_CLKB
369is the synonym for
370.BR ADJ_TICK .
371.IP *
372The is no synonym for
373.BR ADJ_OFFSET_SS_READ ,
374which is not described in the KAPI.
47297adb 375.SH RETURN VALUE
fea681da 376On success,
e511ffb6 377.BR adjtimex ()
b346e7a0
MK
378and
379.BR ntp_adjtime ()
380return the clock state; that is, one of the following values:
0a8916e6
MK
381.TP 12
382.BR TIME_OK
de69c712 383Clock synchronized, no leap second adjustment pending.
0a8916e6
MK
384.TP
385.BR TIME_INS
2f016202 386Indicates that a leap second will be added at the end of the UTC day.
0a8916e6
MK
387.TP
388.BR TIME_DEL
de69c712 389Indicates that a leap second will be deleted at the end of the UTC day.
0a8916e6
MK
390.TP
391.BR TIME_OOP
2f016202 392Insertion of a leap second is in progress.
0a8916e6
MK
393.TP
394.BR TIME_WAIT
2f016202
MK
395A leap-second insertion or deletion has been completed.
396This value will be returned until the next
397.BR ADJ_STATUS
398operation clears the
399.B STA_INS
400and
401.B STA_DEL
402flags.
0a8916e6 403.TP
4ce77a32 404.BR TIME_ERROR
2f016202
MK
405The system clock is not synchronized to a reliable server.
406This value is returned when any of the following holds true:
407.RS
408.IP * 3
409Either
410.B STA_UNSYNC
411or
412.B STA_CLOCKERR
413is set.
414.IP *
415.B STA_PPSSIGNAL
416is clear and either
417.B STA_PPSFREQ
418or
419.B STA_PPSTIME
420is set.
421.IP *
422.B STA_PPSTIME
423and
424.B STA_PPSJITTER
425are both set.
426.IP *
427.B STA_PPSFREQ
428is set and either
429.B STA_PPSWANDER
430or
431.B STA_PPSJITTER
432is set.
433.RE
434.IP
4ce77a32
MK
435The symbolic name
436.B TIME_BAD
437is a synonym for
438.BR TIME_ERROR ,
d58d906e 439provided for backward compatibility.
2f016202 440.PP
f3910b47
WP
441Note that starting with Linux 3.4,
442.\" commit 6b43ae8a619d17c4935c3320d2ef9e92bdeed05d changed to asynchronous
443.\" operation, so we can no longer rely on the return code.
444the call operates asynchronously and the return value usually will
445not reflect a state change caused by the call itself.
fea681da 446.PP
b346e7a0 447On failure, these calls return \-1 and set
fea681da
MK
448.IR errno .
449.SH ERRORS
450.TP
451.B EFAULT
452.I buf
453does not point to writable memory.
454.TP
a2300b58 455.BR EINVAL " (kernels before Linux 2.6.26)"
b2eeb390 456An attempt was made to set
f4d9c97d
MK
457.I buf.freq
458to a value outside the range (\-33554432, +33554432).
5fec8763 459.\" From a quick glance, it appears there was no clamping or range check
f4d9c97d
MK
460.\" for buf.freq in kernels before 2.0
461.TP
462.BR EINVAL " (kernels before Linux 2.6.26)"
463An attempt was made to set
fea681da 464.I buf.offset
a2300b58
MK
465to a value outside the permitted range.
466In kernels before Linux 2.0, the permitted range was (\-131072, +131072).
467From Linux 2.0 onwards, the permitted range was (\-512000, +512000).
77a47e47
MK
468.TP
469.B EINVAL
470An attempt was made to set
fea681da 471.I buf.status
77a47e47
MK
472to a value other than those listed above.
473.TP
474.B EINVAL
475An attempt was made to set
fea681da 476.I buf.tick
c13182ef 477to a value outside the range
fea681da 478.RB 900000/ HZ
c13182ef 479to
fea681da
MK
480.RB 1100000/ HZ ,
481where
482.B HZ
483is the system timer interrupt frequency.
484.TP
485.B EPERM
432c7b6a 486.I buf.modes
6eaec6b1
MK
487is neither 0 nor
488.BR ADJ_OFFSET_SS_READ ,
489and the caller does not have sufficient privilege.
5de5062a 490Under Linux, the
fea681da
MK
491.B CAP_SYS_TIME
492capability is required.
ebfc893e
MK
493.SH ATTRIBUTES
494For an explanation of the terms used in this section, see
495.BR attributes (7).
496.TS
497allbox;
498lb lb lb
499l l l.
500Interface Attribute Value
501T{
502.BR ntp_adjtime ()
503T} Thread safety MT-Safe
504.TE
47297adb 505.SH CONFORMING TO
b346e7a0
MK
506Neither of these interfaces is described in POSIX.1
507
60a90ecd 508.BR adjtimex ()
8382f16d 509is Linux-specific and should not be used in programs
dffb0109 510intended to be portable.
b346e7a0 511
c40843ae
MK
512The preferred API for the NTP daemon is
513.BR ntp_adjtime (3).
81036dab
MK
514.SH NOTES
515In struct
516.IR timex ,
517.IR freq ,
518.IR ppsfreq ,
519and
520.I stabil
521are ppm (parts per million) with a 16-bit fractional part,
522which means that a value of 1 in one of those fields
523actually means 2^-16 ppm, and 2^16=65536 is 1 ppm.
524This is the case for both input values (in the case of
525.IR freq )
526and output values.
527
528The leap-second processing triggered by
529.B STA_INS
530and
531.B STA_DEL
532is done by the kernel in timer context
533Thus, it will take one tick into the second
534for the leap second to be inserted or deleted.
47297adb 535.SH SEE ALSO
fea681da 536.BR settimeofday (2),
dffb0109 537.BR adjtime (3),
cf19a3b9 538.BR ntp_gettime (3),
1d7c4d16 539.BR capabilities (7),
bd641654 540.BR time (7),
1ce611a3
MK
541.BR adjtimex (8),
542.BR hwclock (8)
2f016202
MK
543
544.ad l
178635c4 545.UR http://www.slac.stanford.edu/comp/unix/\:package/\:rtems/\:src/\:ssrlApps/\:ntpNanoclock/\:api.htm
2f016202
MK
546NTP "Kernel Application Program Interface"
547.UE