| 1 |
<pre>Network Working Group D. Mills |
| 2 |
Request for Comments: 1589 University of Delaware |
| 3 |
Category: Informational March 1994 |
| 4 |
|
| 5 |
|
| 6 |
<span class="h1">A Kernel Model for Precision Timekeeping</span> |
| 7 |
|
| 8 |
Status of this Memo |
| 9 |
|
| 10 |
This memo provides information for the Internet community. This memo |
| 11 |
does not specify an Internet standard of any kind. Distribution of |
| 12 |
this memo is unlimited. |
| 13 |
|
| 14 |
Overview |
| 15 |
|
| 16 |
This memorandum describes an engineering model which implements a |
| 17 |
precision time-of-day function for a generic operating system. The |
| 18 |
model is based on the principles of disciplined oscillators and |
| 19 |
phase-lock loops (PLL) often found in the engineering literature. It |
| 20 |
has been implemented in the Unix kernel for several workstations, |
| 21 |
including those made by Sun Microsystems and Digital Equipment. The |
| 22 |
model changes the way the system clock is adjusted in time and |
| 23 |
frequency, as well as provides mechanisms to discipline its frequency |
| 24 |
to an external precision timing source. The model incorporates a |
| 25 |
generic system-call interface for use with the Network Time Protocol |
| 26 |
(NTP) or similar time synchronization protocol. The NTP Version 3 |
| 27 |
daemon xntpd operates with this model to provide synchronization |
| 28 |
limited in principle only by the accuracy and stability of the |
| 29 |
external timing source. |
| 30 |
|
| 31 |
This memorandum does not obsolete or update any RFC. It does not |
| 32 |
propose a standard protocol, specification or algorithm. It is |
| 33 |
intended to provoke comment, refinement and alternative |
| 34 |
implementations. While a working knowledge of NTP is not required for |
| 35 |
an understanding of the design principles or implementation of the |
| 36 |
model, it may be helpful in understanding how the model behaves in a |
| 37 |
fully functional timekeeping system. The architecture and design of |
| 38 |
NTP is described in [<a href="#ref-1" title=""Internet time synchronization: the Network Time Protocol"">1</a>], while the current NTP Version 3 protocol |
| 39 |
specification is given in <a href="./rfc1305">RFC-1305</a> [<a href="#ref-2" title=""Network Time Protocol (Version 3) specification, implementation and analysis"">2</a>] and a subset of the protocol, |
| 40 |
the Simple Network Time Protocol (SNTP), in <a href="./rfc1361">RFC-1361</a> [<a href="#ref-4" title=""Simple Network Time Protocol (SNTP)"">4</a>]. |
| 41 |
|
| 42 |
The model has been implemented in three Unix kernels for Sun |
| 43 |
Microsystems and Digital Equipment workstations. In addition, for the |
| 44 |
Digital machines the model provides improved precision to one |
| 45 |
microsecond (us). Since these specific implementations involve |
| 46 |
modifications to licensed code, they cannot be provided directly. |
| 47 |
Inquiries should be directed to the manufacturer's representatives. |
| 48 |
However, the engineering model for these implementations, including a |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
<span class="grey">Mills [Page 1]</span></pre> |
| 53 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-2" ></span> |
| 54 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 55 |
|
| 56 |
|
| 57 |
simulator with code segments almost identical to the implementations, |
| 58 |
but not involving licensed code, is available via anonymous FTP from |
| 59 |
host louie.udel.edu in the directory pub/ntp and compressed tar |
| 60 |
archive kernel.tar.Z. The NTP Version 3 distribution can be obtained |
| 61 |
via anonymous ftp from the same host and directory in the compressed |
| 62 |
tar archive xntp3.3g.tar.Z, where the version number shown as 3.3g |
| 63 |
may be adjusted for new versions as they occur. |
| 64 |
|
| 65 |
<span class="h2"><a class="selflink" id="section-1" href="#section-1">1</a>. Introduction</span> |
| 66 |
|
| 67 |
This memorandum describes a model and programming interface for |
| 68 |
generic operating system software that manages the system clock and |
| 69 |
timer functions. The model provides improved accuracy and stability |
| 70 |
for most workstations and servers using the Network Time Protocol |
| 71 |
(NTP) or similar time synchronization protocol. This memorandum |
| 72 |
describes the principles of design and implementation of the model. |
| 73 |
Related technical reports discuss the design approach, engineering |
| 74 |
analysis and performance evaluation of the model as implemented in |
| 75 |
Unix kernels for Sun Microsystems and Digital Equipment workstations. |
| 76 |
The NTP Version 3 daemon xntpd operates with these implementations to |
| 77 |
provide improved accuracy and stability, together with diminished |
| 78 |
overhead in the operating system and network. In addition, the model |
| 79 |
supports the use of external timing sources, such as precision |
| 80 |
pulse-per-second (PPS) signals and the industry standard IRIG timing |
| 81 |
signals. The NTP daemon automatically detects the presence of the new |
| 82 |
features and utilizes them when available. |
| 83 |
|
| 84 |
There are three prototype implementations of the model presented in |
| 85 |
this memorandum, one each for the Sun Microsystems SPARCstation with |
| 86 |
the SunOS 4.1.x kernel, Digital Equipment DECstation 5000 with the |
| 87 |
Ultrix 4.x kernel and Digital Equipment 3000 AXP Alpha with the OSF/1 |
| 88 |
V1.x kernel. In addition, for the DECstation 5000/240 and 3000 AXP |
| 89 |
Alpha machines, a special feature provides improved precision to 1 us |
| 90 |
(Sun 4.1.x kernels already do provide 1-us precision). Other than |
| 91 |
improving the system clock accuracy, stability and precision, these |
| 92 |
implementations do not change the operation of existing Unix system |
| 93 |
calls which manage the system clock, such as gettimeofday(), |
| 94 |
settimeofday() and adjtime(); however, if the new features are in |
| 95 |
use, the operations of gettimeofday() and adjtime() can be controlled |
| 96 |
instead by new system calls ntp_gettime() and ntp_adjtime() as |
| 97 |
described below. |
| 98 |
|
| 99 |
A detailed description of the variables and algorithms is given in |
| 100 |
the hope that similar functionality can be incorporated in Unix |
| 101 |
kernels for other machines. The algorithms involve only minor changes |
| 102 |
to the system clock and interval timer routines and include |
| 103 |
interfaces for application programs to learn the system clock status |
| 104 |
and certain statistics of the time synchronization process. Detailed |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
<span class="grey">Mills [Page 2]</span></pre> |
| 109 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-3" ></span> |
| 110 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 111 |
|
| 112 |
|
| 113 |
installation instructions are given in a specific README files |
| 114 |
included in the kernel distributions. |
| 115 |
|
| 116 |
In this memorandum, NTP Version 3 and the Unix implementation xntp3 |
| 117 |
are used as an example application of the new system calls for use by |
| 118 |
a synchronization daemon. In principle, the new system calls can be |
| 119 |
used by other protocols and implementations as well. Even in cases |
| 120 |
where the local time is maintained by periodic exchanges of messages |
| 121 |
at relatively long intervals, such as using the NIST Automated |
| 122 |
Computer Time Service, the ability to precisely adjust the system |
| 123 |
clock frequency simplifies the synchronization procedures and allows |
| 124 |
the telephone call frequency to be considerably reduced. |
| 125 |
|
| 126 |
<span class="h2"><a class="selflink" id="section-2" href="#section-2">2</a>. Design Approach</span> |
| 127 |
|
| 128 |
While not strictly necessary for an understanding or implementation |
| 129 |
of the model, it may be helpful to briefly describe how NTP operates |
| 130 |
to control the system clock in a client workstation. As described in |
| 131 |
[<a href="#ref-1" title=""Internet time synchronization: the Network Time Protocol"">1</a>], the NTP protocol exchanges timestamps with one or more peers |
| 132 |
sharing a synchronization subnet to calculate the time offsets |
| 133 |
between peer clocks and the local clock. These offsets are processed |
| 134 |
by several algorithms which refine and combine the offsets to produce |
| 135 |
an ensemble average, which is then used to adjust the local clock |
| 136 |
time and frequency. The manner in which the local clock is adjusted |
| 137 |
represents the main topic of this memorandum. The goal in the |
| 138 |
enterprise is the most accurate and stable system clock possible with |
| 139 |
the available kernel software and workstation hardware. |
| 140 |
|
| 141 |
In order to understand how the new software works, it is useful to |
| 142 |
review how most Unix kernels maintain the system time. In the Unix |
| 143 |
design a hardware counter interrupts the kernel at a fixed rate: 100 |
| 144 |
Hz in the SunOS kernel, 256 Hz in the Ultrix kernel and 1024 Hz in |
| 145 |
the OSF/1 kernel. Since the Ultrix timer interval (reciprocal of the |
| 146 |
rate) does not evenly divide one second in microseconds, the Ultrix |
| 147 |
kernel adds 64 microseconds once each second, so the timescale |
| 148 |
consists of 255 advances of 3906 us plus one of 3970 us. Similarly, |
| 149 |
the OSF/1 kernel adds 576 us once each second, so its timescale |
| 150 |
consists of 1023 advances of 976 us plus one of 1552 us. |
| 151 |
|
| 152 |
2.1. Mechanisms to Adjust Time and Frequency |
| 153 |
|
| 154 |
In most Unix kernels it is possible to slew the system clock to a |
| 155 |
new offset relative to the current time by using the adjtime() |
| 156 |
system call. To do this the clock frequency is changed by adding |
| 157 |
or subtracting a fixed amount (tickadj) at each timer interrupt |
| 158 |
(tick) for a calculated number of ticks. Since this calculation |
| 159 |
involves dividing the requested offset by tickadj, it is possible |
| 160 |
to slew to a new offset with a precision only of tickadj, which is |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
<span class="grey">Mills [Page 3]</span></pre> |
| 165 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-4" ></span> |
| 166 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 167 |
|
| 168 |
|
| 169 |
usually in the neighborhood of 5 us, but sometimes much more. This |
| 170 |
results in a roundoff error which can accumulate to an |
| 171 |
unacceptable degree, so that special provisions must be made in |
| 172 |
the clock adjustment procedures of the synchronization daemon. |
| 173 |
|
| 174 |
In order to implement a frequency-discipline function, it is |
| 175 |
necessary to provide time offset adjustments to the kernel at |
| 176 |
regular adjustment intervals using the adjtime() system call. In |
| 177 |
order to reduce the system clock jitter to the regime considered |
| 178 |
in this memorandum, it is necessary that the adjustment interval |
| 179 |
be relatively small, in the neighborhood of 1 s. However, the Unix |
| 180 |
adjtime() implementation requires each offset adjustment to |
| 181 |
complete before another one can be begun, which means that large |
| 182 |
adjustments must be amortized in possibly many adjustment |
| 183 |
intervals. The requirement to implement the adjustment interval |
| 184 |
and compensate for roundoff error considerably complicates the |
| 185 |
synchronizing daemon implementation. |
| 186 |
|
| 187 |
In the new model this scheme is replaced by another that |
| 188 |
represents the system clock as a multiple-word, precision-time |
| 189 |
variable in order to provide very precise clock adjustments. At |
| 190 |
each timer interrupt a precisely calibrated quantity is added to |
| 191 |
the kernel time variable and overflows propagated as required. The |
| 192 |
quantity is computed as in the NTP local clock model described in |
| 193 |
[<a href="#ref-3" title=""Modelling and analysis of computer network clocks"">3</a>], which operates as an adaptive-parameter, first-order, type-II |
| 194 |
phase-lock loop (PLL). In principle, this PLL design can provide |
| 195 |
precision control of the system clock oscillator within 1 us and |
| 196 |
frequency to within parts in 10^11. While precisions of this order |
| 197 |
are surely well beyond the capabilities of the CPU clock |
| 198 |
oscillator used in typical workstations, they are appropriate |
| 199 |
using precision external oscillators as described below. |
| 200 |
|
| 201 |
The PLL design is identical to the one originally implemented in |
| 202 |
NTP and described in [<a href="#ref-3" title=""Modelling and analysis of computer network clocks"">3</a>]. In this design the software daemon |
| 203 |
simulates the PLL using the adjtime() system call; however, the |
| 204 |
daemon implementation is considerably complicated by the |
| 205 |
considerations described above. The modified kernel routines |
| 206 |
implement the PLL in the kernel using precision time and frequency |
| 207 |
representions, so that these complications are avoided. A new |
| 208 |
system call ntp_adjtime() is called only as each new time update |
| 209 |
is determined, which in NTP occurs at intervals of from 16 s to |
| 210 |
1024 s. In addition, doing frequency compensation in the kernel |
| 211 |
means that the system time runs true even if the daemon were to |
| 212 |
cease operation or the network paths to the primary |
| 213 |
synchronization source fail. |
| 214 |
|
| 215 |
In the new model the new ntp_adjtime() operates in a way similar |
| 216 |
to the original adjtime() system call, but does so independently |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
<span class="grey">Mills [Page 4]</span></pre> |
| 221 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-5" ></span> |
| 222 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 223 |
|
| 224 |
|
| 225 |
of adjtime(), which continues to operate in its traditional |
| 226 |
fashion. When used with NTP, it is the design intent that |
| 227 |
settimeofday() or adjtime() be used only for system time |
| 228 |
adjustments greater than +-128 ms, although the dynamic range of |
| 229 |
the new model is much larger at +-512 ms. It has been the Internet |
| 230 |
experience that the need to change the system time in increments |
| 231 |
greater than +-128 ms is extremely rare and is usually associated |
| 232 |
with a hardware or software malfunction or system reboot. |
| 233 |
|
| 234 |
The easiest way to set the time is with the settimeofday() system |
| 235 |
call; however, this can under some conditions cause the clock to |
| 236 |
jump backward. If this cannot be tolerated, adjtime() can be used |
| 237 |
to slew the clock to the new value without running backward or |
| 238 |
affecting the frequency discipline process. Once the system clock |
| 239 |
has been set within +-128 ms, the ntp_adjtime() system call is |
| 240 |
used to provide periodic updates including the time offset, |
| 241 |
maximum error, estimated error and PLL time constant. With NTP the |
| 242 |
update interval depends on the measured dispersion and time |
| 243 |
constant; however, the scheme is quite forgiving and neither |
| 244 |
moderate loss of updates nor variations in the update interval are |
| 245 |
serious. |
| 246 |
|
| 247 |
2.2 Daemon and Application Interface |
| 248 |
|
| 249 |
Unix application programs can read the system clock using the |
| 250 |
gettimeofday() system call, which returns only the system time and |
| 251 |
timezone data. For some applications it is useful to know the |
| 252 |
maximum error of the reported time due to all causes, including |
| 253 |
clock reading errors, oscillator frequency errors and accumulated |
| 254 |
latencies on the path to a primary synchronization source. |
| 255 |
However, in the new model the PLL adjusts the system clock to |
| 256 |
compensate for its intrinsic frequency error, so that the time |
| 257 |
errors expected in normal operation will usually be much less than |
| 258 |
the maximum error. The programming interface includes a new system |
| 259 |
call ntp_gettime(), which returns the system time, as well as the |
| 260 |
maximum error and estimated error. This interface is intended to |
| 261 |
support applications that need such things, including distributed |
| 262 |
file systems, multimedia teleconferencing and other real-time |
| 263 |
applications. The programming interface also includes the new |
| 264 |
system call ntp_adjtime() mentioned previously, which can be used |
| 265 |
to read and write kernel variables for time and frequency |
| 266 |
adjustment, PLL time constant, leap-second warning and related |
| 267 |
data. |
| 268 |
|
| 269 |
In addition, the kernel adjusts the maximum error to grow by an |
| 270 |
amount equal to the oscillator frequency tolerance times the |
| 271 |
elapsed time since the last update. The default engineering |
| 272 |
parameters have been optimized for update intervals in the order |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
<span class="grey">Mills [Page 5]</span></pre> |
| 277 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-6" ></span> |
| 278 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 279 |
|
| 280 |
|
| 281 |
of 64 s. For other intervals the PLL time constant can be adjusted |
| 282 |
to optimize the dynamic response over intervals of 16-1024 s. |
| 283 |
Normally, this is automatically done by NTP. In any case, if |
| 284 |
updates are suspended, the PLL coasts at the frequency last |
| 285 |
determined, which usually results in errors increasing only to a |
| 286 |
few tens of milliseconds over a day using room-temperature quartz |
| 287 |
oscillators of typical modern workstations. |
| 288 |
|
| 289 |
While any synchronization daemon can in principle be modified to |
| 290 |
use the new system calls, the most likely will be users of the NTP |
| 291 |
Version 3 daemon xntpd. The xntpd code determines whether the new |
| 292 |
system calls are implemented and automatically reconfigures as |
| 293 |
required. When implemented, the daemon reads the frequency offset |
| 294 |
from a file and provides it and the initial time constant via |
| 295 |
ntp_adjtime(). In subsequent calls to ntp_adjtime(), only the time |
| 296 |
offset and time constant are affected. The daemon reads the |
| 297 |
frequency from the kernel using ntp_adjtime() at intervals of |
| 298 |
about one hour and writes it to a system file. This information is |
| 299 |
recovered when the daemon is restarted after reboot, for example, |
| 300 |
so the sometimes extensive training period to learn the frequency |
| 301 |
separately for each system can be avoided. |
| 302 |
|
| 303 |
2.3. Precision Clocks for DECstation 5000/240 and 3000 AXP Alpha |
| 304 |
|
| 305 |
The stock microtime() routine in the Ultrix kernel returns system |
| 306 |
time to the precision of the timer interrupt interval, which is in |
| 307 |
the 1-4 ms range. However, in the DECstation 5000/240 and possibly |
| 308 |
other machines of that family, there is an undocumented IOASIC |
| 309 |
hardware register that counts system bus cycles at a rate of 25 |
| 310 |
MHz. The new microtime() routine for the Ultrix kernel uses this |
| 311 |
register to interpolate system time between timer interrupts. This |
| 312 |
results in a precision of 1 us for all time values obtained via |
| 313 |
the gettimeofday() and ntp_gettime() system calls. For the Digital |
| 314 |
Equipment 3000 AXP Alpha, the architecture provides a hardware |
| 315 |
Process Cycle Counter and a machine instruction rpcc to read it. |
| 316 |
This counter operates at the fundamental frequency of the CPU |
| 317 |
clock or some submultiple of it, 133.333 MHz for the 3000/400 for |
| 318 |
example. The new microtime() routine for the OSF/1 kernel uses |
| 319 |
this counter in the same fashion as the Ultrix routine. |
| 320 |
|
| 321 |
In both the Ultrix and OSF/1 kernels the gettimeofday() and |
| 322 |
ntp_gettime() system call use the new microtime() routine, which |
| 323 |
returns the actual interpolated value, but does not change the |
| 324 |
kernel time variable. Therefore, other routines that access the |
| 325 |
kernel time variable directly and do not call either |
| 326 |
gettimeofday(), ntp_gettime() or microtime() will continue their |
| 327 |
present behavior. The microtime() feature is independent of other |
| 328 |
features described here and is operative even if the kernel PLL or |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
<span class="grey">Mills [Page 6]</span></pre> |
| 333 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-7" ></span> |
| 334 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 335 |
|
| 336 |
|
| 337 |
new system calls have not been implemented. |
| 338 |
|
| 339 |
The SunOS kernel already includes a system clock with 1-us |
| 340 |
resolution; so, in principle, no microtime() routine is necessary. |
| 341 |
An existing kernel routine uniqtime() implements this function, |
| 342 |
but it is coded in the C language and is rather slow at 42-85 us |
| 343 |
per call. A replacement microtime() routine coded in assembler |
| 344 |
language is available in the NTP Version 3 distribution and is |
| 345 |
much faster at about 3 us per call. |
| 346 |
|
| 347 |
2.4. External Time and Frequency Discipline |
| 348 |
|
| 349 |
The overall accuracy of a time synchronization subnet with respect |
| 350 |
to Coordinated Universal Time (UTC) depends on the accuracy and |
| 351 |
stability of the primary synchronization source, usually a radio |
| 352 |
or satellite receiver, and the system clock oscillator of the |
| 353 |
primary server. As discussed in [<a href="#ref-5" title=""Precision synchronizatin of computer network clocks"">5</a>], the traditional interface |
| 354 |
using an RS232 protocol and serial port precludes the full |
| 355 |
accuracy of the radio clock. In addition, the poor stability of |
| 356 |
typical CPU clock oscillators limits the accuracy, whether or not |
| 357 |
precision time sources are available. There are, however, several |
| 358 |
ways in which the system clock accuracy and stability can be |
| 359 |
improved to the degree limited only by the accuracy and stability |
| 360 |
of the synchronization source and the jitter of the operating |
| 361 |
system. |
| 362 |
|
| 363 |
Many radio clocks produce special signals that can be used by |
| 364 |
external equipment to precisely synchronize time and frequency. |
| 365 |
Most produce a pulse-per-second (PPS) signal that can be read via |
| 366 |
a modem-control lead of a serial port and some produce a special |
| 367 |
IRIG signal that can be read directly by a bus peripheral, such as |
| 368 |
the KSI/Odetics TPRO IRIG SBus interface, or indirectly via the |
| 369 |
audio codec of some workstations, as described in [<a href="#ref-5" title=""Precision synchronizatin of computer network clocks"">5</a>]. In the NTP |
| 370 |
Version 3 distribution, the PPS signal can be used to augment the |
| 371 |
less precise ASCII serial timecode to improve accuracy to the |
| 372 |
order of microseconds. Support is also included in the |
| 373 |
distribution for the TPRO interface as well as the audio codec; |
| 374 |
however, the latter requires a modified kernel audio driver |
| 375 |
contained in the bsd_audio.tar.Z distribution in the same host and |
| 376 |
directory as the NTP Version 3 distribution mentioned previously. |
| 377 |
|
| 378 |
2.4.1. PPS Signal |
| 379 |
|
| 380 |
The NTP Version 3 distribution includes a special ppsclock |
| 381 |
module for the SunOS 4.1.x kernel that captures the PPS signal |
| 382 |
presented via a modem-control lead of a serial port. Normally, |
| 383 |
the ppsclock module produces a timestamp at each transition of |
| 384 |
the PPS signal and provides it to the synchronization daemon |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
<span class="grey">Mills [Page 7]</span></pre> |
| 389 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-8" ></span> |
| 390 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 391 |
|
| 392 |
|
| 393 |
for integration with the serial ASCII timecode, also produced |
| 394 |
by the radio clock. With the conventional PLL implementation in |
| 395 |
either the daemon or the kernel as described above, the |
| 396 |
accuracy of this scheme is limited by the intrinsic stability |
| 397 |
of the CPU clock oscillator to a millisecond or two, depending |
| 398 |
on environmental temperature variations. |
| 399 |
|
| 400 |
The ppsclock module has been modified to in addition call a new |
| 401 |
kernel routine hardpps() once each second. The kernel routine |
| 402 |
compares the timestamp with a sample of the CPU clock |
| 403 |
oscillator to develop a frequency offset estimate. This offset |
| 404 |
is used to discipline the oscillator frequency, nominally to |
| 405 |
within a few parts in 10^8, which is about two orders of |
| 406 |
magnitude better than the undisciplined oscillator. The new |
| 407 |
feature is conditionally compiled in the code described below |
| 408 |
only if the PPS_SYNC option is used in the kernel configuration |
| 409 |
file. |
| 410 |
|
| 411 |
When using the PPS signal to adjust the time, there is a |
| 412 |
problem with the SunOS implementation which is very delicate to |
| 413 |
fix. The Sun serial port interrupt routine operates at |
| 414 |
interrupt priority level 12, while the timer interrupt routine |
| 415 |
operates at priority 10. Thus, it is possible that the PPS |
| 416 |
signal interrupt can occur during the timer interrupt routine, |
| 417 |
with result that a tick increment can be missed and the |
| 418 |
returned time early by one tick. It may happen that, if the CPU |
| 419 |
clock oscillator is within a few ppm of the PPS oscillator, |
| 420 |
this condition can persist for two or more successive PPS |
| 421 |
interrupts. A useful workaround has been to use a median filter |
| 422 |
to process the PPS sample offsets. In this filter the sample |
| 423 |
offsets in a window of 20 samples are sorted by offset and the |
| 424 |
six highest and six lowest outlyers discarded. The average of |
| 425 |
the eight samples remaining becomes the output of the filter. |
| 426 |
|
| 427 |
The problem is not nearly so serious when using the PPS signal |
| 428 |
to discipline the frequency of the CPU clock oscillator. In |
| 429 |
this case the quantity of interest is the contents of the |
| 430 |
microseconds counter only, which does not depend on the kernel |
| 431 |
time variable. |
| 432 |
|
| 433 |
2.4.2. External Clocks |
| 434 |
|
| 435 |
It is possible to replace the system clock function with an |
| 436 |
external bus peripheral. The TPRO device mentioned previously |
| 437 |
can be used to provide IRIG-synchronized time with a precision |
| 438 |
of 1 us. A driver for this device tprotime.c and header file |
| 439 |
tpro.h are included in the kernel.tar.Z distribution mentioned |
| 440 |
previously. Using this device the system clock is read directly |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
<span class="grey">Mills [Page 8]</span></pre> |
| 445 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-9" ></span> |
| 446 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 447 |
|
| 448 |
|
| 449 |
from the interface; however, the device does not record the |
| 450 |
year, so special provisions have to be made to obtain the year |
| 451 |
from the kernel time variable and initialize the driver |
| 452 |
accordingly. This feature is conditionally compiled in the code |
| 453 |
described below only if the EXT_CLOCK option is used in the |
| 454 |
kernel configuration file. |
| 455 |
|
| 456 |
While the system clock function is provided directly by the |
| 457 |
microtime() routine in the driver, the kernel time variable |
| 458 |
must be disciplined as well, since not all system timing |
| 459 |
functions use the microtime() routine. This is done by |
| 460 |
measuring the difference between the microtime() clock and |
| 461 |
kernel time variable and using the difference to adjust the |
| 462 |
kernel PLL as if the adjustment were provided by an external |
| 463 |
peer and NTP. |
| 464 |
|
| 465 |
A good deal of error checking is done in the TPRO driver, since |
| 466 |
the system clock is vulnerable to a misbehaving radio clock, |
| 467 |
IRIG signal source, interface cables and TPRO device itself. |
| 468 |
Unfortunately, there is no easy way to utilize the extensive |
| 469 |
diversity and redundancy capabilities available in the NTP |
| 470 |
synchronization daemon. In order to avoid disruptions that |
| 471 |
might occur if the TPRO time is far different from the kernel |
| 472 |
time variable, the latter is used instead of the former if the |
| 473 |
difference between the two exceeds 1000 s; presumably in that |
| 474 |
case operator intervention is required. |
| 475 |
|
| 476 |
2.4.3. External Oscillators |
| 477 |
|
| 478 |
Even if a source of PPS or IRIG signals is not available, it is |
| 479 |
still possible to improve the stability of the system clock |
| 480 |
through the use of a specialized bus peripheral. In order to |
| 481 |
explore the benefits of such an approach, a special SBus |
| 482 |
peripheral caled HIGHBALL has been constructed. The device |
| 483 |
includes a pair of 32-bit hardware counters in Unix timeval |
| 484 |
format, together with a precision, oven-controlled quartz |
| 485 |
oscillator with a stability of a few parts in 10^9. A driver |
| 486 |
for this device hightime.c and header file high.h are included |
| 487 |
in the kernel.tar.Z distribution mentioned previously. This |
| 488 |
feature is conditionally compiled in the code described below |
| 489 |
only if the EXT_CLOCK and HIGHBALL options are used in the |
| 490 |
kernel configuration file. |
| 491 |
|
| 492 |
Unlike the external clock case, where the system clock function |
| 493 |
is provided directly by the microtime() routine in the driver, |
| 494 |
the HIGHBALL counter offsets with respect to UTC must be |
| 495 |
provided first. This is done using the ordinary kernel PLL, |
| 496 |
but controlling the counter offsets directly, rather than the |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
<span class="grey">Mills [Page 9]</span></pre> |
| 501 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-10" ></span> |
| 502 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 503 |
|
| 504 |
|
| 505 |
kernel time variable. At first, this might seem to defeat the |
| 506 |
purpose of the design, since the jitter and wander of the |
| 507 |
synchronization source will affect the counter offsets and thus |
| 508 |
the accuracy of the time. However, the jitter is much reduced |
| 509 |
by the PLL and the wander is small, especially if using a radio |
| 510 |
clock or another primary server disciplined in the same way. |
| 511 |
In practice, the scheme works to reduce the incidental wander |
| 512 |
to a few parts in 10^8, or about the same as using the PPS |
| 513 |
signal. |
| 514 |
|
| 515 |
As in the previous case, the kernel time variable must be |
| 516 |
disciplined as well, since not all system timing functions use |
| 517 |
the microtime() routine. However, the kernel PLL cannot be used |
| 518 |
for this, since it is already in use providing offsets for the |
| 519 |
HIGHBALL counters. Therefore, a special correction is |
| 520 |
calculated from the difference between the microtime() clock |
| 521 |
and the kernel time variable and used to adjust the kernel time |
| 522 |
variable at the next timer interrupt. This somewhat roundabout |
| 523 |
approach is necessary in order that the adjustment does not |
| 524 |
cause the kernel time variable to jump backwards and possibly |
| 525 |
lose or duplicate a timer event. |
| 526 |
|
| 527 |
2.5 Other Features |
| 528 |
|
| 529 |
It is a design feature of the NTP architecture that the system |
| 530 |
clocks in a synchronization subnet are to read the same or nearly |
| 531 |
the same values before during and after a leap-second event, as |
| 532 |
declared by national standards bodies. The new model is designed |
| 533 |
to implement the leap event upon command by an ntp_adjtime() |
| 534 |
argument. The intricate and sometimes arcane details of the model |
| 535 |
and implementation are discussed in [<a href="#ref-3" title=""Modelling and analysis of computer network clocks"">3</a>] and [<a href="#ref-5" title=""Precision synchronizatin of computer network clocks"">5</a>]. Further details |
| 536 |
are given in the technical summary later in this memorandum. |
| 537 |
|
| 538 |
<span class="h2"><a class="selflink" id="section-3" href="#section-3">3</a>. Technical Summary</span> |
| 539 |
|
| 540 |
In order to more fully understand the workings of the model, a stand- |
| 541 |
alone simulator kern.c and header file timex.h are included in the |
| 542 |
kernel.tar.Z distribution mentioned previously. In addition, a |
| 543 |
complete C program kern_ntptime.c which implements the ntp_gettime() |
| 544 |
and ntp_adjtime() functions is provided, but with the vendor-specific |
| 545 |
argument-passing code deleted. Since the distribution is somewhat |
| 546 |
large, due to copious comments and ornamentation, it is impractical |
| 547 |
to include a listing of these programs in this memorandum. In any |
| 548 |
case, implementors may choose to snip portions of the simulator for |
| 549 |
use in new kernel designs, but, due to formatting conventions, this |
| 550 |
would be difficult if included in this memorandum. |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
<span class="grey">Mills [Page 10]</span></pre> |
| 557 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-11" ></span> |
| 558 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 559 |
|
| 560 |
|
| 561 |
The kern.c program is an implementation of an adaptive-parameter, |
| 562 |
first-order, type-II phase-lock loop. The system clock is implemented |
| 563 |
using a set of variables and algorithms defined in the simulator and |
| 564 |
driven by explicit offsets generated by a driver program also |
| 565 |
included in the program. The algorithms include code fragments almost |
| 566 |
identical to those in the machine-specific kernel implementations and |
| 567 |
operate in the same way, but the operations can be understood |
| 568 |
separately from any licensed source code into which these fragments |
| 569 |
may be integrated. The code fragments themselves are not derived from |
| 570 |
any licensed code. The following discussion assumes that the |
| 571 |
simulator code is available for inspection. |
| 572 |
|
| 573 |
3.1. PLL Simulation |
| 574 |
|
| 575 |
The simulator operates in conformance with the analytical model |
| 576 |
described in [<a href="#ref-3" title=""Modelling and analysis of computer network clocks"">3</a>]. The main() program operates as a driver for the |
| 577 |
fragments hardupdate(), hardclock(), second_overflow(), hardpps() |
| 578 |
and microtime(), although not all functions implemented in these |
| 579 |
fragments are simulated. The program simulates the PLL at each |
| 580 |
timer interrupt and prints a summary of critical program variables |
| 581 |
at each time update. |
| 582 |
|
| 583 |
There are three defined options in the kernel configuration file |
| 584 |
specific to each implementation. The PPS_SYNC option provides |
| 585 |
support for a pulse-per-second (PPS) signal, which is used to |
| 586 |
discipline the frequency of the CPU clock oscillator. The |
| 587 |
EXT_CLOCK option provides support for an external kernel-readable |
| 588 |
clock, such as the KSI/Odetics TPRO IRIG interface or HIGHBALL |
| 589 |
precision oscillator, both for the SBus. The TPRO option provides |
| 590 |
support for the former, while the HIGHBALL option provides support |
| 591 |
for the latter. External clocks are implemented as the microtime() |
| 592 |
clock driver, with the specific source code selected by the kernel |
| 593 |
configuration file. |
| 594 |
|
| 595 |
3.1.1. The hardupdate() Fragment |
| 596 |
|
| 597 |
The hardupdate() fragment is called by ntp_adjtime() as each |
| 598 |
update is computed to adjust the system clock phase and |
| 599 |
frequency. Note that the time constant is in units of powers of |
| 600 |
two, so that multiplies can be done by simple shifts. The phase |
| 601 |
variable is computed as the offset divided by the time |
| 602 |
constant. Then, the time since the last update is computed and |
| 603 |
clamped to a maximum (for robustness) and to zero if |
| 604 |
initializing. The offset is multiplied (sorry about the ugly |
| 605 |
multiply) by the result and divided by the square of the time |
| 606 |
constant and then added to the frequency variable. Note that |
| 607 |
all shifts are assumed to be positive and that a shift of a |
| 608 |
signed quantity to the right requires a little dance. |
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
<span class="grey">Mills [Page 11]</span></pre> |
| 613 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-12" ></span> |
| 614 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 615 |
|
| 616 |
|
| 617 |
With the defines given, the maximum time offset is determined |
| 618 |
by the size in bits of the long type (32 or 64) less the |
| 619 |
SHIFT_UPDATE scale factor (12) or at least 20 bits (signed). |
| 620 |
The scale factor is chosen so that there is no loss of |
| 621 |
significance in later steps, which may involve a right shift up |
| 622 |
to SHIFT_UPDATE bits. This results in a time adjustment range |
| 623 |
over +-512 ms. Since time_constant must be greater than or |
| 624 |
equal to zero, the maximum frequency offset is determined by |
| 625 |
the SHIFT_USEC scale factor (16) or at least 16 bits (signed). |
| 626 |
This results in a frequency adjustment range over +-31,500 ppm. |
| 627 |
|
| 628 |
In the addition step, the value of offset * mtemp is not |
| 629 |
greater than MAXPHASE * MAXSEC = 31 bits (signed), which will |
| 630 |
not overflow a long add on a 32-bit machine. There could be a |
| 631 |
loss of precision due to the right shift of up to 12 bits, |
| 632 |
since time_constant is bounded at 6. This results in a net |
| 633 |
worst-case frequency resolution of about .063 ppm, which is not |
| 634 |
significant for most quartz oscillators. The worst case could |
| 635 |
be realized only if the NTP peer misbehaves according to the |
| 636 |
protocol specification. |
| 637 |
|
| 638 |
The time_offset value is clamped upon entry. The time_phase |
| 639 |
variable is an accumulator, so is clamped to the tolerance on |
| 640 |
every call. This helps to damp transients before the oscillator |
| 641 |
frequency has been determined, as well as to satisfy the |
| 642 |
correctness assertions if the time synchronization protocol or |
| 643 |
implementation misbehaves. |
| 644 |
|
| 645 |
3.1.2. The hardclock() Fragment |
| 646 |
|
| 647 |
The hardclock() fragment is inserted in the hardware timer |
| 648 |
interrupt routine at the point the system clock is to be |
| 649 |
incremented. Previous to this fragment the time_update variable |
| 650 |
has been initialized to the value computed by the adjtime() |
| 651 |
system call in the stock Unix kernel, normally plus/minus the |
| 652 |
tickadj value, which is usually in the order of 5 us. The |
| 653 |
time_phase variable, which represents the instantaneous phase |
| 654 |
of the system clock, is advanced by time_adj, which is |
| 655 |
calculated in the second_overflow() fragment described below. |
| 656 |
If the value of time_phase exceeds 1 us in scaled units, |
| 657 |
time_update is increased by the (signed) excess and time_phase |
| 658 |
retains the residue. |
| 659 |
|
| 660 |
Except in the case of an external oscillator such as the |
| 661 |
HIGHBALL interface, the hardclock() fragment advances the |
| 662 |
system clock by the value of tick plus time_update. However, in |
| 663 |
the case of an external oscillator, the system clock is |
| 664 |
obtained directly from the interface and time_update used to |
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
<span class="grey">Mills [Page 12]</span></pre> |
| 669 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-13" ></span> |
| 670 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 671 |
|
| 672 |
|
| 673 |
discipline that interface instead. However, the system clock |
| 674 |
must still be disciplined as explained previously, so the value |
| 675 |
of clock_cpu computed by the second_overflow() fragment is used |
| 676 |
instead. |
| 677 |
|
| 678 |
3.1.3. The second_overflow() Fragment |
| 679 |
|
| 680 |
The second_overflow() fragment is inserted at the point where |
| 681 |
the microseconds field of the system time variable is being |
| 682 |
checked for overflow. Upon overflow the maximum error |
| 683 |
time_maxerror is increased by time_tolerance to reflect the |
| 684 |
maximum time offset due to oscillator frequency error. Then, |
| 685 |
the increment time_adj to advance the kernel time variable is |
| 686 |
calculated from the (scaled) time_offset and time_freq |
| 687 |
variables updated at the last call to the hardclock() fragment. |
| 688 |
|
| 689 |
The phase adjustment is calculated as a (signed) fraction of |
| 690 |
the time_offset remaining, where the fraction is added to |
| 691 |
time_adj, then subtracted from time_offset. This technique |
| 692 |
provides a rapid convergence when offsets are high, together |
| 693 |
with good resolution when offsets are low. The frequency |
| 694 |
adjustment is the sum of the (scaled) time_freq variable, an |
| 695 |
adjustment necessary when the tick interval does not evenly |
| 696 |
divide one second fixtick and PPS frequency adjustment pps_ybar |
| 697 |
(if configured). |
| 698 |
|
| 699 |
The scheme of approximating exact multiply/divide operations |
| 700 |
with shifts produces good results, except when an exact |
| 701 |
calculation is required, such as when the PPS signal is being |
| 702 |
used to discipling the CPU clock oscillator frequency, as |
| 703 |
described below. As long as the actual oscillator frequency is |
| 704 |
a power of two in seconds, no correction is required. However, |
| 705 |
in the SunOS kernel the clock frequency is 100 Hz, which |
| 706 |
results in an error factor of 0.78. In this case the code |
| 707 |
increases time_adj by a factor of 1.25, which results in an |
| 708 |
overall error less than three percent. |
| 709 |
|
| 710 |
On rollover of the day, the leap-second state machine described |
| 711 |
below determines whether a second is to be inserted or deleted |
| 712 |
in the timescale. The microtime() routine insures that the |
| 713 |
reported time is always monotonically increasing. |
| 714 |
|
| 715 |
3.1.4. The hardpps() Fragment |
| 716 |
|
| 717 |
The hardpps() fragment is operative only if the PPS_SYNC option |
| 718 |
is specified in the kernel configuration file. It is called |
| 719 |
from the serial port driver or equivalent interface at the on- |
| 720 |
time transition of the PPS signal. The fragment operates as a |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
<span class="grey">Mills [Page 13]</span></pre> |
| 725 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-14" ></span> |
| 726 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 727 |
|
| 728 |
|
| 729 |
first-order, type-I frequency-lock loop (FLL) controlled by the |
| 730 |
difference between the frequency represented by the pps_ybar |
| 731 |
variable and the frequency of the hardware clock oscillator. |
| 732 |
|
| 733 |
In order to avoid calling the microtime() routine more than |
| 734 |
once for each PPS transition, the interface requires the |
| 735 |
calling program to capture the system time and hardware counter |
| 736 |
contents at the on-time transition of the PPS signal and |
| 737 |
provide a pointer to the timestamp (Unix timeval) and counter |
| 738 |
contents as arguments to the hardpps() call. The hardware |
| 739 |
counter contents can be determined by saving the microseconds |
| 740 |
field of the system time, calling the microtime() routine, and |
| 741 |
subtracting the saved value. If a counter overflow has occured |
| 742 |
during the process, the resulting microseconds value will be |
| 743 |
negative, in which case the caller adds 1000000 to normalize |
| 744 |
the microseconds field. |
| 745 |
|
| 746 |
The frequency of the hardware oscillator can be determined from |
| 747 |
the difference in hardware counter readings at the beginning |
| 748 |
and end of the calibration interval divided by the duration of |
| 749 |
the interval. However, the oscillator frequency tolerance, as |
| 750 |
much as 100 ppm, may cause the difference to exceed the tick |
| 751 |
value, creating an ambiguity. In order to avoid this ambiguity, |
| 752 |
the hardware counter value at the beginning of the interval is |
| 753 |
increased by the current pps_ybar value once each second, but |
| 754 |
computed modulo the tick value. At the end of the interval, the |
| 755 |
difference between this value and the value computed from the |
| 756 |
hardware counter is used as a control signal sample for the |
| 757 |
FLL. |
| 758 |
|
| 759 |
Control signal samples which exceed the frequency tolerance are |
| 760 |
discarded, as well as samples resulting from excessive interval |
| 761 |
duration jitter. Surviving samples are then processed by a |
| 762 |
three-stage median filter. The signal which drives the FLL is |
| 763 |
derived from the median sample, while the average of |
| 764 |
differences between the other two samples is used as a measure |
| 765 |
of dispersion. If the dispersion is below the threshold |
| 766 |
pps_dispmax, the median is used to correct the pps_ybar value |
| 767 |
with a weight expressed as a shift PPS_AVG (2). In addition to |
| 768 |
the averaging function, pps_disp is increased by the amount |
| 769 |
pps_dispinc once each second. The result is that, should the |
| 770 |
dispersion be exceptionally high, or if the PPS signal fails |
| 771 |
for some reason, the pps_disp will eventually exceed |
| 772 |
pps_dispmax and raise an alarm. |
| 773 |
|
| 774 |
Initially, an approximate value for pps_ybar is not known, so |
| 775 |
the duration of the calibration interval must be kept small to |
| 776 |
avoid overflowing the tick. The time difference at the end of |
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
<span class="grey">Mills [Page 14]</span></pre> |
| 781 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-15" ></span> |
| 782 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 783 |
|
| 784 |
|
| 785 |
the calibration interval is measured. If greater than a |
| 786 |
fraction tick/4, the interval is reduced by half. If less than |
| 787 |
this fraction for four successive calibration intervals, the |
| 788 |
interval is doubled. This design automatically adapts to |
| 789 |
nominal jitter in the PPS signal, as well as the value of tick. |
| 790 |
The duration of the calibration interval is set by the |
| 791 |
pps_shift variable as a shift in powers of two. The minimum |
| 792 |
value PPS_SHIFT (2) is chosen so that with the highest CPU |
| 793 |
oscillator frequency 1024 Hz and frequency tolerance 100 ppm |
| 794 |
the tick will not overflow. The maximum value PPS_SHIFTMAX (8) |
| 795 |
is chosen such that the maximum averaging time is about 1000 s |
| 796 |
as determined by measurements of Allan variance [<a href="#ref-5" title=""Precision synchronizatin of computer network clocks"">5</a>]. |
| 797 |
|
| 798 |
Should the PPS signal fail, the current frequency estimate |
| 799 |
pps_ybar continues to be used, so the nominal frequency remains |
| 800 |
correct subject only to the instability of the undisciplined |
| 801 |
oscillator. The procedure to save and restore the frequency |
| 802 |
estimate works as follows. When setting the frequency from a |
| 803 |
file, the time_freq value is set as the file value minus the |
| 804 |
pps_ybar value; when retrieving the frequency, the two values |
| 805 |
are added before saving in the file. This scheme provides a |
| 806 |
seamless interface should the PPS signal fail or the kernel |
| 807 |
configuration change. Note that the frequency discipline is |
| 808 |
active whether or not the synchronization daemon is active. |
| 809 |
Since all Unix systems take some time after reboot to build a |
| 810 |
running system, usually by that time the discipline process has |
| 811 |
already settled down and the initial transients due to |
| 812 |
frequency discipline have damped out. |
| 813 |
|
| 814 |
3.1.4. External Clock Interface |
| 815 |
|
| 816 |
The external clock driver interface is implemented with two |
| 817 |
routines, microtime(), which returns the current clock time, |
| 818 |
and clock_set(), which furnishes the apparent system time |
| 819 |
derived from the kernel time variable. The latter routine is |
| 820 |
called only when the clock is set using the settimeofday() |
| 821 |
system call, but can be called from within the driver, such as |
| 822 |
when the year rolls over, for example. |
| 823 |
|
| 824 |
In the stock SunOS kernel and modified Ultrix and OSF/1 |
| 825 |
kernels, the microtime() routine returns the kernel time |
| 826 |
variable plus an interpolation between timer interrupts based |
| 827 |
on the contents of a hardware counter. In the case of an |
| 828 |
external clock, such as described above, the system clock is |
| 829 |
read directly from the hardware clock registers. Examples of |
| 830 |
external clock drivers are in the tprotime.c and hightime.c |
| 831 |
routines included in the kernel.tar.Z distribution. |
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
<span class="grey">Mills [Page 15]</span></pre> |
| 837 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-16" ></span> |
| 838 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 839 |
|
| 840 |
|
| 841 |
The external clock routines return a status code which |
| 842 |
indicates whether the clock is operating correctly and the |
| 843 |
nature of the problem, if not. The return code is interpreted |
| 844 |
by the ntp_gettime() system call, which transitions the status |
| 845 |
state machine to the TIME_ERR state if an error code is |
| 846 |
returned. This is the only error checking implemented for the |
| 847 |
external clock in the present version of the code. |
| 848 |
|
| 849 |
The simulator has been used to check the PLL operation over the |
| 850 |
design envelope of +-512 ms in time error and +-100 ppm in |
| 851 |
frequency error. This confirms that no overflows occur and that |
| 852 |
the loop initially converges in about 15 minutes for timer |
| 853 |
interrupt rates from 50 Hz to 1024 Hz. The loop has a normal |
| 854 |
overshoot of a few percent and a final convergence time of several |
| 855 |
hours, depending on the initial time and frequency error. |
| 856 |
|
| 857 |
3.2. Leap Seconds |
| 858 |
|
| 859 |
It does not seem generally useful in the user application |
| 860 |
interface to provide additional details private to the kernel and |
| 861 |
synchronization protocol, such as stratum, reference identifier, |
| 862 |
reference timestamp and so forth. It would in principle be |
| 863 |
possible for the application to independently evaluate the quality |
| 864 |
of time and project into the future how long this time might be |
| 865 |
"valid." However, to do that properly would duplicate the |
| 866 |
functionality of the synchronization protocol and require |
| 867 |
knowledge of many mundane details of the platform architecture, |
| 868 |
such as the subnet configuration, reachability status and related |
| 869 |
variables. For the curious, the ntp_adjtime() system call can be |
| 870 |
used to reveal some of these mysteries. |
| 871 |
|
| 872 |
However, the user application may need to know whether a leap |
| 873 |
second is scheduled, since this might affect interval calculations |
| 874 |
spanning the event. A leap-warning condition is determined by the |
| 875 |
synchronization protocol (if remotely synchronized), by the |
| 876 |
timecode receiver (if available), or by the operator (if awake). |
| 877 |
This condition is set by the synchronization daemon on the day the |
| 878 |
leap second is to occur (30 June or 31 December, as announced) by |
| 879 |
specifying in a ntp_adjtime() system call a clock status of either |
| 880 |
TIME_DEL, if a second is to be deleted, or TIME_INS, if a second |
| 881 |
is to be inserted. Note that, on all occasions since the inception |
| 882 |
of the leap-second scheme, there has never been a deletion |
| 883 |
occasion, nor is there likely to be one in future. If the value is |
| 884 |
TIME_DEL, the kernel adds one second to the system time |
| 885 |
immediately following second 23:59:58 and resets the clock status |
| 886 |
to TIME_OK. If the value is TIME_INS, the kernel subtracts one |
| 887 |
second from the system time immediately following second 23:59:59 |
| 888 |
and resets the clock status to TIME_OOP, in effect causing system |
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
<span class="grey">Mills [Page 16]</span></pre> |
| 893 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-17" ></span> |
| 894 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 895 |
|
| 896 |
|
| 897 |
time to repeat second 59. Immediately following the repeated |
| 898 |
second, the kernel resets the clock status to TIME_OK. |
| 899 |
|
| 900 |
Depending upon the system call implementation, the reported time |
| 901 |
during a leap second may repeat (with the TIME_OOP return code set |
| 902 |
to advertise that fact) or be monotonically adjusted until system |
| 903 |
time "catches up" to reported time. With the latter scheme the |
| 904 |
reported time will be correct before and shortly after the leap |
| 905 |
second (depending on the number of microtime() calls during the |
| 906 |
leap second), but freeze or slowly advance during the leap second |
| 907 |
itself. However, Most programs will probably use the ctime() |
| 908 |
library routine to convert from timeval (seconds, microseconds) |
| 909 |
format to tm format (seconds, minutes,...). If this routine is |
| 910 |
modified to use the ntp_gettime() system call and inspect the |
| 911 |
return code, it could simply report the leap second as second 60. |
| 912 |
|
| 913 |
3.3. Clock Status State Machine |
| 914 |
|
| 915 |
The various options possible with the system clock model described |
| 916 |
in this memorandum require a careful examination of the state |
| 917 |
transitions, status indications and recovery procedures should a |
| 918 |
crucial signal or interface fail. In this section is presented a |
| 919 |
prototype state machine designed to support leap second insertion |
| 920 |
and deletion, as well as reveal various kinds of errors in the |
| 921 |
synchronization process. The states of this machine are decoded as |
| 922 |
follows: |
| 923 |
|
| 924 |
TIME_OK If an external clock is present, it is working properly |
| 925 |
and the system clock is derived from it. If no external |
| 926 |
clock is present, the synchronization daemon is working |
| 927 |
properly and the system clock is synchronized to a radio |
| 928 |
clock or one or more peers. |
| 929 |
|
| 930 |
TIME_INS An insertion of one second in the system clock has been |
| 931 |
declared following the last second of the current day, |
| 932 |
but has not yet been executed. |
| 933 |
|
| 934 |
TIME_DEL A deletion of the last second of the current day has |
| 935 |
been declared, but not yet executed. |
| 936 |
|
| 937 |
TIME_OOP An insertion of one second in the system clock has been |
| 938 |
declared following the last second of the current day. |
| 939 |
The second is in progress, but not yet completed. |
| 940 |
Library conversion routines should interpret this second |
| 941 |
as 23:59:60. |
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
<span class="grey">Mills [Page 17]</span></pre> |
| 949 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-18" ></span> |
| 950 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 951 |
|
| 952 |
|
| 953 |
TIME_BAD Either (a) the synchronization daemon has declared the |
| 954 |
protocol is not working properly, (b) all sources of |
| 955 |
outside synchronization have been lost or (c) an |
| 956 |
external clock is present and it has just become |
| 957 |
operational following a non-operational condition. |
| 958 |
|
| 959 |
TIME_ERR An external clock is present, but is in a non- |
| 960 |
operational condition. |
| 961 |
|
| 962 |
In all except the TIME_ERR state the system clock is derived from |
| 963 |
either an external clock, if present, or the kernel time variable, |
| 964 |
if not. In the TIME_ERR state the external clock is present, but |
| 965 |
not working properly, so the system clock may be derived from the |
| 966 |
kernel time variable. The following diagram indicates the normal |
| 967 |
transitions of the state machine. Not all valid transitions are |
| 968 |
shown. |
| 969 |
|
| 970 |
+--------+ +--------+ +--------+ +--------+ |
| 971 |
| | | | | | | | |
| 972 |
|TIME_BAD|---->|TIME_OK |<----|TIME_OOP|<----|TIME_INS| |
| 973 |
| | | | | | | | |
| 974 |
+--------+ +--------+ +--------+ +--------+ |
| 975 |
A A |
| 976 |
| | |
| 977 |
| | |
| 978 |
+--------+ +--------+ |
| 979 |
| | | | |
| 980 |
|TIME_ERR| |TIME_DEL| |
| 981 |
| | | | |
| 982 |
+--------+ +--------+ |
| 983 |
|
| 984 |
The state machine makes a transition once each second at an |
| 985 |
instant where the microseconds field of the kernel time variable |
| 986 |
overflows and one second is added to the seconds field. However, |
| 987 |
this condition is checked at each timer interrupt, which may not |
| 988 |
exactly coincide with the actual instant of overflow. This may |
| 989 |
lead to some interesting anomalies, such as a status indication of |
| 990 |
a leap second in progress (TIME_OOP) when actually the leap second |
| 991 |
had already expired. |
| 992 |
|
| 993 |
The following state transitions are executed automatically by the |
| 994 |
kernel: |
| 995 |
|
| 996 |
any state -> TIME_ERR This transition occurs when an external |
| 997 |
clock is present and an attempt is made to |
| 998 |
read it when in a non-operational |
| 999 |
condition. |
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
<span class="grey">Mills [Page 18]</span></pre> |
| 1005 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-19" ></span> |
| 1006 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 1007 |
|
| 1008 |
|
| 1009 |
TIME_INS -> TIME_OOP This transition occurs immediately |
| 1010 |
following second 86,400 of the current day |
| 1011 |
when an insert-second event has been |
| 1012 |
declared. |
| 1013 |
|
| 1014 |
TIME_OOP -> TIME_OK This transition occurs immediately |
| 1015 |
following second 86,401 of the current |
| 1016 |
day; that is, one second after entry to |
| 1017 |
the TIME_OOP state. |
| 1018 |
|
| 1019 |
TIME_DEL -> TIME_OK This transition occurs immediately |
| 1020 |
following second 86,399 of the current day |
| 1021 |
when a delete-second event has been |
| 1022 |
declared. |
| 1023 |
|
| 1024 |
The following state transitions are executed by specific |
| 1025 |
ntp_adjtime() system calls: |
| 1026 |
|
| 1027 |
TIME_OK -> TIME_INS This transition occurs as the result of a |
| 1028 |
ntp_adjtime() system call to declare an |
| 1029 |
insert-second event. |
| 1030 |
|
| 1031 |
TIME_OK -> TIME_DEL This transition occurs as the result of a |
| 1032 |
ntp_adjtime() system call to declare a |
| 1033 |
delete-second event. |
| 1034 |
|
| 1035 |
any state -> TIME_BAD This transition occurs as the result of a |
| 1036 |
ntp_adjtime() system call to declare loss |
| 1037 |
of all sources of synchronization or in |
| 1038 |
other cases of error. |
| 1039 |
|
| 1040 |
The following table summarizes the actions just before, during and |
| 1041 |
just after a leap-second event. Each line in the table shows the |
| 1042 |
UTC and NTP times at the beginning of the second. The left column |
| 1043 |
shows the behavior when no leap event is to occur. In the middle |
| 1044 |
column the state machine is in TIME_INS at the end of UTC second |
| 1045 |
23:59:59 and the NTP time has just reached 400. The NTP time is |
| 1046 |
set back one second to 399 and the machine enters TIME_OOP. At the |
| 1047 |
end of the repeated second the machine enters TIME_OK and the UTC |
| 1048 |
and NTP times are again in correspondence. In the right column the |
| 1049 |
state machine is in TIME_DEL at the end of UTC second 23:59:58 and |
| 1050 |
the NTP time has just reached 399. The NTP time is incremented, |
| 1051 |
the machine enters TIME_OK and both UTC and NTP times are again in |
| 1052 |
correspondence. |
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
<span class="grey">Mills [Page 19]</span></pre> |
| 1061 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-20" ></span> |
| 1062 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 1063 |
|
| 1064 |
|
| 1065 |
No Leap Leap Insert Leap Delete |
| 1066 |
UTC NTP UTC NTP UTC NTP |
| 1067 |
--------------------------------------------- |
| 1068 |
23:59:58|398 23:59:58|398 23:59:58|398 |
| 1069 |
| | | |
| 1070 |
23:59:59|399 23:59:59|399 00:00:00|400 |
| 1071 |
| | | |
| 1072 |
00:00:00|400 23:59:60|399 00:00:01|401 |
| 1073 |
| | | |
| 1074 |
00:00:01|401 00:00:00|400 00:00:02|402 |
| 1075 |
| | | |
| 1076 |
00:00:02|402 00:00:01|401 00:00:03|403 |
| 1077 |
| | | |
| 1078 |
|
| 1079 |
To determine local midnight without fuss, the kernel code simply |
| 1080 |
finds the residue of the time.tv_sec (or time.tv_sec + 1) value |
| 1081 |
mod 86,400, but this requires a messy divide. Probably a better |
| 1082 |
way to do this is to initialize an auxiliary counter in the |
| 1083 |
settimeofday() routine using an ugly divide and increment the |
| 1084 |
counter at the same time the time.tv_sec is incremented in the |
| 1085 |
timer interrupt routine. For future embellishment. |
| 1086 |
|
| 1087 |
<span class="h2"><a class="selflink" id="section-4" href="#section-4">4</a>. Programming Model and Interfaces</span> |
| 1088 |
|
| 1089 |
This section describes the programming model for the synchronization |
| 1090 |
daemon and user application programs. The ideas are based on |
| 1091 |
suggestions from Jeff Mogul and Philip Gladstone and a similar |
| 1092 |
interface designed by the latter. It is important to point out that |
| 1093 |
the functionality of the original Unix adjtime() system call is |
| 1094 |
preserved, so that the modified kernel will work as the unmodified |
| 1095 |
one, should the new features not be in use. In this case the |
| 1096 |
ntp_adjtime() system call can still be used to read and write kernel |
| 1097 |
variables that might be used by a synchronization daemon other than |
| 1098 |
NTP, for example. |
| 1099 |
|
| 1100 |
4.1. The ntp_gettime() System Call |
| 1101 |
|
| 1102 |
The syntax and semantics of the ntp_gettime() call are given in |
| 1103 |
the following fragment of the timex.h header file. This file is |
| 1104 |
identical, except for the SHIFT_HZ define, in the SunOS, Ultrix |
| 1105 |
and OSF/1 kernel distributions. (The SHIFT_HZ define represents |
| 1106 |
the logarithm to the base 2 of the clock oscillator frequency |
| 1107 |
specific to each system type.) Note that the timex.h file calls |
| 1108 |
the syscall.h system header file, which must be modified to define |
| 1109 |
the SYS_ntp_gettime system call specific to each system type. The |
| 1110 |
kernel distributions include directions on how to do this. |
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
<span class="grey">Mills [Page 20]</span></pre> |
| 1117 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-21" ></span> |
| 1118 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 1119 |
|
| 1120 |
|
| 1121 |
/* |
| 1122 |
* This header file defines the Network Time Protocol (NTP) |
| 1123 |
* interfaces for user and daemon application programs. These are |
| 1124 |
* implemented using private system calls and data structures and |
| 1125 |
* require specific kernel support. |
| 1126 |
* |
| 1127 |
* NAME |
| 1128 |
* ntp_gettime - NTP user application interface |
| 1129 |
* |
| 1130 |
* SYNOPSIS |
| 1131 |
* #include <sys/timex.h> |
| 1132 |
* |
| 1133 |
* int system call(SYS_ntp_gettime, tptr) |
| 1134 |
* |
| 1135 |
* int SYS_ntp_gettime defined in syscall.h header file |
| 1136 |
* struct ntptimeval *tptr pointer to ntptimeval structure |
| 1137 |
* |
| 1138 |
* NTP user interface - used to read kernel clock values |
| 1139 |
* Note: maximum error = NTP synch distance = dispersion + delay / |
| 1140 |
* 2 |
| 1141 |
* estimated error = NTP dispersion. |
| 1142 |
*/ |
| 1143 |
struct ntptimeval { |
| 1144 |
struct timeval time; /* current time */ |
| 1145 |
long maxerror; /* maximum error (us) */ |
| 1146 |
long esterror; /* estimated error (us) */ |
| 1147 |
}; |
| 1148 |
|
| 1149 |
The ntp_gettime() system call returns three values in the |
| 1150 |
ntptimeval structure: the current time in unix timeval format plus |
| 1151 |
the maximum and estimated errors in microseconds. While the 32-bit |
| 1152 |
long data type limits the error quantities to something more than |
| 1153 |
an hour, in practice this is not significant, since the protocol |
| 1154 |
itself will declare an unsynchronized condition well below that |
| 1155 |
limit. In the NTP Version 3 specification, if the protocol |
| 1156 |
computes either of these values in excess of 16 seconds, they are |
| 1157 |
clamped to that value and the system clock declared |
| 1158 |
unsynchronized. |
| 1159 |
|
| 1160 |
Following is a detailed description of the ntptimeval structure |
| 1161 |
members. |
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
<span class="grey">Mills [Page 21]</span></pre> |
| 1173 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-22" ></span> |
| 1174 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 1175 |
|
| 1176 |
|
| 1177 |
struct timeval time; /* current time */ |
| 1178 |
|
| 1179 |
This member returns the current system time, expressed as a |
| 1180 |
Unix timeval structure. The timeval structure consists of two |
| 1181 |
32-bit words; the first returns the number of seconds past 1 |
| 1182 |
January 1970, while the second returns the number of |
| 1183 |
microseconds. |
| 1184 |
|
| 1185 |
long maxerror; /* maximum error (us) */ |
| 1186 |
|
| 1187 |
This member returns the time_maxerror kernel variable in |
| 1188 |
microseconds. See the entry for this variable in <a href="#section-5">section 5</a> for |
| 1189 |
additional information. |
| 1190 |
|
| 1191 |
long esterror; /* estimated error (us) */ |
| 1192 |
|
| 1193 |
This member returns the time_esterror kernel variable in |
| 1194 |
microseconds. See the entry for this variable in <a href="#section-5">section 5</a> for |
| 1195 |
additional information. |
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
<span class="grey">Mills [Page 22]</span></pre> |
| 1229 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-23" ></span> |
| 1230 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 1231 |
|
| 1232 |
|
| 1233 |
4.2. The ntp_adjtime() System Call |
| 1234 |
|
| 1235 |
The syntax and semantics of the ntp_adjtime() call are given in |
| 1236 |
the following fragment of the timex.h header file. Note that, as |
| 1237 |
in the ntp_gettime() system call, the syscall.h system header file |
| 1238 |
must be modified to define the SYS_ntp_adjtime system call |
| 1239 |
specific to each system type. |
| 1240 |
|
| 1241 |
/* |
| 1242 |
* NAME |
| 1243 |
* ntp_adjtime - NTP daemon application interface |
| 1244 |
* |
| 1245 |
* SYNOPSIS |
| 1246 |
* #include <sys/timex.h> |
| 1247 |
* |
| 1248 |
* int system call(SYS_ntp_adjtime, mode, tptr) |
| 1249 |
* |
| 1250 |
* int SYS_ntp_adjtime defined in syscall.h header file |
| 1251 |
* struct timex *tptr pointer to timex structure |
| 1252 |
* |
| 1253 |
* NTP daemon interface - used to discipline kernel clock |
| 1254 |
* oscillator |
| 1255 |
*/ |
| 1256 |
struct timex { |
| 1257 |
int mode; /* mode selector */ |
| 1258 |
long offset; /* time offset (us) */ |
| 1259 |
long frequency; /* frequency offset (scaled ppm) */ |
| 1260 |
long maxerror; /* maximum error (us) */ |
| 1261 |
long esterror; /* estimated error (us) */ |
| 1262 |
int status; /* clock command/status */ |
| 1263 |
long time_constant; /* pll time constant */ |
| 1264 |
long precision; /* clock precision (us) (read only) |
| 1265 |
*/ |
| 1266 |
long tolerance; /* clock frequency tolerance (scaled |
| 1267 |
* ppm) (read only) */ |
| 1268 |
/* |
| 1269 |
* The following read-only structure members are implemented |
| 1270 |
* only if the PPS signal discipline is configured in the |
| 1271 |
* kernel. |
| 1272 |
*/ |
| 1273 |
long ybar; /* frequency estimate (scaled ppm) */ |
| 1274 |
long disp; /* dispersion estimate (scaled ppm) |
| 1275 |
*/ |
| 1276 |
int shift; /* interval duration (s) (shift) */ |
| 1277 |
long calcnt; /* calibration intervals */ |
| 1278 |
long jitcnt; /* jitter limit exceeded */ |
| 1279 |
long discnt; /* dispersion limit exceeded */ |
| 1280 |
}; |
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
<span class="grey">Mills [Page 23]</span></pre> |
| 1285 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-24" ></span> |
| 1286 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 1287 |
|
| 1288 |
|
| 1289 |
The ntp_adjtime() system call is used to read and write certain |
| 1290 |
time-related kernel variables summarized in this and subsequent |
| 1291 |
sections. Writing these variables can only be done in superuser |
| 1292 |
mode. To write a variable, the mode structure member is set with |
| 1293 |
one or more bits, one of which is assigned each of the following |
| 1294 |
variables in turn. The current values for all variables are |
| 1295 |
returned in any case; therefore, a mode argument of zero means to |
| 1296 |
return these values without changing anything. |
| 1297 |
|
| 1298 |
Following is a description of the timex structure members. |
| 1299 |
|
| 1300 |
int mode; /* mode selector */ |
| 1301 |
|
| 1302 |
This is a bit-coded variable selecting one or more structure |
| 1303 |
members, with one bit assigned each member. If a bit is set, |
| 1304 |
the value of the associated member variable is copied to the |
| 1305 |
corresponding kernel variable; if not, the member is ignored. |
| 1306 |
The bits are assigned as given in the following fragment of the |
| 1307 |
timex.h header file. Note that the precision and tolerance are |
| 1308 |
determined by the kernel and cannot be changed by |
| 1309 |
ntp_adjtime(). |
| 1310 |
|
| 1311 |
/* |
| 1312 |
* Mode codes (timex.mode) |
| 1313 |
*/ |
| 1314 |
#define ADJ_OFFSET 0x0001 /* time offset */ |
| 1315 |
#define ADJ_FREQUENCY 0x0002 /* frequency offset */ |
| 1316 |
#define ADJ_MAXERROR 0x0004 /* maximum time error */ |
| 1317 |
#define ADJ_ESTERROR 0x0008 /* estimated time error */ |
| 1318 |
#define ADJ_STATUS 0x0010 /* clock status */ |
| 1319 |
#define ADJ_TIMECONST 0x0020 /* pll time constant */ |
| 1320 |
|
| 1321 |
long offset; /* time offset (us) */ |
| 1322 |
|
| 1323 |
If selected, this member replaces the value of the time_offset |
| 1324 |
kernel variable in microseconds. The absolute value must be |
| 1325 |
less than MAXPHASE microseconds defined in the timex.h header |
| 1326 |
file. See the entry for this variable in <a href="#section-5">section 5</a> for |
| 1327 |
additional information. |
| 1328 |
|
| 1329 |
If within range and the PPS signal and/or external oscillator |
| 1330 |
are configured and operating properly, the clock status is |
| 1331 |
automatically set to TIME_OK. |
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
<span class="grey">Mills [Page 24]</span></pre> |
| 1341 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-25" ></span> |
| 1342 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 1343 |
|
| 1344 |
|
| 1345 |
long time_constant; /* pll time constant */ |
| 1346 |
|
| 1347 |
If selected, this member replaces the value of the |
| 1348 |
time_constant kernel variable. The value must be between zero |
| 1349 |
and MAXTC defined in the timex.h header file. See the entry for |
| 1350 |
this variable in <a href="#section-5">section 5</a> for additional information. |
| 1351 |
|
| 1352 |
long frequency; /* frequency offset (scaled ppm) */ |
| 1353 |
|
| 1354 |
If selected, this member replaces the value of the |
| 1355 |
time_frequency kernel variable. The value is in ppm, with the |
| 1356 |
integer part in the high order 16 bits and fraction in the low |
| 1357 |
order 16 bits. The absolute value must be in the range less |
| 1358 |
than MAXFREQ ppm defined in the timex.h header file. See the |
| 1359 |
entry for this variable in <a href="#section-5">section 5</a> for additional |
| 1360 |
information. |
| 1361 |
|
| 1362 |
long maxerror; /* maximum error (us) */ |
| 1363 |
|
| 1364 |
If selected, this member replaces the value of the |
| 1365 |
time_maxerror kernel variable in microseconds. See the entry |
| 1366 |
for this variable in <a href="#section-5">section 5</a> for additional information. |
| 1367 |
|
| 1368 |
long esterror; /* estimated error (us) */ |
| 1369 |
|
| 1370 |
If selected, this member replaces the value of the |
| 1371 |
time_esterror kernel variable in microseconds. See the entry |
| 1372 |
for this variable in <a href="#section-5">section 5</a> for additional information. |
| 1373 |
|
| 1374 |
int status; /* clock command/status */ |
| 1375 |
|
| 1376 |
If selected, this member replaces the value of the time_status |
| 1377 |
kernel variable. See the entry for this variable in <a href="#section-5">section 5</a> |
| 1378 |
for additional information. |
| 1379 |
|
| 1380 |
In order to set this variable by ntp_adjtime(), either (a) the |
| 1381 |
current clock status must be TIME_OK or (b) the member value is |
| 1382 |
TIME_BAD; that is, the ntp_adjtime() call can always set the |
| 1383 |
clock to the unsynchronized state or, if the clock is running |
| 1384 |
correctly, can set it to any state. In any case, the |
| 1385 |
ntp_adjtime() call always returns the current state in this |
| 1386 |
member, so the caller can determine whether or not the request |
| 1387 |
succeeded. |
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
<span class="grey">Mills [Page 25]</span></pre> |
| 1397 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-26" ></span> |
| 1398 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 1399 |
|
| 1400 |
|
| 1401 |
long time_constant; /* pll time constant */ |
| 1402 |
|
| 1403 |
If selected, this member replaces the value of the |
| 1404 |
time_constant kernel variable. The value must be between zero |
| 1405 |
and MAXTC defined in the timex.h header file. See the entry for |
| 1406 |
this variable in <a href="#section-5">section 5</a> for additional information. |
| 1407 |
|
| 1408 |
long precision; /* clock precision (us) (read only) */ |
| 1409 |
|
| 1410 |
This member returns the time_precision kernel variable in |
| 1411 |
microseconds. The variable can be written only by the kernel. |
| 1412 |
See the entry for this variable in <a href="#section-5">section 5</a> for additional |
| 1413 |
information. |
| 1414 |
|
| 1415 |
long tolerance; /* clock frequency tolerance (scaled ppm) |
| 1416 |
*/ |
| 1417 |
|
| 1418 |
This member returns the time_tolerance kernel variable in |
| 1419 |
microseconds. The variable can be written only by the kernel. |
| 1420 |
See the entry for this variable in <a href="#section-5">section 5</a> for additional |
| 1421 |
information. |
| 1422 |
|
| 1423 |
long ybar; /* frequency estimate (scaled ppm) */ |
| 1424 |
|
| 1425 |
This member returns the pps_ybar kernel variable in |
| 1426 |
microseconds. The variable can be written only by the kernel. |
| 1427 |
See the entry for this variable in <a href="#section-5">section 5</a> for additional |
| 1428 |
information. |
| 1429 |
|
| 1430 |
long disp; /* dispersion estimate (scaled ppm) */ |
| 1431 |
|
| 1432 |
This member returns the pps_disp kernel variable in |
| 1433 |
microseconds. The variable can be written only by the kernel. |
| 1434 |
See the entry for this variable in <a href="#section-5">section 5</a> for additional |
| 1435 |
information. |
| 1436 |
|
| 1437 |
int shift; /* interval duration (s) (shift) */ |
| 1438 |
|
| 1439 |
This member returns the pps_shift kernel variable in |
| 1440 |
microseconds. The variable can be written only by the kernel. |
| 1441 |
See the entry for this variable in <a href="#section-5">section 5</a> for additional |
| 1442 |
information. |
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
<span class="grey">Mills [Page 26]</span></pre> |
| 1453 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-27" ></span> |
| 1454 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 1455 |
|
| 1456 |
|
| 1457 |
long calcnt; /* calibration intervals */ |
| 1458 |
|
| 1459 |
This member returns the pps_calcnt kernel variable in |
| 1460 |
microseconds. The variable can be written only by the kernel. |
| 1461 |
See the entry for this variable in <a href="#section-5">section 5</a> for additional |
| 1462 |
information. |
| 1463 |
|
| 1464 |
long jitcnt; /* jitter limit exceeded */ |
| 1465 |
|
| 1466 |
This member returns the pps_jittcnt kernel variable in |
| 1467 |
microseconds. The variable can be written only by the kernel. |
| 1468 |
See the entry for this variable in <a href="#section-5">section 5</a> for additional |
| 1469 |
information. |
| 1470 |
|
| 1471 |
long discnt; /* dispersion limit exceeded */ |
| 1472 |
|
| 1473 |
This member returns the pps_discnt kernel variable in |
| 1474 |
microseconds. The variable can be written only by the kernel. |
| 1475 |
See the entry for this variable in <a href="#section-5">section 5</a> for additional |
| 1476 |
information. |
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
<span class="grey">Mills [Page 27]</span></pre> |
| 1509 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-28" ></span> |
| 1510 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 1511 |
|
| 1512 |
|
| 1513 |
4.3. Command/Status Codes |
| 1514 |
|
| 1515 |
The kernel routines use the system clock status variable |
| 1516 |
time_status, which records whether the clock is synchronized, |
| 1517 |
waiting for a leap second, etc. The value of this variable is |
| 1518 |
returned as the result code by both the ntp_gettime() and |
| 1519 |
ntp_adjtime() system calls. In addition, it can be explicitly read |
| 1520 |
and written using the ntp_adjtime() system call, but can be |
| 1521 |
written only in superuser mode. Values presently defined in the |
| 1522 |
timex.h header file are as follows: |
| 1523 |
|
| 1524 |
/* |
| 1525 |
* Clock command/status codes (timex.status) |
| 1526 |
*/ |
| 1527 |
#define TIME_OK 0 /* clock synchronized */ |
| 1528 |
#define TIME_INS 1 /* insert leap second */ |
| 1529 |
#define TIME_DEL 2 /* delete leap second */ |
| 1530 |
#define TIME_OOP 3 /* leap second in progress */ |
| 1531 |
#define TIME_BAD 4 /* kernel clock not synchronized */ |
| 1532 |
#define TIME_ERR 5 /* external oscillator not |
| 1533 |
synchronized */ |
| 1534 |
|
| 1535 |
A detailed description of these codes as used by the leap-second |
| 1536 |
state machine is given later in this memorandum. In case of a |
| 1537 |
negative result code, the kernel has intercepted an invalid |
| 1538 |
address or (in case of the ntp_adjtime() system call), a superuser |
| 1539 |
violation. |
| 1540 |
|
| 1541 |
<span class="h2"><a class="selflink" id="section-5" href="#section-5">5</a>. Kernel Variables</span> |
| 1542 |
|
| 1543 |
This section contains a list of kernel variables and a detailed |
| 1544 |
description of their function, initial value, scaling and limits. |
| 1545 |
|
| 1546 |
5.1. Interface Variables |
| 1547 |
|
| 1548 |
The following variables are read and set by the ntp_adjtime() |
| 1549 |
system call. Additional automatic variables are used as |
| 1550 |
temporaries as described in the code fragments. |
| 1551 |
|
| 1552 |
int time_status = TIME_BAD; |
| 1553 |
|
| 1554 |
This variable controls the state machine used to insert or |
| 1555 |
delete leap seconds and show the status of the timekeeping |
| 1556 |
system, PPS signal and external oscillator, if configured. |
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
<span class="grey">Mills [Page 28]</span></pre> |
| 1565 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-29" ></span> |
| 1566 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 1567 |
|
| 1568 |
|
| 1569 |
long time_offset = 0; |
| 1570 |
|
| 1571 |
This variable is used by the PLL to adjust the system time in |
| 1572 |
small increments. It is scaled by (1 << SHIFT_UPDATE) (12) in |
| 1573 |
microseconds. The maximum value that can be represented is |
| 1574 |
about +-512 ms and the minimum value or precision is a few |
| 1575 |
parts in 10^10 s. |
| 1576 |
|
| 1577 |
long time_constant = 0; /* pll time constant */ |
| 1578 |
|
| 1579 |
This variable determines the bandwidth or "stiffness" of the |
| 1580 |
PLL. The value is used as a shift between zero and MAXTC (6), |
| 1581 |
with the effective PLL time constant equal to a multiple of (1 |
| 1582 |
<< time_constant) in seconds. For room-temperature quartz |
| 1583 |
oscillator the recommended default value is 2, which |
| 1584 |
corresponds to a PLL time constant of about 900 s and a maximum |
| 1585 |
update interval of about 64 s. The maximum update interval |
| 1586 |
scales directly with the time constant, so that at the maximum |
| 1587 |
time constant of 6, the update interval can be as large as 1024 |
| 1588 |
s. |
| 1589 |
|
| 1590 |
Values of time_constant between zero and 2 can be used if quick |
| 1591 |
convergence is necessary; values between 2 and 6 can be used to |
| 1592 |
reduce network load, but at a modest cost in accuracy. Values |
| 1593 |
above 6 are appropriate only if an external oscillator is |
| 1594 |
present. |
| 1595 |
|
| 1596 |
long time_tolerance = MAXFREQ; /* frequency tolerance (ppm) */ |
| 1597 |
|
| 1598 |
This variable represents the maximum frequency error or |
| 1599 |
tolerance in ppm of the particular CPU clock oscillator and is |
| 1600 |
a property of the architecture; however, in principle it could |
| 1601 |
change as result of the presence of external discipline |
| 1602 |
signals, for instance. It is expressed as a positive number |
| 1603 |
greater than zero in parts-per-million (ppm). |
| 1604 |
|
| 1605 |
The recommended value of MAXFREQ is 200 ppm is appropriate for |
| 1606 |
room-temperature quartz oscillators used in typical |
| 1607 |
workstations. However, it can change due to the operating |
| 1608 |
condition of the PPS signal and/or external oscillator. With |
| 1609 |
either the PPS signal or external oscillator, the recommended |
| 1610 |
value for MAXFREQ is 100 ppm. |
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
<span class="grey">Mills [Page 29]</span></pre> |
| 1621 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-30" ></span> |
| 1622 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 1623 |
|
| 1624 |
|
| 1625 |
long time_precision = 1000000 / HZ; /* clock precision (us) */ |
| 1626 |
|
| 1627 |
This variable represents the maximum error in reading the |
| 1628 |
system clock in microseconds. It is usually based on the number |
| 1629 |
of microseconds between timer interrupts, 10000 us for the |
| 1630 |
SunOS kernel, 3906 us for the Ultrix kernel, 976 us for the |
| 1631 |
OSF/1 kernel. However, in cases where the time can be |
| 1632 |
interpolated between timer interrupts with microsecond |
| 1633 |
resolution, such as in the unmodified SunOS kernel and modified |
| 1634 |
Ultrix and OSF/1 kernels, the precision is specified as 1 us. |
| 1635 |
In cases where a PPS signal or external oscillator is |
| 1636 |
available, the precision can depend on the operating condition |
| 1637 |
of the signal or oscillator. This variable is determined by the |
| 1638 |
kernel for use by the synchronization daemon, but is otherwise |
| 1639 |
not used by the kernel. |
| 1640 |
|
| 1641 |
long time_maxerror = MAXPHASE; /* maximum error */ |
| 1642 |
|
| 1643 |
This variable establishes the maximum error of the indicated |
| 1644 |
time relative to the primary synchronization source in |
| 1645 |
microseconds. For NTP, the value is initialized by a |
| 1646 |
ntp_adjtime() call to the synchronization distance, which is |
| 1647 |
equal to the root dispersion plus one-half the root delay. It |
| 1648 |
is increased by a small amount (time_tolerance) each second to |
| 1649 |
reflect the clock frequency tolerance. This variable is |
| 1650 |
computed by the synchronization daemon and the kernel, but is |
| 1651 |
otherwise not used by the kernel. |
| 1652 |
|
| 1653 |
long time_esterror = MAXPHASE; /* estimated error */ |
| 1654 |
|
| 1655 |
This variable establishes the expected error of the indicated |
| 1656 |
time relative to the primary synchronization source in |
| 1657 |
microseconds. For NTP, the value is determined as the root |
| 1658 |
dispersion, which represents the best estimate of the actual |
| 1659 |
error of the system clock based on its past behavior, together |
| 1660 |
with observations of multiple clocks within the peer group. |
| 1661 |
This variable is computed by the synchronization daemon and |
| 1662 |
returned in system calls, but is otherwise not used by the |
| 1663 |
kernel. |
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
<span class="grey">Mills [Page 30]</span></pre> |
| 1677 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-31" ></span> |
| 1678 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 1679 |
|
| 1680 |
|
| 1681 |
5.2. Phase-Lock Loop Variables |
| 1682 |
|
| 1683 |
The following variables establish the state of the PLL and the |
| 1684 |
residual time and frequency offset of the system clock. Additional |
| 1685 |
automatic variables are used as temporaries as described in the |
| 1686 |
code fragments. |
| 1687 |
|
| 1688 |
long time_phase = 0; /* phase offset (scaled us) */ |
| 1689 |
|
| 1690 |
The time_phase variable represents the phase of the kernel time |
| 1691 |
variable at each tick of the clock. This variable is scaled by |
| 1692 |
(1 << SHIFT_SCALE) (23) in microseconds, giving a maximum |
| 1693 |
adjustment of about +-256 us/tick and a resolution less than |
| 1694 |
one part in 10^12. |
| 1695 |
|
| 1696 |
long time_offset = 0; /* time offset (scaled us) */ |
| 1697 |
|
| 1698 |
The time_offset variable represents the time offset of the CPU |
| 1699 |
clock oscillator. It is recalculated as each update to the |
| 1700 |
system clock is received via the hardupdate() routine and at |
| 1701 |
each second in the seconds_overflow routine. This variable is |
| 1702 |
scaled by (1 << SHIFT_UPDATE) (12) in microseconds, giving a |
| 1703 |
maximum adjustment of about +-512 ms and a resolution of a few |
| 1704 |
parts in 10^10 s. |
| 1705 |
|
| 1706 |
long time_freq = 0; /* frequency offset (scaled ppm) */ |
| 1707 |
|
| 1708 |
The time_freq variable represents the frequency offset of the |
| 1709 |
CPU clock oscillator. It is recalculated as each update to the |
| 1710 |
system clock is received via the hardupdate() routine. It can |
| 1711 |
also be set via ntp_adjtime() from a value stored in a file |
| 1712 |
when the synchronization daemon is first started. It can be |
| 1713 |
retrieved via ntp_adjtime() and written to the file about once |
| 1714 |
per hour by the daemon. The time_freq variable is scaled by (1 |
| 1715 |
<< SHIFT_KF) (16) ppm, giving it a maximum value well in excess |
| 1716 |
of the limit of +-256 ppm imposed by other constraints. The |
| 1717 |
precision of this representation (frequency resolution) is |
| 1718 |
parts in 10^11, which is adequate for all but the best external |
| 1719 |
oscillators. |
| 1720 |
|
| 1721 |
time_adj = 0; /* tick adjust (scaled 1 / HZ) */ |
| 1722 |
|
| 1723 |
The time_adj variable is the adjustment added to the value of |
| 1724 |
tick at each timer interrupt. It is computed once each second |
| 1725 |
from the time_offset, time_freq and, if the PPS signal is |
| 1726 |
present, the ps_ybar variable once each second. |
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
<span class="grey">Mills [Page 31]</span></pre> |
| 1733 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-32" ></span> |
| 1734 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 1735 |
|
| 1736 |
|
| 1737 |
long time_reftime = 0; /* time at last adjustment (s) */ |
| 1738 |
|
| 1739 |
This variable is the seconds portion of the system time on the |
| 1740 |
last update received by the hardupdate() routine. It is used to |
| 1741 |
compute the time_freq variable as the time since the last |
| 1742 |
update increases. |
| 1743 |
|
| 1744 |
int fixtick = 1000000 % HZ; /* amortization factor */ |
| 1745 |
|
| 1746 |
In the Ultrix and OSF/1 kernels, the interval between timer |
| 1747 |
interrupts does not evenly divide the number of microseconds in |
| 1748 |
the second. In order that the clock runs at a precise rate, it |
| 1749 |
is necessary to introduce an amortization factor into the local |
| 1750 |
timescale. In the original Unix code, the value of fixtick is |
| 1751 |
amortized once each second, introducing an additional source of |
| 1752 |
jitter; in the new model the value is amortized at each tick of |
| 1753 |
the system clock, reducing the jitter by the reciprocal of the |
| 1754 |
clock oscillator frequency. This is not a new kernel variable, |
| 1755 |
but a new use of an existing kernel variable. |
| 1756 |
|
| 1757 |
5.3. Pulse-per-second (PPS) Frequency-Lock Loop Variables |
| 1758 |
|
| 1759 |
The following variables are used only if a pulse-per-second (PPS) |
| 1760 |
signal is available and connected via a modem-control lead, such |
| 1761 |
as produced by the optional ppsclock feature incorporated in the |
| 1762 |
serial port driver. They establish the design parameters of the |
| 1763 |
PPS frequency-lock loop used to discipline the CPU clock |
| 1764 |
oscillator to an external PPS signal. Additional automatic |
| 1765 |
variables are used as temporaries as described in the code |
| 1766 |
fragments. |
| 1767 |
|
| 1768 |
long pps_usec; /* microseconds at last pps */ |
| 1769 |
|
| 1770 |
The pps_usec variable is latched from a high resolution counter |
| 1771 |
or external oscillator at each PPS interrupt. In determining |
| 1772 |
this value, only the hardware counter contents are used, not |
| 1773 |
the contents plus the kernel time variable, as returned by the |
| 1774 |
microtime() routine. |
| 1775 |
|
| 1776 |
long pps_ybar = 0; /* pps frequency offset estimate */ |
| 1777 |
|
| 1778 |
The pps_ybar variable is the average CPU clock oscillator |
| 1779 |
frequency offset relative to the PPS disciplining signal. It is |
| 1780 |
scaled in the same units as the time_freq variable. |
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
<span class="grey">Mills [Page 32]</span></pre> |
| 1789 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-33" ></span> |
| 1790 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 1791 |
|
| 1792 |
|
| 1793 |
pps_disp = MAXFREQ; /* dispersion estimate (scaled ppm) */ |
| 1794 |
|
| 1795 |
The pps_disp variable represents the average sample dispersion |
| 1796 |
measured over the last three samples. It is scaled in the same |
| 1797 |
units as the time_freq variable. |
| 1798 |
|
| 1799 |
pps_dispmax = MAXFREQ / 2; /* dispersion threshold */ |
| 1800 |
|
| 1801 |
The pps_dispmax variable is used as a dispersion threshold. If |
| 1802 |
pps_disp is less than this threshold, the median sample is used |
| 1803 |
to update the pps_ybar estimate; if not, the sample is |
| 1804 |
discarded. |
| 1805 |
|
| 1806 |
pps_dispinc = MAXFREQ >> (PPS_SHIFT + 4); /* pps dispersion |
| 1807 |
increment/sec */ |
| 1808 |
|
| 1809 |
The pps_dispinc variable is the increment to add to pps_disp |
| 1810 |
once each second. It is computed such that, if no PPS samples |
| 1811 |
have arrived for several calibration intervals, the value of |
| 1812 |
pps_disp will exceed the pps_dispmax threshold and raise an |
| 1813 |
alarm. |
| 1814 |
|
| 1815 |
int pps_mf[] = {0, 0, 0}; /* pps median filter */ |
| 1816 |
|
| 1817 |
The pps-mf[] array is used as a median filter to detect and |
| 1818 |
discard jitter in the PPS signal. |
| 1819 |
|
| 1820 |
int pps_count = 0; /* pps calibrate interval counter */ |
| 1821 |
|
| 1822 |
The pps_count variable measures the length of the calibration |
| 1823 |
interval used to calculate the frequency. It normally counts |
| 1824 |
from zero to the value 1 << pps_shift. |
| 1825 |
|
| 1826 |
pps_shift = PPS_SHIFT; /* interval duration (s) (shift) */ |
| 1827 |
|
| 1828 |
The pps_shift variable determines the duration of the |
| 1829 |
calibration interval, 1 << pps_shift s. |
| 1830 |
|
| 1831 |
pps_intcnt = 0; /* intervals at current duration */ |
| 1832 |
|
| 1833 |
The pps_intcnt variable counts the number of calibration |
| 1834 |
intervals at the current interval duration. It is reset to zero |
| 1835 |
after four intervals and when the interval duration is changed. |
| 1836 |
|
| 1837 |
long pps_calcnt = 0; /* calibration intervals */ |
| 1838 |
|
| 1839 |
The pps_calcnt variable counts the number of calibration |
| 1840 |
intervals. |
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
<span class="grey">Mills [Page 33]</span></pre> |
| 1845 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-34" ></span> |
| 1846 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 1847 |
|
| 1848 |
|
| 1849 |
long pps_jitcnt = 0; /* jitter limit exceeded */ |
| 1850 |
|
| 1851 |
The pps_jitcnt variable counts the number of resets due to |
| 1852 |
excessive jitter or frequency offset. These resets are |
| 1853 |
usually due to excessive noise in the PPS signal or |
| 1854 |
interface. |
| 1855 |
|
| 1856 |
long pps_discnt = 0; /* dispersion limit exceeded */ |
| 1857 |
|
| 1858 |
The pps_discnt variable counts the number of calibration |
| 1859 |
intervals where the dispersion is above the pps_dispmax |
| 1860 |
limit. These resets are usually due to excessive frequency |
| 1861 |
wander in the PPS signal source. |
| 1862 |
|
| 1863 |
|
| 1864 |
|
| 1865 |
|
| 1866 |
|
| 1867 |
|
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
|
| 1886 |
|
| 1887 |
|
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
<span class="grey">Mills [Page 34]</span></pre> |
| 1901 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-35" ></span> |
| 1902 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 1903 |
|
| 1904 |
|
| 1905 |
5.4. External Oscillator Variables |
| 1906 |
|
| 1907 |
The following variables are used only if an external oscillator |
| 1908 |
(HIGHBALL or TPRO) is present. Additional automatic variables are |
| 1909 |
used as temporaries as described in the code fragments. |
| 1910 |
|
| 1911 |
int clock_count = 0; /* CPU clock counter */ |
| 1912 |
|
| 1913 |
The clock_count variable counts the seconds between adjustments |
| 1914 |
to the kernel time variable to discipline it to the external |
| 1915 |
clock. |
| 1916 |
|
| 1917 |
struct timeval clock_offset; /* HIGHBALL clock offset */ |
| 1918 |
|
| 1919 |
The clock_offset variable defines the offset between system |
| 1920 |
time and the HIGHBALL counters. |
| 1921 |
|
| 1922 |
long clock_cpu = 0; /* CPU clock adjust */ |
| 1923 |
|
| 1924 |
The clock_cpu variable contains the offset between the system |
| 1925 |
clock and the HIGHBALL clock for use in disciplining the kernel |
| 1926 |
time variable. |
| 1927 |
|
| 1928 |
<span class="h2"><a class="selflink" id="section-6" href="#section-6">6</a>. Architecture Constants</span> |
| 1929 |
|
| 1930 |
Following is a list of the important architecture constants that |
| 1931 |
establish the response and stability of the PLL and provide maximum |
| 1932 |
bounds on behavior in order to satisfy correctness assertions made in |
| 1933 |
the protocol specification. Additional definitions are given in the |
| 1934 |
timex.h header file. |
| 1935 |
|
| 1936 |
6.1. Phase-lock loop (PLL) definitions |
| 1937 |
|
| 1938 |
The following defines establish the performance envelope of the |
| 1939 |
PLL. They establish the maximum phase error (MAXPHASE), maximum |
| 1940 |
frequency error (MAXFREQ), minimum interval between updates |
| 1941 |
(MINSEC) and maximum interval between updates (MAXSEC). The intent |
| 1942 |
of these bounds is to force the PLL to operate within predefined |
| 1943 |
limits in order to satisfy correctness assertions of the |
| 1944 |
synchronization protocol. An excursion which exceeds these bounds |
| 1945 |
is clamped to the bound and operation proceeds normally. In |
| 1946 |
practice, this can occur only if something has failed or is |
| 1947 |
operating out of tolerance, but otherwise the PLL continues to |
| 1948 |
operate in a stable mode. |
| 1949 |
|
| 1950 |
MAXPHASE must be set greater than or equal to CLOCK.MAX (128 ms), |
| 1951 |
as defined in the NTP specification. CLOCK.MAX establishes the |
| 1952 |
maximum time offset allowed before the system time is reset, |
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
<span class="grey">Mills [Page 35]</span></pre> |
| 1957 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-36" ></span> |
| 1958 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 1959 |
|
| 1960 |
|
| 1961 |
rather than incrementally adjusted. Here, the maximum offset is |
| 1962 |
clamped to MAXPHASE only in order to prevent overflow errors due |
| 1963 |
to defective programming. |
| 1964 |
|
| 1965 |
MAXFREQ reflects the manufacturing frequency tolerance of the CPU |
| 1966 |
oscillator plus the maximum slew rate allowed by the protocol. It |
| 1967 |
should be set to at least the intrinsic frequency tolerance of the |
| 1968 |
oscillator plus 100 ppm for vernier frequency adjustments. If the |
| 1969 |
kernel frequency discipline code is installed (PPS_SYNC), the CPU |
| 1970 |
oscillator frequency is disciplined to an external source, |
| 1971 |
presumably with negligible frequency error. |
| 1972 |
|
| 1973 |
#define MAXPHASE 512000 /* max phase error (us) */ |
| 1974 |
#ifdef PPS_SYNC |
| 1975 |
#define MAXFREQ 100 /* max frequency error (ppm) */ |
| 1976 |
#else |
| 1977 |
#define MAXFREQ 200 /* max frequency error (ppm) */ |
| 1978 |
#endif /* PPS_SYNC */ |
| 1979 |
#define MINSEC 16 /* min interval between updates (s) |
| 1980 |
*/ |
| 1981 |
#define MAXSEC 1200 /* max interval between updates (s) |
| 1982 |
*/ |
| 1983 |
|
| 1984 |
6.2. Pulse-per-second (PPS) Frequency-lock Loop (FLL) Definitions |
| 1985 |
|
| 1986 |
The following defines and declarations are used only if a pulse- |
| 1987 |
per-second (PPS) signal is available and connected via a modem- |
| 1988 |
control lead, such as produced by the optional ppsclock feature |
| 1989 |
incorporated in the serial port driver. They establish the design |
| 1990 |
parameters of the frequency-lock loop (FLL) used to discipline the |
| 1991 |
CPU clock oscillator to the PPS oscillator. |
| 1992 |
|
| 1993 |
PPS_AVG is the averaging constant used to update the FLL from |
| 1994 |
frequency samples measured for each calibration interval. |
| 1995 |
PPS_SHIFT and PPS_SHIFTMAX are the minimum and maximem, |
| 1996 |
respectively, of the calibration interval represented as a power |
| 1997 |
of two. The PPS_DISPINC is the initial increment to pps_disp at |
| 1998 |
each second. |
| 1999 |
|
| 2000 |
#define PPS_AVG 2 /* pps averaging constant (shift) */ |
| 2001 |
#define PPS_SHIFT 2 /* min interval duration (s) (shift) |
| 2002 |
*/ |
| 2003 |
#define PPS_SHIFTMAX 6 /* max interval duration (s) (shift) |
| 2004 |
*/ |
| 2005 |
#define PPS_DISPINC 0 /* dispersion increment (us/s) */ |
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
<span class="grey">Mills [Page 36]</span></pre> |
| 2013 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-37" ></span> |
| 2014 |
<span class="grey"><a href="./rfc1589">RFC 1589</a> Kernel Model for Precision Timekeeping March 1994</span> |
| 2015 |
|
| 2016 |
|
| 2017 |
6.3. External Oscillator Definitions |
| 2018 |
|
| 2019 |
The following definitions and declarations are used only if an |
| 2020 |
external oscillator (HIGHBALL or TPRO) is configured on the |
| 2021 |
system. |
| 2022 |
|
| 2023 |
#define CLOCK_INTERVAL 30 /* CPU clock update interval (s) */ |
| 2024 |
|
| 2025 |
<span class="h2"><a class="selflink" id="section-7" href="#section-7">7</a>. References</span> |
| 2026 |
|
| 2027 |
[<a id="ref-1">1</a>] Mills, D., "Internet time synchronization: the Network Time |
| 2028 |
Protocol", IEEE Trans. Communications COM-39, 10 (October 1991), |
| 2029 |
1482- 1493. Also in: Yang, Z., and T.A. Marsland (Eds.). Global |
| 2030 |
States and Time in Distributed Systems, IEEE Press, Los Alamitos, |
| 2031 |
CA, 91-102. |
| 2032 |
|
| 2033 |
[<a id="ref-2">2</a>] Mills, D., "Network Time Protocol (Version 3) specification, |
| 2034 |
implementation and analysis", <a href="./rfc1305">RFC 1305</a>, University of Delaware, |
| 2035 |
March 1992, 113 pp. |
| 2036 |
|
| 2037 |
[<a id="ref-3">3</a>] Mills, D., "Modelling and analysis of computer network clocks", |
| 2038 |
Electrical Engineering Department Report 92-5-2, University of |
| 2039 |
Delaware, May 1992, 29 pp. |
| 2040 |
|
| 2041 |
[<a id="ref-4">4</a>] Mills, D., "Simple Network Time Protocol (SNTP)", <a href="./rfc1361">RFC 1361</a>, |
| 2042 |
University of Delaware, August 1992, 10 pp. |
| 2043 |
|
| 2044 |
[<a id="ref-5">5</a>] Mills, D., "Precision synchronizatin of computer network clocks", |
| 2045 |
Electrical Engineering Department Report 93-11-1, University of |
| 2046 |
Delaware, November 1993, 66 pp. |
| 2047 |
|
| 2048 |
Security Considerations |
| 2049 |
|
| 2050 |
Security issues are not discussed in this memo. |
| 2051 |
|
| 2052 |
Author's Address |
| 2053 |
|
| 2054 |
David L. Mills |
| 2055 |
Electrical Engineering Department |
| 2056 |
University of Delaware |
| 2057 |
Newark, DE 19716 |
| 2058 |
|
| 2059 |
Phone: (302) 831-8247 |
| 2060 |
EMail: [email protected] |
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
Mills [Page 37] |
| 2069 |
</pre> |