Skip to content
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/newlib: gettimeofday() returns time since boot, not current wall time. #9187

Open
jcarrano opened this issue May 24, 2018 · 2 comments
Open
Labels
Area: POSIX Area: POSIX API wrapper Area: timers Area: timer subsystems Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Comments

@jcarrano
Copy link
Contributor

jcarrano commented May 24, 2018

Description

PR #4286 added support for gettimeofday() by implementing it on top of xtimer_now_usec64().

This definition is in conflict with the specification, which says:

The gettimeofday() function shall obtain the current time, expressed as seconds and microseconds since the Epoch, and store it in the timeval structure pointed to by tp. The resolution of the system clock is unspecified.

Expected results

The current wall time is returned (if the board has a RTC). Otherwise, either the function should be made unavailable (this triggering a linker error if it is used), or it should always fail.

Actual results

gettimeofday() returns time since boot if xtimer was compiled in. If not, it fails with ENOSYS.

Related to

issue: #10523

@virajsahai
Copy link

virajsahai commented May 25, 2018

@jcarrano just saw the implementation, it uses xtimer_now64() which returns the current timestamp as a 64 bit value. And according to that, the calculations are correct. Not sure what might be going wrong here.

@jcarrano
Copy link
Contributor Author

@virajsahai As far as I know, xtimer_now() returns a timestamp since an unspecified time in the past (since last reset, maybe?). The docs are not 100% clear, but I would assume that, as measuring absolute time would require a RTC or some other time-setting mechanism.
gettimeofday(), on the other hand, requires time since Epoch.

@smlng smlng added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: timers Area: timer subsystems Area: POSIX Area: POSIX API wrapper labels May 28, 2018
@miri64 miri64 added this to the Release 2020.07 milestone Jul 2, 2020
@MrKevinWeiss MrKevinWeiss removed this from the Release 2021.07 milestone Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: POSIX Area: POSIX API wrapper Area: timers Area: timer subsystems Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

No branches or pull requests

5 participants