Skip to content

Commit 4d56576

Browse files
committed
runtime: move timer recheck after GC recheck
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 <[email protected]> Trust: Michael Knyszek <[email protected]> Run-TryBot: Michael Pratt <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
1 parent 381252f commit 4d56576

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/runtime/proc.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2810,13 +2810,7 @@ top:
28102810
goto top
28112811
}
28122812

2813-
// Similar to above, check for timer creation or expiry concurrently with
2814-
// transitioning from spinning to non-spinning. Note that we cannot use
2815-
// checkTimers here because it calls adjusttimers which may need to allocate
2816-
// memory, and that isn't allowed when we don't have an active P.
2817-
pollUntil = checkTimersNoP(allpSnapshot, timerpMaskSnapshot, pollUntil)
2818-
2819-
// Finally, check for idle-priority GC work.
2813+
// Check for idle-priority GC work again.
28202814
_p_, gp = checkIdleGCNoP()
28212815
if _p_ != nil {
28222816
acquirep(_p_)
@@ -2834,6 +2828,14 @@ top:
28342828
return gp, false
28352829
}
28362830

2831+
// Finally, check for timer creation or expiry concurrently with
2832+
// transitioning from spinning to non-spinning.
2833+
//
2834+
// Note that we cannot use checkTimers here because it calls
2835+
// adjusttimers which may need to allocate memory, and that isn't
2836+
// allowed when we don't have an active P.
2837+
pollUntil = checkTimersNoP(allpSnapshot, timerpMaskSnapshot, pollUntil)
2838+
28372839
// Poll network until next timer.
28382840
if netpollinited() && (atomic.Load(&netpollWaiters) > 0 || pollUntil != 0) && atomic.Xchg64(&sched.lastpoll, 0) != 0 {
28392841
atomic.Store64(&sched.pollUntil, uint64(pollUntil))

0 commit comments

Comments
 (0)