From 3b8fd13152099617dea67432fa9e14c8c21e5810 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Tue, 17 May 2016 16:03:27 -0500 Subject: [PATCH 1/2] libCom: NTP Time Provider adjusts to OS tick rate changes Allow 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. Changing the tick rate after iocInit() is not advisable, other software might still misbehave if initialized before an OS tick rate change. Back-ported from the 3.15 branch (commit 12468). --- documentation/RELEASE_NOTES.html | 8 ++++++++ src/libCom/osi/osiNTPTime.c | 21 ++++++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/documentation/RELEASE_NOTES.html b/documentation/RELEASE_NOTES.html index efec011ba..7c6692898 100644 --- a/documentation/RELEASE_NOTES.html +++ b/documentation/RELEASE_NOTES.html @@ -13,6 +13,14 @@ +

NTP Time Provider adjusts to OS tick rate changes

+ +

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. This change was back-ported from the 3.15 branch.

+

Making IOC ca_get operations atomic

When a CA client gets data from an IOC record using a compound data type such diff --git a/src/libCom/osi/osiNTPTime.c b/src/libCom/osi/osiNTPTime.c index d085cca31..909e6f121 100644 --- a/src/libCom/osi/osiNTPTime.c +++ b/src/libCom/osi/osiNTPTime.c @@ -47,8 +47,6 @@ static struct { epicsUInt32 syncTick; epicsTimeStamp clockTime; epicsUInt32 clockTick; - epicsUInt32 nsecsPerTick; - epicsUInt32 ticksPerSecond; epicsUInt32 ticksToSkip; double tickRate; } NTPTimePvt; @@ -90,8 +88,6 @@ static void NTPTime_InitOnce(void *pprio) 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 @@ static void NTPTime_InitOnce(void *pprio) if (!osdNTPGet(×pecNow)) { NTPTimePvt.syncTick = osdTickGet(); if (timespecNow.tv_sec > POSIX_TIME_AT_EPICS_EPOCH && epicsTimeOK == - epicsTimeFromTimespec(&NTPTimePvt.syncTime, ×pecNow)) { + epicsTimeFromTimespec(&NTPTimePvt.syncTime, ×pecNow)) { NTPTimePvt.clockTick = NTPTimePvt.syncTick; NTPTimePvt.clockTime = NTPTimePvt.syncTime; NTPTimePvt.synchronized = 1; @@ -191,7 +187,7 @@ static void NTPTimeSync(void *dummy) 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 @@ static int NTPTimeGetCurrent(epicsTimeStamp *pDest) } 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 @@ int NTPTime_Report(int level) } 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(); From 6c9555310ab644f2a2c38fa0bc486a83fdde452d Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 18 May 2016 10:26:04 -0500 Subject: [PATCH 2/2] Update EPICS_TIMEZONE with info for 2016-2021 --- configure/CONFIG_SITE_ENV | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/configure/CONFIG_SITE_ENV b/configure/CONFIG_SITE_ENV index 75bf1a2f8..41ebb09db 100644 --- a/configure/CONFIG_SITE_ENV +++ b/configure/CONFIG_SITE_ENV @@ -30,21 +30,23 @@ # local timezone info for vxWorks and RTEMS IOCs. The format is # :::: # where the start and end are mmddhh - that is month,day,hour -# e.g. for ANL in 2010: EPICS_TIMEZONE=CUS::360:031402:110702 +# e.g. for ANL in 2016: EPICS_TIMEZONE=CUS::360:031302:110602 # -# DST for 2011 US: Mar 13 - Nov 06 +# DST for 2016 US: Mar 13 - Nov 06 # EU: Mar 27 - Oct 30 -# DST for 2012 US: Mar 11 - Nov 04 +# DST for 2017 US: Mar 12 - Nov 05 +# EU: Mar 26 - Oct 29 +# DST for 2018 US: Mar 11 - Nov 04 # EU: Mar 25 - Oct 28 -# DST for 2013 US: Mar 10 - Nov 03 +# DST for 2019 US: Mar 10 - Nov 03 # EU: Mar 31 - Oct 27 -# DST for 2014 US: Mar 09 - Nov 02 -# EU: Mar 30 - Oct 26 -# DST for 2015 US: Mar 08 - Nov 01 +# DST for 2020 US: Mar 08 - Nov 01 # EU: Mar 29 - Oct 25 -# (see: http://www.worldtimezone.org/daylight.html) +# DST for 2021 US: Mar 14 - Nov 07 +# EU: Mar 28 - Oct 31 +# (see: http://www.timeanddate.com/time/dst/2016.html etc. ) # -# These values are for 2011: +# These values are for 2016: EPICS_TIMEZONE=CUS::360:031302:110602 #EPICS_TIMEZONE=MET::-60:032702:103002