From c890d40d0db00a6a91fd48acee024f0478f10ce4 Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Wed, 10 May 2023 03:14:22 +0000 Subject: runtime: factor our oneNewExtraM trace code In the interest of further cleaning up the trace.go API, move the trace logic in oneNewExtraM into its own function. Change-Id: I5cf478cb8cd0d301ee3b068347ed48ce768b8882 Reviewed-on: https://go-review.googlesource.com/c/go/+/494186 Reviewed-by: Michael Pratt Run-TryBot: Michael Knyszek Auto-Submit: Michael Knyszek TryBot-Result: Gopher Robot --- src/runtime/proc.go | 7 +------ src/runtime/trace.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 2c8750a5fe..b5e1c3e3b1 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -2004,12 +2004,7 @@ func oneNewExtraM() { gp.racectx = racegostart(abi.FuncPCABIInternal(newextram) + sys.PCQuantum) } if traceEnabled() { - // Trigger two trace events for the locked g in the extra m, - // since the next event of the g will be traceEvGoSysExit in exitsyscall, - // while calling from C thread to Go. - traceGoCreate(gp, 0) // no start pc - gp.traceseq++ - traceEvent(traceEvGoInSyscall, -1, gp.goid) + traceOneNewExtraM(gp) } // put on allg for garbage collector allgadd(gp) diff --git a/src/runtime/trace.go b/src/runtime/trace.go index fd3ee273a3..27d58c2217 100644 --- a/src/runtime/trace.go +++ b/src/runtime/trace.go @@ -1713,3 +1713,16 @@ func startPCforTrace(pc uintptr) uintptr { } return f.datap.textAddr(*(*uint32)(w)) } + +// traceOneNewExtraM registers the fact that a new extra M was created with +// the tracer. This matters if the M (which has an attached G) is used while +// the trace is still active because if it is, we need the fact that it exists +// to show up in the final trace. +func traceOneNewExtraM(gp *g) { + // Trigger two trace events for the locked g in the extra m, + // since the next event of the g will be traceEvGoSysExit in exitsyscall, + // while calling from C thread to Go. + traceGoCreate(gp, 0) // no start pc + gp.traceseq++ + traceEvent(traceEvGoInSyscall, -1, gp.goid) +} -- cgit v1.2.1