Skip to content

Commit 2f35a65

Browse files
mknyszekgopherbot
authored andcommitted
runtime: capture per-m trace state in a type
More tightening up of the tracer's interface. While we're here, clarify why waittraceskip isn't included by explaining what the wait* fields in the M are really for. Change-Id: I0e7b4cac79fb77a7a0b3ca6b6cc267668e3610bc Reviewed-on: https://go-review.googlesource.com/c/go/+/494190 Auto-Submit: Michael Knyszek <[email protected]> Run-TryBot: Michael Knyszek <[email protected]> Reviewed-by: Michael Pratt <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent c213c90 commit 2f35a65

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/runtime/runtime2.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,13 +577,17 @@ type m struct {
577577
lockedExt uint32 // tracking for external LockOSThread
578578
lockedInt uint32 // tracking for internal lockOSThread
579579
nextwaitm muintptr // next m waiting for lock
580+
581+
// wait* are used to carry arguments from gopark into park_m, because
582+
// there's no stack to put them on. That is their sole purpose.
580583
waitunlockf func(*g, unsafe.Pointer) bool
581584
waitlock unsafe.Pointer
582585
waittraceev byte
583586
waittraceskip int
584-
startingtrace bool
585-
syscalltick uint32
586-
freelink *m // on sched.freem
587+
588+
syscalltick uint32
589+
freelink *m // on sched.freem
590+
trace mTraceState
587591

588592
// these are here because they are too large to be on the stack
589593
// of low-level NOSPLIT functions.

src/runtime/trace.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ type gTraceState struct {
169169
lastP puintptr // last P emitted an event for this goroutine
170170
}
171171

172+
// mTraceState is per-M state for the tracer.
173+
type mTraceState struct {
174+
startingTrace bool // this M is in TraceStart, potentially before traceEnabled is true
175+
}
176+
172177
// traceLockInit initializes global trace locks.
173178
func traceLockInit() {
174179
lockInit(&trace.bufLock, lockRankTraceBuf)
@@ -252,10 +257,10 @@ func StartTrace() error {
252257
// That would lead to an inconsistent trace:
253258
// - either GoSysExit appears before EvGoInSyscall,
254259
// - or GoSysExit appears for a goroutine for which we don't emit EvGoInSyscall below.
255-
// To instruct traceEvent that it must not ignore events below, we set startingtrace.
260+
// To instruct traceEvent that it must not ignore events below, we set trace.startingTrace.
256261
// trace.enabled is set afterwards once we have emitted all preliminary events.
257262
mp := getg().m
258-
mp.startingtrace = true
263+
mp.trace.startingTrace = true
259264

260265
// Obtain current stack ID to use in all traceEvGoCreate events below.
261266
stkBuf := make([]uintptr, traceStackSize)
@@ -324,7 +329,7 @@ func StartTrace() error {
324329
trace.strings = make(map[string]uint64)
325330

326331
trace.seqGC = 0
327-
mp.startingtrace = false
332+
mp.trace.startingTrace = false
328333
trace.enabled = true
329334

330335
// Register runtime goroutine labels.
@@ -698,7 +703,7 @@ func traceEvent(ev byte, skip int, args ...uint64) {
698703
// during tracing in exitsyscall is resolved by locking trace.bufLock in traceLockBuffer.
699704
//
700705
// Note trace_userTaskCreate runs the same check.
701-
if !trace.enabled && !mp.startingtrace {
706+
if !trace.enabled && !mp.trace.startingTrace {
702707
traceReleaseBuffer(mp, pid)
703708
return
704709
}
@@ -1642,7 +1647,7 @@ func trace_userTaskCreate(id, parentID uint64, taskType string) {
16421647

16431648
// Same as in traceEvent.
16441649
mp, pid, bufp := traceAcquireBuffer()
1645-
if !trace.enabled && !mp.startingtrace {
1650+
if !trace.enabled && !mp.trace.startingTrace {
16461651
traceReleaseBuffer(mp, pid)
16471652
return
16481653
}
@@ -1664,7 +1669,7 @@ func trace_userRegion(id, mode uint64, name string) {
16641669
}
16651670

16661671
mp, pid, bufp := traceAcquireBuffer()
1667-
if !trace.enabled && !mp.startingtrace {
1672+
if !trace.enabled && !mp.trace.startingTrace {
16681673
traceReleaseBuffer(mp, pid)
16691674
return
16701675
}
@@ -1681,7 +1686,7 @@ func trace_userLog(id uint64, category, message string) {
16811686
}
16821687

16831688
mp, pid, bufp := traceAcquireBuffer()
1684-
if !trace.enabled && !mp.startingtrace {
1689+
if !trace.enabled && !mp.trace.startingTrace {
16851690
traceReleaseBuffer(mp, pid)
16861691
return
16871692
}

0 commit comments

Comments
 (0)