adjtimex(2) System Calls Manual adjtimex(2) adjtimex, clock_adjtime, ntp_adjtime - LIBRARY Standard C library (libc, -lc) #include int adjtimex(struct timex *buf); int clock_adjtime(clockid_t clk_id, struct timex *buf); int ntp_adjtime(struct timex *buf); Linux . (David L. Mills) ( RFC 5905). adjtimex() () . timex, () . : struct timex { int modes; /* */ long offset; /* ; , STA_NANO, */ long freq; /* ; */ */ long maxerror; /* () */ long esterror; /* () */ int status; /* / */ long constant; /* PLL (phase-locked loop) */ long precision; /* (, ) */ long tolerance; /* ( ); */ struct timeval time; /* ( , ADJ_SETOFFSET); time.tv_usec , STA_NANO, */ long tick; /* */ long ppsfreq; /* PPS ( ) ( ); */ long jitter; /* PPS ( ); , STA_NANO, int shift; /* PPS (, ) */ long stabil; /* PPS ( ); */ long jitcnt; /* PPS ( ) */ long calcnt; /* PPS ( ) */ long errcnt; /* PPS ( ) */ long stbcnt; /* PPS ( ) */ int tai; /* TAI offset, ADJ_TAI (, , Linux 2.6.26) */ /* , */ }; The modes field determines which parameters, if any, to set. (As described later in this page, the constants used for ntp_adjtime() are equivalent but differently named.) It is a bit mask containing a bitwise OR combination of zero or more of the following bits: ADJ_OFFSET buf.offset. Linux 2.6.26, (-0.5s, +0.5s). , , EINVAL. ADJ_FREQUENCY buf.offset. Linux 2.6.26, (-32768000, +32768000) , , EINVAL. ADJ_MAXERROR buf.maxerror. ADJ_ESTERROR buf.esterror. ADJ_STATUS buf.status. . ADJ_TIMECONST PLL buf.constant. STA_NANO ( ), 4. ADJ_SETOFFSET ( Linux 2.6.39) buf.time . buf.status ADJ_NANO, buf.time.tv_usec ; . The value of buf.time is the sum of its two fields, but the field buf.time.tv_usec must always be nonnegative. The following example shows how to normalize a timeval with nanosecond resolution. while (buf.time.tv_usec < 0) { buf.time.tv_sec -= 1; buf.time.tv_usec += 1000000000; } ADJ_MICRO ( Linux 2.6.26) . ADJ_NANO ( Linux 2.6.26) . - : ADJ_MICRO ADJ_NANO. ADJ_TAI ( Linux 2.6.26) TAI ( ) buf.constant. ADJ_TAI ADJ_TIMECONST, buf.constant. TAI TAI UTC BIPM ADJ_TICK buf.tick. modes ( ), modes: ADJ_OFFSET_SINGLESHOT adjtime(3): () , buf.offset, . ADJ_OFFSET_SS_READ (, Linux 2.6.28) ( buf.offset) ADJ_OFFSET_SINGLESHOT. Linux 2.6.24, Linux 2.6.28. modes ADJ_OFFSET_SS_READ. . buf.status , / , NTP. , , -- . STA_PLL (-) (PLL) ADJ_OFFSET. STA_PPSFREQ (-) PPS ( ). STA_PPSTIME (-) PPS. STA_FLL (-) (FLL). STA_INS (-) UTC, . . STA_DEL (-) UTC. . STA_UNSYNC (-) . STA_FREQHOLD (-) . , ADJ_OFFSET, . , , , , . ADJ_OFFSET. STA_PPSSIGNAL ( ) PPS ( ). STA_PPSJITTER ( ) PPS. STA_PPSWANDER ( ) PPS. STA_PPSERROR ( ) PPS. STA_CLOCKERR ( ) . STA_NANO ( ; Linux 2.6.26) (0 = , 1 = ). ADJ_NANO, ADJ_MICRO. STA_MODE ( Linux 2.6.26) (0 = , 1 = ). STA_CLK ( ; c Linux 2.6.26) (0 = A, 1 = B); . status, , . clock_adjtime () The clock_adjtime() system call (added in Linux 2.6.39) behaves like adjtimex() but takes an additional clk_id argument to specify the particular clock on which to act. ntp_adjtime () ntp_adjtime() ( NTP "Kernel Application Program API", KAPI) , adjtimex(). adjtimex() : o , modes, <>, <>, (MOD_OFFSET, MOD_FREQUENCY, and so on), : o MOD_CLKA -- ADJ_OFFSET_SINGLESHOT. o MOD_CLKB -- ADJ_TICK. o ADJ_OFFSET_SS_READ KAPI . adjtimex() ntp_adjtime() , : TIME_OK , . TIME_INS , UTC . TIME_DEL , UTC . TIME_OOP . TIME_WAIT . ADJ_STATUS STA_INS STA_DEL. TIME_ERROR . : o STA_UNSYNC STA_CLOCKERR. o STA_PPSSIGNAL STA_PPSFREQ STA_PPSTIME. o STA_PPSTIME STA_PPSJITTER. o STA_PPSFREQ STA_PPSWANDER STA_PPSJITTER. TIME_BAD -- TIME_ERROR, . , Linux 3.4 , , , . On failure, these calls return -1 and set errno to indicate the error. EFAULT buf . EINVAL (before Linux 2.6.26) buf.freq (-33554432, +33554432). EINVAL (before Linux 2.6.26) An attempt was made to set buf.offset to a value outside the permitted range. Before Linux 2.0, the permitted range was (-131072, +131072). From Linux 2.0 onwards, the permitted range was (-512000, +512000). EINVAL buf.status , . EINVAL The clk_id given to clock_adjtime() is invalid for one of two reasons. Either the System-V style hard-coded positive clock ID value is out of range, or the dynamic clk_id does not refer to a valid instance of a clock object. See clock_gettime(2) for a discussion of dynamic clocks. EINVAL buf.tick 900000/HZ 1100000/HZ, HZ -- . ENODEV The hot-pluggable device (like USB for example) represented by a dynamic clk_id has disappeared after its character device was opened. See clock_gettime(2) for a discussion of dynamic clocks. EOPNOTSUPP The given clk_id does not support adjustment. EPERM buf.modes 0 ADJ_OFFSET_SS_READ . Linux CAP_SYS_TIME. attributes(7). +----------------------------+----------------------------------------------------------+--------------------------+ | | | | +----------------------------+----------------------------------------------------------+--------------------------+ |ntp_adjtime() | | MT-Safe | +----------------------------+----------------------------------------------------------+--------------------------+ adjtimex() clock_adjtime() Linux. NTP ntp_adjtime(). In struct timex, freq, ppsfreq, and stabil are ppm (parts per million) with a 16-bit fractional part, which means that a value of 1 in one of those fields actually means 2^-16 ppm, and 2^16=65536 is 1 ppm. This is the case for both input values (in the case of freq) and output values. , STA_INS STA_DEL, . , . . clock_gettime(2), clock_settime(2), settimeofday(2), adjtime(3), ntp_gettime(3), capabilities(7), time(7), adjtimex(8), hwclock(8) NTP "Kernel Application Program Interface" Dmitry Bolkhovskikh Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . adjtimex(2)