mirror of
https://github.com/golang/go
synced 2024-11-17 18:04:48 -07:00
runtime: convert schedt.sysmonwait to atomic type
This converts a few unsynchronized accesses. For #53821. Change-Id: Ie2728779111e3e042696f15648981c5d5a86ca6d Reviewed-on: https://go-review.googlesource.com/c/go/+/419448 Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
parent
88ef50e662
commit
09cc9bac72
@ -1271,8 +1271,8 @@ func startTheWorldWithSema(emitTraceEvent bool) int64 {
|
|||||||
}
|
}
|
||||||
p1 := procresize(procs)
|
p1 := procresize(procs)
|
||||||
sched.gcwaiting.Store(false)
|
sched.gcwaiting.Store(false)
|
||||||
if sched.sysmonwait != 0 {
|
if sched.sysmonwait.Load() {
|
||||||
sched.sysmonwait = 0
|
sched.sysmonwait.Store(false)
|
||||||
notewakeup(&sched.sysmonnote)
|
notewakeup(&sched.sysmonnote)
|
||||||
}
|
}
|
||||||
unlock(&sched.lock)
|
unlock(&sched.lock)
|
||||||
@ -3632,7 +3632,7 @@ func reentersyscall(pc, sp uintptr) {
|
|||||||
save(pc, sp)
|
save(pc, sp)
|
||||||
}
|
}
|
||||||
|
|
||||||
if atomic.Load(&sched.sysmonwait) != 0 {
|
if sched.sysmonwait.Load() {
|
||||||
systemstack(entersyscall_sysmon)
|
systemstack(entersyscall_sysmon)
|
||||||
save(pc, sp)
|
save(pc, sp)
|
||||||
}
|
}
|
||||||
@ -3670,8 +3670,8 @@ func entersyscall() {
|
|||||||
|
|
||||||
func entersyscall_sysmon() {
|
func entersyscall_sysmon() {
|
||||||
lock(&sched.lock)
|
lock(&sched.lock)
|
||||||
if atomic.Load(&sched.sysmonwait) != 0 {
|
if sched.sysmonwait.Load() {
|
||||||
atomic.Store(&sched.sysmonwait, 0)
|
sched.sysmonwait.Store(false)
|
||||||
notewakeup(&sched.sysmonnote)
|
notewakeup(&sched.sysmonnote)
|
||||||
}
|
}
|
||||||
unlock(&sched.lock)
|
unlock(&sched.lock)
|
||||||
@ -3908,8 +3908,8 @@ func exitsyscallfast_reacquired() {
|
|||||||
func exitsyscallfast_pidle() bool {
|
func exitsyscallfast_pidle() bool {
|
||||||
lock(&sched.lock)
|
lock(&sched.lock)
|
||||||
pp, _ := pidleget(0)
|
pp, _ := pidleget(0)
|
||||||
if pp != nil && atomic.Load(&sched.sysmonwait) != 0 {
|
if pp != nil && sched.sysmonwait.Load() {
|
||||||
atomic.Store(&sched.sysmonwait, 0)
|
sched.sysmonwait.Store(false)
|
||||||
notewakeup(&sched.sysmonnote)
|
notewakeup(&sched.sysmonnote)
|
||||||
}
|
}
|
||||||
unlock(&sched.lock)
|
unlock(&sched.lock)
|
||||||
@ -3944,8 +3944,8 @@ func exitsyscall0(gp *g) {
|
|||||||
// could race with another M transitioning gp from unlocked to
|
// could race with another M transitioning gp from unlocked to
|
||||||
// locked.
|
// locked.
|
||||||
locked = gp.lockedm != 0
|
locked = gp.lockedm != 0
|
||||||
} else if atomic.Load(&sched.sysmonwait) != 0 {
|
} else if sched.sysmonwait.Load() {
|
||||||
atomic.Store(&sched.sysmonwait, 0)
|
sched.sysmonwait.Store(false)
|
||||||
notewakeup(&sched.sysmonnote)
|
notewakeup(&sched.sysmonnote)
|
||||||
}
|
}
|
||||||
unlock(&sched.lock)
|
unlock(&sched.lock)
|
||||||
@ -5161,7 +5161,7 @@ func sysmon() {
|
|||||||
syscallWake := false
|
syscallWake := false
|
||||||
next := timeSleepUntil()
|
next := timeSleepUntil()
|
||||||
if next > now {
|
if next > now {
|
||||||
atomic.Store(&sched.sysmonwait, 1)
|
sched.sysmonwait.Store(true)
|
||||||
unlock(&sched.lock)
|
unlock(&sched.lock)
|
||||||
// Make wake-up period small enough
|
// Make wake-up period small enough
|
||||||
// for the sampling to be correct.
|
// for the sampling to be correct.
|
||||||
@ -5178,7 +5178,7 @@ func sysmon() {
|
|||||||
osRelax(false)
|
osRelax(false)
|
||||||
}
|
}
|
||||||
lock(&sched.lock)
|
lock(&sched.lock)
|
||||||
atomic.Store(&sched.sysmonwait, 0)
|
sched.sysmonwait.Store(false)
|
||||||
noteclear(&sched.sysmonnote)
|
noteclear(&sched.sysmonnote)
|
||||||
}
|
}
|
||||||
if syscallWake {
|
if syscallWake {
|
||||||
@ -5410,7 +5410,7 @@ func schedtrace(detailed bool) {
|
|||||||
lock(&sched.lock)
|
lock(&sched.lock)
|
||||||
print("SCHED ", (now-starttime)/1e6, "ms: gomaxprocs=", gomaxprocs, " idleprocs=", sched.npidle.Load(), " threads=", mcount(), " spinningthreads=", sched.nmspinning.Load(), " idlethreads=", sched.nmidle, " runqueue=", sched.runqsize)
|
print("SCHED ", (now-starttime)/1e6, "ms: gomaxprocs=", gomaxprocs, " idleprocs=", sched.npidle.Load(), " threads=", mcount(), " spinningthreads=", sched.nmspinning.Load(), " idlethreads=", sched.nmidle, " runqueue=", sched.runqsize)
|
||||||
if detailed {
|
if detailed {
|
||||||
print(" gcwaiting=", sched.gcwaiting.Load(), " nmidlelocked=", sched.nmidlelocked, " stopwait=", sched.stopwait, " sysmonwait=", sched.sysmonwait, "\n")
|
print(" gcwaiting=", sched.gcwaiting.Load(), " nmidlelocked=", sched.nmidlelocked, " stopwait=", sched.stopwait, " sysmonwait=", sched.sysmonwait.Load(), "\n")
|
||||||
}
|
}
|
||||||
// We must be careful while reading data from P's, M's and G's.
|
// We must be careful while reading data from P's, M's and G's.
|
||||||
// Even if we hold schedlock, most data can be changed concurrently.
|
// Even if we hold schedlock, most data can be changed concurrently.
|
||||||
|
@ -820,7 +820,7 @@ type schedt struct {
|
|||||||
gcwaiting atomic.Bool // gc is waiting to run
|
gcwaiting atomic.Bool // gc is waiting to run
|
||||||
stopwait int32
|
stopwait int32
|
||||||
stopnote note
|
stopnote note
|
||||||
sysmonwait uint32
|
sysmonwait atomic.Bool
|
||||||
sysmonnote note
|
sysmonnote note
|
||||||
|
|
||||||
// safepointFn should be called on each P at the next GC
|
// safepointFn should be called on each P at the next GC
|
||||||
|
Loading…
Reference in New Issue
Block a user