diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 07c7b1b7c15..55c82ffa3e5 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -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 } diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index 17d47c07263..bc482b00a2e 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -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