EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  <20162017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  <20162017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: NTP time provider and ticksPerSecond
From: Andrew Johnson <[email protected]>
To: Michael Westfall <[email protected]>, <[email protected]>
Date: Tue, 17 May 2016 11:24:08 -0500
Hi Mike,

On 05/17/2016 11:05 AM, Michael Westfall wrote:
> Is there a way to delay initializing the NTP time provider until after
> my custom clock tick provider has set the system clock tick rate?

There was a change committed to the 3.15 branch of Base before 3.15.1 to
make the NTP time provider adjust automatically to changes in the system
clock tick rate. Changing the tick rate after iocInit is not advisable,
but in your case this change may be all you need. Since you're evidently
using a 3.14.12 release of Base you should be able to apply the attached
patch file to your copy.

HTH,

- Andrew

-- 
Arguing for surveillance because you have nothing to hide is no
different than making the claim, "I don't care about freedom of
speech because I have nothing to say." -- Edward Snowdon
=== modified file 'documentation/RELEASE_NOTES.html'
--- documentation/RELEASE_NOTES.html	2014-02-13 15:59:10 +0000
+++ documentation/RELEASE_NOTES.html	2014-02-13 16:09:12 +0000
@@ -15,6 +15,14 @@
 <h2 align="center">Changes between 3.15.0.1 and 3.15.0.2</h2>
 <!-- Insert new items immediately below here ... -->
 
+<h3>NTP Time Provider adjusts to OS tick rate changes</h3>
+
+<p>Dirk Zimoch provided code that allows the NTP Time provider (used on VxWorks
+and RTEMS only) to adapt to changes in the OS clock tick rate after the provider
+has been initialized. Note that changing the tick rate after iocInit() is not
+advisable, and that other software might still misbehave if initialized before
+an OS tick rate change.</p>
+
 <h3>Added newEpicsMutex macro</h3>
 
 <p>Internal C++ uses of <tt>new epicsMutex()</tt> have been replaced with a new

=== modified file 'src/libCom/osi/osiNTPTime.c'
--- src/libCom/osi/osiNTPTime.c	2010-10-22 22:34:13 +0000
+++ src/libCom/osi/osiNTPTime.c	2014-02-13 16:09:12 +0000
@@ -47,8 +47,6 @@
     epicsUInt32     syncTick;
     epicsTimeStamp  clockTime;
     epicsUInt32     clockTick;
-    epicsUInt32     nsecsPerTick;
-    epicsUInt32     ticksPerSecond;
     epicsUInt32     ticksToSkip;
     double          tickRate;
 } NTPTimePvt;
@@ -90,8 +88,6 @@
     NTPTimePvt.loopEvent      = epicsEventMustCreate(epicsEventEmpty);
     NTPTimePvt.syncsFailed    = 0;
     NTPTimePvt.lock           = epicsMutexCreate();
-    NTPTimePvt.ticksPerSecond = osdTickRateGet();
-    NTPTimePvt.nsecsPerTick   = NSEC_PER_SEC / NTPTimePvt.ticksPerSecond;
 
     /* Initialize OS-dependent code */
     osdNTPInit();
@@ -100,7 +96,7 @@
     if (!osdNTPGet(&timespecNow)) {
         NTPTimePvt.syncTick = osdTickGet();
         if (timespecNow.tv_sec > POSIX_TIME_AT_EPICS_EPOCH && epicsTimeOK ==
-            epicsTimeFromTimespec(&NTPTimePvt.syncTime, &timespecNow)) {
+                epicsTimeFromTimespec(&NTPTimePvt.syncTime, &timespecNow)) {
             NTPTimePvt.clockTick = NTPTimePvt.syncTick;
             NTPTimePvt.clockTime = NTPTimePvt.syncTime;
             NTPTimePvt.synchronized = 1;
@@ -191,7 +187,7 @@
         if (diff >= 0.0) {
             NTPTimePvt.ticksToSkip = 0;
         } else { /* dont go back in time */
-            NTPTimePvt.ticksToSkip = -diff * NTPTimePvt.ticksPerSecond;
+            NTPTimePvt.ticksToSkip = -diff * osdTickRateGet();
         }
         NTPTimePvt.clockTick = tickNow;
         NTPTimePvt.clockTime = timeNow;
@@ -230,10 +226,12 @@
         }
 
         if (ticksSince) {
-            epicsUInt32 secsSince = ticksSince / NTPTimePvt.ticksPerSecond;
-            ticksSince -= secsSince * NTPTimePvt.ticksPerSecond;
+            epicsUInt32 ticksPerSecond = osdTickRateGet();
+            epicsUInt32 nsecsPerTick = NSEC_PER_SEC / ticksPerSecond;
+            epicsUInt32 secsSince = ticksSince / ticksPerSecond;
 
-            NTPTimePvt.clockTime.nsec += ticksSince * NTPTimePvt.nsecsPerTick;
+            ticksSince -= secsSince * ticksPerSecond;
+            NTPTimePvt.clockTime.nsec += ticksSince * nsecsPerTick;
             if (NTPTimePvt.clockTime.nsec >= NSEC_PER_SEC) {
                 secsSince++;
                 NTPTimePvt.clockTime.nsec -= NSEC_PER_SEC;
@@ -265,14 +263,15 @@
         }
         if (level) {
             char lastSync[32];
+
             epicsTimeToStrftime(lastSync, sizeof(lastSync),
                 "%Y-%m-%d %H:%M:%S.%06f", &NTPTimePvt.syncTime);
             printf("Syncronization interval = %.1f seconds\n",
                 NTPTimeSyncInterval);
             printf("Last synchronized at %s\n",
                 lastSync);
-            printf("OS tick rate = %u Hz (nominal)\n",
-                NTPTimePvt.ticksPerSecond);
+            printf("Current OS tick rate = %u Hz\n",
+                osdTickRateGet());
             printf("Measured tick rate = %.3f Hz\n",
                 NTPTimePvt.tickRate);
             osdNTPReport();


Replies:
Re: NTP time provider and ticksPerSecond Michael Westfall
Re: NTP time provider and ticksPerSecond Matt Rippa
References:
NTP time provider and ticksPerSecond Michael Westfall

Navigate by Date:
Prev: NTP time provider and ticksPerSecond Michael Westfall
Next: Re: NTP time provider and ticksPerSecond Michael Westfall
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  <20162017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: NTP time provider and ticksPerSecond Michael Westfall
Next: Re: NTP time provider and ticksPerSecond Michael Westfall
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  <20162017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 15 Jul 2016 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·