root/include/linux/timex.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   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 #ifdef __alpha__
  36 # define SHIFT_HZ 10            /* log2(HZ) */
  37 #else
  38 # define SHIFT_HZ 7             /* log2(HZ) */
  39 #endif
  40 
  41 /*
  42  * The SHIFT_KG and SHIFT_KF defines establish the damping of the PLL
  43  * and are chosen by analysis for a slightly underdamped convergence
  44  * characteristic. The MAXTC define establishes the maximum time constant
  45  * of the PLL. With the parameters given and the default time constant of
  46  * zero, the PLL will converge in about 15 minutes.
  47  */
  48 #define SHIFT_KG 8              /* shift for phase increment */
  49 #define SHIFT_KF 20             /* shift for frequency increment */
  50 #define MAXTC 6                 /* maximum time constant (shift) */
  51 
  52 /*
  53  * The SHIFT_SCALE define establishes the decimal point of the time_phase
  54  * variable which serves as a an extension to the low-order bits of the
  55  * system clock variable. The SHIFT_UPDATE define establishes the decimal
  56  * point of the time_offset variable which represents the current offset
  57  * with respect to standard time. The FINEUSEC define represents 1 usec in
  58  * scaled units.
  59  */
  60 #define SHIFT_SCALE 24          /* shift for phase scale factor */
  61 #define SHIFT_UPDATE (SHIFT_KG + MAXTC) /* shift for offset scale factor */
  62 #define FINEUSEC (1 << SHIFT_SCALE) /* 1 us in scaled units */
  63 
  64 #define MAXPHASE 128000         /* max phase error (us) */
  65 #define MAXFREQ 100             /* max frequency error (ppm) */
  66 #define MINSEC 16               /* min interval between updates (s) */
  67 #define MAXSEC 1200             /* max interval between updates (s) */
  68 
  69 #define CLOCK_TICK_RATE 1193180 /* Underlying HZ */
  70 #define CLOCK_TICK_FACTOR       20      /* Factor of both 1000000 and CLOCK_TICK_RATE */
  71 #define LATCH  ((CLOCK_TICK_RATE + HZ/2) / HZ)  /* For divider */
  72 
  73 #define FINETUNE ((((((long)LATCH * HZ - CLOCK_TICK_RATE) << SHIFT_HZ) * \
  74         (1000000/CLOCK_TICK_FACTOR) / (CLOCK_TICK_RATE/CLOCK_TICK_FACTOR)) \
  75                 << (SHIFT_SCALE-SHIFT_HZ)) / HZ)
  76 
  77 /*
  78  * syscall interface - used (mainly by NTP daemon)
  79  * to discipline kernel clock oscillator
  80  */
  81 struct timex {
  82         int mode;               /* mode selector */
  83         long offset;            /* time offset (usec) */
  84         long frequency;         /* frequency offset (scaled ppm) */
  85         long maxerror;          /* maximum error (usec) */
  86         long esterror;          /* estimated error (usec) */
  87         int status;             /* clock command/status */
  88         long time_constant;     /* pll time constant */
  89         long precision;         /* clock precision (usec) (read only) */
  90         long tolerance;         /* clock frequency tolerance (ppm)
  91                                  * (read only)
  92                                  */
  93         struct timeval time;    /* (read only) */
  94         long tick;              /* (modified) usecs between clock ticks */
  95 
  96         long ppsfreq;           /* pps frequency (scaled ppm) (ro) */
  97         long jitter;            /* pps jitter (us) (ro) */
  98         int shift;              /* interval duration (s) (shift) (ro) */
  99         long stabil;            /* pps stability (scaled ppm) (ro) */
 100         long jitcnt;            /* jitter limit exceeded (ro) */
 101         long calcnt;            /* calibration intervals (ro) */
 102         long errcnt;            /* calibration errors (ro) */
 103         long stbcnt;            /* stability limit exceeded (ro) */
 104 
 105         int  :32; int  :32; int  :32; int  :32;
 106         int  :32; int  :32; int  :32; int  :32;
 107         int  :32; int  :32; int  :32; int  :32;
 108 };
 109 
 110 /*
 111  * Mode codes (timex.mode) 
 112  */
 113 #define ADJ_OFFSET              0x0001  /* time offset */
 114 #define ADJ_FREQUENCY           0x0002  /* frequency offset */
 115 #define ADJ_MAXERROR            0x0004  /* maximum time error */
 116 #define ADJ_ESTERROR            0x0008  /* estimated time error */
 117 #define ADJ_STATUS              0x0010  /* clock status */
 118 #define ADJ_TIMECONST           0x0020  /* pll time constant */
 119 #define ADJ_TICK                0x4000  /* tick value */
 120 #define ADJ_OFFSET_SINGLESHOT   0x8001  /* old-fashioned adjtime */
 121 
 122 /*
 123  * Clock command/status codes (timex.status)
 124  */
 125 #define TIME_OK         0       /* clock synchronized */
 126 #define TIME_INS        1       /* insert leap second */
 127 #define TIME_DEL        2       /* delete leap second */
 128 #define TIME_OOP        3       /* leap second in progress */
 129 #define TIME_BAD        4       /* clock not synchronized */
 130 
 131 #ifdef __KERNEL__
 132 /*
 133  * kernel variables
 134  */
 135 extern long tick;                      /* timer interrupt period */
 136 extern int tickadj;                     /* amount of adjustment per tick */
 137 
 138 /*
 139  * phase-lock loop variables
 140  */
 141 extern int time_status;         /* clock synchronization status */
 142 extern long time_offset;        /* time adjustment (us) */
 143 extern long time_constant;      /* pll time constant */
 144 extern long time_tolerance;     /* frequency tolerance (ppm) */
 145 extern long time_precision;     /* clock precision (us) */
 146 extern long time_maxerror;      /* maximum error */
 147 extern long time_esterror;      /* estimated error */
 148 extern long time_phase;         /* phase offset (scaled us) */
 149 extern long time_freq;          /* frequency offset (scaled ppm) */
 150 extern long time_adj;           /* tick adjust (scaled 1 / HZ) */
 151 extern long time_reftime;       /* time at last adjustment (s) */
 152 
 153 extern long time_adjust;        /* The amount of adjtime left */
 154 #endif /* KERNEL */
 155 
 156 #endif /* LINUX_TIMEX_H */

/* [previous][next][first][last][top][bottom][index][help] */