OSDN Git Service

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