OSI monotonic time source
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
EPICS Base |
In Progress
|
Wishlist
|
mdavidsaver |
Bug Description
There is a need for seperate real (wall clock) and monotonic time sources.
On 11/13/2014 04:18 PM, J. Lewis Muir wrote:> Hello, Tech-Talkers.
>
> Is there a way to get monotonic time from EPICS Base libCom?
>
> By "monotonic time," I mean a system time that increases at a steady
> rate and is not affected by a change to the system's RTC. The origin of
> the time is unspecified, but the difference between two monotonic times
> can be used to compute elapsed time. [1]
>
> I think the answer is no, but I thought I'd ask. I'd like a simple way
> to implement a timeout in a C function like this:
>
> start_time = epicsTimeGetMon
> for (;;) {
> if (is_data_ready()) goto out;
> elapsed_time = epicsTimeGetMon
> if (elapsed_time > timeout) goto timeout;
> epicsThreadSlee
> }
>
> Without monotonic time, the closest I can get to this in a simple way
> is to use epicsTimeGetCurrent and epicsTimeDiffIn
> suboptimal because I have to deal with time that can advance backward
> or forward in an unpredictable way, and it's not possible to correctly
> compensate for that. For example, if the elapsed time is negative, time
> has advanced backward, and I need to set the start time to the new time.
> This has the undesirable effect of extending the timeout to an actual
> amount of time longer than the caller requested. If time is slowly
> advancing backward, this could have the undesirable effect of extending
> the actual timeout indefinitely. And if time has advanced forward
> faster than normal (either by being set or due to a system suspend), it
> would have the undesirable effect of reducing the actual timeout to an
> amount of time shorter than the caller requested.
>
> Thank you!
>
> Lewis
>
> [1] It seems that most, if not all, implementations of monotonic time
> will suspend the monotonic clock during a system suspend. This
> way, programs using time from such a monotonic clock will function
> normally through a system suspend-resume cycle. However, if
> the process itself is suspended, when it resumes, it will see a
> monotonic time that has advanced "faster" than it expected. In
> other words, the monotonic time is per-system, not per-process. (I
> see that Linux has a CLOCK_PROCESS_
> overcome this, but I'm not sure something like this is available on
> the other OSes supported by EPICS.)
>
Related branches
- mdavidsaver: Disapprove
-
Diff: 416 lines (+262/-1)12 files modifiedsrc/libCom/osi/Makefile (+1/-0)
src/libCom/osi/epicsTime.h (+11/-0)
src/libCom/osi/os/Darwin/osdMonotonic.c (+32/-0)
src/libCom/osi/os/Darwin/osdTime.cpp (+3/-0)
src/libCom/osi/os/RTEMS/osdTime.cpp (+3/-0)
src/libCom/osi/os/WIN32/osdMonotonic.c (+53/-0)
src/libCom/osi/os/WIN32/osdTime.cpp (+3/-0)
src/libCom/osi/os/iOS/osdMonotonic.c (+31/-0)
src/libCom/osi/os/posix/osdMonotonic.c (+75/-0)
src/libCom/osi/os/posix/osdTime.cpp (+3/-0)
src/libCom/osi/os/vxWorks/osdTime.cpp (+3/-0)
src/libCom/test/epicsTimeTest.cpp (+44/-1)
Changed in epics-base: | |
assignee: | nobody → mdavidsaver (mdavidsaver) |
Changed in epics-base: | |
status: | New → In Progress |
I think it wouldn't be difficult to add a real monotonic time source which defaults to epicsTimeGetCur rent() for platforms without such a time source. POSIX has clock_gettime w/ CLOCK_MONOTONIC and similar (RTEMS implements this). Windows has something as well. Not sure about vxWorks.