Hi folks,
Today when changing an IOC from 3.14.12 to EPICS 7, I got a new warning message:
initPeriodic: Scan rate '.01 second' is not achievable.
At least on Linux this is not true. The scan rate works perfectly fine.
The reason for this message is that the scan rate gets compared to
epicsThreadSleepQuantum(), which for posix systems is 1.0/sysconf(_SC_CLK_TCK).
However sysconf(_SC_CLK_TCK) always(?) returns 100(Hz) on Linux and is not at
all related to the minimal time a thread can wait (with pthread_cond_timedwait()
on posix systems).
The posix implementation for convertDoubleToWakeTime() uses
clock_gettime(CLOCK_REALTIME, &now) on systems where CLOCK_REALTIME exists (all
Linux?) and gettimeofday() on all others. Thus the value returned by
clock_getres(CLOCK_REALTIME, &res) is probably a better value for
epicsThreadSleepQuantum() on such systems. And 1e-3 on systems where
CLOCK_REALTIME does not exist, as that is the resolution of gettimeofday().
However on all Linux systems I tested clock_getres() returns 1 nanosecond, which
I do not really believe to be the real sleep quantum either. Maybe the bogomips
value from /proc/cpuinfo is more realistic?
I suggest to change epicsThreadSleepQuantum() for posix to use
clock_getres(CLOCK_REALTIME, ...) until a better method can be found.
Patch attached.
Dirk
diff --git a/modules/libcom/src/osi/os/posix/osdThread.c b/modules/libcom/src/osi/os/posix/osdThread.c
index 8544418..7b75bdd 100644
--- a/modules/libcom/src/osi/os/posix/osdThread.c
+++ b/modules/libcom/src/osi/os/posix/osdThread.c
@@ -904,11 +904,13 @@ epicsShareFunc void epicsShareAPI *epicsThreadPrivateGet(epicsThreadPrivateId id
epicsShareFunc double epicsShareAPI epicsThreadSleepQuantum ()
{
- double hz;
- hz = sysconf ( _SC_CLK_TCK );
- if(hz<0)
- return 0.0;
- return 1.0 / hz;
+#ifdef CLOCK_REALTIME
+ struct timespec res;
+ if (clock_getres(CLOCK_REALTIME, &res) == 0)
+ return res.tv_sec + 1e-9 * res.tv_nsec;
+ else
+#endif
+ return 1e-3;
}
epicsShareFunc int epicsThreadGetCPUs(void)
- Navigate by Date:
- Prev:
[Merge] ~epics-core/epics-base/+git/Com:thread-join into epics-base:7.0 Andrew Johnson via Core-talk
- Next:
EPICS 7 array link inconsistencies Zimoch Dirk (PSI) via Core-talk
- Index:
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
<2019>
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
Normative Types document Timo Korhonen via Core-talk
- Next:
Re: Misleading "initPeriodic: Scan rate ... is not achievable" and sleep quantum implementation Zimoch Dirk (PSI) via Core-talk
- Index:
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
<2019>
2020
2021
2022
2023
2024
|