]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: convert schedt.ngsys to atomic type
authorMichael Pratt <mpratt@google.com>
Wed, 20 Jul 2022 21:48:19 +0000 (17:48 -0400)
committerMichael Pratt <mpratt@google.com>
Fri, 12 Aug 2022 01:51:51 +0000 (01:51 +0000)
Note that this converts ngsys from uint32 to int32 to match the other
(non-atomic) counters.

For #53821.

Change-Id: I3acbfbbd1dabc59b0ea5ddc86a97e0d0afa9f80c
Reviewed-on: https://go-review.googlesource.com/c/go/+/419444
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/proc.go
src/runtime/runtime2.go

index 07c7b1b7c1539f25c9d9a6318d6c1faaf1e9821d..55c82ffa3e54c78b7a8f85198b3000c67655d14d 100644 (file)
@@ -1868,7 +1868,7 @@ func needm() {
 
        // mp.curg is now a real goroutine.
        casgstatus(mp.curg, _Gdead, _Gsyscall)
-       atomic.Xadd(&sched.ngsys, -1)
+       sched.ngsys.Add(-1)
 }
 
 var earlycgocallback = []byte("fatal error: cgo callback before cgo call\n")
@@ -1930,7 +1930,7 @@ func oneNewExtraM() {
        // counted by gcount. It would be more "proper" to increment
        // sched.ngfree, but that requires locking. Incrementing ngsys
        // has the same effect.
-       atomic.Xadd(&sched.ngsys, +1)
+       sched.ngsys.Add(1)
 
        // Add m to the extra list.
        mnext := lockextra(true)
@@ -1971,7 +1971,7 @@ func dropm() {
        // Return mp.curg to dead state.
        casgstatus(mp.curg, _Gsyscall, _Gdead)
        mp.curg.preemptStop = false
-       atomic.Xadd(&sched.ngsys, +1)
+       sched.ngsys.Add(1)
 
        // Block signals before unminit.
        // Unminit unregisters the signal handling stack (but needs g on some systems).
@@ -3474,7 +3474,7 @@ func goexit0(gp *g) {
        casgstatus(gp, _Grunning, _Gdead)
        gcController.addScannableStack(pp, -int64(gp.stack.hi-gp.stack.lo))
        if isSystemGoroutine(gp, false) {
-               atomic.Xadd(&sched.ngsys, -1)
+               sched.ngsys.Add(-1)
        }
        gp.m = nil
        locked := gp.lockedm != 0
@@ -4141,7 +4141,7 @@ func newproc1(fn *funcval, callergp *g, callerpc uintptr) *g {
        newg.ancestors = saveAncestors(callergp)
        newg.startpc = fn.fn
        if isSystemGoroutine(newg, false) {
-               atomic.Xadd(&sched.ngsys, +1)
+               sched.ngsys.Add(1)
        } else {
                // Only user goroutines inherit pprof labels.
                if mp.curg != nil {
@@ -4462,7 +4462,7 @@ func badunlockosthread() {
 }
 
 func gcount() int32 {
-       n := int32(atomic.Loaduintptr(&allglen)) - sched.gFree.n - int32(atomic.Load(&sched.ngsys))
+       n := int32(atomic.Loaduintptr(&allglen)) - sched.gFree.n - sched.ngsys.Load()
        for _, pp := range allp {
                n -= pp.gFree.n
        }
index 17d47c07263aaa47d28185bbe5e21b61f70790d3..bc482b00a2e3944f7c77583584740e7de4e74158 100644 (file)
@@ -775,7 +775,7 @@ type schedt struct {
        nmsys        int32    // number of system m's not counted for deadlock
        nmfreed      int64    // cumulative number of freed m's
 
-       ngsys uint32 // number of system goroutines; updated atomically
+       ngsys atomic.Int32 // number of system goroutines
 
        pidle      puintptr // idle p's
        npidle     uint32