Skip to content

Commit 44286b1

Browse files
committed
runtime: replace system goroutine whitelist with symbol test
Currently isSystemGoroutine has a hard-coded list of known entry points into system goroutines. This list is annoying to maintain. For example, it's missing the ensureSigM goroutine. Replace it with a check that simply looks for any goroutine with runtime function as its entry point, with a few exceptions. This also matches the definition recently added to the trace viewer (CL 81315). Change-Id: Iaed723d4a6e8c2ffb7c0c48fbac1688b00b30f01 Reviewed-on: https://go-review.googlesource.com/81655 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent a8a0508 commit 44286b1

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

src/cmd/internal/objabi/funcid.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type FuncID uint32
1313

1414
const (
1515
FuncID_normal FuncID = iota // not a special function
16+
FuncID_runtime_main
1617
FuncID_goexit
1718
FuncID_jmpdefer
1819
FuncID_mcall
@@ -22,9 +23,6 @@ const (
2223
FuncID_asmcgocall
2324
FuncID_sigpanic
2425
FuncID_runfinq
25-
FuncID_bgsweep
26-
FuncID_forcegchelper
27-
FuncID_timerproc
2826
FuncID_gcBgMarkWorker
2927
FuncID_systemstack_switch
3028
FuncID_systemstack

src/cmd/link/internal/ld/pcln.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ func (ctxt *Link) pclntab() {
312312
// funcID uint32
313313
funcID := objabi.FuncID_normal
314314
switch s.Name {
315+
case "runtime.main":
316+
funcID = objabi.FuncID_runtime_main
315317
case "runtime.goexit":
316318
funcID = objabi.FuncID_goexit
317319
case "runtime.jmpdefer":
@@ -330,12 +332,6 @@ func (ctxt *Link) pclntab() {
330332
funcID = objabi.FuncID_sigpanic
331333
case "runtime.runfinq":
332334
funcID = objabi.FuncID_runfinq
333-
case "runtime.bgsweep":
334-
funcID = objabi.FuncID_bgsweep
335-
case "runtime.forcegchelper":
336-
funcID = objabi.FuncID_forcegchelper
337-
case "runtime.timerproc":
338-
funcID = objabi.FuncID_timerproc
339335
case "runtime.gcBgMarkWorker":
340336
funcID = objabi.FuncID_gcBgMarkWorker
341337
case "runtime.systemstack_switch":

src/cmd/trace/trace.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ func generateTrace(params *traceParams, consumer traceConsumer) error {
576576

577577
fname := stk[0].Fn
578578
info.name = fmt.Sprintf("G%v %s", newG, fname)
579-
info.isSystemG = strings.HasPrefix(fname, "runtime.") && fname != "runtime.main"
579+
info.isSystemG = isSystemGoroutine(fname)
580580

581581
ctx.gcount++
582582
setGState(ev, newG, gDead, gRunnable)
@@ -1125,6 +1125,12 @@ func (ctx *traceContext) buildBranch(parent frameNode, stk []*trace.Frame) int {
11251125
return ctx.buildBranch(node, stk)
11261126
}
11271127

1128+
func isSystemGoroutine(entryFn string) bool {
1129+
// This mimics runtime.isSystemGoroutine as closely as
1130+
// possible.
1131+
return entryFn != "runtime.main" && strings.HasPrefix(entryFn, "runtime.")
1132+
}
1133+
11281134
// firstTimestamp returns the timestamp of the first event record.
11291135
func firstTimestamp() int64 {
11301136
res, _ := parseTrace()

src/runtime/symtab.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ type funcID uint32
358358

359359
const (
360360
funcID_normal funcID = iota // not a special function
361+
funcID_runtime_main
361362
funcID_goexit
362363
funcID_jmpdefer
363364
funcID_mcall
@@ -367,9 +368,6 @@ const (
367368
funcID_asmcgocall
368369
funcID_sigpanic
369370
funcID_runfinq
370-
funcID_bgsweep
371-
funcID_forcegchelper
372-
funcID_timerproc
373371
funcID_gcBgMarkWorker
374372
funcID_systemstack_switch
375373
funcID_systemstack

src/runtime/traceback.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -990,18 +990,25 @@ func topofstack(f funcInfo, g0 bool) bool {
990990
(g0 && f.funcID == funcID_asmcgocall)
991991
}
992992

993-
// isSystemGoroutine reports whether the goroutine g must be omitted in
994-
// stack dumps and deadlock detector.
993+
// isSystemGoroutine reports whether the goroutine g must be omitted
994+
// in stack dumps and deadlock detector. This is any goroutine that
995+
// starts at a runtime.* entry point, except for runtime.main and
996+
// sometimes runtime.runfinq.
995997
func isSystemGoroutine(gp *g) bool {
998+
// Keep this in sync with cmd/trace/trace.go:isSystemGoroutine.
996999
f := findfunc(gp.startpc)
9971000
if !f.valid() {
9981001
return false
9991002
}
1000-
return f.funcID == funcID_runfinq && !fingRunning ||
1001-
f.funcID == funcID_bgsweep ||
1002-
f.funcID == funcID_forcegchelper ||
1003-
f.funcID == funcID_timerproc ||
1004-
f.funcID == funcID_gcBgMarkWorker
1003+
if f.funcID == funcID_runtime_main {
1004+
return false
1005+
}
1006+
if f.funcID == funcID_runfinq {
1007+
// We include the finalizer goroutine if it's calling
1008+
// back into user code.
1009+
return !fingRunning
1010+
}
1011+
return hasprefix(funcname(f), "runtime.")
10051012
}
10061013

10071014
// SetCgoTraceback records three C functions to use to gather

0 commit comments

Comments
 (0)