]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: move timer recheck after GC recheck
authorMichael Pratt <mpratt@google.com>
Thu, 8 Apr 2021 20:57:57 +0000 (16:57 -0400)
committerMichael Pratt <mpratt@google.com>
Wed, 21 Apr 2021 13:38:59 +0000 (13:38 +0000)
When rechecking for work after transitioning from a spinning to
non-spinning M, checking timers before GC isn't useful. That is, if
there is GC work available, it will run immediately and the updated
pollUntil is unused.

Move this check to just before netpoll, where pollUntil is used. While
this technically improves efficiency in the (rare) case that we find
GC work in this block, the primary motivation is simply to improve
clarity by moving the update closer to use.

For #43997

Change-Id: Ibc7fb308ac4a582875c200659c9e272121a89f3b
Reviewed-on: https://go-review.googlesource.com/c/go/+/308654
Trust: Michael Pratt <mpratt@google.com>
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/runtime/proc.go

index ef3b373b1cbd59c5ffc5c9c5defd41569d2b0890..b3f113f6abea0f0364b0ecc949d4b5edbc401d7c 100644 (file)
@@ -2810,13 +2810,7 @@ top:
                goto top
        }
 
-       // Similar to above, check for timer creation or expiry concurrently with
-       // transitioning from spinning to non-spinning. Note that we cannot use
-       // checkTimers here because it calls adjusttimers which may need to allocate
-       // memory, and that isn't allowed when we don't have an active P.
-       pollUntil = checkTimersNoP(allpSnapshot, timerpMaskSnapshot, pollUntil)
-
-       // Finally, check for idle-priority GC work.
+       // Check for idle-priority GC work again.
        _p_, gp = checkIdleGCNoP()
        if _p_ != nil {
                acquirep(_p_)
@@ -2834,6 +2828,14 @@ top:
                return gp, false
        }
 
+       // Finally, check for timer creation or expiry concurrently with
+       // transitioning from spinning to non-spinning.
+       //
+       // Note that we cannot use checkTimers here because it calls
+       // adjusttimers which may need to allocate memory, and that isn't
+       // allowed when we don't have an active P.
+       pollUntil = checkTimersNoP(allpSnapshot, timerpMaskSnapshot, pollUntil)
+
        // Poll network until next timer.
        if netpollinited() && (atomic.Load(&netpollWaiters) > 0 || pollUntil != 0) && atomic.Xchg64(&sched.lastpoll, 0) != 0 {
                atomic.Store64(&sched.pollUntil, uint64(pollUntil))