-
Notifications
You must be signed in to change notification settings - Fork 7.4k
sys: clock: add sys_clock api and remove posix 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
Open
cfriedt
wants to merge
12
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.
+418
−267
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
25e3ea4
sys: clock: additional sys_clock api calls
cfriedt 232e470
doc: release: 4.2.0: add sys_clock gettime settime nanosleep notes
cfriedt d26f68e
libc: common: time: use sys_clock api rather than posix
cfriedt 2e2f674
libc: use the common libc time() implementation for most libcs
cfriedt cd2ec96
libc: common: thrd: use sys_clock_nanosleep() instead of nanosleep()
cfriedt ffe47aa
tests: libc: thrd: compare with thrd_success rather than ok or zero
cfriedt e5f9083
tests: libc: thrd: do not pass NULL for thrd_sleep() duration
cfriedt 645e772
tests: libc: thrd: use timespec_from_timeout()
cfriedt 1e0c9e2
tests: lib: move time testsuite to c_lib
cfriedt 7ea1422
posix: use kernel sys_clock implementation
cfriedt bc02dc3
net: remove dependency on posix for iso c time() function
cfriedt a4f6b31
samples: net: remove POSIX_TIMERS and XSI_SINGLE_PROCESS
cfriedt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright (c) 2025 Tenstorrent AI ULC | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** | ||
* @file | ||
* @brief System clock APIs | ||
* | ||
* APIs for getting, setting, and sleeping with respect to system clocks. | ||
*/ | ||
|
||
#ifndef ZEPHYR_INCLUDE_SYSCLOCK_H_ | ||
#define ZEPHYR_INCLUDE_SYSCLOCK_H_ | ||
|
||
#include <time.h> | ||
|
||
#include <zephyr/toolchain.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @addtogroup clock_apis | ||
* @{ | ||
*/ | ||
|
||
/** | ||
* @brief The real-time clock (i.e. "wall clock") | ||
* | ||
* This clock is used to measure time since the epoch (1970-01-01 00:00:00 UTC). | ||
* | ||
* It is not a steady clock; i.e. it may be adjusted for a number of reasons from initialization | ||
* of a hardware real-time-clock, to network-time synchronization, to manual adjustment from the | ||
* application. | ||
*/ | ||
#define SYS_CLOCK_REALTIME 1 | ||
|
||
/** | ||
* @brief The monotonic clock | ||
* | ||
* This steady clock is used to measure time since the system booted. Time from this clock is | ||
* always monotonically increasing, modulo the upper bound of `{.tv_sec = INT64_MAX, .tv_nsec = | ||
* 1000000000}`. | ||
*/ | ||
#define SYS_CLOCK_MONOTONIC 4 | ||
|
||
/** | ||
* @brief The flag used for specifying absolute timeouts | ||
* | ||
* This flag may be passed to @ref sys_clock_nanosleep to indicate the requested timeout is an | ||
* absolute time with respect to the specified clock. | ||
*/ | ||
#define SYS_TIMER_ABSTIME 4 | ||
|
||
/** | ||
* @brief Get the current time from the specified clock | ||
* | ||
* @param clock_id The clock from which to query time. | ||
* @param tp Pointer to memory where time will be written. | ||
* @retval 0 on success. | ||
* @retval -EINVAL when an invalid @a clock_id is specified. | ||
*/ | ||
__syscall int sys_clock_gettime(int clock_id, struct timespec *tp); | ||
|
||
/** | ||
* @brief Set the current time for the specified clock | ||
* | ||
* @param clock_id The clock for which the time should be set. | ||
* @param tp Pointer to memory specifying the desired time. | ||
* @retval 0 on success. | ||
* @retval -EINVAL when an invalid @a clock_id is specified or when @a tp contains nanoseconds | ||
* outside of the range `[0, 999999999]`. | ||
*/ | ||
__syscall int sys_clock_settime(int clock_id, const struct timespec *tp); | ||
|
||
/** | ||
* @brief Sleep for the specified amount of time with respect to the specified clock. | ||
* | ||
* This function will cause the calling thread to sleep either | ||
* - until the absolute time specified by @a rqtp (if @a flags includes @ref SYS_TIMER_ABSTIME), or | ||
* - until the relative time specified by @a rqtp (if @a flags does not include | ||
* @ref SYS_TIMER_ABSTIME). | ||
* | ||
* The accepted values for @a clock_id include | ||
* - @ref SYS_CLOCK_REALTIME | ||
* - @ref SYS_CLOCK_MONOTONIC | ||
* | ||
* If @a rmtp is not NULL, and the thread is awoken prior to the time specified by @a rqtp, then | ||
* any remaining time will be written to @a rmtp. If the thread has slept for at least the time | ||
* specified by @a rqtp, then @a rmtp will be set to zero. | ||
* | ||
* @param clock_id The clock to by which to sleep. | ||
* @param flags Flags to modify the behavior of the sleep operation. | ||
* @param rqtp Pointer to the requested time to sleep. | ||
* @param rmtp Pointer to memory into which to copy the remaining time, if any. | ||
* | ||
* @retval 0 on success. | ||
* @retval -EINVAL when an invalid @a clock_id, when @a rqtp contains nanoseconds outside of the | ||
* range `[0, 999999999]`, or when @a rqtp contains a negative value. | ||
*/ | ||
__syscall int sys_clock_nanosleep(int clock_id, int flags, const struct timespec *rqtp, | ||
struct timespec *rmtp); | ||
|
||
/** | ||
* @} | ||
*/ | ||
|
||
#include <zephyr/syscalls/clock.h> | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit message refers to k_clock instead of sys_clock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!