Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect time to first callback when using OS_TimerCreate API #271

Closed
jphickey opened this issue Oct 22, 2019 · 0 comments · Fixed by #281
Closed

Incorrect time to first callback when using OS_TimerCreate API #271

jphickey opened this issue Oct 22, 2019 · 0 comments · Fixed by #281
Assignees
Labels
Milestone

Comments

@jphickey
Copy link
Contributor

Describe the bug
There discrepancies between the expected first callback and the time the first callback actually occurs, for timers created via OS_TimerCreate(). This is with regards to the "start_time" parameter.

To Reproduce
The timer-test example program exposes this bug. It was never seen because on POSIX the difference is not substantial enough to cause failure, but on VxWorks it does fail.

General sequence is:
Create a timer via OS_TimerCreate()
Set the timer using OS_TimerSet() with start_time=2000000 (2 sec) and interval_time=400000 (400ms).

The time between the OS_TimerSet call and the first timer callback should be 2 seconds (within system timer tick tolerances) but it is approximately 2.4 seconds on POSIX. On VxWorks the difference is even more substantial, causing failure of the timer-test example program.

Expected behavior
The time between the OS_TimerSet call and the first timer callback should be equivalent to the start_time parameter from the OS_TimerSet call.

System observed on:
Ubuntu 18.04.2 LTS, 64 bit, using posix OSAL build
VxWorks 6.9 on MCP750, using vxworks OSAL build
Both running the "timer-test" example program.

Additional context
This appears to be limited to cases where the backward-compatible OS_TimerCreate API is used. In this case an implicit timebase object is created just to service the single timer. In this mode, there is an initial condition issue in the wait routine, and the first interval therefore is not correct.

If the timer callback is registered via OS_TimeBaseCreate() followed by OS_TimerAdd(), then it is OK.

Reporter Info
Joseph Hickey, Vantage Systems, Inc.

@jphickey jphickey self-assigned this Oct 23, 2019
jphickey added a commit that referenced this issue Oct 23, 2019
In VxWorks, the sigwait routine was not handling the actual time of
the first interval, which basically meant that the start_time was
elapsed twice before the first callback was generated.

This exposed a few other small but significant details regarding
how the intervals were dealt with across all operating systems.

For VxWorks and RTEMS, where the timer interval is rounded up to
an integer number of ticks, compute the actual interval time and
write a debug message in case it is different than the intended
value.  This makes it more obvious to the user that some
application/bsp changes might be necessary to get accurate timing.

For all operating systems, the "reset" flag needs to be sampled
AFTER the sigwait returns, not before it.  This flag gets set when
the OS_TimeBaseSet() API is called.

Removes an unused POSIX delay routine that was intended to support
use of clock_nanosleep() in place of the timer signal.  This mode
was never usable because OS_TimerCreate always allocates a signal and
fails if it cannot do so.  This code caused problems/incompatibilities
for the sigwait model which IS used, so it needed to be removed.
jphickey added a commit to jphickey/osal that referenced this issue Oct 25, 2019
The timer code for VxWorks was fixed in bug nasa#271 and the
coverage code test needs a corresponding update to cover
the code change.

This is kept as a separate update commit as neither
changeset is merged to master yet.
@skliper skliper added the bug label Oct 30, 2019
@skliper skliper added this to the 5.1.0 milestone Oct 30, 2019
skliper pushed a commit that referenced this issue Oct 31, 2019
In VxWorks, the sigwait routine was not handling the actual time of
the first interval, which basically meant that the start_time was
elapsed twice before the first callback was generated.

This exposed a few other small but significant details regarding
how the intervals were dealt with across all operating systems.

For VxWorks and RTEMS, where the timer interval is rounded up to
an integer number of ticks, compute the actual interval time and
write a debug message in case it is different than the intended
value.  This makes it more obvious to the user that some
application/bsp changes might be necessary to get accurate timing.

For all operating systems, the "reset" flag needs to be sampled
AFTER the sigwait returns, not before it.  This flag gets set when
the OS_TimeBaseSet() API is called.

Removes an unused POSIX delay routine that was intended to support
use of clock_nanosleep() in place of the timer signal.  This mode
was never usable because OS_TimerCreate always allocates a signal and
fails if it cannot do so.  This code caused problems/incompatibilities
for the sigwait model which IS used, so it needed to be removed.
skliper added a commit that referenced this issue Oct 31, 2019
Fixes #271 #272 #273 #274
Code reviewed and approved at 20191030 CCB
jphickey added a commit to jphickey/osal that referenced this issue Dec 18, 2019
This is related to the change for nasa#271, where the return value
of this function depends on the configured timer interval.  The
coverage test case for this was not updated in the original change.
skliper pushed a commit that referenced this issue Dec 30, 2019
This is related to the change for #271, where the return value
of this function depends on the configured timer interval.  The
coverage test case for this was not updated in the original change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants