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

runtime: start nanotime at runtime start #22436

Closed
aclements opened this issue Oct 25, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@aclements
Copy link
Member

commented Oct 25, 2017

Currently the zero value of runtime.nanotime means different things on different systems. On some, it's system boot time, on others it's program start time. We should make it measure time from program start on all platforms for consistency. Then we can also eliminate runtimeInitTime. (If we do this, we should also make it harder to call nanotime too early in runtime init, either by panicking if the program start time isn't established or by establishing program start time much earlier during init.)

More discussion in #22394.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Oct 25, 2017

Re last bit, initializing startTime explicitly in runtime.schedinit SGTM. At that point the only worry is that osinit might refer to nanotime, but that seems very unlikely.

@ianlancetaylor ianlancetaylor modified the milestones: Go1.11, Go1.12 Jul 10, 2018

@aclements

This comment has been minimized.

Copy link
Member Author

commented Jan 9, 2019

This was obviated by a1ee0a2, which moved startNano out of the runtime and into the time package. So now nanotime is consistent on all platforms in that it doesn't start at zero. See @dvyukov's argument in a1ee0a2 for why this makes more sense.

Moving startNano out of the runtime fixed the issue where calling nanotime too early (before startNano was set) led to a confusing and potentially buggy shift in time. There's some danger it could legitimately return a zero value, leading to issue #22394, but this will only happen once in 584 years, and typically nanotime's base is system boot time anyway.

@aclements aclements closed this Jan 9, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.