Skip to main content

5. Kernel Variables

This section contains a list of kernel variables and a detailed description of their function, initial value, scaling and limits.

5.1. Interface Variables​

The following variables are read and set by the ntp_adjtime() system call. Additional automatic variables are used as temporaries as described in the code fragments.

      int time_status = TIME_BAD;

This variable controls the state machine used to insert or delete leap seconds and show the status of the timekeeping system, PPS signal and external oscillator, if configured.

      long time_offset = 0;

This variable is used by the PLL to adjust the system time in small increments. It is scaled by (1 << SHIFT_UPDATE) (12) in microseconds. The maximum value that can be represented is about +-512 ms and the minimum value or precision is a few parts in 10^10 s.

      long time_constant = 0;      /* pll time constant */

This variable determines the bandwidth or "stiffness" of the PLL. The value is used as a shift between zero and MAXTC (6), with the effective PLL time constant equal to a multiple of (1 << time_constant) in seconds. For room-temperature quartz oscillator the recommended default value is 2, which corresponds to a PLL time constant of about 900 s and a maximum update interval of about 64 s. The maximum update interval scales directly with the time constant, so that at the maximum time constant of 6, the update interval can be as large as 1024 s.

Values of time_constant between zero and 2 can be used if quick convergence is necessary; values between 2 and 6 can be used to reduce network load, but at a modest cost in accuracy. Values above 6 are appropriate only if an external oscillator is present.

      long time_tolerance = MAXFREQ; /* frequency tolerance (ppm) */

This variable represents the maximum frequency error or tolerance in ppm of the particular CPU clock oscillator and is a property of the architecture; however, in principle it could change as result of the presence of external discipline signals, for instance. It is expressed as a positive number greater than zero in parts-per-million (ppm).

The recommended value of MAXFREQ is 200 ppm is appropriate for room-temperature quartz oscillators used in typical workstations. However, it can change due to the operating condition of the PPS signal and/or external oscillator. With either the PPS signal or external oscillator, the recommended value for MAXFREQ is 100 ppm.

      long time_precision = 1000000 / HZ; /* clock precision (us) */

This variable represents the maximum error in reading the system clock in microseconds. It is usually based on the number of microseconds between timer interrupts, 10000 us for the SunOS kernel, 3906 us for the Ultrix kernel, 976 us for the OSF/1 kernel. However, in cases where the time can be interpolated between timer interrupts with microsecond resolution, such as in the unmodified SunOS kernel and modified Ultrix and OSF/1 kernels, the precision is specified as 1 us. In cases where a PPS signal or external oscillator is available, the precision can depend on the operating condition of the signal or oscillator. This variable is determined by the kernel for use by the synchronization daemon, but is otherwise not used by the kernel.

      long time_maxerror = MAXPHASE; /* maximum error */

This variable establishes the maximum error of the indicated time relative to the primary synchronization source in microseconds. For NTP, the value is initialized by a ntp_adjtime() call to the synchronization distance, which is equal to the root dispersion plus one-half the root delay. It is increased by a small amount (time_tolerance) each second to reflect the clock frequency tolerance. This variable is computed by the synchronization daemon and the kernel, but is otherwise not used by the kernel.

      long time_esterror = MAXPHASE; /* estimated error */

This variable establishes the expected error of the indicated time relative to the primary synchronization source in microseconds. For NTP, the value is determined as the root dispersion, which represents the best estimate of the actual error of the system clock based on its past behavior, together with observations of multiple clocks within the peer group. This variable is computed by the synchronization daemon and returned in system calls, but is otherwise not used by the kernel.

5.2. Phase-Lock Loop Variables​

The following variables establish the state of the PLL and the residual time and frequency offset of the system clock. Additional automatic variables are used as temporaries as described in the code fragments.

      long time_phase = 0;         /* phase offset (scaled us) */

The time_phase variable represents the phase of the kernel time variable at each tick of the clock. This variable is scaled by (1 << SHIFT_SCALE) (23) in microseconds, giving a maximum adjustment of about +-256 us/tick and a resolution less than one part in 10^12.

      long time_offset = 0;        /* time offset (scaled us) */

The time_offset variable represents the time offset of the CPU clock oscillator. It is recalculated as each update to the system clock is received via the hardupdate() routine and at each second in the seconds_overflow routine. This variable is scaled by (1 << SHIFT_UPDATE) (12) in microseconds, giving a maximum adjustment of about +-512 ms and a resolution of a few parts in 10^10 s.

      long time_freq = 0;          /* frequency offset (scaled ppm) */

The time_freq variable represents the frequency offset of the CPU clock oscillator. It is recalculated as each update to the system clock is received via the hardupdate() routine. It can also be set via ntp_adjtime() from a value stored in a file when the synchronization daemon is first started. It can be retrieved via ntp_adjtime() and written to the file about once per hour by the daemon. The time_freq variable is scaled by (1 << SHIFT_KF) (16) ppm, giving it a maximum value well in excess of the limit of +-256 ppm imposed by other constraints. The precision of this representation (frequency resolution) is parts in 10^11, which is adequate for all but the best external oscillators.

      time_adj = 0;                /* tick adjust (scaled 1 / HZ) */

The time_adj variable is the adjustment added to the value of tick at each timer interrupt. It is computed once each second from the time_offset, time_freq and, if the PPS signal is present, the ps_ybar variable once each second.

      long time_reftime = 0;       /* time at last adjustment (s) */

This variable is the seconds portion of the system time on the last update received by the hardupdate() routine. It is used to compute the time_freq variable as the time since the last update increases.

      int fixtick = 1000000 % HZ;  /* amortization factor */

In the Ultrix and OSF/1 kernels, the interval between timer interrupts does not evenly divide the number of microseconds in the second. In order that the clock runs at a precise rate, it is necessary to introduce an amortization factor into the local timescale. In the original Unix code, the value of fixtick is amortized once each second, introducing an additional source of jitter; in the new model the value is amortized at each tick of the system clock, reducing the jitter by the reciprocal of the clock oscillator frequency. This is not a new kernel variable, but a new use of an existing kernel variable.

5.3. Pulse-per-second (PPS) Frequency-Lock Loop Variables​

The following variables are used only if a pulse-per-second (PPS) signal is available and connected via a modem-control lead, such as produced by the optional ppsclock feature incorporated in the serial port driver. They establish the design parameters of the PPS frequency-lock loop used to discipline the CPU clock oscillator to an external PPS signal. Additional automatic variables are used as temporaries as described in the code fragments.

      long pps_usec;          /* microseconds at last pps */

The pps_usec variable is latched from a high resolution counter or external oscillator at each PPS interrupt. In determining this value, only the hardware counter contents are used, not the contents plus the kernel time variable, as returned by the microtime() routine.

      long pps_ybar = 0;      /* pps frequency offset estimate */

The pps_ybar variable is the average CPU clock oscillator frequency offset relative to the PPS disciplining signal. It is scaled in the same units as the time_freq variable.

      pps_disp = MAXFREQ;     /* dispersion estimate (scaled ppm) */

The pps_disp variable represents the average sample dispersion measured over the last three samples. It is scaled in the same units as the time_freq variable.

      pps_dispmax = MAXFREQ / 2; /* dispersion threshold */

The pps_dispmax variable is used as a dispersion threshold. If pps_disp is less than this threshold, the median sample is used to update the pps_ybar estimate; if not, the sample is discarded.

      pps_dispinc = MAXFREQ >> (PPS_SHIFT + 4); /* pps dispersion
increment/sec */

The pps_dispinc variable is the increment to add to pps_disp once each second. It is computed such that, if no PPS samples have arrived for several calibration intervals, the value of pps_disp will exceed the pps_dispmax threshold and raise an alarm.

      int pps_mf[] = {0, 0, 0};    /* pps median filter */

The pps-mf[] array is used as a median filter to detect and discard jitter in the PPS signal.

      int pps_count = 0;           /* pps calibrate interval counter */

The pps_count variable measures the length of the calibration interval used to calculate the frequency. It normally counts from zero to the value 1 << pps_shift.

      pps_shift = PPS_SHIFT;       /* interval duration (s) (shift) */

The pps_shift variable determines the duration of the calibration interval, 1 << pps_shift s.

      pps_intcnt = 0;              /* intervals at current duration */

The pps_intcnt variable counts the number of calibration intervals at the current interval duration. It is reset to zero after four intervals and when the interval duration is changed.

      long pps_calcnt = 0;         /* calibration intervals */

The pps_calcnt variable counts the number of calibration intervals.

      long pps_jitcnt = 0;         /* jitter limit exceeded */

The pps_jitcnt variable counts the number of resets due to excessive jitter or frequency offset. These resets are usually due to excessive noise in the PPS signal or interface.

      long pps_discnt = 0;         /* dispersion limit exceeded */

The pps_discnt variable counts the number of calibration intervals where the dispersion is above the pps_dispmax limit. These resets are usually due to excessive frequency wander in the PPS signal source.

5.4. External Oscillator Variables​

The following variables are used only if an external oscillator (HIGHBALL or TPRO) is present. Additional automatic variables are used as temporaries as described in the code fragments.

      int clock_count = 0;         /* CPU clock counter */

The clock_count variable counts the seconds between adjustments to the kernel time variable to discipline it to the external clock.

      struct timeval clock_offset; /* HIGHBALL clock offset */

The clock_offset variable defines the offset between system time and the HIGHBALL counters.

      long clock_cpu = 0;          /* CPU clock adjust */

The clock_cpu variable contains the offset between the system clock and the HIGHBALL clock for use in disciplining the kernel time variable.