1
0
mirror of https://github.com/golang/go synced 2024-11-24 11:00:08 -07:00

runtime: get tracking time only when needed

casgstatus currently calls nanotime on every casgstatus when tracking,
even though the time is only used in some cases. For goroutines making
lots of transitions that aren't covered here, this can add a small
overhead. Switch to calling nanotime only when necessary.

Change-Id: I2617869332e8289ef33dd674d786e44dea09aaba
Reviewed-on: https://go-review.googlesource.com/c/go/+/364375
Trust: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
Michael Pratt 2021-11-16 11:46:42 -05:00
parent 79d0013f53
commit 29ec902efc

View File

@ -980,17 +980,18 @@ func casgstatus(gp *g, oldval, newval uint32) {
gp.trackingSeq++ gp.trackingSeq++
} }
if gp.tracking { if gp.tracking {
now := nanotime()
if oldval == _Grunnable { if oldval == _Grunnable {
// We transitioned out of runnable, so measure how much // We transitioned out of runnable, so measure how much
// time we spent in this state and add it to // time we spent in this state and add it to
// runnableTime. // runnableTime.
now := nanotime()
gp.runnableTime += now - gp.runnableStamp gp.runnableTime += now - gp.runnableStamp
gp.runnableStamp = 0 gp.runnableStamp = 0
} }
if newval == _Grunnable { if newval == _Grunnable {
// We just transitioned into runnable, so record what // We just transitioned into runnable, so record what
// time that happened. // time that happened.
now := nanotime()
gp.runnableStamp = now gp.runnableStamp = now
} else if newval == _Grunning { } else if newval == _Grunning {
// We're transitioning into running, so turn off // We're transitioning into running, so turn off