1 .\" Copyright (c) 1995 Michael Chastain (mec@shell.portal.com), 15 April 1995.
2 .\" and Copyright (C) 2014, 2016 Michael Kerrisk <mtk.manpages@gmail.com>
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.
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.
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.
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/>.
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>
29 .TH ADJTIMEX 2 2021-03-22 "Linux" "Linux Programmer's Manual"
31 adjtimex, clock_adjtime, ntp_adjtime \- tune kernel clock
34 .B #include <sys/timex.h>
36 .BI "int adjtimex(struct timex *" "buf" );
38 .BI "int clock_adjtime(clockid_t " clk_id, " struct timex *" "buf" );
40 .BI "int ntp_adjtime(struct timex *" buf );
43 Linux uses David L.\& Mills' clock adjustment algorithm (see RFC\ 5905).
46 reads and optionally sets adjustment parameters for this algorithm.
47 It takes a pointer to a
49 structure, updates kernel parameters from (selected) field values,
50 and returns the same structure updated with the current kernel values.
51 This structure is declared as follows:
56 int modes; /* Mode selector */
57 long offset; /* Time offset; nanoseconds, if STA_NANO
58 status flag is set, otherwise
60 long freq; /* Frequency offset; see NOTES for units */
61 long maxerror; /* Maximum error (microseconds) */
62 long esterror; /* Estimated error (microseconds) */
63 int status; /* Clock command/status */
64 long constant; /* PLL (phase\-locked loop) time constant */
65 long precision; /* Clock precision
66 (microseconds, read\-only) */
67 long tolerance; /* Clock frequency tolerance (read\-only);
68 see NOTES for units */
70 /* Current time (read\-only, except for
71 ADJ_SETOFFSET); upon return, time.tv_usec
72 contains nanoseconds, if STA_NANO status
73 flag is set, otherwise microseconds */
74 long tick; /* Microseconds between clock ticks */
75 long ppsfreq; /* PPS (pulse per second) frequency
76 (read\-only); see NOTES for units */
77 long jitter; /* PPS jitter (read\-only); nanoseconds, if
78 STA_NANO status flag is set, otherwise
80 int shift; /* PPS interval duration
81 (seconds, read\-only) */
82 long stabil; /* PPS stability (read\-only);
83 see NOTES for units */
84 long jitcnt; /* PPS count of jitter limit exceeded
85 events (read\-only) */
86 long calcnt; /* PPS count of calibration intervals
88 long errcnt; /* PPS count of calibration errors
90 long stbcnt; /* PPS count of stability limit exceeded
91 events (read\-only) */
92 int tai; /* TAI offset, as set by previous ADJ_TAI
93 operation (seconds, read\-only,
94 since Linux 2.6.26) */
95 /* Further padding bytes to allow for future expansion */
102 field determines which parameters, if any, to set.
103 (As described later in this page,
104 the constants used for
106 are equivalent but differently named.)
107 It is a bit mask containing a
109 combination of zero or more of the following bits:
115 .\" commit 074b3b87941c99bc0ce35385b5817924b1ed0c23
116 the supplied value is clamped to the range (\-0.5s, +0.5s).
119 error occurs if the supplied value is out of range.
122 Set frequency offset from
125 .\" commit 074b3b87941c99bc0ce35385b5817924b1ed0c23
126 the supplied value is clamped to the range (\-32768000, +32768000).
129 error occurs if the supplied value is out of range.
132 Set maximum time error from
136 Set estimated time error from
140 Set clock status bits from
142 A description of these bits is provided below.
145 Set PLL time constant from
149 status flag (see below) is clear, the kernel adds 4 to this value.
151 .BR ADJ_SETOFFSET " (since Linux 2.6.39)"
152 .\" commit 094aa1881fdc1b8889b442eb3511b31f3ec2b762
153 .\" Author: Richard Cochran <richardcochran@gmail.com>
163 is interpreted as a nanosecond value;
164 otherwise it is interpreted as microseconds.
168 is the sum of its two fields, but the
171 must always be nonnegative.
172 The following example shows how to
175 with nanosecond resolution.
179 while (buf.time.tv_usec < 0) {
180 buf.time.tv_sec \-= 1;
181 buf.time.tv_usec += 1000000000;
186 .BR ADJ_MICRO " (since Linux 2.6.26)"
187 .\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
188 .\" Author: Roman Zippel <zippel@linux-m68k.org>
189 Select microsecond resolution.
191 .BR ADJ_NANO " (since Linux 2.6.26)"
192 .\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
193 .\" Author: Roman Zippel <zippel@linux-m68k.org>
194 Select nanosecond resolution.
201 .BR ADJ_TAI " (since Linux 2.6.26)"
202 .\" commit 153b5d054ac2d98ea0d86504884326b6777f683d
203 Set TAI (Atomic International Time) offset from
207 should not be used in conjunction with
209 since the latter mode also employs the
213 For a complete explanation of TAI
214 and the difference between TAI and UTC, see
215 .UR http://www.bipm.org/en/bipm/tai/tai.html
225 can be specified as either of the following (multibit mask) values,
226 in which case other bits should not be specified in
228 .\" In general, the other bits are ignored, but ADJ_OFFSET_SINGLESHOT 0x8001
229 .\" ORed with ADJ_NANO (0x2000) gives 0xa0001 == ADJ_OFFSET_SS_READ!!
231 .BR ADJ_OFFSET_SINGLESHOT
232 .\" In user space, ADJ_OFFSET_SINGLESHOT is 0x8001
233 .\" In kernel space it is 0x0001, and must be ANDed with ADJ_ADJTIME (0x8000)
236 (gradually) adjust time by value specified in
238 which specifies an adjustment in microseconds.
240 .BR ADJ_OFFSET_SS_READ " (functional since Linux 2.6.28)"
241 .\" In user space, ADJ_OFFSET_SS_READ is 0xa001
242 .\" In kernel space there is ADJ_OFFSET_READONLY (0x2000) anded with
243 .\" ADJ_ADJTIME (0x8000) and ADJ_OFFSET_SINGLESHOT (0x0001) to give 0xa001)
246 the remaining amount of time to be adjusted after an earlier
247 .BR ADJ_OFFSET_SINGLESHOT
249 This feature was added in Linux 2.6.24,
250 .\" commit 52bfb36050c8529d9031d2c2513b281a360922ec
251 but did not work correctly
252 .\" commit 916c7a855174e3b53d182b97a26b2e27a29726a1
255 Ordinary users are restricted to a value of either 0 or
256 .B ADJ_OFFSET_SS_READ
259 Only the superuser may set any parameters.
263 field is a bit mask that is used to set and/or retrieve status
264 bits associated with the NTP implementation.
265 Some bits in the mask are both readable and settable,
266 while others are read-only.
268 .BR STA_PLL " (read-write)"
269 Enable phase-locked loop (PLL) updates via
272 .BR STA_PPSFREQ " (read-write)"
273 Enable PPS (pulse-per-second) frequency discipline.
275 .BR STA_PPSTIME " (read-write)"
276 Enable PPS time discipline.
278 .BR STA_FLL " (read-write)"
279 Select frequency-locked loop (FLL) mode.
281 .BR STA_INS " (read-write)"
282 Insert a leap second after the last second of the UTC day,
283 thus extending the last minute of the day by one second.
284 Leap-second insertion will occur each day, so long as this flag remains set.
286 .\" Usually this is written as extending the day by one second,
287 .\" which is represented as:
292 .\" But since posix cannot represent 23:59:60, we repeat the last second:
293 .\" 23:59:59 + TIME_INS
294 .\" 23:59:59 + TIME_OOP
295 .\" 00:00:00 + TIME_WAIT
298 .BR STA_DEL " (read-write)"
299 Delete a leap second at the last second of the UTC day.
301 .\" Similarly the progression here is:
302 .\" 23:59:57 + TIME_DEL
303 .\" 23:59:58 + TIME_DEL
304 .\" 00:00:00 + TIME_WAIT
305 Leap second deletion will occur each day, so long as this flag
307 .\" FIXME Does there need to be a statement that it is nonsensical to set
308 .\" to set both STA_INS and STA_DEL?
310 .BR STA_UNSYNC " (read-write)"
311 Clock unsynchronized.
313 .BR STA_FREQHOLD " (read-write)"
315 .\" Following text from John Stultz:
316 Normally adjustments made via
318 result in dampened frequency adjustments also being made.
319 So a single call corrects the current offset,
320 but as offsets in the same direction are made repeatedly,
321 the small frequency adjustments will accumulate to fix the long-term skew.
323 This flag prevents the small frequency adjustment from being made
324 when correcting for an
327 .\" According to the Kernel Application Program Interface document,
328 .\" STA_FREQHOLD is not used by the NTP version 4 daemon
330 .BR STA_PPSSIGNAL " (read-only)"
331 A valid PPS (pulse-per-second) signal is present.
333 .BR STA_PPSJITTER " (read-only)"
334 PPS signal jitter exceeded.
336 .BR STA_PPSWANDER " (read-only)"
337 PPS signal wander exceeded.
339 .BR STA_PPSERROR " (read-only)"
340 PPS signal calibration error.
342 .BR STA_CLOCKERR " (read-only)"
343 Clock hardware fault.
344 .\" Not set in current kernel (4.5), but checked in a few places
346 .BR STA_NANO " (read-only; since Linux 2.6.26)"
347 .\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
348 .\" Author: Roman Zippel <zippel@linux-m68k.org>
349 Resolution (0 = microsecond, 1 = nanoseconds).
355 .BR STA_MODE " (since Linux 2.6.26)"
356 .\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
357 .\" Author: Roman Zippel <zippel@linux-m68k.org>
358 Mode (0 = Phase Locked Loop, 1 = Frequency Locked Loop).
360 .BR STA_CLK " (read-only; since Linux 2.6.26)"
361 .\" commit eea83d896e318bda54be2d2770d2c5d6668d11db
362 .\" Author: Roman Zippel <zippel@linux-m68k.org>
363 Clock source (0 = A, 1 = B); currently unused.
365 Attempts to set read-only
367 bits are silently ignored.
372 system call (added in Linux 2.6.39) behaves like
374 but takes an additional
376 argument to specify the particular clock on which to act.
381 (described in the NTP "Kernel Application Program API", KAPI)
382 is a more portable interface for performing the same task as
384 Other than the following points, it is identical to
387 The constants used in
389 are prefixed with "MOD_" rather than "ADJ_", and have the same suffixes (thus,
392 and so on), other than the exceptions noted in the following points.
396 .BR ADJ_OFFSET_SINGLESHOT .
402 The is no synonym for
403 .BR ADJ_OFFSET_SS_READ ,
404 which is not described in the KAPI.
410 return the clock state; that is, one of the following values:
413 Clock synchronized, no leap second adjustment pending.
416 Indicates that a leap second will be added at the end of the UTC day.
419 Indicates that a leap second will be deleted at the end of the UTC day.
422 Insertion of a leap second is in progress.
425 A leap-second insertion or deletion has been completed.
426 This value will be returned until the next
435 The system clock is not synchronized to a reliable server.
436 This value is returned when any of the following holds true:
469 provided for backward compatibility.
471 Note that starting with Linux 3.4,
472 .\" commit 6b43ae8a619d17c4935c3320d2ef9e92bdeed05d changed to asynchronous
473 .\" operation, so we can no longer rely on the return code.
474 the call operates asynchronously and the return value usually will
475 not reflect a state change caused by the call itself.
477 On failure, these calls return \-1 and set
479 to indicate the error.
484 does not point to writable memory.
486 .BR EINVAL " (kernels before Linux 2.6.26)"
487 An attempt was made to set
489 to a value outside the range (\-33554432, +33554432).
490 .\" From a quick glance, it appears there was no clamping or range check
491 .\" for buf.freq in kernels before 2.0
493 .BR EINVAL " (kernels before Linux 2.6.26)"
494 An attempt was made to set
496 to a value outside the permitted range.
497 In kernels before Linux 2.0, the permitted range was (\-131072, +131072).
498 From Linux 2.0 onwards, the permitted range was (\-512000, +512000).
501 An attempt was made to set
503 to a value other than those listed above.
510 is invalid for one of two reasons.
511 Either the System-V style hard-coded
512 positive clock ID value is out of range, or the dynamic
514 does not refer to a valid instance of a clock object.
516 .BR clock_gettime (2)
517 for a discussion of dynamic clocks.
520 An attempt was made to set
522 to a value outside the range
528 is the system timer interrupt frequency.
531 The hot-pluggable device (like USB for example) represented by a
534 has disappeared after its character device was opened.
536 .BR clock_gettime (2)
537 for a discussion of dynamic clocks.
542 does not support adjustment.
547 .BR ADJ_OFFSET_SS_READ ,
548 and the caller does not have sufficient privilege.
551 capability is required.
553 For an explanation of the terms used in this section, see
561 Interface Attribute Value
564 T} Thread safety MT-Safe
570 None of these interfaces is described in POSIX.1
575 are Linux-specific and should not be used in programs
576 intended to be portable.
578 The preferred API for the NTP daemon is
587 are ppm (parts per million) with a 16-bit fractional part,
588 which means that a value of 1 in one of those fields
589 actually means 2^-16 ppm, and 2^16=65536 is 1 ppm.
590 This is the case for both input values (in the case of
594 The leap-second processing triggered by
598 is done by the kernel in timer context.
599 Thus, it will take one tick into the second
600 for the leap second to be inserted or deleted.
602 .BR clock_gettime (2),
603 .BR clock_settime (2),
604 .BR settimeofday (2),
607 .BR capabilities (7),
613 .UR http://www.slac.stanford.edu/comp/unix/\:package/\:rtems/\:src/\:ssrlApps/\:ntpNanoclock/\:api.htm
614 NTP "Kernel Application Program Interface"