-
Notifications
You must be signed in to change notification settings - Fork 7.4k
kernel: add k_clock api: remove posix dependency from iso c time #90096
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
Draft
cfriedt
wants to merge
17
commits into
zephyrproject-rtos:main
Choose a base branch
from
cfriedt:remove-posix-from-time-equation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
kernel: add k_clock api: remove posix dependency from iso c time #90096
cfriedt
wants to merge
17
commits into
zephyrproject-rtos:main
from
cfriedt:remove-posix-from-time-equation
+1,278
−260
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a403e85
to
83dc940
Compare
375c774
to
7872928
Compare
swap the relative position of the __cplusplus closing bracket and the doxygen end-group comment. Signed-off-by: Chris Friedt <[email protected]>
Add a number of utility functions for manipulating struct timespec. * timespec_add() * timespec_compare() * timespec_equal() * timespec_is_valid() * timespec_negate() * timespec_normalize() * timespec_sub() If the `__builtin_add_overflow()` function is available, then the API is mostly branchless, which should provide decent performance on systems with an instruction cache and branch prediction. Otherwise, manually written alternatives exist that are also perhaps more readable. Signed-off-by: Chris Friedt <[email protected]>
Add a timespec util testsuite. This should have reasonably high enough coverage to be useful. I would have preferred to add this as an architecture-independent unit test (for the unit_testing platform) under tests/unit/timeutil but there is an inconsistency about the size of time_t on the unit_testing and native_sim/native platforms. On every other platform supported by Zephyr, time_t is 64-bits. However, on those platforms, time_t is only 32-bits. Signed-off-by: Chris Friedt <[email protected]>
Use the newly added timespec util functions to manipulate and compare timespec structures with overflow detection. Signed-off-by: Chris Friedt <[email protected]>
Add documentation in the timeutil group for recently added functions for validating, comparing, and manipulating `struct timespec` objects. Signed-off-by: Chris Friedt <[email protected]>
Add the k_clock API, comprised of: * k_clock_gettime() * k_clock_settime() * k_clock_nanosleep() along with the constants * K_CLOCK_REALTIME * K_CLOCK_MONOTONIC * K_TIMER_ABSTIME The primary motivation for this API is so that libc and other libraries have a familiar-enough API to reach to when POSIX is not available, since POSIX is optional in Zephyr. By adding this API to the Zephyr kernel, we also eliminate dependency cycles between libc and posix, as the kernel is a mutual dependency. Signed-off-by: Chris Friedt <[email protected]>
7536ee9
to
cd3e327
Compare
Add functions to convert durations between representation as struct timespec and k_timeout_t. Signed-off-by: Chris Friedt <[email protected]>
Add documentation to timeutil.rst for timespec_to_timeout() and timespec_from_timeout(). Signed-off-by: Chris Friedt <[email protected]>
Remove POSIX clock_gettime() from the common libc time implementation, since POSIX should not be a dependency for ISO C. Signed-off-by: Chris Friedt <[email protected]>
Use the implementation of time() from the common libc, since there it no longer pulls in POSIX. Use is implied for minimal, newlib, and picolibc, and selected for IAR. Signed-off-by: Chris Friedt <[email protected]>
Reduce the dependency on POSIX by taking advantage of the newly added k_clock_nanosleep(). Signed-off-by: Chris Friedt <[email protected]>
cd3e327
to
b0c459f
Compare
Use `timespec_from_timeout(K_MSEC(msec), &ts)` instead of leaning on lazily-crafted timespecs with invalid tv_nsec fields. Signed-off-by: Chris Friedt <[email protected]>
Presumably the time testsuite was separate from the c library set of testsuites because it had a depedency on POSIX. Since that dependency no longer exists, colocate the time testsuite with the other c library testsuites. Signed-off-by: Chris Friedt <[email protected]>
Use the newly added k_clock API in the kernel for * clock_gettime() * clock_settime() * clock_nanosleep() and nanosleep() * gettimeofday() Signed-off-by: Chris Friedt <[email protected]>
The ISO C function time() should not depend on POSIX and this was corrected recently via the common libc time() implementation. Remove this dependency from the network subsystem where it has been unduly needed for some time. Similarly, XSI_SINGLE_PROCESS was a dependency for time() via picolibc, because the time() implementation in picolibc relies on the POSIX gettimeofday() call. However, since Zephyr's common libc time() implementation no longer depends on that, it can be removed as a dependency in the network subsystem as well. Signed-off-by: Chris Friedt <[email protected]>
Remove POSIX_TIMERS and XSI_SINGLE_PROCESS dependencies from the aws cloud sample and the lwm2m client sample, as they are no longer required. Signed-off-by: Chris Friedt <[email protected]>
b0c459f
to
b8923f3
Compare
WIP: this isn't quite done yet. Add tests for timespec_to_timeout() and timespec_from_timeout() Signed-off-by: Chris Friedt <[email protected]>
db7b057
to
fe430cf
Compare
I'd like to get those in better shape before marking this ready for review. |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Should be merged after #90060