Skip to content

Conversation

cfriedt
Copy link
Member

@cfriedt cfriedt commented Oct 10, 2025

Add support for the times() function, which can be used to get the number of ticks spent in "system" and "user" mode, and which returns the "real time" that has expired, since an arbitrary point in the past.

The following invariant should always hold:

rtime <= stime + utime

The times() function measures time for the calling process and all of it's child processes. In Zephyr, we don't support separate processes (yet), so the time spent in child processes is zero.

Additionally, in Zephyr we do not differentiate between "system" time (i.e. time spent executing kernel code) and "user" time (time spent executing application code). We only have information on "total time" (time spent executing code) and "execution time" (time spent executing code plus idle time).

For now, only report utime, since it is not clear how to obtain other values.

The times() function is part of the POSIX_MULTI_PROCESS Option Group. For more information, please see
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html

Closes #51978

Note

This was added in order to facilitate lua as a Zephyr module

cc @tenllado @oscarbaselga @alexayl @agguo @danjshaw

@cfriedt cfriedt requested review from sylvioalves and ycsin October 10, 2025 13:37
@cfriedt cfriedt force-pushed the add-rough-times-support branch from 2231380 to 911a06e Compare October 10, 2025 13:39
Add support for the `times()` function, which can be used to get the
number of ticks spent in "system" and "user" mode, and which returns
the "real time" that has expired, since an arbitrary point in the past.

The following invariant should always hold:

rtime <= stime + utime

The `times()` function measures time for the calling process and all
of it's child processes. In Zephyr, we don't support separate processes
(yet), so the time spent in child processes is zero.

Additionally, in Zephyr we do not differentiate between "system" time
(i.e. time spent executing kernel code) and "user" time (time spent
executing application code). We only have information on "total time"
(time spent executing code) and "execution time" (time spent executing
code plus idle time).

For now, only report utime, since it is not clear how to obtain other
values.

Signed-off-by: Chris Friedt <[email protected]>
@cfriedt cfriedt force-pushed the add-rough-times-support branch from 911a06e to 9cfe84e Compare October 10, 2025 14:11
@cfriedt cfriedt marked this pull request as ready for review October 10, 2025 15:44
@zephyrbot zephyrbot added area: POSIX POSIX API Library area: Tests Issues related to a particular existing or missing test labels Oct 10, 2025
@zephyrbot zephyrbot requested a review from nashif October 10, 2025 15:46
@cfriedt
Copy link
Member Author

cfriedt commented Oct 13, 2025

Code Sonar warning is a false positive

Add a testsuite for the POSIX_MULTI_PROCESS Option Group.

Signed-off-by: Chris Friedt <[email protected]>
@cfriedt cfriedt force-pushed the add-rough-times-support branch from 9cfe84e to 06f75c6 Compare October 13, 2025 22:05
@cfriedt cfriedt requested a review from sylvioalves October 13, 2025 22:05
Copy link

@cfriedt cfriedt merged commit f02391a into zephyrproject-rtos:main Oct 14, 2025
26 checks passed
@cfriedt cfriedt deleted the add-rough-times-support branch October 14, 2025 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: POSIX POSIX API Library area: Tests Issues related to a particular existing or missing test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add POSIX times() support

4 participants