NTP_ADJTIME(2)
πΈ NAME πΈ
okay so bestie, welcome to NTP_ADJTIME(2) from the System Calls Manual β this page is literally the kernel interface to the Network Time Protocol daemon, ntpd(8), and it covers the ntp_adjtime and ntp_gettime system calls. β¨
π LIBRARY π
Standard C Library (libc, -lc) π«Ά
π οΈ SYNOPSIS π οΈ
#include <sys/timex.h>
int
ntp_adjtime(struct timex *);
int
ntp_gettime(struct ntptimeval *);
π DESCRIPTION π
The two system calls ntp_adjtime() and ntp_gettime() are the kernel interface to the Network Time Protocol (NTP) daemon ntpd(8). π
The ntp_adjtime() function is what the NTP daemon uses to adjust the system clock to an externally derived time. The time offset and related variables that get set by ntp_adjtime() are used by hardclock() to adjust the phase and frequency of the phase- or frequency-lock loop (PLL resp. FLL) that controls the system clock. This is genuinely main character clock business. π
The ntp_gettime() function provides the time, maximum error (sync distance) and estimated error (dispersion) to client user application programs. π°οΈ
In the following, all variables that refer PPS are only relevant if the PPS_SYNC option is enabled in the kernel. no cap π
ntp_adjtime() has as argument a struct timex * of the following form:
struct timex {
unsigned int modes; /* clock mode bits (wo) */
long offset; /* time offset (us) (rw) */
long freq; /* frequency offset (scaled ppm) (rw) */
long maxerror; /* maximum error (us) (rw) */
long esterror; /* estimated error (us) (rw) */
int status; /* clock status bits (rw) */
long constant; /* pll time constant (rw) */
long precision; /* clock precision (us) (ro) */
long tolerance; /* clock frequency tolerance (scaled
* ppm) (ro) */
/*
* The following read-only structure members are implemented
* only if the PPS signal discipline is configured in the
* kernel.
*/
long ppsfreq; /* pps frequency (scaled ppm) (ro) */
long jitter; /* pps jitter (us) (ro) */
int shift; /* interval duration (s) (shift) (ro) */
long stabil; /* pps stability (scaled ppm) (ro) */
long jitcnt; /* jitter limit exceeded (ro) */
long calcnt; /* calibration intervals (ro) */
long errcnt; /* calibration errors (ro) */
long stbcnt; /* stability limit exceeded (ro) */
};
The members of this struct have the following meanings when used as argument for ntp_adjtime():
modesβ defines what settings should be changed with the currentntp_adjtime()call (write-only). It's a bitwise OR of the following:MOD_OFFSETβ set time offsetMOD_FREQUENCYβ set frequency offsetMOD_MAXERRORβ set maximum time errorMOD_ESTERRORβ set estimated time errorMOD_STATUSβ set clock status bitsMOD_TIMECONSTβ set PLL time constantMOD_CLKAβ set clock AMOD_CLKBβ set clock B
offsetβ time offset (in microseconds), used by the PLL/FLL to adjust the system time in small increments (read-write).freqβ frequency offset (scaled ppm) (read-write).maxerrorβ maximum error (in microseconds). Initialized by anntp_adjtime()call, and increased by the kernel once each second to reflect the maximum error bound growth (read-write).esterrorβ estimated error (in microseconds). Set and read byntp_adjtime(), but unused by the kernel (read-write).statusβ system clock status bits (read-write). Bitwise OR of the following:STA_PLLβ enable PLL updates (read-write).STA_PPSFREQβ enable PPS freq discipline (read-write).STA_PPSTIMEβ enable PPS time discipline (read-write).STA_FLLβ select frequency-lock mode (read-write).STA_INSβ insert leap (read-write).STA_DELβ delete leap (read-write).STA_UNSYNCβ clock unsynchronized (read-write).STA_FREQHOLDβ hold frequency (read-write).STA_PPSSIGNALβ PPS signal present (read-only).STA_PPSJITTERβ PPS signal jitter exceeded (read-only).STA_PPSWANDERβ PPS signal wander exceeded (read-only).STA_PPSERRORβ PPS signal calibration error (read-only).STA_CLOCKERRβ clock hardware fault (read-only).
constantβ PLL time constant, determines the bandwidth, or βstiffnessβ, of the PLL (read-write).precisionβ clock precision (in microseconds). In most cases the same as the kernel tick variable (seehz(9)). If a precision clock counter or external time-keeping signal is available, it could be much lower (and depend on the state of the signal) (read-only).toleranceβ maximum frequency error, or tolerance of the CPU clock oscillator (scaled ppm). Ordinarily a property of the architecture, but could change under the influence of external time-keeping signals (read-only).ppsfreqβ PPS frequency offset produced by the frequency median filter (scaled ppm) (read-only).jitterβ PPS jitter measured by the time median filter in microseconds (read-only).shiftβ logarithm to base 2 of the interval duration in seconds (PPS, read-only).stabilβ PPS stability (scaled ppm); dispersion (wander) measured by the frequency median filter (read-only).jitcntβ number of seconds that have been discarded because the jitter measured by the time median filter exceeded the limitMAXTIME(PPS, read-only).calcntβ count of calibration intervals (PPS, read-only).errcntβ number of calibration intervals that have been discarded because the wander exceeded the limitMAXFREQor where the calibration interval jitter exceeded two ticks (PPS, read-only).stbcntβ number of calibration intervals that have been discarded because the frequency wander exceeded the limitMAXFREQ/4(PPS, read-only).
After the ntp_adjtime() call, the struct timex * structure contains the current values of the corresponding variables. π
ntp_gettime() has as argument a struct ntptimeval * with the following members:
struct ntptimeval {
struct timeval time; /* current time (ro) */
long maxerror; /* maximum error (us) (ro) */
long esterror; /* estimated error (us) (ro) */
};
These have the following meaning:
timeβ current time (read-only).maxerrorβ maximum error in microseconds (read-only).esterrorβ estimated error in microseconds (read-only).
π RETURN VALUES π
ntp_adjtime() and ntp_gettime() return the current state of the clock on success, or any of the errors of copyin(9) and copyout(9). π«Ά
ntp_adjtime() may additionally return EPERM if the user calling ntp_adjtime() does not have sufficient permissions. π
Possible states of the clock are:
TIME_OKβ everything okay, no leap second warning.TIME_INSβ βinsert leap secondβ warning. At the end of the day, a leap second will be inserted after23:59:59.TIME_DELβ βdelete leap secondβ warning. At the end of the day, second23:59:59will be skipped.TIME_OOPβ leap second in progress.TIME_WAITβ leap second has occurred within the last few seconds.TIME_ERRORβ clock not synchronized.
π¨ ERRORS π¨
The ntp_adjtime() system call may return EPERM if the caller does not have sufficient permissions. π₯
π SEE ALSO π
options(4)ntpd(8)hardclock(9)hz(9)http://www.bipm.fr/enus/5_Scientific/c_time/time_1.htmlhttp://www.boulder.nist.gov/timefreq/general/faq.htmftp://time.nist.gov/pub/leap-seconds.list
π BUGS π
Take note that this API is extremely complex and stateful. Users should not attempt modification without first reviewing the ntpd(8) sources in depth. bestie, this is not a βjust vibe and change stuffβ situation, fr fr π
π sign-off: Debian Β· March 22, 2026 Β· NTP_ADJTIME(2) π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2001 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms