Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

linux: use CLOCK_MONOTONIC_COARSE if available #975

Closed
wants to merge 1 commit into from
Closed

linux: use CLOCK_MONOTONIC_COARSE if available #975

wants to merge 1 commit into from

Conversation

bnoordhuis
Copy link
Contributor

clock_gettime(CLOCK_MONOTONIC_COARSE) eliminates the SYS_clock_gettime
system call entirely. It just reads from the vDSO timestamp, which is
the kernel's idea of "now" and is good enough for our purposes.

Suggested reviewer: @indutny

On some systems, clock_gettime(CLOCK_MONOTONIC) is only serviced from
the vDSO when the __vdso_clock_gettime() wrapper is confident enough
that the vDSO timestamp is highly accurate.  When in doubt, it falls
back to making a traditional SYS_clock_gettime system call with all
the overhead that entails.

While a commendable approach, it's overkill for our purposes because we
don't usually need high precision time. That's why this commit changes
the default clock to CLOCK_MONOTONIC_COARSE, provided it supports a
granularity of one millisecond or better.

This change should eliminate the system call on almost all systems,
including virtualized ones, provided the kernel is >= 2.6.32 and your
glibc is new enough to find and parse the vDSO.
int* skip_fst) {
int rc;

if (*skip_fst == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

fst stands for first or fast?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whatever works for you. :-) It stands for 'first' in my head but that's because I'm a closet ML programmer.

@indutny
Copy link
Contributor

indutny commented Oct 29, 2013

LGTM

@bnoordhuis bnoordhuis closed this Oct 31, 2013
@bnoordhuis
Copy link
Contributor Author

Landed in 21c37a7 for great justice.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants