1 /***************************************************************************** 2 * * 3 * Copyright (c) David L. Mills 1993 * 4 * * 5 * Permission to use, copy, modify, and distribute this software and its * 6 * documentation for any purpose and without fee is hereby granted, provided * 7 * that the above copyright notice appears in all copies and that both the * 8 * copyright notice and this permission notice appear in supporting * 9 * documentation, and that the name University of Delaware not be used in * 10 * advertising or publicity pertaining to distribution of the software * 11 * without specific, written prior permission. The University of Delaware * 12 * makes no representations about the suitability this software for any * 13 * purpose. It is provided "as is" without express or implied warranty. * 14 * * 15 *****************************************************************************/ 16 17 /* 18 * Modification history timex.h 19 * 20 * 17 Sep 93 David L. Mills 21 * Created file $NTP/include/sys/timex.h 22 * 07 Oct 93 Torsten Duwe 23 * Derived linux/timex.h 24 */ 25 #ifndef _LINUX_TIMEX_H 26 #define _LINUX_TIMEX_H 27 28 /* 29 * The following defines establish the engineering parameters of the PLL 30 * model. The HZ variable establishes the timer interrupt frequency, 100 Hz 31 * for the SunOS kernel, 256 Hz for the Ultrix kernel and 1024 Hz for the 32 * OSF/1 kernel. The SHIFT_HZ define expresses the same value as the 33 * nearest power of two in order to avoid hardware multiply operations. 34 */ 35 #define SHIFT_HZ 7 /* log2(HZ) */ 36 37 /* 38 * The SHIFT_KG and SHIFT_KF defines establish the damping of the PLL 39 * and are chosen by analysis for a slightly underdamped convergence 40 * characteristic. The MAXTC define establishes the maximum time constant 41 * of the PLL. With the parameters given and the default time constant of 42 * zero, the PLL will converge in about 15 minutes. 43 */ 44 #define SHIFT_KG 8 /* shift for phase increment */ 45 #define SHIFT_KF 20 /* shift for frequency increment */ 46 #define MAXTC 6 /* maximum time constant (shift) */ 47 48 /* 49 * The SHIFT_SCALE define establishes the decimal point of the time_phase 50 * variable which serves as a an extension to the low-order bits of the 51 * system clock variable. The SHIFT_UPDATE define establishes the decimal 52 * point of the time_offset variable which represents the current offset 53 * with respect to standard time. The FINEUSEC define represents 1 usec in 54 * scaled units. 55 */ 56 #define SHIFT_SCALE 24 /* shift for phase scale factor */ 57 #define SHIFT_UPDATE (SHIFT_KG + MAXTC) /* shift for offset scale factor */ 58 #define FINEUSEC (1 << SHIFT_SCALE) /* 1 us in scaled units */ 59 60 #define MAXPHASE 128000 /* max phase error (us) */ 61 #define MAXFREQ 100 /* max frequency error (ppm) */ 62 #define MINSEC 16 /* min interval between updates (s) */ 63 #define MAXSEC 1200 /* max interval between updates (s) */ 64 65 #define CLOCK_TICK_RATE 1193180 /* Underlying HZ */ 66 #define CLOCK_TICK_FACTOR 20 /* Factor of both 1000000 and CLOCK_TICK_RATE */ 67 #define LATCH ((CLOCK_TICK_RATE + HZ/2) / HZ) /* For divider */ 68 69 #define FINETUNE (((((LATCH * HZ - CLOCK_TICK_RATE) << SHIFT_HZ) * \ 70 (1000000/CLOCK_TICK_FACTOR) / (CLOCK_TICK_RATE/CLOCK_TICK_FACTOR)) \ 71 << (SHIFT_SCALE-SHIFT_HZ)) / HZ) 72 73 /* 74 * syscall interface - used (mainly by NTP daemon) 75 * to discipline kernel clock oscillator 76 */ 77 struct timex { 78 int mode; /* mode selector */ 79 long offset; /* time offset (usec) */ 80 long frequency; /* frequency offset (scaled ppm) */ 81 long maxerror; /* maximum error (usec) */ 82 long esterror; /* estimated error (usec) */ 83 int status; /* clock command/status */ 84 long time_constant; /* pll time constant */ 85 long precision; /* clock precision (usec) (read only) */ 86 long tolerance; /* clock frequency tolerance (ppm) 87 * (read only) 88 */ 89 struct timeval time; /* (read only) */ 90 long tick; /* (modified) usecs between clock ticks */ 91 92 long ppsfreq; /* pps frequency (scaled ppm) (ro) */ 93 long jitter; /* pps jitter (us) (ro) */ 94 int shift; /* interval duration (s) (shift) (ro) */ 95 long stabil; /* pps stability (scaled ppm) (ro) */ 96 long jitcnt; /* jitter limit exceeded (ro) */ 97 long calcnt; /* calibration intervals (ro) */ 98 long errcnt; /* calibration errors (ro) */ 99 long stbcnt; /* stability limit exceeded (ro) */ 100 101 int :32; int :32; int :32; int :32; 102 int :32; int :32; int :32; int :32; 103 int :32; int :32; int :32; int :32; 104 }; 105 106 /* 107 * Mode codes (timex.mode) 108 */ 109 #define ADJ_OFFSET 0x0001 /* time offset */ 110 #define ADJ_FREQUENCY 0x0002 /* frequency offset */ 111 #define ADJ_MAXERROR 0x0004 /* maximum time error */ 112 #define ADJ_ESTERROR 0x0008 /* estimated time error */ 113 #define ADJ_STATUS 0x0010 /* clock status */ 114 #define ADJ_TIMECONST 0x0020 /* pll time constant */ 115 #define ADJ_TICK 0x4000 /* tick value */ 116 #define ADJ_OFFSET_SINGLESHOT 0x8001 /* old-fashioned adjtime */ 117 118 /* 119 * Clock command/status codes (timex.status) 120 */ 121 #define TIME_OK 0 /* clock synchronized */ 122 #define TIME_INS 1 /* insert leap second */ 123 #define TIME_DEL 2 /* delete leap second */ 124 #define TIME_OOP 3 /* leap second in progress */ 125 #define TIME_BAD 4 /* clock not synchronized */ 126 127 #ifdef __KERNEL__ 128 /* 129 * kernel variables 130 */ 131 extern long tick; /* timer interrupt period */ 132 extern int tickadj; /* amount of adjustment per tick */ 133 134 /* 135 * phase-lock loop variables 136 */ 137 extern int time_status; /* clock synchronization status */ 138 extern long time_offset; /* time adjustment (us) */ 139 extern long time_constant; /* pll time constant */ 140 extern long time_tolerance; /* frequency tolerance (ppm) */ 141 extern long time_precision; /* clock precision (us) */ 142 extern long time_maxerror; /* maximum error */ 143 extern long time_esterror; /* estimated error */ 144 extern long time_phase; /* phase offset (scaled us) */ 145 extern long time_freq; /* frequency offset (scaled ppm) */ 146 extern long time_adj; /* tick adjust (scaled 1 / HZ) */ 147 extern long time_reftime; /* time at last adjustment (s) */ 148 149 extern long time_adjust; /* The amount of adjtime left */ 150 #endif /* KERNEL */ 151 152 #endif /* LINUX_TIMEX_H */