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
Closed

runtime: start nanotime at runtime start #22436

aclements opened this issue Oct 25, 2017 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@aclements
Copy link
Member

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
Copy link
Contributor

rsc 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 added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 10, 2018
@ianlancetaylor ianlancetaylor modified the milestones: Go1.11, Go1.12 Jul 10, 2018
@aclements
Copy link
Member Author

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.

@golang golang locked and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants