Skip to content

Commit

Permalink
runtime: don't call wakeNetPoller during timerModifying
Browse files Browse the repository at this point in the history
Reduce the length of time that other timer functions can see timerModifying.
In particular avoid system calls.

Fixes #38023

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>
  • Loading branch information
ianlancetaylor committed Mar 24, 2020
1 parent f95ff37 commit 355f53f
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/runtime/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,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()
Expand All @@ -268,7 +263,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
Expand Down Expand Up @@ -443,10 +437,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
Expand Down

0 comments on commit 355f53f

Please sign in to comment.