Skip to content

Commit

Permalink
runtime: elide timer re-check if P has no timers
Browse files Browse the repository at this point in the history
In golang.org/cl/264477, I missed this new block after rebasing past
golang.org/cl/232298. These fields must be zero if there are no timers.

Updates #28808
Updates #18237

Change-Id: I2d9e1cbf326497c833daa26b11aed9a1e12c2270
Reviewed-on: https://go-review.googlesource.com/c/go/+/266367
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Michael Pratt <mpratt@google.com>
  • Loading branch information
prattmic committed Oct 30, 2020
1 parent 9393b5b commit 89a6540
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/runtime/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2606,9 +2606,10 @@ stop:
// safe-points. We don't need to snapshot the contents because
// everything up to cap(allp) is immutable.
allpSnapshot := allp
// Also snapshot idlepMask. Value changes are OK, but we can't allow
// Also snapshot masks. Value changes are OK, but we can't allow
// len to change out from under us.
idlepMaskSnapshot := idlepMask
timerpMaskSnapshot := timerpMask

// return P and block
lock(&sched.lock)
Expand Down Expand Up @@ -2670,10 +2671,12 @@ stop:
// 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.
for _, _p_ := range allpSnapshot {
w := nobarrierWakeTime(_p_)
if w != 0 && (pollUntil == 0 || w < pollUntil) {
pollUntil = w
for id, _p_ := range allpSnapshot {
if timerpMaskSnapshot.read(uint32(id)) {
w := nobarrierWakeTime(_p_)
if w != 0 && (pollUntil == 0 || w < pollUntil) {
pollUntil = w
}
}
}
if pollUntil != 0 {
Expand Down

0 comments on commit 89a6540

Please sign in to comment.