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