Skip to content

Commit 29b21ec

Browse files
committed
runtime: add a more stable isSystemGoroutine mode
Currently, isSystemGoroutine varies on whether it considers the finalizer goroutine a user goroutine or a system goroutine. For the next CL, we're going to want to always consider the finalier goroutine a user goroutine, so add a flag that indicates that. Updates #26903. This is preparation for unifying STW GC and concurrent GC. Change-Id: Iafc92e519c13d9f8d879332cb5f0d12164104c33 Reviewed-on: https://go-review.googlesource.com/c/134778 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rick Hudson <[email protected]>
1 parent 198440c commit 29b21ec

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

src/runtime/heapdump.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func dumpgoroutine(gp *g) {
346346
dumpint(uint64(gp.goid))
347347
dumpint(uint64(gp.gopc))
348348
dumpint(uint64(readgstatus(gp)))
349-
dumpbool(isSystemGoroutine(gp))
349+
dumpbool(isSystemGoroutine(gp, false))
350350
dumpbool(false) // isbackground
351351
dumpint(uint64(gp.waitsince))
352352
dumpstr(gp.waitreason.String())

src/runtime/mprof.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ func GoroutineProfile(p []StackRecord) (n int, ok bool) {
723723
isOK := func(gp1 *g) bool {
724724
// Checking isSystemGoroutine here makes GoroutineProfile
725725
// consistent with both NumGoroutine and Stack.
726-
return gp1 != gp && readgstatus(gp1) != _Gdead && !isSystemGoroutine(gp1)
726+
return gp1 != gp && readgstatus(gp1) != _Gdead && !isSystemGoroutine(gp1, false)
727727
}
728728

729729
stopTheWorld("profile")

src/runtime/proc.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -2730,7 +2730,7 @@ func goexit0(gp *g) {
27302730
_g_ := getg()
27312731

27322732
casgstatus(gp, _Grunning, _Gdead)
2733-
if isSystemGoroutine(gp) {
2733+
if isSystemGoroutine(gp, false) {
27342734
atomic.Xadd(&sched.ngsys, -1)
27352735
}
27362736
gp.m = nil
@@ -3381,7 +3381,7 @@ func newproc1(fn *funcval, argp *uint8, narg int32, callergp *g, callerpc uintpt
33813381
if _g_.m.curg != nil {
33823382
newg.labels = _g_.m.curg.labels
33833383
}
3384-
if isSystemGoroutine(newg) {
3384+
if isSystemGoroutine(newg, false) {
33853385
atomic.Xadd(&sched.ngsys, +1)
33863386
}
33873387
newg.gcscanvalid = false
@@ -4244,7 +4244,7 @@ func checkdead() {
42444244
lock(&allglock)
42454245
for i := 0; i < len(allgs); i++ {
42464246
gp := allgs[i]
4247-
if isSystemGoroutine(gp) {
4247+
if isSystemGoroutine(gp, false) {
42484248
continue
42494249
}
42504250
s := readgstatus(gp)

src/runtime/traceback.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ func tracebackothers(me *g) {
945945

946946
lock(&allglock)
947947
for _, gp := range allgs {
948-
if gp == me || gp == g.m.curg || readgstatus(gp) == _Gdead || isSystemGoroutine(gp) && level < 2 {
948+
if gp == me || gp == g.m.curg || readgstatus(gp) == _Gdead || isSystemGoroutine(gp, false) && level < 2 {
949949
continue
950950
}
951951
print("\n")
@@ -1031,7 +1031,11 @@ func topofstack(f funcInfo, g0 bool) bool {
10311031
// in stack dumps and deadlock detector. This is any goroutine that
10321032
// starts at a runtime.* entry point, except for runtime.main and
10331033
// sometimes runtime.runfinq.
1034-
func isSystemGoroutine(gp *g) bool {
1034+
//
1035+
// If fixed is true, any goroutine that can vary between user and
1036+
// system (that is, the finalizer goroutine) is considered a user
1037+
// goroutine.
1038+
func isSystemGoroutine(gp *g, fixed bool) bool {
10351039
// Keep this in sync with cmd/trace/trace.go:isSystemGoroutine.
10361040
f := findfunc(gp.startpc)
10371041
if !f.valid() {
@@ -1043,6 +1047,11 @@ func isSystemGoroutine(gp *g) bool {
10431047
if f.funcID == funcID_runfinq {
10441048
// We include the finalizer goroutine if it's calling
10451049
// back into user code.
1050+
if fixed {
1051+
// This goroutine can vary. In fixed mode,
1052+
// always consider it a user goroutine.
1053+
return false
1054+
}
10461055
return !fingRunning
10471056
}
10481057
return hasPrefix(funcname(f), "runtime.")

0 commit comments

Comments
 (0)