]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: elide timer re-check if P has no timers
authorMichael Pratt <mpratt@google.com>
Thu, 29 Oct 2020 20:03:57 +0000 (16:03 -0400)
committerMichael Pratt <mpratt@google.com>
Fri, 30 Oct 2020 20:36:27 +0000 (20:36 +0000)
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>

src/runtime/proc.go

index ced27ceb3afd5e0b04e58aa44a4ebc35bff12dc4..071257b5a505590a3b79b0dbdfc14efdead24992 100644 (file)
@@ -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)
@@ -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 {