1
0
mirror of https://github.com/golang/go synced 2024-11-19 15:24:46 -07:00

runtime: replace sched.mcount int32 with sched.mnext int64

Currently, since Ms never exit, the number of Ms, the number of Ms
ever created, and the ID of the next M are all the same and must be
small. That's about to change, so rename sched.mcount to sched.mnext
to make it clear it's the number of Ms ever created (and the ID of the
next M), change its type to int64, and use mcount() for the number of
Ms. In the next commit, mcount() will become slightly less trivial.

For #20395.

Change-Id: I9af34d36bd72416b5656555d16e8085076f1b196
Reviewed-on: https://go-review.googlesource.com/68750
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Austin Clements 2017-10-05 21:28:01 -04:00
parent d7ac5ce8a3
commit 6c7bea6309
3 changed files with 17 additions and 14 deletions

View File

@ -518,7 +518,7 @@ func dumpgstatus(gp *g) {
func checkmcount() { func checkmcount() {
// sched lock is held // sched lock is held
if sched.mcount > sched.maxmcount { if mcount() > sched.maxmcount {
print("runtime: program exceeds ", sched.maxmcount, "-thread limit\n") print("runtime: program exceeds ", sched.maxmcount, "-thread limit\n")
throw("thread exhaustion") throw("thread exhaustion")
} }
@ -533,8 +533,11 @@ func mcommoninit(mp *m) {
} }
lock(&sched.lock) lock(&sched.lock)
mp.id = sched.mcount if sched.mnext+1 < sched.mnext {
sched.mcount++ throw("runtime: thread ID overflow")
}
mp.id = sched.mnext
sched.mnext++
checkmcount() checkmcount()
mp.fastrand[0] = 1597334677 * uint32(mp.id) mp.fastrand[0] = 1597334677 * uint32(mp.id)
@ -3374,7 +3377,7 @@ func gcount() int32 {
} }
func mcount() int32 { func mcount() int32 {
return sched.mcount return int32(sched.mnext)
} }
var prof struct { var prof struct {
@ -3854,7 +3857,7 @@ func acquirep1(_p_ *p) {
throw("acquirep: already in go") throw("acquirep: already in go")
} }
if _p_.m != 0 || _p_.status != _Pidle { if _p_.m != 0 || _p_.status != _Pidle {
id := int32(0) id := int64(0)
if _p_.m != 0 { if _p_.m != 0 {
id = _p_.m.ptr().id id = _p_.m.ptr().id
} }
@ -3915,12 +3918,12 @@ func checkdead() {
return return
} }
run := sched.mcount - sched.nmidle - sched.nmidlelocked - sched.nmsys run := mcount() - sched.nmidle - sched.nmidlelocked - sched.nmsys
if run > 0 { if run > 0 {
return return
} }
if run < 0 { if run < 0 {
print("runtime: checkdead: nmidle=", sched.nmidle, " nmidlelocked=", sched.nmidlelocked, " mcount=", sched.mcount, " nmsys=", sched.nmsys, "\n") print("runtime: checkdead: nmidle=", sched.nmidle, " nmidlelocked=", sched.nmidlelocked, " mcount=", mcount(), " nmsys=", sched.nmsys, "\n")
throw("checkdead: inconsistent counts") throw("checkdead: inconsistent counts")
} }
@ -4234,7 +4237,7 @@ func schedtrace(detailed bool) {
} }
lock(&sched.lock) lock(&sched.lock)
print("SCHED ", (now-starttime)/1e6, "ms: gomaxprocs=", gomaxprocs, " idleprocs=", sched.npidle, " threads=", sched.mcount, " spinningthreads=", sched.nmspinning, " idlethreads=", sched.nmidle, " runqueue=", sched.runqsize) print("SCHED ", (now-starttime)/1e6, "ms: gomaxprocs=", gomaxprocs, " idleprocs=", sched.npidle, " threads=", mcount(), " spinningthreads=", sched.nmspinning, " idlethreads=", sched.nmidle, " runqueue=", sched.runqsize)
if detailed { if detailed {
print(" gcwaiting=", sched.gcwaiting, " nmidlelocked=", sched.nmidlelocked, " stopwait=", sched.stopwait, " sysmonwait=", sched.sysmonwait, "\n") print(" gcwaiting=", sched.gcwaiting, " nmidlelocked=", sched.nmidlelocked, " stopwait=", sched.stopwait, " sysmonwait=", sched.sysmonwait, "\n")
} }
@ -4246,7 +4249,7 @@ func schedtrace(detailed bool) {
h := atomic.Load(&_p_.runqhead) h := atomic.Load(&_p_.runqhead)
t := atomic.Load(&_p_.runqtail) t := atomic.Load(&_p_.runqtail)
if detailed { if detailed {
id := int32(-1) id := int64(-1)
if mp != nil { if mp != nil {
id = mp.id id = mp.id
} }
@ -4294,11 +4297,11 @@ func schedtrace(detailed bool) {
gp := allgs[gi] gp := allgs[gi]
mp := gp.m mp := gp.m
lockedm := gp.lockedm.ptr() lockedm := gp.lockedm.ptr()
id1 := int32(-1) id1 := int64(-1)
if mp != nil { if mp != nil {
id1 = mp.id id1 = mp.id
} }
id2 := int32(-1) id2 := int64(-1)
if lockedm != nil { if lockedm != nil {
id2 = lockedm.id id2 = lockedm.id
} }

View File

@ -399,7 +399,7 @@ type m struct {
caughtsig guintptr // goroutine running during fatal signal caughtsig guintptr // goroutine running during fatal signal
p puintptr // attached p for executing go code (nil if not executing go code) p puintptr // attached p for executing go code (nil if not executing go code)
nextp puintptr nextp puintptr
id int32 id int64
mallocing int32 mallocing int32
throwing int32 throwing int32
preemptoff string // if != "", keep curg running on this m preemptoff string // if != "", keep curg running on this m
@ -531,7 +531,7 @@ type schedt struct {
midle muintptr // idle m's waiting for work midle muintptr // idle m's waiting for work
nmidle int32 // number of idle m's waiting for work nmidle int32 // number of idle m's waiting for work
nmidlelocked int32 // number of locked m's waiting for work nmidlelocked int32 // number of locked m's waiting for work
mcount int32 // number of m's that have been created mnext int64 // number of m's that have been created and next M ID
maxmcount int32 // maximum number of m's allowed (or die) maxmcount int32 // maximum number of m's allowed (or die)
nmsys int32 // number of system m's not counted for deadlock nmsys int32 // number of system m's not counted for deadlock

View File

@ -111,7 +111,7 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
if docrash { if docrash {
crashing++ crashing++
if crashing < sched.mcount-int32(extraMCount) { if crashing < mcount()-int32(extraMCount) {
// There are other m's that need to dump their stacks. // There are other m's that need to dump their stacks.
// Relay SIGQUIT to the next m by sending it to the current process. // Relay SIGQUIT to the next m by sending it to the current process.
// All m's that have already received SIGQUIT have signal masks blocking // All m's that have already received SIGQUIT have signal masks blocking