mirror of
https://github.com/golang/go
synced 2024-11-19 13:04:45 -07:00
runtime: capture runtimeInitTime after nanotime is initialized
CL 36428 changed the way nanotime works so on Darwin and Windows it now depends on runtime.startNano, which is computed at runtime.init time. Unfortunately, the `runtimeInitTime = nanotime()` initialization happened *before* runtime.init, so on these platforms runtimeInitTime is set incorrectly. The one (and only) consequence of this is that the start time printed in gctrace lines is bogus: gc 1 18446653480.186s 0%: 0.092+0.47+0.038 ms clock, 0.37+0.15/0.81/1.8+0.15 ms cpu, 4->4->1 MB, 5 MB goal, 8 P To fix this, this commit moves the runtimeInitTime initialization to shortly after runtime.init, at which point nanotime is safe to use. This also requires changing the condition in newproc1 that currently uses runtimeInitTime != 0 simply to detect whether or not the main M has started. Since runtimeInitTime could genuinely be 0 now, this introduces a separate flag to newproc1. Fixes #21554. Change-Id: Id874a4b912d3fa3d22f58d01b31ffb3548266d3b Reviewed-on: https://go-review.googlesource.com/58690 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rick Hudson <rlh@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
05ff6bfe33
commit
9d17e175e0
@ -96,6 +96,9 @@ var main_init_done chan bool
|
||||
//go:linkname main_main main.main
|
||||
func main_main()
|
||||
|
||||
// mainStarted indicates that the main M has started.
|
||||
var mainStarted bool
|
||||
|
||||
// runtimeInitTime is the nanotime() at which the runtime started.
|
||||
var runtimeInitTime int64
|
||||
|
||||
@ -119,8 +122,8 @@ func main() {
|
||||
maxstacksize = 250000000
|
||||
}
|
||||
|
||||
// Record when the world started.
|
||||
runtimeInitTime = nanotime()
|
||||
// Allow newproc to start new Ms.
|
||||
mainStarted = true
|
||||
|
||||
systemstack(func() {
|
||||
newm(sysmon, nil)
|
||||
@ -148,6 +151,10 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
// Record when the world started. Must be after runtime_init
|
||||
// because nanotime on some platforms depends on startNano.
|
||||
runtimeInitTime = nanotime()
|
||||
|
||||
gcenable()
|
||||
|
||||
main_init_done = make(chan bool)
|
||||
@ -3029,7 +3036,7 @@ func newproc1(fn *funcval, argp *uint8, narg int32, nret int32, callerpc uintptr
|
||||
}
|
||||
runqput(_p_, newg, true)
|
||||
|
||||
if atomic.Load(&sched.npidle) != 0 && atomic.Load(&sched.nmspinning) == 0 && runtimeInitTime != 0 {
|
||||
if atomic.Load(&sched.npidle) != 0 && atomic.Load(&sched.nmspinning) == 0 && mainStarted {
|
||||
wakep()
|
||||
}
|
||||
_g_.m.locks--
|
||||
|
Loading…
Reference in New Issue
Block a user