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 memoy 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        <hr>
15        <h4>Synopsis</h4>
16        <p>Address: 127.127.28.<i>u</i><br>
17            Reference ID: <tt>SHM</tt><br>
18            Driver ID: <tt>SHM</tt></p>
19
20        <h4>Description</h4>
21        <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>
22
23        <h4>Structure of shared memory-segment</h4>
24        <pre>struct shmTime {
25&nbsp; int&nbsp;&nbsp;&nbsp; mode; /* 0 - if valid set
26&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; use values,&nbsp;
27&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clear valid
28&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 1 - if valid set&nbsp;
29&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if count before and after read of&nbsp;
30&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; values is equal,
31&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; use values&nbsp;
32&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clear valid
33&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */
34&nbsp; int&nbsp;&nbsp;&nbsp; count;
35&nbsp; time_t clockTimeStampSec;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* external clock */
36&nbsp; int&nbsp;&nbsp;&nbsp; clockTimeStampUSec;&nbsp;&nbsp;&nbsp;&nbsp; /* external clock */
37&nbsp; time_t receiveTimeStampSec;&nbsp;&nbsp;&nbsp; /* internal clock, when external value was received */
38&nbsp; int&nbsp;&nbsp;&nbsp; receiveTimeStampUSec;&nbsp;&nbsp; /* internal clock, when external value was received */
39&nbsp; int&nbsp;&nbsp;&nbsp; leap;
40&nbsp; int&nbsp;&nbsp;&nbsp; precision;
41&nbsp; int&nbsp;&nbsp;&nbsp; nsamples;
42&nbsp; int&nbsp;&nbsp;&nbsp; valid;
43&nbsp; int&nbsp;&nbsp;&nbsp; dummy[10];&nbsp;
44};</pre>
45
46        <h4>Operation mode=0</h4>
47        <p>Each second, the valid-flag of the shared memory-segment is checked:</p>
48        <p>If set, the values in the record (clockTimeStampSec, clockTimeStampUSec, receiveTimeStampSec, receiveTimeStampUSec, leap, precision) are passed to ntp, and the valid-flag is cleared and a counter is bumped.</p>
49        <p>If not set, a counter is bumped</p>
50        <h4>Operation mode=1</h4>
51        <p>Each second, the valid-flag of the shared memory-segment is checked:</p>
52        <p>If set, the count-field of the record is remembered, and the values in the record (clockTimeStampSec, clockTimeStampUSec, receiveTimeStampSec, receiveTimeStampUSec, leap, precision) are read. Then, the remembered count is compared to the count 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 valid flag is cleared and a counter is bumped.</p>
53        <p>If not set, a counter is bumped</p>
54
55
56<h4>gpsd</h4>
57
58<a href="http://gpsd.berlios.de/"><i>gpsd</i></a>
59knows how to talk to many GPS devices.
60It works with <i>ntpd</i> through the SHM driver.
61<P>
62The <i>gpsd</i> man page suggests setting minpoll and maxpoll to 4.
63That was an attempt to reduce jitter.
64The SHM driver was fixed (ntp-4.2.5p138) to collect data each second rather than
65once per polling interval so that suggestion is no longer reasonable.
66<P>
67
68
69<h4>Clockstats</h4>
70If flag4 is set when the driver is polled, a clockstats record is written.
71The first 3 fields are the normal date, time, and IP address common to all clockstats records.
72<P>
73The 4th field is the number of second ticks since the last poll.
74The 5th field is the number of good data samples found.  The last 64 will be used by ntpd.
75The 6th field is the number of sample that didn't have valid data ready.
76The 7th field is the number of bad samples.
77The 8th field is the number of times the the mode 1 info was update while nptd was trying to grab a sample.
78<P>
79
80Here is a sample showing the GPS reception fading out:
81<pre>
8254364 84927.157 127.127.28.0  66  65   1   0   0
8354364 84990.161 127.127.28.0  63  63   0   0   0
8454364 85053.160 127.127.28.0  63  63   0   0   0
8554364 85116.159 127.127.28.0  63  62   1   0   0
8654364 85180.158 127.127.28.0  64  63   1   0   0
8754364 85246.161 127.127.28.0  66  66   0   0   0
8854364 85312.157 127.127.28.0  66  50  16   0   0
8954364 85375.160 127.127.28.0  63  41  22   0   0
9054364 85439.155 127.127.28.0  64  64   0   0   0
9154364 85505.158 127.127.28.0  66  36  30   0   0
9254364 85569.157 127.127.28.0  64   0  64   0   0
9354364 85635.157 127.127.28.0  66   0  66   0   0
9454364 85700.160 127.127.28.0  65   0  65   0   0
95</pre>
96
97	<h4>Fudge Factors</h4>
98        <dl>
99            <dt><tt>time1 <i>time</i></tt>
100            <dd>Specifies the time offset calibration factor, in seconds and fraction, with default 0.0.
101            <dt><tt>time2 <i>time</i></tt>
102            <dd>Not used by this driver.
103            <dt><tt>stratum <i>number</i></tt>
104            <dd>Specifies the driver stratum, in decimal from 0 to 15, with default 0.
105            <dt><tt>refid <i>string</i></tt>
106            <dd>Specifies the driver reference identifier, an ASCII string from one to four characters, with default <tt>SHM</tt>.
107            <dt><tt>flag1 0 | 1</tt>
108            <dd>Not used by this driver.
109            <dt><tt>flag2 0 | 1</tt>
110            <dd>Not used by this driver.
111            <dt><tt>flag3 0 | 1</tt>
112            <dd>Not used by this driver.
113            <dt><tt>flag4 0 | 1</tt>
114            <dd>If flag4 is set, clockstats records will be written when the driver is polled.
115            <h4>Additional Information</h4>
116            <p><a href="/refclock.html">Reference Clock Drivers</a></p>
117        </dl>
118        <hr>
119        <script type="text/javascript" language="javascript" src="scripts/footer.txt"></script>
120    </body>
121
122</html>
123
124