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 #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 
  93 /*
  94  * Mode codes (timex.mode) 
  95  */
  96 #define ADJ_OFFSET              0x0001  /* time offset */
  97 #define ADJ_FREQUENCY           0x0002  /* frequency offset */
  98 #define ADJ_MAXERROR            0x0004  /* maximum time error */
  99 #define ADJ_ESTERROR            0x0008  /* estimated time error */
 100 #define ADJ_STATUS              0x0010  /* clock status */
 101 #define ADJ_TIMECONST           0x0020  /* pll time constant */
 102 #define ADJ_TICK                0x4000  /* tick value */
 103 #define ADJ_OFFSET_SINGLESHOT   0x8001  /* old-fashioned adjtime */
 104 
 105 /*
 106  * Clock command/status codes (timex.status)
 107  */
 108 #define TIME_OK         0       /* clock synchronized */
 109 #define TIME_INS        1       /* insert leap second */
 110 #define TIME_DEL        2       /* delete leap second */
 111 #define TIME_OOP        3       /* leap second in progress */
 112 #define TIME_BAD        4       /* clock not synchronized */
 113 
 114 #ifdef __KERNEL__
 115 /*
 116  * kernel variables
 117  */
 118 extern long tick;                      /* timer interrupt period */
 119 extern int tickadj;                     /* amount of adjustment per tick */
 120 
 121 /*
 122  * phase-lock loop variables
 123  */
 124 extern int time_status;         /* clock synchronization status */
 125 extern long time_offset;        /* time adjustment (us) */
 126 extern long time_constant;      /* pll time constant */
 127 extern long time_tolerance;     /* frequency tolerance (ppm) */
 128 extern long time_precision;     /* clock precision (us) */
 129 extern long time_maxerror;      /* maximum error */
 130 extern long time_esterror;      /* estimated error */
 131 extern long time_phase;         /* phase offset (scaled us) */
 132 extern long time_freq;          /* frequency offset (scaled ppm) */
 133 extern long time_adj;           /* tick adjust (scaled 1 / HZ) */
 134 extern long time_reftime;       /* time at last adjustment (s) */
 135 
 136 extern long time_adjust;        /* The amount of adjtime left */
 137 #endif /* KERNEL */
 138 
 139 #endif /* LINUX_TIMEX_H */

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