Argonne National Laboratory

Experimental Physics and
Industrial Control System

2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  <2020 Index 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  <2020
<== Date ==> <== Thread ==>

Subject: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0
From: Freddie Akeroyd via Core-talk <core-talk at aps.anl.gov>
To: mp+391018 at code.launchpad.net
Date: Fri, 18 Sep 2020 23:20:39 -0000
Freddie Akeroyd has proposed merging ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0.

Commit message:
Fix and enable use of QueryPerformanceCounter() on WIN32, also fallback to using GetTickCount64() to avoid issues with to GetTickCount() wrapping  

Requested reviews:
  EPICS Core Developers (epics-core)

For more details, see:
https://code.launchpad.net/~freddie-akeroyd/epics-base/+git/epics-base/+merge/391018
-- 
Your team EPICS Core Developers is requested to review the proposed merge of ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0.
diff --git a/modules/libcom/src/osi/os/WIN32/osdMonotonic.c b/modules/libcom/src/osi/os/WIN32/osdMonotonic.c
index cb84643..e9fce38 100644
--- a/modules/libcom/src/osi/os/WIN32/osdMonotonic.c
+++ b/modules/libcom/src/osi/os/WIN32/osdMonotonic.c
@@ -14,17 +14,18 @@
 #include "generalTimeSup.h"
 
 static unsigned char osdUsePrefCounter;
-static epicsUInt64 osdMonotonicResolution;
+static epicsUInt64 osdMonotonicResolution; /* timer resolution in nanoseconds */
+static double perfCounterScale; /* convert performance counter tics to nanoseconds */
 
 void osdMonotonicInit(void)
 {
     LARGE_INTEGER freq, val;
 
-    if(!QueryPerformanceFrequency(&freq) ||
-            !QueryPerformanceCounter(&val))
+    if(QueryPerformanceFrequency(&freq) &&
+            QueryPerformanceCounter(&val))
     {
-        double period = 1.0/freq.QuadPart;
-        osdMonotonicResolution = period*1e9;
+        perfCounterScale = 1e9 / freq.QuadPart;
+        osdMonotonicResolution = 1 + (int)perfCounterScale;
         osdUsePrefCounter = 1;
     } else {
         osdMonotonicResolution = 1e6; /* 1 ms TODO place holder */
@@ -44,9 +45,14 @@ epicsUInt64 epicsMonotonicGet(void)
             errMessage(errlogMinor, "Warning: failed to fetch performance counter\n");
             return 0;
         } else
-            return val.QuadPart;
+            return val.QuadPart * perfCounterScale;
     } else {
-        epicsUInt64 ret = GetTickCount();
+        epicsUInt64 ret =
+#if _WIN32_WINNT >= 0x0600 /* Windows Vista / Server 2008 and later */
+                   GetTickCount64();
+#else
+                   GetTickCount(); /* this wraps every 49.7 days */
+#endif /* _WIN32_WINNT >= 0x0600 */
         ret *= 1000000;
         return ret;
     }

Replies:
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 mdavidsaver via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 Freddie Akeroyd via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 Freddie Akeroyd via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 Freddie Akeroyd via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 mdavidsaver via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 Freddie Akeroyd via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 Freddie Akeroyd via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 Freddie Akeroyd via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 mdavidsaver via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 mdavidsaver via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 mdavidsaver via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 Freddie Akeroyd via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 Freddie Akeroyd via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 mdavidsaver via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 Freddie Akeroyd via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 Freddie Akeroyd via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 mdavidsaver via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 mdavidsaver via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 Freddie Akeroyd via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 Freddie Akeroyd via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 mdavidsaver via Core-talk
Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 mdavidsaver via Core-talk

Navigate by Date:
Prev: [Bug 1896295] Re: WIN32: IOC scan loops hang mdavidsaver via Core-talk
Next: [Bug 1896295] Re: WIN32: IOC scan loops hang Freddie Akeroyd via Core-talk
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  <2020
Navigate by Thread:
Prev: [Bug 1896295] Re: WIN32: IOC scan loops hang mdavidsaver via Core-talk
Next: Re: [Merge] ~freddie-akeroyd/epics-base:fix_win32_monotonic_time into epics-base:7.0 mdavidsaver via Core-talk
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  <2020
ANJ, 03 Nov 2020 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·