Skip to content

Commit 7588546

Browse files
committed
runtime: clean up duplicate function
For #65355
1 parent ae457e8 commit 7588546

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

src/go/build/deps_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var depsRules = `
5454
internal/goarch, unsafe
5555
< internal/abi, internal/chacha8rand;
5656
57-
unsafe < maps;
57+
unsafe < maps, internal/runtime/goroutine;
5858
5959
# RUNTIME is the core runtime group of packages, all of them very light-weight.
6060
internal/abi,
@@ -63,6 +63,7 @@ var depsRules = `
6363
internal/cpu,
6464
internal/goarch,
6565
internal/godebugs,
66+
internal/runtime/goroutine,
6667
internal/goexperiment,
6768
internal/goos
6869
< internal/bytealg
@@ -189,7 +190,7 @@ var depsRules = `
189190
190191
# FMT is OS (which includes string routines) plus reflect and fmt.
191192
# It does not include package log, which should be avoided in core packages.
192-
arena, strconv, unicode
193+
arena, strconv, unicode, internal/runtime/goroutine
193194
< reflect;
194195
195196
os, reflect
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2024 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package goroutine
6+
7+
import "strings"
8+
9+
func IsSystemGoroutine(entryFn string) bool {
10+
// Locked g in extra M (with empty entryFn) is system goroutine.
11+
return entryFn == "" || entryFn != "runtime.main" && strings.HasPrefix(entryFn, "runtime.")
12+
}

src/internal/trace/goroutines.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
package trace
66

77
import (
8+
"internal/runtime/goroutine"
89
"sort"
9-
"strings"
1010
)
1111

1212
// GDesc contains statistics and execution details of a single goroutine.
@@ -134,7 +134,7 @@ func (g *GDesc) finalize(lastTs, activeGCStartTime int64, trigger *Event) {
134134
// "inherit" a task due to creation (EvGoCreate) from within a region.
135135
// This may happen e.g. if the first GC is triggered within a region,
136136
// starting the GC worker goroutines.
137-
if !IsSystemGoroutine(g.Name) {
137+
if !goroutine.IsSystemGoroutine(g.Name) {
138138
for _, s := range g.activeRegions {
139139
s.End = trigger
140140
s.GExecutionStat = finalStat.sub(s.GExecutionStat)
@@ -349,10 +349,3 @@ func RelatedGoroutines(events []*Event, goid uint64) map[uint64]bool {
349349
gmap[0] = true // for GC events
350350
return gmap
351351
}
352-
353-
func IsSystemGoroutine(entryFn string) bool {
354-
// This mimics runtime.isSystemGoroutine as closely as
355-
// possible.
356-
// Also, locked g in extra M (with empty entryFn) is system goroutine.
357-
return entryFn == "" || entryFn != "runtime.main" && strings.HasPrefix(entryFn, "runtime.")
358-
}

src/internal/trace/summary.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package trace
66

77
import (
8+
"internal/runtime/goroutine"
89
tracev2 "internal/trace/v2"
910
"sort"
1011
"time"
@@ -231,7 +232,7 @@ func (g *GoroutineSummary) finalize(lastTs tracev2.Time, trigger *tracev2.Event)
231232
// "inherit" a task due to creation (EvGoCreate) from within a region.
232233
// This may happen e.g. if the first GC is triggered within a region,
233234
// starting the GC worker goroutines.
234-
if !IsSystemGoroutine(g.Name) {
235+
if !goroutine.IsSystemGoroutine(g.Name) {
235236
for _, s := range g.activeRegions {
236237
s.End = trigger
237238
s.GoroutineExecStats = finalStat.sub(s.GoroutineExecStats)

src/runtime/traceback.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"internal/abi"
99
"internal/bytealg"
1010
"internal/goarch"
11+
"internal/runtime/goroutine"
1112
"runtime/internal/sys"
1213
"unsafe"
1314
)
@@ -1321,7 +1322,6 @@ func tracebackHexdump(stk stack, frame *stkframe, bad uintptr) {
13211322
// system (that is, the finalizer goroutine) is considered a user
13221323
// goroutine.
13231324
func isSystemGoroutine(gp *g, fixed bool) bool {
1324-
// Keep this in sync with internal/trace.IsSystemGoroutine.
13251325
f := findfunc(gp.startpc)
13261326
if !f.valid() {
13271327
return false
@@ -1339,7 +1339,7 @@ func isSystemGoroutine(gp *g, fixed bool) bool {
13391339
}
13401340
return fingStatus.Load()&fingRunningFinalizer == 0
13411341
}
1342-
return hasPrefix(funcname(f), "runtime.")
1342+
return goroutine.IsSystemGoroutine(funcname(f))
13431343
}
13441344

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

0 commit comments

Comments
 (0)