1*8269e767SBrooks Davis.\" $NetBSD: ntp_adjtime.2,v 1.6 2003/04/16 13:34:55 wiz Exp $ 2*8269e767SBrooks Davis.\" 3*8269e767SBrooks Davis.\" Copyright (c) 2001 The NetBSD Foundation, Inc. 4*8269e767SBrooks Davis.\" All rights reserved. 5*8269e767SBrooks Davis.\" 6*8269e767SBrooks Davis.\" This code is derived from software contributed to The NetBSD Foundation 7*8269e767SBrooks Davis.\" by Thomas Klausner. 8*8269e767SBrooks Davis.\" 9*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without 10*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions 11*8269e767SBrooks Davis.\" are met: 12*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright 13*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer. 14*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright 15*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer in the 16*8269e767SBrooks Davis.\" documentation and/or other materials provided with the distribution. 17*8269e767SBrooks Davis.\" 18*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*8269e767SBrooks Davis.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28*8269e767SBrooks Davis.\" SUCH DAMAGE. 29*8269e767SBrooks Davis.\" 30*8269e767SBrooks Davis.Dd July 13, 2005 31*8269e767SBrooks Davis.Dt NTP_ADJTIME 2 32*8269e767SBrooks Davis.Os 33*8269e767SBrooks Davis.Sh NAME 34*8269e767SBrooks Davis.Nm ntp_adjtime , 35*8269e767SBrooks Davis.Nm ntp_gettime 36*8269e767SBrooks Davis.Nd Network Time Protocol (NTP) daemon interface system calls 37*8269e767SBrooks Davis.Sh LIBRARY 38*8269e767SBrooks Davis.Lb libc 39*8269e767SBrooks Davis.Sh SYNOPSIS 40*8269e767SBrooks Davis.In sys/timex.h 41*8269e767SBrooks Davis.Ft int 42*8269e767SBrooks Davis.Fn ntp_adjtime "struct timex *" 43*8269e767SBrooks Davis.Ft int 44*8269e767SBrooks Davis.Fn ntp_gettime "struct ntptimeval *" 45*8269e767SBrooks Davis.Sh DESCRIPTION 46*8269e767SBrooks DavisThe two system calls 47*8269e767SBrooks Davis.Fn ntp_adjtime 48*8269e767SBrooks Davisand 49*8269e767SBrooks Davis.Fn ntp_gettime 50*8269e767SBrooks Davisare the kernel interface to the Network Time Protocol (NTP) daemon 51*8269e767SBrooks Davis.Xr ntpd 8 . 52*8269e767SBrooks Davis.Pp 53*8269e767SBrooks DavisThe 54*8269e767SBrooks Davis.Fn ntp_adjtime 55*8269e767SBrooks Davisfunction is used by the NTP daemon to adjust the system clock to an 56*8269e767SBrooks Davisexternally derived time. 57*8269e767SBrooks DavisThe time offset and related variables which are set by 58*8269e767SBrooks Davis.Fn ntp_adjtime 59*8269e767SBrooks Davisare used by 60*8269e767SBrooks Davis.Fn hardclock 61*8269e767SBrooks Davisto adjust the phase and frequency of the phase- or frequency-lock loop 62*8269e767SBrooks Davis(PLL resp. FLL) which controls the system clock. 63*8269e767SBrooks Davis.Pp 64*8269e767SBrooks DavisThe 65*8269e767SBrooks Davis.Fn ntp_gettime 66*8269e767SBrooks Davisfunction provides the time, maximum error (sync distance) and 67*8269e767SBrooks Davisestimated error (dispersion) to client user application programs. 68*8269e767SBrooks Davis.Pp 69*8269e767SBrooks DavisIn the following, all variables that refer PPS are only relevant if 70*8269e767SBrooks Davisthe 71*8269e767SBrooks Davis.Em PPS_SYNC 72*8269e767SBrooks Davisoption is enabled in the kernel. 73*8269e767SBrooks Davis.Pp 74*8269e767SBrooks Davis.Fn ntp_adjtime 75*8269e767SBrooks Davishas as argument a 76*8269e767SBrooks Davis.Va struct timex * 77*8269e767SBrooks Davisof the following form: 78*8269e767SBrooks Davis.Bd -literal 79*8269e767SBrooks Davisstruct timex { 80*8269e767SBrooks Davis unsigned int modes; /* clock mode bits (wo) */ 81*8269e767SBrooks Davis long offset; /* time offset (us) (rw) */ 82*8269e767SBrooks Davis long freq; /* frequency offset (scaled ppm) (rw) */ 83*8269e767SBrooks Davis long maxerror; /* maximum error (us) (rw) */ 84*8269e767SBrooks Davis long esterror; /* estimated error (us) (rw) */ 85*8269e767SBrooks Davis int status; /* clock status bits (rw) */ 86*8269e767SBrooks Davis long constant; /* pll time constant (rw) */ 87*8269e767SBrooks Davis long precision; /* clock precision (us) (ro) */ 88*8269e767SBrooks Davis long tolerance; /* clock frequency tolerance (scaled 89*8269e767SBrooks Davis * ppm) (ro) */ 90*8269e767SBrooks Davis /* 91*8269e767SBrooks Davis * The following read-only structure members are implemented 92*8269e767SBrooks Davis * only if the PPS signal discipline is configured in the 93*8269e767SBrooks Davis * kernel. 94*8269e767SBrooks Davis */ 95*8269e767SBrooks Davis long ppsfreq; /* pps frequency (scaled ppm) (ro) */ 96*8269e767SBrooks Davis long jitter; /* pps jitter (us) (ro) */ 97*8269e767SBrooks Davis int shift; /* interval duration (s) (shift) (ro) */ 98*8269e767SBrooks Davis long stabil; /* pps stability (scaled ppm) (ro) */ 99*8269e767SBrooks Davis long jitcnt; /* jitter limit exceeded (ro) */ 100*8269e767SBrooks Davis long calcnt; /* calibration intervals (ro) */ 101*8269e767SBrooks Davis long errcnt; /* calibration errors (ro) */ 102*8269e767SBrooks Davis long stbcnt; /* stability limit exceeded (ro) */ 103*8269e767SBrooks Davis}; 104*8269e767SBrooks Davis.Ed 105*8269e767SBrooks Davis.Pp 106*8269e767SBrooks DavisThe members of this struct have the following meanings when used as 107*8269e767SBrooks Davisargument for 108*8269e767SBrooks Davis.Fn ntp_adjtime : 109*8269e767SBrooks Davis.Bl -tag -width tolerance -compact 110*8269e767SBrooks Davis.It Fa modes 111*8269e767SBrooks DavisDefines what settings should be changed with the current 112*8269e767SBrooks Davis.Fn ntp_adjtime 113*8269e767SBrooks Daviscall (write-only). 114*8269e767SBrooks DavisBitwise OR of the following: 115*8269e767SBrooks Davis.Bl -tag -width MOD_TIMECONST -compact -offset indent 116*8269e767SBrooks Davis.It MOD_OFFSET 117*8269e767SBrooks Davisset time offset 118*8269e767SBrooks Davis.It MOD_FREQUENCY 119*8269e767SBrooks Davisset frequency offset 120*8269e767SBrooks Davis.It MOD_MAXERROR 121*8269e767SBrooks Davisset maximum time error 122*8269e767SBrooks Davis.It MOD_ESTERROR 123*8269e767SBrooks Davisset estimated time error 124*8269e767SBrooks Davis.It MOD_STATUS 125*8269e767SBrooks Davisset clock status bits 126*8269e767SBrooks Davis.It MOD_TIMECONST 127*8269e767SBrooks Davisset PLL time constant 128*8269e767SBrooks Davis.It MOD_CLKA 129*8269e767SBrooks Davisset clock A 130*8269e767SBrooks Davis.It MOD_CLKB 131*8269e767SBrooks Davisset clock B 132*8269e767SBrooks Davis.El 133*8269e767SBrooks Davis.It Fa offset 134*8269e767SBrooks DavisTime offset (in microseconds), used by the PLL/FLL to adjust the 135*8269e767SBrooks Davissystem time in small increments (read-write). 136*8269e767SBrooks Davis.It Fa freq 137*8269e767SBrooks DavisFrequency offset (scaled ppm) (read-write). 138*8269e767SBrooks Davis.It Fa maxerror 139*8269e767SBrooks DavisMaximum error (in microseconds). 140*8269e767SBrooks DavisInitialized by an 141*8269e767SBrooks Davis.Fn ntp_adjtime 142*8269e767SBrooks Daviscall, and increased by the kernel once each second to reflect the maximum 143*8269e767SBrooks Daviserror bound growth (read-write). 144*8269e767SBrooks Davis.It Fa esterror 145*8269e767SBrooks DavisEstimated error (in microseconds). 146*8269e767SBrooks DavisSet and read by 147*8269e767SBrooks Davis.Fn ntp_adjtime , 148*8269e767SBrooks Davisbut unused by the kernel (read-write). 149*8269e767SBrooks Davis.It Fa status 150*8269e767SBrooks DavisSystem clock status bits (read-write). 151*8269e767SBrooks DavisBitwise OR of the following: 152*8269e767SBrooks Davis.Bl -tag -width STA_PPSJITTER -compact -offset indent 153*8269e767SBrooks Davis.It STA_PLL 154*8269e767SBrooks DavisEnable PLL updates (read-write). 155*8269e767SBrooks Davis.It STA_PPSFREQ 156*8269e767SBrooks DavisEnable PPS freq discipline (read-write). 157*8269e767SBrooks Davis.It STA_PPSTIME 158*8269e767SBrooks DavisEnable PPS time discipline (read-write). 159*8269e767SBrooks Davis.It STA_FLL 160*8269e767SBrooks DavisSelect frequency-lock mode (read-write). 161*8269e767SBrooks Davis.It STA_INS 162*8269e767SBrooks DavisInsert leap (read-write). 163*8269e767SBrooks Davis.It STA_DEL 164*8269e767SBrooks DavisDelete leap (read-write). 165*8269e767SBrooks Davis.It STA_UNSYNC 166*8269e767SBrooks DavisClock unsynchronized (read-write). 167*8269e767SBrooks Davis.It STA_FREQHOLD 168*8269e767SBrooks DavisHold frequency (read-write). 169*8269e767SBrooks Davis.It STA_PPSSIGNAL 170*8269e767SBrooks DavisPPS signal present (read-only). 171*8269e767SBrooks Davis.It STA_PPSJITTER 172*8269e767SBrooks DavisPPS signal jitter exceeded (read-only). 173*8269e767SBrooks Davis.It STA_PPSWANDER 174*8269e767SBrooks DavisPPS signal wander exceeded (read-only). 175*8269e767SBrooks Davis.It STA_PPSERROR 176*8269e767SBrooks DavisPPS signal calibration error (read-only). 177*8269e767SBrooks Davis.It STA_CLOCKERR 178*8269e767SBrooks DavisClock hardware fault (read-only). 179*8269e767SBrooks Davis.El 180*8269e767SBrooks Davis.It Fa constant 181*8269e767SBrooks DavisPLL time constant, determines the bandwidth, or 182*8269e767SBrooks Davis.Dq stiffness , 183*8269e767SBrooks Davisof the PLL (read-write). 184*8269e767SBrooks Davis.It Fa precision 185*8269e767SBrooks DavisClock precision (in microseconds). 186*8269e767SBrooks DavisIn most cases the same as the kernel tick variable (see 187*8269e767SBrooks Davis.Xr hz 9 ) . 188*8269e767SBrooks DavisIf a precision clock counter or external time-keeping signal is available, 189*8269e767SBrooks Davisit could be much lower (and depend on the state of the signal) 190*8269e767SBrooks Davis(read-only). 191*8269e767SBrooks Davis.It Fa tolerance 192*8269e767SBrooks DavisMaximum frequency error, or tolerance of the CPU clock oscillator (scaled 193*8269e767SBrooks Davisppm). 194*8269e767SBrooks DavisOrdinarily a property of the architecture, but could change under 195*8269e767SBrooks Davisthe influence of external time-keeping signals (read-only). 196*8269e767SBrooks Davis.It Fa ppsfreq 197*8269e767SBrooks DavisPPS frequency offset produced by the frequency median filter (scaled 198*8269e767SBrooks Davisppm) (read-only). 199*8269e767SBrooks Davis.It Fa jitter 200*8269e767SBrooks DavisPPS jitter measured by the time median filter in microseconds 201*8269e767SBrooks Davis(read-only). 202*8269e767SBrooks Davis.It Fa shift 203*8269e767SBrooks DavisLogarithm to base 2 of the interval duration in seconds (PPS, 204*8269e767SBrooks Davisread-only). 205*8269e767SBrooks Davis.It Fa stabil 206*8269e767SBrooks DavisPPS stability (scaled ppm); dispersion (wander) measured by the 207*8269e767SBrooks Davisfrequency median filter (read-only). 208*8269e767SBrooks Davis.It Fa jitcnt 209*8269e767SBrooks DavisNumber of seconds that have been discarded because the jitter measured 210*8269e767SBrooks Davisby the time median filter exceeded the limit 211*8269e767SBrooks Davis.Em MAXTIME 212*8269e767SBrooks Davis(PPS, read-only). 213*8269e767SBrooks Davis.It Fa calcnt 214*8269e767SBrooks DavisCount of calibration intervals (PPS, read-only). 215*8269e767SBrooks Davis.It Fa errcnt 216*8269e767SBrooks DavisNumber of calibration intervals that have been discarded because the 217*8269e767SBrooks Daviswander exceeded the limit 218*8269e767SBrooks Davis.Em MAXFREQ 219*8269e767SBrooks Davisor where the calibration interval jitter exceeded two ticks (PPS, 220*8269e767SBrooks Davisread-only). 221*8269e767SBrooks Davis.It Fa stbcnt 222*8269e767SBrooks DavisNumber of calibration intervals that have been discarded because the 223*8269e767SBrooks Davisfrequency wander exceeded the limit 224*8269e767SBrooks Davis.Em MAXFREQ Ns /4 225*8269e767SBrooks Davis(PPS, read-only). 226*8269e767SBrooks Davis.El 227*8269e767SBrooks DavisAfter the 228*8269e767SBrooks Davis.Fn ntp_adjtime 229*8269e767SBrooks Daviscall, the 230*8269e767SBrooks Davis.Va struct timex * 231*8269e767SBrooks Davisstructure contains the current values of the corresponding variables. 232*8269e767SBrooks Davis.Pp 233*8269e767SBrooks Davis.Fn ntp_gettime 234*8269e767SBrooks Davishas as argument a 235*8269e767SBrooks Davis.Va struct ntptimeval * 236*8269e767SBrooks Daviswith the following members: 237*8269e767SBrooks Davis.Bd -literal 238*8269e767SBrooks Davisstruct ntptimeval { 239*8269e767SBrooks Davis struct timeval time; /* current time (ro) */ 240*8269e767SBrooks Davis long maxerror; /* maximum error (us) (ro) */ 241*8269e767SBrooks Davis long esterror; /* estimated error (us) (ro) */ 242*8269e767SBrooks Davis}; 243*8269e767SBrooks Davis.Ed 244*8269e767SBrooks Davis.Pp 245*8269e767SBrooks DavisThese have the following meaning: 246*8269e767SBrooks Davis.Bl -tag -width tolerance -compact 247*8269e767SBrooks Davis.It Fa time 248*8269e767SBrooks DavisCurrent time (read-only). 249*8269e767SBrooks Davis.It Fa maxerror 250*8269e767SBrooks DavisMaximum error in microseconds (read-only). 251*8269e767SBrooks Davis.It Fa esterror 252*8269e767SBrooks DavisEstimated error in microseconds (read-only). 253*8269e767SBrooks Davis.El 254*8269e767SBrooks Davis.Sh RETURN VALUES 255*8269e767SBrooks Davis.Fn ntp_adjtime 256*8269e767SBrooks Davisand 257*8269e767SBrooks Davis.Fn ntp_gettime 258*8269e767SBrooks Davisreturn the current state of the clock on success, or any of the errors 259*8269e767SBrooks Davisof 260*8269e767SBrooks Davis.Xr copyin 9 261*8269e767SBrooks Davisand 262*8269e767SBrooks Davis.Xr copyout 9 . 263*8269e767SBrooks Davis.Fn ntp_adjtime 264*8269e767SBrooks Davismay additionally return 265*8269e767SBrooks Davis.Er EPERM 266*8269e767SBrooks Davisif the user calling 267*8269e767SBrooks Davis.Fn ntp_adjtime 268*8269e767SBrooks Davisdoes not have sufficient permissions. 269*8269e767SBrooks Davis.Pp 270*8269e767SBrooks DavisPossible states of the clock are: 271*8269e767SBrooks Davis.Bl -tag -width TIME_ERROR -compact -offset indent 272*8269e767SBrooks Davis.It TIME_OK 273*8269e767SBrooks DavisEverything okay, no leap second warning. 274*8269e767SBrooks Davis.It TIME_INS 275*8269e767SBrooks Davis.Dq insert leap second 276*8269e767SBrooks Daviswarning. 277*8269e767SBrooks DavisAt the end of the day, a leap second will be inserted after 23:59:59. 278*8269e767SBrooks Davis.It TIME_DEL 279*8269e767SBrooks Davis.Dq delete leap second 280*8269e767SBrooks Daviswarning. 281*8269e767SBrooks DavisAt the end of the day, second 23:59:59 will be skipped. 282*8269e767SBrooks Davis.It TIME_OOP 283*8269e767SBrooks DavisLeap second in progress. 284*8269e767SBrooks Davis.It TIME_WAIT 285*8269e767SBrooks DavisLeap second has occurred within the last few seconds. 286*8269e767SBrooks Davis.It TIME_ERROR 287*8269e767SBrooks DavisClock not synchronized. 288*8269e767SBrooks Davis.El 289*8269e767SBrooks Davis.Sh ERRORS 290*8269e767SBrooks DavisThe 291*8269e767SBrooks Davis.Fn ntp_adjtime 292*8269e767SBrooks Davissystem call may return 293*8269e767SBrooks Davis.Er EPERM 294*8269e767SBrooks Davisif the caller 295*8269e767SBrooks Davisdoes not have sufficient permissions. 296*8269e767SBrooks Davis.Sh SEE ALSO 297*8269e767SBrooks Davis.Xr options 4 , 298*8269e767SBrooks Davis.Xr ntpd 8 , 299*8269e767SBrooks Davis.Xr hardclock 9 , 300*8269e767SBrooks Davis.Xr hz 9 301*8269e767SBrooks Davis.Bl -tag -width indent 302*8269e767SBrooks Davis.It Pa http://www.bipm.fr/enus/5_Scientific/c_time/time_1.html 303*8269e767SBrooks Davis.It Pa http://www.boulder.nist.gov/timefreq/general/faq.htm 304*8269e767SBrooks Davis.It Pa ftp://time.nist.gov/pub/leap-seconds.list 305*8269e767SBrooks Davis.El 306*8269e767SBrooks Davis.Sh BUGS 307*8269e767SBrooks DavisTake note that this 308*8269e767SBrooks Davis.Tn API 309*8269e767SBrooks Davisis extremely complex and stateful. 310*8269e767SBrooks DavisUsers should not attempt modification without first 311*8269e767SBrooks Davisreviewing the 312*8269e767SBrooks Davis.Xr ntpd 8 313*8269e767SBrooks Davissources in depth. 314