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

Consolidate CFE_PSP_Get_Timebase and CFE_PSP_GetTime #1244

Open
jphickey opened this issue Mar 18, 2021 · 1 comment
Open

Consolidate CFE_PSP_Get_Timebase and CFE_PSP_GetTime #1244

jphickey opened this issue Mar 18, 2021 · 1 comment
Assignees

Comments

@jphickey
Copy link
Contributor

Describe the bug
This PSP function is not particularly well-documented. On some systems (pc-linux) it ultimately returns the value of the POSIX "CLOCK_MONOTONIC" clock from the kernel. But on MCP750 it is calculated from a hardware tick counter that wraps every 27 seconds. There is a bunch of logic in CFE TIME to handle handle this wrap.

To Reproduce
The bug is that the background task also samples CFE_PSP_GetTime but does not check for wrap, which works fine on Linux but on VxWorks this probably introduces a timing anomaly every 27 seconds when it wraps. This probably isn't all that noticeable/serious because the background job will just runs an extra cycle and then resume normal operation, but incorrect nonetheless.

Expected behavior
Background job should sample a clock that is known/defined to be monotonic and has consistent/simpler rollover logic.

Alternatives could be the OSAL timebase that drives the 1Hz. However this is not guaranteed to exist on platforms that do not use the RTOS for the 1Hz. So it might be necessary to define a new PSP function, similar to CFE_PSP_GetTime, but is defined to be monotonic and has a more well-defined rollover characteristic. Then this PSP function can just read whatever facility is providing 1Hz signal - RTOS/OSAL, hardware register, or whatever.

Code snips
In particular the code here:

CFE_PSP_GetTime(&CurrTime);
ElapsedTime = OS_TimeGetTotalMilliseconds(OS_TimeSubtract(CurrTime, LastTime));

This works fine on Linux but likely causes an anomaly every 27 seconds on MCP750 when the clock rolls over.

System observed on:
Found during Inspection when looking at other issues.

Reporter Info
Joseph Hickey, Vantage Systems, Inc.

@jphickey
Copy link
Contributor Author

With the fix in nasa/PSP#286 this makes it so CFE_PSP_GetTime is properly monotonic and does not wrap - at least not within a few thousand years of uptime.

It would still be good to consolidate CFE_PSP_GetTime() and CFE_PSP_Get_Timebase() such that the latter can be deprecated/removed - having two functions that do very similar things is not really ideal.

@jphickey jphickey changed the title Inconsistent use of CFE_PSP_GetTime Consolidate CFE_PSP_Get_Timebase and CFE_PSP_GetTime Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant