-
Notifications
You must be signed in to change notification settings - Fork 217
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
Use a better time representation in OS_stat call #429
Comments
Two potential approaches:
Advantage: Should be mostly backward compatible. Code reading "seconds" and "microsecs" fields should still work as expected.
Advantage: Keeps the same size (8) and resolution (microseconds) but expands the useful range to over 100,000 years. Also makes adding and subtracting times much simpler as simple arithmetic just works and no need to worry about carrying over microseconds to seconds. My preference leans toward the option 2 above, because of the simplicity it allows with respect to time arithmetic. |
After some more experimentation, I am still leaning toward (2) above. It will break the API by changing the format of this structure, but the net result will be more robust and easier to use. To minimize breakage it needs to be done in 3 steps: Step 1 - Add static inline functions to serve as Accessors for
Not strictly necessary initially but recommend adding for completeness, as it allows use of more optimized conversions depending on how OS_time_t gets ultimately defined:
Step 2 - Scrub all refs in CFE/Apps to use the accessors above rather than accessing Step 3 - Change OSAL |
Do not access members of OS_time_t directly, instead use conversion/accessor inline functions to get the desired value.
Do not access members of OS_time_t directly, instead use conversion/accessor inline functions to get the desired value.
Do not access members of OS_time_t directly, instead use conversion/accessor inline functions to get the desired value.
Do not access members of OS_time_t directly, instead use conversion/accessor inline functions to get the desired value. Update the "stat" structure output by OS_stat to use the OS_time_t struct instead of int32, and update the OS_stat implemention to transfer the full resolution if it supports it (POSIX.1-2008 or newer).
Do not access members of OS_time_t directly, instead use conversion/accessor inline functions to get the desired value. Update the "stat" structure output by OS_stat to use the OS_time_t struct instead of int32, and update the OS_stat implemention to transfer the full resolution if it supports it (POSIX.1-2008 or newer).
Add test cases to coverage test to validate all basic OS_time_t access operations and conversions.
Use a single 64-bit tick counter as OS_time_t, rather than a split 32 bit seconds + 32 bit microseconds counter. This benefits in several ways: - increases the timing precision by 10x (0.1us ticks) - increases the representable range by 400x (+/-14000 yrs) - simplifies addition/subtraction (no carry over) - avoids "year 2038" bug w/32-bit timestamps
Regarding the PRs for this - this currently has two PRs linked to close it. First is #723, which represents "step 1" in my previous comment above and has no special dependencies and does not break anything. Second is #735, which represents "step 3" in my previous comment above. This has to be merged with the other PRs that resolve its dependencies. Submitted separately so the CCB can choose how to merge them (play it slow or just put them all in at once). |
Add OS_TimeAssembleFromMilliseconds and OS_TimeAssembleFromMicroseconds for a complete set of conversion routines in both directions.
Fix nasa#429, add OS_time_t access functions
Use a single 64-bit tick counter as OS_time_t, rather than a split 32 bit seconds + 32 bit microseconds counter. This benefits in several ways: - increases the timing precision by 10x (0.1us ticks) - increases the representable range by 400x (+/-14000 yrs) - simplifies addition/subtraction (no carry over) - avoids "year 2038" bug w/32-bit timestamps
Fix #429, OS_time_t with single tick counter
Is your feature request related to a problem? Please describe.
The
OS_stat
call currently returns the file time as anint32
member within theos_fstat_t
structure, as defined here:osal/src/os/inc/osapi-os-filesys.h
Line 154 in a66eb2d
This isn't really documented in the API but the field is a traditional UNIX-style timestamp, which is seconds elapsed since Jan 1 1970 UTC.
This type of timestamp suffers from the "year 2038" bug, where the int32 value rolls over and becomes negative. Although this is 18 years from now, at the timescales of space software development cycles, it is entirely possible that coding being developed now will still be in service at the time this happens, so it should be fixed sooner rather than later.
Describe the solution you'd like
There are two fixes needed:
OS_time_t
representation as used inOS_GetLocalTime
andOS_SetLocalTime
. This is just for consistency - shouldn't use a different representation of time as the other API calls do.OS_time_t
to accommodate larger timestamp values and/or use a different epoch (latter would be risk but keep the structure the same size).Additional context
Discussion regarding use of this field in nasa/cFE#519
Requester Info
Joseph Hickey, Vantage Systems, Inc.
The text was updated successfully, but these errors were encountered: