]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: move condition into wakep
authorAustin Clements <austin@google.com>
Wed, 29 Apr 2020 00:54:31 +0000 (20:54 -0400)
committerAustin Clements <austin@google.com>
Thu, 30 Apr 2020 00:42:35 +0000 (00:42 +0000)
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>
src/runtime/proc.go

index 939c68a94d8d234a7b292e5f09f5d306c318bc8a..9c2ec56c35a7d35cfe6aae6f978a3eb721c51e7a 100644 (file)
@@ -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()
                }
        })