]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/adjtimex.2
adjtimex.2: Update details of buf.offset EINVAL error
[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-12-31 "Linux" "Linux Programmer's Manual"
30 .SH NAME
31 adjtimex \- tune kernel clock
32 .SH SYNOPSIS
33 .nf
34 .B #include <sys/timex.h>
35
36 .BI "int adjtimex(struct timex *" "buf" );
37 .fi
38 .SH DESCRIPTION
39 Linux uses David L. Mills' clock adjustment algorithm (see RFC\ 5905).
40 The system call
41 .BR adjtimex ()
42 reads and optionally sets adjustment parameters for this algorithm.
43 It takes a pointer to a
44 .I timex
45 structure, updates kernel parameters from field values,
46 and returns the same structure with current kernel values.
47 This structure is declared as follows:
48 .PP
49 .in +4n
50 .nf
51 struct timex {
52 int modes; /* Mode selector */
53 long offset; /* Time offset; nanoseconds, if STA_NANO
54 status flag is set, otherwise microseconds */
55 long freq; /* Frequency offset, in units of 2^-16 ppm
56 (parts per million, see NOTES below) */
57 long maxerror; /* Maximum error (microseconds) */
58 long esterror; /* Estimated error (microseconds) */
59 int status; /* Clock command/status */
60 long constant; /* PLL (phase-locked loop) time constant */
61 long precision; /* Clock precision (microseconds, read-only) */
62 long tolerance; /* Clock frequency tolerance (ppm, read-only) */
63 struct timeval time;
64 /* Current time (read-only, except for
65 ADJ_SETOFFSET); upon return, time.tv_usec
66 contains nanoseconds, if STA_NANO status
67 flag is set, otherwise microseconds */
68 long tick; /* Microseconds between clock ticks */
69 long ppsfreq; /* PPS (pulse per second) frequency (in units
70 of 2^-16 ppm\-\-see NOTES, read-only) */
71 long jitter; /* PPS jitter (read-only); nanoseconds, if
72 STA_NANO status flag is set, otherwise
73 microseconds */
74 int shift; /* PPS interval duration (seconds, read-only) */
75 long stabil; /* PPS stability (2^-16 ppm\-\-see NOTES,
76 read-only) */
77 long jitcnt; /* PPS jitter limit exceeded (read-only) */
78 long calcnt; /* PPS calibration intervals (read-only) */
79 long errcnt; /* PPS calibration errors (read-only) */
80 long stbcnt; /* PPS stability limit exceeded (read-only) */
81 int tai; /* TAI offset, as set by previous ADJ_TAI
82 operation (seconds, read-only,
83 since Linux 2.6.26) */
84 /* Further padding bytes to allow for future expansion */
85 };
86 .fi
87 .in
88 .PP
89 The
90 .I modes
91 field determines which parameters, if any, to set.
92 It is a bit mask containing a
93 .RI bitwise- or
94 combination of zero or more of the following bits:
95 .TP
96 .BR ADJ_OFFSET
97 Set time offset from
98 .IR buf.offset .
99 .TP
100 .BR ADJ_FREQUENCY
101 Set frequency offset from
102 .IR buf.freq .
103 .TP
104 .BR ADJ_MAXERROR
105 Set maximum time error from
106 .IR buf.maxerror .
107 .TP
108 .BR ADJ_ESTERROR
109 Set estimated time error from
110 .IR buf.esterror .
111 .TP
112 .BR ADJ_STATUS
113 Set clock status from
114 .IR buf.status .
115 .TP
116 .BR ADJ_TIMECONST
117 Set PLL time constant from
118 .IR buf.constant .
119 If the
120 .B STA_NANO
121 status flag (see below) is clear, the kernel adds 4 to this value.
122 .TP
123 .BR ADJ_SETOFFSET " (since Linux 2.6.29)"
124 .\" commit 094aa1881fdc1b8889b442eb3511b31f3ec2b762
125 .\" Author: Richard Cochran <richardcochran@gmail.com>
126 Add
127 .I buf.time
128 to the current time.
129 If
130 .I buf.status
131 includes the
132 .B ADJ_NANO
133 flag, then
134 .I buf.time.tv_usec
135 is interpreted as a nanosecond value;
136 otherwise it is interpreted as microseconds.
137 .TP
138 .BR ADJ_MICRO " (since Linux 2.6.36)"
139 .\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
140 .\" Author: Roman Zippel <zippel@linux-m68k.org>
141 Select microsecond resolution.
142 .TP
143 .BR ADJ_NANO " (since Linux 2.6.36)"
144 .\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
145 .\" Author: Roman Zippel <zippel@linux-m68k.org>
146 Select nanosecond resolution.
147 Only one of
148 .BR ADJ_MICRO
149 and
150 .BR ADJ_NANO
151 should be specified.
152 .TP
153 .BR ADJ_TAI " (since Linux 2.6.26)"
154 .\" commit 153b5d054ac2d98ea0d86504884326b6777f683d
155 Set TAI (Atomic International Time) offset from
156 .IR buf->constant .
157
158 .BR ADJ_TAI
159 should not be used in conjunction with
160 .BR ADJ_TIMECONST ,
161 since the latter mode also employs the
162 .IR buf->constant
163 field.
164
165 For a complete explanation of TAI
166 and the difference between TAI and UTC, see
167 .UR http://www.bipm.org/en/bipm/tai/tai.html
168 .I BIPM
169 .UE
170 .TP
171 .BR ADJ_TICK
172 Set tick value from
173 .IR buf.tick .
174 .PP
175 Alternatively,
176 .I modes
177 can be specified as either of the following (multibit mask) values,
178 in which case other bits should not be specified in
179 .IR modes :
180 .\" In general, the other bits are ignored, but ADJ_OFFSET_SINGLESHOT 0x8001
181 .\" ORed with ADJ_NANO (0x2000) gives 0xa0001 == ADJ_OFFSET_SS_READ!!
182 .TP
183 .BR ADJ_OFFSET_SINGLESHOT
184 .\" In user space, ADJ_OFFSET_SINGLESHOT is 0x8001
185 .\" In kernel space it is 0x0001, and must be ANDed with ADJ_ADJTIME (0x8000)
186 Old-fashioned
187 .BR adjtime ():
188 (gradually) adjust time by value specified in
189 .IR buf.offset ,
190 which specifies an adjustment in microseconds.
191 .TP
192 .BR ADJ_OFFSET_SS_READ " (functional since Linux 2.6.28)"
193 .\" In user space, ADJ_OFFSET_SS_READ is 0xa001
194 .\" In kernel space there is ADJ_OFFSET_READONLY (0x2000) anded with
195 .\" ADJ_ADJTIME (0x8000) and ADJ_OFFSET_SINGLESHOT (0x0001) to give 0xa001)
196 Return (in
197 .IR buf.offset )
198 the remaining amount of time to be adjusted after an earlier
199 .BR ADJ_OFFSET_SINGLESHOT
200 operation.
201 This feature was added in Linux 2.6.24,
202 .\" commit 52bfb36050c8529d9031d2c2513b281a360922ec
203 but did not work correctly
204 .\" commit 916c7a855174e3b53d182b97a26b2e27a29726a1
205 until Linux 2.6.28.
206 .PP
207 Ordinary users are restricted to a value of either 0 or
208 .B ADJ_OFFSET_SS_READ
209 for
210 .IR modes .
211 Only the superuser may set any parameters.
212
213 The
214 .I buf.status
215 field is a bit mask that is used to set and/or retrieve status
216 bits associated with the NTP implementation.
217 Some bits in the mask are both readable and settable,
218 while others are read-only.
219 .TP
220 .BR STA_PLL
221 Enable phase-locked loop (PLL) updates (read-write) via
222 .\" FIXME Any pointer to further information about what this means?
223 .\" (It was not immediately obvious from a scan of the RFC, whether
224 .\" this is described in the RFC.)
225 .BR ADJ_OFFSET .
226 .TP
227 .BR STA_PPSFREQ
228 Enable PPS freq discipline (read-write).
229 .\" FIXME Any pointer to further information about what this means?
230 .\" (It was not immediately obvious from a scan of the RFC, whether
231 .\" this is described in the RFC.)
232 .TP
233 .BR STA_PPSTIME
234 Enable PPS time discipline (read-write).
235 .\" FIXME Any pointer to further information about what this means?
236 .\" (It was not immediately obvious from a scan of the RFC, whether
237 .\" this is described in the RFC.)
238 .TP
239 .BR STA_FLL
240 Select frequency-locked loop (FLL) mode (read-write).
241 .\" FIXME Any pointer to further information about what this means?
242 .\" (It was not immediately obvious from a scan of the RFC, whether
243 .\" this is described in the RFC.)
244 .TP
245 .BR STA_INS
246 Insert leap second (read-write).
247 .\" FIXME Is the following correct?
248 .\" Insert a leap second after the last second of the day.
249 .\" That is, at 24:00:00, set the clock 1 second back, thus extending
250 .\" the last minute of the day by one second.
251 .\" Leap second insertion will occur each day, so long as this flag
252 .\" remains set.
253 .TP
254 .BR STA_DEL
255 Delete leap second (read-write).
256 .\" FIXME Is the following correct?
257 .\" Delete a leap second at the last second of the leap day.
258 .\" That is, at 23:5:59, add one extra second to the clock.
259 .\" Leap second deletion will occur each day, so long as this flag
260 .\" remains set.
261 .\" FIXME Does there need to be a statement that it is nonsensical to set
262 .\" to set both STA_INS and STA_DEL?
263 .TP
264 .BR STA_UNSYNC
265 Clock unsynchronized (read-write).
266 .TP
267 .BR STA_FREQHOLD
268 Hold frequency (read-write).
269 .\" FIXME Any pointer to further information about what this means?
270 .\" (It was not immediately obvious from a scan of the RFC, whether
271 .\" this is described in the RFC.)
272 .TP
273 .BR STA_PPSSIGNAL
274 PPS signal present (read-only).
275 .\" FIXME Any pointer to further information about what this means?
276 .\" (It was not immediately obvious from a scan of the RFC, whether
277 .\" this is described in the RFC.)
278 .TP
279 .BR STA_PPSJITTER
280 PPS signal jitter exceeded (read-only).
281 .\" FIXME Any pointer to further information about what this means?
282 .\" (It was not immediately obvious from a scan of the RFC, whether
283 .\" this is described in the RFC.)
284 .TP
285 .BR STA_PPSWANDER
286 PPS signal wander exceeded (read-only).
287 .\" FIXME Any pointer to further information about what this means?
288 .\" (It was not immediately obvious from a scan of the RFC, whether
289 .\" this is described in the RFC.)
290 .TP
291 .BR STA_PPSERROR
292 PPS signal calibration error (read-only).
293 .\" FIXME Any pointer to further information about what this means?
294 .\" (It was not immediately obvious from a scan of the RFC, whether
295 .\" this is described in the RFC.)
296 .TP
297 .BR STA_CLOCKERR
298 Clock hardware fault (read-only).
299 .\" FIXME Any pointer to further information about what this means?
300 .\" (It was not immediately obvious from a scan of the RFC, whether
301 .\" this is described in the RFC.)
302 .TP
303 .BR STA_NANO " (since Linux 2.6.26)"
304 .\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
305 .\" Author: Roman Zippel <zippel@linux-m68k.org>
306 Resolution (0 = microsecond, 1 = nanoseconds; read-only).
307 Set via
308 .BR ADJ_NANO ,
309 cleared via
310 .BR ADJ_MICRO .
311 .TP
312 .BR STA_MODE " (since Linux 2.6.26)"
313 .\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
314 .\" Author: Roman Zippel <zippel@linux-m68k.org>
315 Mode (0 = Phase Locked Loop, 1 = Frequency Locked Loop; read-only).
316 .TP
317 .BR STA_CLK " (since Linux 2.6.26)"
318 .\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
319 .\" Author: Roman Zippel <zippel@linux-m68k.org>
320 Clock source (0 = A, 1 = B; read-only).
321 .\" FIXME It would be helpful to have some explanation of what
322 .\" "Clock source" is.
323 .PP
324 Attempts to set read-only
325 .I status
326 bits are silently ignored.
327 .SH RETURN VALUE
328 On success,
329 .BR adjtimex ()
330 returns the clock state; that is, one of the following values:
331 .TP 12
332 .BR TIME_OK
333 Clock synchronized.
334 .TP
335 .BR TIME_INS
336 Insert leap second.
337 .\" FIXME Is the following correct:
338 .\" Indicates that a leap second will be added at the end of the day
339 .TP
340 .BR TIME_DEL
341 Delete leap second.
342 .\" FIXME Is the following correct:
343 .\" Indicates that a leap second will be deleted at the end of the day
344 .TP
345 .BR TIME_OOP
346 Leap second in progress.
347 .\" FIXME Is the following correct:
348 .\" Indicates that we are currently in the middle of the leap second
349 .\" that is being added at the end of the day (as a result of STA_INS)
350 .TP
351 .BR TIME_WAIT
352 Leap second has occurred.
353 .\" FIXME Is the following correct:
354 .\" Indicates that a leap second has just been added or deleted
355 .\" during the previous second
356 .TP
357 .BR TIME_ERROR
358 Clock not synchronized.
359 .\" FIXME Should more be said about how the TIME_ERROR state can occur?
360 The symbolic name
361 .B TIME_BAD
362 is a synonym for
363 .BR TIME_ERROR ,
364 provided for backward compatibility.
365 Note that starting with Linux 3.4,
366 .\" commit 6b43ae8a619d17c4935c3320d2ef9e92bdeed05d changed to asynchronous
367 .\" operation, so we can no longer rely on the return code.
368 the call operates asynchronously and the return value usually will
369 not reflect a state change caused by the call itself.
370 .PP
371 On failure,
372 .BR adjtimex ()
373 returns \-1 and sets
374 .IR errno .
375 .SH ERRORS
376 .TP
377 .B EFAULT
378 .I buf
379 does not point to writable memory.
380 .TP
381 .BR EINVAL " (kernels before Linux 2.6.26)"
382 An attempt was made to set
383 .I buf.offset
384 to a value outside the permitted range.
385 In kernels before Linux 2.0, the permitted range was (\-131072, +131072).
386 From Linux 2.0 onwards, the permitted range was (\-512000, +512000).
387 .TP
388 .B EINVAL
389 An attempt was made to set
390 .I buf.status
391 to a value other than those listed above.
392 .TP
393 .B EINVAL
394 An attempt was made to set
395 .I buf.tick
396 to a value outside the range
397 .RB 900000/ HZ
398 to
399 .RB 1100000/ HZ ,
400 where
401 .B HZ
402 is the system timer interrupt frequency.
403 .TP
404 .B EPERM
405 .I buf.modes
406 is neither 0 nor
407 .BR ADJ_OFFSET_SS_READ ,
408 and the caller does not have sufficient privilege.
409 Under Linux, the
410 .B CAP_SYS_TIME
411 capability is required.
412 .SH NOTES
413 In struct
414 .IR timex ,
415 .IR freq ,
416 .IR ppsfreq ,
417 and
418 .I stabil
419 are ppm (parts per million) with a 16-bit fractional part,
420 which means that a value of 1 in one of those fields
421 actually means 2^-16 ppm, and 2^16=65536 is 1 ppm.
422 This is the case for both input values (in the case of
423 .IR freq )
424 and output values.
425 .SH CONFORMING TO
426 .BR adjtimex ()
427 is Linux-specific and should not be used in programs
428 intended to be portable.
429 See
430 .BR adjtime (3)
431 for a more portable, but less flexible,
432 method of adjusting the system clock.
433 .SH SEE ALSO
434 .BR settimeofday (2),
435 .BR adjtime (3),
436 .BR capabilities (7),
437 .BR time (7),
438 .BR adjtimex (8)