-
Notifications
You must be signed in to change notification settings - Fork 8.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
sys: clock: add sys_clock api and remove posix from iso c time #90096
Conversation
a403e85 to
83dc940
Compare
db7b057 to
fe430cf
Compare
I'd like to get those in better shape before marking this ready for review. |
fe430cf to
9a4203b
Compare
5078a47 to
730558c
Compare
|
Question ... would the proposed k_clock APIs be better served somewhere under /subsys as something like sys_clock APIs? I am wary of them being placed under /kernel. |
It might be possible to reuse existing APIs for calculating some of those things though. |
793d367 to
19947db
Compare
370277c to
c5bbd4f
Compare
Reduce the dependency on POSIX by taking advantage of the newly added sys_clock_nanosleep(). Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
The C standard does not guarantee that `thrd_success` is equal to zero, so ensure that the test takes that into account. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
The specification does not say that the first struct timespec passed to thrd_sleep() may be NULL. Preserving the testpoint so that a possible future testsuite can be run that expects faults to occur when undefined behaviour is used. Faults are one possible solution to handling undefined behaviour, but it would be good to come to a concensus about how that should be handled in Zephyr for standard function calls belonging to ISO C or POSIX. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
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 <cfriedt@tenstorrent.com>
Use sys_clock_gettime() instead of clock_gettime() and use timespec_add() instead of manually adding timespec structures. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
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 <cfriedt@tenstorrent.com>
Use the newly added sys_clock API in lib/os for * clock_gettime() * clock_settime() * clock_nanosleep() and nanosleep() * gettimeofday() Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
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 <cfriedt@tenstorrent.com>
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 <cfriedt@tenstorrent.com>
Merge sys_clock.h into sys/clock.h and preserve the original header. This allows us to use a slightly more intuitive name for the sys/clock.h header, while reducing churn throughout the codebase. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
400c18a to
ee874a7
Compare
|
|
@nashif - this still requires assignee approval |



Previously, both the common libc
time()as well as picolibctime()(an ISO C function) relied on eitherclock_gettime()orgettimeofday(). That had the unfortunate consequence that many areas had an indirect dependency on POSIX.This change removes the dependency cycle that existed between POSIX and some libc's by creating a mutual dependency (i.e. new API) for both POSIX and the common C library under
lib/os. With this change, the ISO C functiontime()can also be used without relying on POSIX support.sys_clock_gettime()sys_clock_settime()sys_clock_nanosleep()sys_clock_getrtoffset()Areas that should no longer have POSIX dependencies for getting the "wall clock" time include, but are not limited to
lib/libc/common/source/thrdlib/libc/common/source/timetime())samples/net/cloud/aws_iot_mqttsamples/net/lwm2m_clientsubsys/logging/log_core.csubsys/net/lib/config(sntp)subsys/net/lib/lwm2mPlease see individual commits for details
Fixes #88555
Fixes #88882
Note
There have been many RFCs on this topic already #19030, #40099, #76335 and most of them agree on the need for an abstract clock source at the OS level. There isn't a huge need for another RFC here.
K_prefix, theSYS_prefix was suggested by @peter-mitsissys_clock_getres().