Skip to content

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

Merged

Conversation

ramakrishnapallala
Copy link

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]

@codecov-io
Copy link

codecov-io commented Jun 2, 2018

Codecov Report

Merging #8124 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
lib/posix/clock.c 100% <100%> (ø) ⬆️
samples/philosophers/src/main.c 98.43% <0%> (+1.56%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 158ea97...24b3e4a. Read the comment docs.

Copy link
Collaborator

@andyross andyross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nitpickery

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);
Copy link
Collaborator

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.

Copy link
Author

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.

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]>
@nashif nashif merged commit 03a3c99 into zephyrproject-rtos:master Jun 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants