Skip to content

Base approximate time on a monotonic clock, like absolute time #320

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
merged 2 commits into from
Nov 13, 2017

Conversation

jblache
Copy link
Contributor

@jblache jblache commented Nov 12, 2017

Caught this today; _dispatch_approximate_time() uses CLOCK_REALTIME on Linux for some reason, while _dispatch_absolute_time() uses CLOCK_MONOTONIC. This seems wrong and I can't think of a reason why this would be desirable in the first place.

Darwin code uses the same clock family for both, so use CLOCK_MONOTONIC_COARSE on Linux as the approximate time source, and test for it during configure.

@jblache jblache requested a review from das November 12, 2017 21:04
src/shims/time.h Outdated
@@ -152,9 +152,9 @@ _dispatch_approximate_time(void)
struct timespec ts;
dispatch_assume_zero(clock_gettime(CLOCK_UPTIME_FAST, &ts));
return _dispatch_timespec_to_nano(ts);
#elif defined(__linux__)
#elif HAVE_DECL_CLOCK_MONOTONIC_COARSE
Copy link
Contributor

Choose a reason for hiding this comment

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

please keep the if defined(__linux__) because CLOCK_MONOTONIC is supposed to tick during machine sleeps if you look at POSIX, and it happens to not be the case on linux which eventually became ABI on this platform.

However if a platform has (1) MONOTONIC_COARSE and not UPTIME_FAST, and (2) is POSIX compliant, then this would cause a bug for the said platform.

However you're right that MONOTONIC_COARSE is what we want here.

@jblache
Copy link
Contributor Author

jblache commented Nov 13, 2017

Amended; do we want to do the same in _dispatch_absolute_time() with a comment on top?

@jblache jblache assigned MadCoder and unassigned jblache Nov 13, 2017
@MadCoder
Copy link
Contributor

we probably should now that you point this out.

@jblache jblache force-pushed the jblache/clock_monotonic branch from 700d08a to 58b23b8 Compare November 13, 2017 17:28
@jblache
Copy link
Contributor Author

jblache commented Nov 13, 2017

How does that look? Ship it?

@MadCoder MadCoder merged commit e245cbe into master Nov 13, 2017
@MadCoder MadCoder deleted the jblache/clock_monotonic branch November 13, 2017 17:31
ktopley-apple pushed a commit that referenced this pull request Dec 6, 2018
Base approximate time on a monotonic clock, like absolute time

Signed-off-by: Daniel A. Steffen <dsteffen@apple.com>
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.

4 participants