]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/adjtimex.2
adjtimex.2: tfix
[thirdparty/man-pages.git] / man2 / adjtimex.2
1 .\" Copyright (c) 1995 Michael Chastain (mec@shell.portal.com), 15 April 1995.
2 .\" and Copyright (C) 2014 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
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
21 .\" License along with this manual; if not, see
22 .\" <http://www.gnu.org/licenses/>.
23 .\" %%%LICENSE_END
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>
27 .\" Modified 2004-05-27 by Michael Kerrisk <mtk.manpages@gmail.com>
28 .\"
29 .TH ADJTIMEX 2 2014-05-28 "Linux" "Linux Programmer's Manual"
30 .SH NAME
31 adjtimex \- tune kernel clock
32 .SH SYNOPSIS
33 .nf
34 .BR "#define _BSD_SOURCE" " /* See feature_test_macros(7) */"
35 .B #include <sys/timex.h>
36
37 .BI "int adjtimex(struct timex *" "buf" );
38 .fi
39 .SH DESCRIPTION
40 Linux uses David L. Mills' clock adjustment algorithm (see RFC\ 5905).
41 The system call
42 .BR adjtimex ()
43 reads and optionally sets adjustment parameters for this algorithm.
44 It takes a pointer to a
45 .I timex
46 structure, updates kernel parameters from field values,
47 and returns the same structure with current kernel values.
48 This structure is declared as follows:
49 .PP
50 .in +4n
51 .nf
52 struct timex {
53 int modes; /* Mode selector */
54 long offset; /* Time offset; nanoseconds, if STA_NANO
55 status flag is set, otherwise
56 microseconds */
57 long freq; /* Frequency offset, as scaled PPM
58 (parts per million) */
59 .\" FIXME What is the scaling unit of timex.freq? 2^16 ?
60 long maxerror; /* Maximum error (microseconds) */
61 long esterror; /* Estimated error (microseconds) */
62 int status; /* Clock command/status */
63 long constant; /* PLL (phase-locked loop) time constant */
64 long precision; /* Clock precision (microseconds,
65 read-only) */
66 long tolerance; /* Clock frequency tolerance (PPM,
67 read-only) */
68 struct timeval time;
69 /* Current time (read-only, except for
70 ADJ_SETOFFSET); upon return, time.tv_usec
71 contains nanoseconds, if STA_NANO status
72 flag is set, otherwise microseconds */
73 long tick; /* Microseconds between clock ticks */
74 long ppsfreq; /* PPS (pulse per second) frequency
75 (scaled PPM, read-only) */
76 long jitter; /* PPS jitter (read-only); nanoseconds, if
77 STA_NANO status flag is set, otherwise
78 microseconds */
79 int shift; /* PPS interval duration
80 (seconds, read-only) */
81 long stabil; /* PPS stability (scaled PPM, read-only) */
82 long jitcnt; /* PPS jitter limit exceeded (read-only) */
83 long calcnt; /* PPS calibration intervals (read-only) */
84 long errcnt; /* PPS calibration errors (read-only) */
85 long stbcnt; /* PPS stability limit exceeded
86 (read-only) */
87 int tai; /* TAI offset, as set by previous ADJ_TAI
88 operation (seconds, read-only,
89 since Linux 2.6.26) */
90 /* Further padding bytes to allow for future expansion */
91 };
92 .fi
93 .in
94 .PP
95 The
96 .I modes
97 field determines which parameters, if any, to set.
98 It is a bit mask containing a
99 .RI bitwise- or
100 combination of zero or more of the following bits:
101 .TP
102 .BR ADJ_OFFSET
103 Set time offset from
104 .IR buf.offset .
105 .TP
106 .BR ADJ_FREQUENCY
107 Set frequency offset from
108 .IR buf.freq .
109 .TP
110 .BR ADJ_MAXERROR
111 Set maximum time error from
112 .IR buf.maxerror .
113 .TP
114 .BR ADJ_ESTERROR
115 Set estimated time error from
116 .IR buf.esterror .
117 .TP
118 .BR ADJ_STATUS
119 Set clock status from
120 .IR buf.status .
121 .TP
122 .BR ADJ_TIMECONST
123 Set PLL time constant from
124 .IR buf.constant .
125 If the
126 .B STA_NANO
127 status flag (see below) is clear, the kernel adds 4 to this value.
128 .TP
129 .BR ADJ_SETOFFSET " (since Linux 2.6.29)"
130 .\" commit 094aa1881fdc1b8889b442eb3511b31f3ec2b762
131 .\" Author: Richard Cochran <richardcochran@gmail.com>
132 Add
133 .I buf.time
134 to the current time.
135 If
136 .I buf.status
137 includes the
138 .B ADJ_NANO
139 flag, then
140 .I buf.time.tv_usec
141 is interpreted as a nanosecond value;
142 otherwise it is interpreted as microseconds.
143 .TP
144 .BR ADJ_MICRO " (since Linux 2.6.36)"
145 .\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
146 .\" Author: Roman Zippel <zippel@linux-m68k.org>
147 Select microsecond resolution.
148 .TP
149 .BR ADJ_NANO " (since Linux 2.6.36)"
150 .\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
151 .\" Author: Roman Zippel <zippel@linux-m68k.org>
152 Select nanosecond resolution.
153 Only one of
154 .BR ADJ_MICRO
155 and
156 .BR ADJ_NANO
157 should be specified.
158 .TP
159 .BR ADJ_TAI " (since Linux 2.6.26)"
160 .\" commit 153b5d054ac2d98ea0d86504884326b6777f683d
161 Set TAI (Atomic International Time) offset from
162 .IR buf->constant .
163
164 .BR ADJ_TAI
165 should not be used in conjunction with
166 .BR ADJ_TIMECONST ,
167 since the latter mode also employs the
168 .IR buf->constant
169 field.
170
171 For a complete explanation of TAI
172 and the difference between TAI and UTC, see
173 .UR http://www.bipm.org/en/bipm/tai/tai.html
174 .I BIPM
175 .UE
176 .TP
177 .BR ADJ_TICK
178 Set tick value from
179 .IR buf.tick .
180 .PP
181 Alternatively,
182 .I modes
183 can be specified as either of the following (multibit mask) values,
184 in which case other bits should not be specified in
185 .IR modes :
186 .\" In general, the other bits are ignored, but ADJ_OFFSET_SINGLESHOT 0x8001
187 .\" ORed with ADJ_NANO (0x2000) gives 0xa0001 == ADJ_OFFSET_SS_READ!!
188 .TP
189 .BR ADJ_OFFSET_SINGLESHOT
190 .\" In user space, ADJ_OFFSET_SINGLESHOT is 0x8001
191 .\" In kernel space it is 0x0001, and must be ANDed with ADJ_ADJTIME (0x8000)
192 Old-fashioned
193 .BR adjtime ():
194 (gradually) adjust time by value specified in
195 .IR buf.offset ,
196 which specifies an adjustment in microseconds.
197 .TP
198 .BR ADJ_OFFSET_SS_READ " (functional since Linux 2.6.28)"
199 .\" In user space, ADJ_OFFSET_SS_READ is 0xa001
200 .\" In kernel space there is ADJ_OFFSET_READONLY (0x2000) anded with
201 .\" ADJ_ADJTIME (0x8000) and ADJ_OFFSET_SINGLESHOT (0x0001) to give 0xa001)
202 Return (in
203 .BR buf.offset )
204 the remaining amount of time to be adjusted after an earlier
205 .BR ADJ_OFFSET_SINGLESHOT
206 operation.
207 This feature was added in Linux 2.6.24,
208 .\" commit 52bfb36050c8529d9031d2c2513b281a360922ec
209 but did not work correctly
210 .\" commit 916c7a855174e3b53d182b97a26b2e27a29726a1
211 until Linux 2.6.28.
212 .PP
213 Ordinary users are restricted to a value of either 0 or
214 .B ADJ_OFFSET_SS_READ
215 for
216 .IR modes .
217 Only the superuser may set any parameters.
218
219 The
220 .I buf.status
221 field is a bit mask that is used to set and/or retrieve status
222 bits associated with the NTP implementation.
223 Some bits in the mask are both readable and settable,
224 while others are read-only.
225 .TP
226 .BR STA_PLL
227 Enable phase-locked loop (PLL) updates (read-write) via
228 .BR ADJ_OFFSET .
229 .TP
230 .BR STA_PPSFREQ
231 Enable PPS freq discipline (read-write).
232 .TP
233 .BR STA_PPSTIME
234 Enable PPS time discipline (read-write).
235 .TP
236 .BR STA_FLL
237 Select frequency-locked loop (FLL) mode (read-write).
238 .TP
239 .BR STA_INS
240 Insert leap second (read-write).
241 .TP
242 .BR STA_DEL
243 Delete leap second (read-write).
244 .TP
245 .BR STA_UNSYNC
246 Clock unsynchronized (read-write).
247 .TP
248 .BR STA_FREQHOLD
249 Hold frequency (read-write).
250 .TP
251 .BR STA_PPSSIGNAL
252 PPS signal present (read-only).
253 .TP
254 .BR STA_PPSJITTER
255 PPS signal jitter exceeded (read-only).
256 .TP
257 .BR STA_PPSWANDER
258 PPS signal wander exceeded (read-only).
259 .TP
260 .BR STA_PPSERROR
261 PPS signal calibration error (read-only).
262 .TP
263 .BR STA_CLOCKERR
264 Clock hardware fault (read-only).
265 .TP
266 .BR STA_NANO " (since Linux 2.6.26)"
267 .\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
268 .\" Author: Roman Zippel <zippel@linux-m68k.org>
269 Resolution (0 = microsecond, 1 = nanoseconds; read-only).
270 Set via
271 .BR ADJ_NANO ,
272 cleared via
273 .BR ADJ_MICRO .
274 .TP
275 .BR STA_MODE " (since Linux 2.6.26)"
276 .\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
277 .\" Author: Roman Zippel <zippel@linux-m68k.org>
278 Mode (0 = Phase Locked Loop, 1 = Frequency Locked Loop; read-only).
279 .TP
280 .BR STA_CLK " (since Linux 2.6.26)"
281 .\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
282 .\" Author: Roman Zippel <zippel@linux-m68k.org>
283 Clock source (0 = A, 1 = B; read-only).
284 .PP
285 Attempts to set read-only
286 .I status
287 bits are silently ignored.
288 .SH RETURN VALUE
289 On success,
290 .BR adjtimex ()
291 returns the clock state; that is, one of the following values:
292 .TP 12
293 .BR TIME_OK
294 Clock synchronized.
295 .TP
296 .BR TIME_INS
297 Insert leap second.
298 .TP
299 .BR TIME_DEL
300 Delete leap second.
301 .TP
302 .BR TIME_OOP
303 Leap second in progress.
304 .TP
305 .BR TIME_WAIT
306 Leap second has occurred.
307 .TP
308 .BR TIME_BAD
309 Clock not synchronized.
310 .PP
311 On failure,
312 .BR adjtimex ()
313 returns \-1 and sets
314 .IR errno .
315 .SH ERRORS
316 .TP
317 .B EFAULT
318 .I buf
319 does not point to writable memory.
320 .TP
321 .B EINVAL
322 An attempt was made to set
323 .I buf.offset
324 to a value outside the range \-131071 to +131071,
325 or to set
326 .I buf.status
327 to a value other than those listed above,
328 or to set
329 .I buf.tick
330 to a value outside the range
331 .RB 900000/ HZ
332 to
333 .RB 1100000/ HZ ,
334 where
335 .B HZ
336 is the system timer interrupt frequency.
337 .TP
338 .B EPERM
339 .I buf.modes
340 is neither 0 nor
341 .BR ADJ_OFFSET_SS_READ ,
342 and the caller does not have sufficient privilege.
343 Under Linux, the
344 .B CAP_SYS_TIME
345 capability is required.
346 .SH CONFORMING TO
347 .BR adjtimex ()
348 is Linux-specific and should not be used in programs
349 intended to be portable.
350 See
351 .BR adjtime (3)
352 for a more portable, but less flexible,
353 method of adjusting the system clock.
354 .SH SEE ALSO
355 .BR settimeofday (2),
356 .BR adjtime (3),
357 .BR capabilities (7),
358 .BR time (7),
359 .BR adjtimex (8)