Skip to content

Commit 29ec902

Browse files
committed
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 <[email protected]> Run-TryBot: Michael Pratt <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 79d0013 commit 29ec902

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/runtime/proc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,17 +980,18 @@ func casgstatus(gp *g, oldval, newval uint32) {
980980
gp.trackingSeq++
981981
}
982982
if gp.tracking {
983-
now := nanotime()
984983
if oldval == _Grunnable {
985984
// We transitioned out of runnable, so measure how much
986985
// time we spent in this state and add it to
987986
// runnableTime.
987+
now := nanotime()
988988
gp.runnableTime += now - gp.runnableStamp
989989
gp.runnableStamp = 0
990990
}
991991
if newval == _Grunnable {
992992
// We just transitioned into runnable, so record what
993993
// time that happened.
994+
now := nanotime()
994995
gp.runnableStamp = now
995996
} else if newval == _Grunning {
996997
// We're transitioning into running, so turn off

0 commit comments

Comments
 (0)