aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/proc.go
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2021-04-07 10:15:33 -0400
committerMichael Pratt <mpratt@google.com>2021-04-16 21:03:44 +0000
commitf6e7fe2711849e2e57f79b89ee7928b8806618c8 (patch)
treea26e3286bdaa1f302611bf0c7b50f338ad154264 /src/runtime/proc.go
parent9fbcba6664840ada5aaedb7f1a587d0cca1c9035 (diff)
downloadgo-f6e7fe2711849e2e57f79b89ee7928b8806618c8.tar.gz
go-f6e7fe2711849e2e57f79b89ee7928b8806618c8.zip
runtime: move findrunnable timer delay computation closer to use
findrunnable has a couple places where delta is recomputed from a new pollUntil value. This proves to be a pain in refactoring, as it is easy to forget to do properly. Move computation of delta closer to its use, where it is more logical anyways. This CL should have no functional changes. For #43997. For #44313. Change-Id: I89980fd7f40f8a4c56c7540cae03ff99e12e1422 Reviewed-on: https://go-review.googlesource.com/c/go/+/307910 Trust: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/runtime/proc.go')
-rw-r--r--src/runtime/proc.go31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/runtime/proc.go b/src/runtime/proc.go
index 6c1c5dd917..3ee5805aef 100644
--- a/src/runtime/proc.go
+++ b/src/runtime/proc.go
@@ -2742,17 +2742,11 @@ stop:
}
}
- delta := int64(-1)
- if pollUntil != 0 {
- // checkTimers ensures that polluntil > now.
- delta = pollUntil - now
- }
-
// wasm only:
// If a callback returned and no other goroutine is awake,
// then wake event handler goroutine which pauses execution
// until a callback was triggered.
- gp, otherReady := beforeIdle(delta)
+ gp, otherReady := beforeIdle(now, pollUntil)
if gp != nil {
casgstatus(gp, _Gwaiting, _Grunnable)
if trace.enabled {
@@ -2842,15 +2836,6 @@ stop:
}
}
}
- if pollUntil != 0 {
- if now == 0 {
- now = nanotime()
- }
- delta = pollUntil - now
- if delta < 0 {
- delta = 0
- }
- }
// Check for idle-priority GC work again.
//
@@ -2909,11 +2894,21 @@ stop:
if _g_.m.spinning {
throw("findrunnable: netpoll with spinning")
}
+ delay := int64(-1)
+ if pollUntil != 0 {
+ if now == 0 {
+ now = nanotime()
+ }
+ delay = pollUntil - now
+ if delay < 0 {
+ delay = 0
+ }
+ }
if faketime != 0 {
// When using fake time, just poll.
- delta = 0
+ delay = 0
}
- list := netpoll(delta) // block until new work is available
+ list := netpoll(delay) // block until new work is available
atomic.Store64(&sched.pollUntil, 0)
atomic.Store64(&sched.lastpoll, uint64(nanotime()))
if faketime != 0 && list.empty() {