-
Notifications
You must be signed in to change notification settings - Fork 7.4k
lib: posix: clock: Use k_uptime_get() to compute tv_nsec #8124
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
lib: posix: clock: Use k_uptime_get() to compute tv_nsec #8124
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8124 +/- ##
==========================================
- Coverage 64.55% 64.55% -0.01%
==========================================
Files 420 420
Lines 40143 40140 -3
Branches 6763 6763
==========================================
- Hits 25914 25912 -2
+ Misses 11108 11107 -1
Partials 3121 3121
Continue to review full report at Codecov.
|
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.
Style nitpickery
lib/posix/clock.c
Outdated
sys_clock_hw_cycles_per_sec); | ||
elapsed_secs = (s64_t) (elapsed_msecs / MSEC_PER_SEC); | ||
elapsed_nsec = (s64_t) ((elapsed_msecs % MSEC_PER_SEC) * | ||
USEC_PER_MSEC * NSEC_PER_USEC); |
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.
Seems like it's still to complicated. If you're going to do this in 64 bit math, don't bother finessing the components, you don't need to:
u64_t ms = k_uptime_get();
ts->tv_sec = (s32_t)(ms / 1000);
ts->tv_nsec = (s32_t)((ms % 1000)*1000);
Also, IMHO it's perfectly fine to assume that the SI standard for unit naming is going to adhere in perpetuity and that humanity will never change the meaning of "micro" or "nano" such that the code needs to adapts. Those x_PER_y constants seem sorta silly to me.
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.
will get rid of the local variables and those constants are from Zephyr include headers so will stick with them.
b54dd9a
to
24b3e4a
Compare
Use k_uptime_get() to compute both tv_sec and tv_nsec members of timespec structure. Fixes zephyrproject-rtos#8009 Signed-off-by: Ramakrishna Pallala <[email protected]>
Use k_uptime_get() to compute both tv_sec and tv_nsec members
of timespec structure.
Fixes #8009
Signed-off-by: Ramakrishna Pallala [email protected]