]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: get tracking time only when needed
authorMichael Pratt <mpratt@google.com>
Tue, 16 Nov 2021 16:46:42 +0000 (11:46 -0500)
committerMichael Pratt <mpratt@google.com>
Tue, 16 Nov 2021 17:13:33 +0000 (17:13 +0000)
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>

src/runtime/proc.go

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