Home | History | Annotate | Line # | Download | only in drivers
driver28.html revision 1.1.1.2.4.1
      1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      2 
      3 <html>
      4 
      5     <head>
      6         <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      7         <meta name="GENERATOR" content="Mozilla/4.01 [en] (Win95; I) [Netscape]">
      8         <title>Shared Memory Driver</title>
      9         <link href="scripts/style.css" type="text/css" rel="stylesheet">
     10     </head>
     11 
     12     <body>
     13         <h3>Shared Memory Driver</h3>
     14 <p>Last update:
     15   <!-- #BeginDate format:En2m -->8-Aug-2014  19:17<!-- #EndDate -->
     16   UTC</p>
     17         <hr>
     18         <h4>Synopsis</h4>
     19         <p>Address: 127.127.28.<i>u</i><br>
     20             Reference ID: <tt>SHM</tt><br>
     21             Driver ID: <tt>SHM</tt></p>
     22 
     23         <h4>Description</h4>
     24         <p>This driver receives its reference clock info from a shared memory-segment. The shared memory-segment is created with owner-only access for unit 0 and 1, and world access for unit 2 and 3</p>
     25 
     26         <h4>Structure of shared memory-segment</h4>
     27         <pre>struct shmTime {
     28         int    mode; /* 0 - if valid is set:
     29                       *       use values,
     30                       *       clear valid
     31                       * 1 - if valid is set:
     32                       *       if count before and after read of data is equal:
     33                       *         use values
     34                       *       clear valid
     35                       */
     36         volatile int    count;
     37         time_t          clockTimeStampSec;
     38         int             clockTimeStampUSec;
     39         time_t          receiveTimeStampSec;
     40         int             receiveTimeStampUSec;
     41         int             leap;
     42         int             precision;
     43         int             nsamples;
     44         volatile int    valid;
     45         unsigned        clockTimeStampNSec;     /* Unsigned ns timestamps */
     46         unsigned        receiveTimeStampNSec;   /* Unsigned ns timestamps */
     47         int             dummy[8];
     48 };</pre>
     49 
     50         <h4>Operation mode=0</h4>
     51         <p>Each second, the value of <code>valid</code> of the shared memory-segment is checked:</p>
     52         <p>If set, the values in the record (clockTimeStampSec, clockTimeStampUSec, receiveTimeStampSec, receiveTimeStampUSec, leap, precision) are passed to ntp, and <code>valid</code> is cleared and <code>count</code> is bumped.</p>
     53         <p>If not set, <code>count</code> is bumped.</p>
     54         <h4>Operation mode=1</h4>
     55         <p>Each second, <code>valid</code> in the shared memory-segment is checked:</p>
     56         <p>If set, the <code>count</code> field of the record is remembered, and the values in the record (clockTimeStampSec, clockTimeStampUSec, receiveTimeStampSec, receiveTimeStampUSec, leap, precision) are read. Then, the remembered <code>count</code> is compared to current value of <code>count</code> now in the record. If both are equal, the values read from the record are passed to ntp. If they differ, another process has modified the record while it was read out (was not able to produce this case), and failure is reported to ntp. The <code>valid</code> flag is cleared and <code>count</code> is bumped.</p>
     57         <p>If not set, <code>count</code> is bumped</p>
     58 
     59 <h4>Mode-independent postprocessing</h4>
     60 After the time stamps have been successfully plucked from the SHM
     61 segment, some sanity checks take place:
     62 <ul>
     63   <li>The receive time stamp of the SHM data must be in the last 5
     64   seconds before the time the data is processed. This helps in weeding
     65   out stale data.
     66   <li>If the absolute difference between remote and local clock
     67   exceeds the limit (either <i>time2</i> or the default of 4hrs), then
     68   the sample is discarded. This check is disabled when <i>flag1</i> is
     69   set to 1.
     70 </ul>
     71 
     72 <h4>gpsd</h4>
     73 
     74 <a href="http://gpsd.berlios.de/"><i>gpsd</i></a>
     75 knows how to talk to many GPS devices.
     76 It can work with <i>ntpd</i> through the SHM driver.
     77 <P>
     78 The <i>gpsd</i> man page suggests setting minpoll and maxpoll to 4.
     79 That was an attempt to reduce jitter.
     80 The SHM driver was fixed (ntp-4.2.5p138) to collect data each second rather than
     81 once per polling interval so that suggestion is no longer reasonable.
     82 <P>
     83   <b>Note:</b> The GPSD client driver (type 46) uses the <i>gpsd</i>
     84   client protocol to connect and talk to <i>gpsd</i>, but using the
     85   SHM driver is the ancient way to have <i>gpsd</i> talk to <i>ntpd</i>.
     86 
     87 <h4>Clockstats</h4>
     88 If flag4 is set when the driver is polled, a clockstats record is written.
     89 The first 3 fields are the normal date, time, and IP address common to all clockstats records.
     90 <P>
     91 The 4th field is the number of second ticks since the last poll.
     92 The 5th field is the number of good data samples found.  The last 64 will be used by ntpd.
     93 The 6th field is the number of sample that didn't have valid data ready.
     94 The 7th field is the number of bad samples.
     95 The 8th field is the number of times the the mode 1 info was update while nptd was trying to grab a sample.
     96 <P>
     97 
     98 Here is a sample showing the GPS reception fading out:
     99 <pre>
    100 54364 84927.157 127.127.28.0  66  65   1   0   0
    101 54364 84990.161 127.127.28.0  63  63   0   0   0
    102 54364 85053.160 127.127.28.0  63  63   0   0   0
    103 54364 85116.159 127.127.28.0  63  62   1   0   0
    104 54364 85180.158 127.127.28.0  64  63   1   0   0
    105 54364 85246.161 127.127.28.0  66  66   0   0   0
    106 54364 85312.157 127.127.28.0  66  50  16   0   0
    107 54364 85375.160 127.127.28.0  63  41  22   0   0
    108 54364 85439.155 127.127.28.0  64  64   0   0   0
    109 54364 85505.158 127.127.28.0  66  36  30   0   0
    110 54364 85569.157 127.127.28.0  64   0  64   0   0
    111 54364 85635.157 127.127.28.0  66   0  66   0   0
    112 54364 85700.160 127.127.28.0  65   0  65   0   0
    113 </pre>
    114 
    115 	<h4>Fudge Factors</h4>
    116         <dl>
    117             <dt><tt>time1 <i>time</i></tt>
    118             <dd>Specifies the time offset calibration factor, in seconds and fraction, with default 0.0.
    119             <dt><tt>time2 <i>time</i></tt>
    120             <dd>Maximum allowed difference between remote and local
    121             clock, in seconds. Values <1.0 or >86400.0 are ignored, and the
    122             default value of 4hrs (14400s) is used instead. See also flag 1. 
    123             <dt><tt>stratum <i>number</i></tt>
    124             <dd>Specifies the driver stratum, in decimal from 0 to 15, with default 0.
    125             <dt><tt>refid <i>string</i></tt>
    126             <dd>Specifies the driver reference identifier, an ASCII string from one to four characters, with default <tt>SHM</tt>.
    127             <dt><tt>flag1 0 | 1</tt>
    128             <dd><i>Skip</i> the difference limit check if set. Useful
    129             for systems where the RTC backup cannot keep the time over
    130             long periods without power and the SHM clock must be able
    131             to force long-distance initial jumps. <i>Check</i> the
    132             difference limit if cleared (default).
    133             <dt><tt>flag2 0 | 1</tt>
    134             <dd>Not used by this driver.
    135             <dt><tt>flag3 0 | 1</tt>
    136             <dd>Not used by this driver.
    137             <dt><tt>flag4 0 | 1</tt>
    138             <dd>If flag4 is set, clockstats records will be written when the driver is polled.
    139             <h4>Additional Information</h4>
    140             <p><a href="../refclock.html">Reference Clock Drivers</a></p>
    141         </dl>
    142         <hr>
    143         <script type="text/javascript" language="javascript" src="scripts/footer.txt"></script>
    144     </body>
    145 
    146 </html>
    147 
    148