Skip to content
This repository has been archived by the owner on Oct 21, 2023. It is now read-only.

Implement a monotonic time source. #6

Closed
Yawning opened this issue Jul 11, 2017 · 1 comment
Closed

Implement a monotonic time source. #6

Yawning opened this issue Jul 11, 2017 · 1 comment
Assignees
Labels

Comments

@Yawning
Copy link
Contributor

Yawning commented Jul 11, 2017

Go does not currently provide one (See: golang/go#12914). While it is assumed that all mixes will run NTP or similar, the scheduling should be resilient to the system clock changing, thus using time.Now() is unacceptable.

There's a few ways to do this, such as exposing runtime.nanotime() with unsafe trickery, or by calling clock_gettime() since the only OS that this actually matters on is Linux.

@Yawning Yawning added the task label Jul 11, 2017
@Yawning
Copy link
Contributor Author

Yawning commented Jul 13, 2017

The timer routines in time use runtime.nanotime(), which on Linux is backed by CLOCK_MONOTONIC. As long as the core scheduling only ever uses absolute time based timing things, this shouldn't be a problem, but I suppose we want to be able to measure time differences (eg: packet queue times) via subtraction.

@Yawning Yawning self-assigned this Jul 14, 2017
Yawning added a commit that referenced this issue Jul 19, 2017
I opted against exposing the Go `runtime.nanotime()` routine using
unsafe trickery and instead did something far more horrific out of NIH
and wanting `CLOCK_MONOTONIC_RAW` instead of `CLOCK_MONOTONIC`.

Caveats:

 * This is quite a bit slower than what I could do if I cribbed or
   exposed the runtime routine, but the vDSO stuff is still a win.  This
   is primarily an implementation difference (I use the stack more, and
   do more math).

 * I didn't write code to parse the symbol versions.

 * vDSO support is Linux AMD64 only.

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

No branches or pull requests

1 participant