]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.14] runtime: don't call wakeNetPoller during timerModifying
authorIan Lance Taylor <iant@golang.org>
Mon, 23 Mar 2020 18:38:49 +0000 (11:38 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 25 Mar 2020 20:24:45 +0000 (20:24 +0000)
Reduce the length of time that other timer functions can see timerModifying.
In particular avoid system calls.

For #38023
Fixes #38051

Change-Id: I1b61229c668e6085d9ee6dca9488a90055386c36
Reviewed-on: https://go-review.googlesource.com/c/go/+/224902
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
(cherry picked from commit 355f53f0a0a5d79032068d4914d7aea3435084ec)
Reviewed-on: https://go-review.googlesource.com/c/go/+/225277

src/runtime/time.go

index 93565cf369b40b0668dcf6fe2a4a9d278bd3c332..ed73bf73749d791fb6d22e73bb7751cd4cda5589 100644 (file)
@@ -245,11 +245,6 @@ func addtimer(t *timer) {
        }
        t.status = timerWaiting
 
-       addInitializedTimer(t)
-}
-
-// addInitializedTimer adds an initialized timer to the current P.
-func addInitializedTimer(t *timer) {
        when := t.when
 
        pp := getg().m.p.ptr()
@@ -262,7 +257,6 @@ func addInitializedTimer(t *timer) {
 }
 
 // doaddtimer adds t to the current P's heap.
-// It reports whether it saw no problems due to races.
 // The caller must have locked the timers for pp.
 func doaddtimer(pp *p, t *timer) {
        // Timers rely on the network poller, so make sure the poller
@@ -437,10 +431,14 @@ loop:
 
        if wasRemoved {
                t.when = when
-               addInitializedTimer(t)
+               pp := getg().m.p.ptr()
+               lock(&pp.timersLock)
+               doaddtimer(pp, t)
+               unlock(&pp.timersLock)
                if !atomic.Cas(&t.status, timerModifying, timerWaiting) {
                        badTimer()
                }
+               wakeNetPoller(when)
        } else {
                // The timer is in some other P's heap, so we can't change
                // the when field. If we did, the other P's heap would