]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Add support for nanoseconds in SHM
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 6 Sep 2012 17:00:32 +0000 (19:00 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 10 Sep 2012 15:31:56 +0000 (17:31 +0200)
chrony.texi
refclock_shm.c

index 923028dadcef73d9e38a558348e336fb3e3fd059..7fd63eed13f70368a3840c3dd8cfd0ebe5e6d2ce 100644 (file)
@@ -2468,7 +2468,7 @@ Some examples of applications that can be used as SHM sources are @code{gpsd},
 @item SOCK
 Unix domain socket driver.  It is similar to the SHM driver, but uses a
 different format and uses a socket instead of shared memory.  It does not
-require polling, the offset resolution is not limited to microseconds and it
+require polling and it
 supports transmitting of PPS data.  The parameter is a path to the socket which
 will be created by @code{chronyd} and used to receive the messages.  The format
 of messages sent over the socket is described in the
index b9edea41a8a62c102d60fbdd294b18d58a848194..110236fbfc839831ebcea3b2ce6b2665b2bb4365 100644 (file)
@@ -45,7 +45,7 @@ struct shmTime {
                 *         use values 
                 *       clear valid
                 */
-  int    count;
+  volatile int count;
   time_t clockTimeStampSec;
   int    clockTimeStampUSec;
   time_t receiveTimeStampSec;
@@ -53,8 +53,10 @@ struct shmTime {
   int    leap;
   int    precision;
   int    nsamples;
-  int    valid;
-  int    dummy[10]; 
+  volatile int valid;
+  int    clockTimeStampNSec;
+  int    receiveTimeStampNSec;
+  int    dummy[8]; 
 };
 
 static int shm_initialise(RCL_Instance instance) {
@@ -89,7 +91,7 @@ static void shm_finalise(RCL_Instance instance)
 
 static int shm_poll(RCL_Instance instance)
 {
-  struct timeval tv1, tv2;
+  struct timeval tv;
   struct shmTime t, *shm;
   double offset;
 
@@ -107,13 +109,17 @@ static int shm_poll(RCL_Instance instance)
 
   shm->valid = 0;
 
-  tv1.tv_sec = t.receiveTimeStampSec;
-  tv1.tv_usec = t.receiveTimeStampUSec;
-  tv2.tv_sec = t.clockTimeStampSec;
-  tv2.tv_usec = t.clockTimeStampUSec;
+  tv.tv_sec = t.receiveTimeStampSec;
+  tv.tv_usec = t.receiveTimeStampUSec;
 
-  UTI_DiffTimevalsToDouble(&offset, &tv2, &tv1);
-  return RCL_AddSample(instance, &tv1, offset, t.leap);
+  offset = t.clockTimeStampSec - t.receiveTimeStampSec;
+  if (t.clockTimeStampNSec / 1000 == t.clockTimeStampUSec &&
+      t.receiveTimeStampNSec / 1000 == t.receiveTimeStampUSec)
+    offset += (t.clockTimeStampNSec - t.receiveTimeStampNSec) * 1e-9;
+  else
+    offset += (t.clockTimeStampUSec - t.receiveTimeStampUSec) * 1e-6;
+
+  return RCL_AddSample(instance, &tv, offset, t.leap);
 }
 
 RefclockDriver RCL_SHM_driver = {