diff options
| author | Austin Clements <austin@google.com> | 2020-04-28 20:54:31 -0400 |
|---|---|---|
| committer | Austin Clements <austin@google.com> | 2020-04-30 00:42:35 +0000 |
| commit | 4e00b4c366f06036509201d3bf19ee2c8fd767c8 (patch) | |
| tree | 1d5b4dbcd897708364d7b31dceafdec5a87f7ceb /src | |
| parent | df2862cf54858ba5b1ada7d2ca99e57f3c13dd23 (diff) | |
| download | go-4e00b4c366f06036509201d3bf19ee2c8fd767c8.tar.xz | |
runtime: move condition into wakep
All five calls to wakep are protected by the same check of nmidle and
nmspinning. Move this check into wakep.
Change-Id: I2094eec211ce551e462e87614578f37f1896ba38
Reviewed-on: https://go-review.googlesource.com/c/go/+/230757
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/runtime/proc.go | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 939c68a94d..9c2ec56c35 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -690,9 +690,7 @@ func ready(gp *g, traceskip int, next bool) { // status is Gwaiting or Gscanwaiting, make Grunnable and put on runq casgstatus(gp, _Gwaiting, _Grunnable) runqput(_g_.m.p.ptr(), gp, next) - if atomic.Load(&sched.npidle) != 0 && atomic.Load(&sched.nmspinning) == 0 { - wakep() - } + wakep() releasem(mp) } @@ -1072,9 +1070,7 @@ func startTheWorldWithSema(emitTraceEvent bool) int64 { // Wakeup an additional proc in case we have excessive runnable goroutines // in local queues or in the global queue. If we don't, the proc will park itself. // If we have lots of excessive work, resetspinning will unpark additional procs as necessary. - if atomic.Load(&sched.npidle) != 0 && atomic.Load(&sched.nmspinning) == 0 { - wakep() - } + wakep() releasem(mp) @@ -1999,8 +1995,11 @@ func handoffp(_p_ *p) { // Tries to add one more P to execute G's. // Called when a G is made runnable (newproc, ready). func wakep() { + if atomic.Load(&sched.npidle) == 0 { + return + } // be conservative about spinning threads - if !atomic.Cas(&sched.nmspinning, 0, 1) { + if atomic.Load(&sched.nmspinning) != 0 || !atomic.Cas(&sched.nmspinning, 0, 1) { return } startm(nil, true) @@ -2464,9 +2463,7 @@ func resetspinning() { // M wakeup policy is deliberately somewhat conservative, so check if we // need to wakeup another P here. See "Worker thread parking/unparking" // comment at the top of the file for details. - if nmspinning == 0 && atomic.Load(&sched.npidle) > 0 { - wakep() - } + wakep() } // injectglist adds each runnable G on the list to some run queue, @@ -2640,9 +2637,7 @@ top: // If about to schedule a not-normal goroutine (a GCworker or tracereader), // wake a P if there is one. if tryWakeP { - if atomic.Load(&sched.npidle) != 0 && atomic.Load(&sched.nmspinning) == 0 { - wakep() - } + wakep() } if gp.lockedm != 0 { // Hands off own p to the locked m, @@ -3476,7 +3471,7 @@ func newproc(siz int32, fn *funcval) { _p_ := getg().m.p.ptr() runqput(_p_, newg, true) - if atomic.Load(&sched.npidle) != 0 && atomic.Load(&sched.nmspinning) == 0 && mainStarted { + if mainStarted { wakep() } }) |
