summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2023-05-10 20:42:23 +0000
committerGopher Robot <gobot@golang.org>2023-05-17 14:46:57 +0000
commitb7e767b022f96687ecbde61ee7efd61a711f798b (patch)
tree420f8dede989e202fb29b818617bf5f0451686a6
parent2f35a655e73837a95941eeda00f56c799ee64591 (diff)
downloadgo-git-b7e767b022f96687ecbde61ee7efd61a711f798b.tar.gz
runtime: capture per-p trace state in a type
More tightening up of the tracer's interface. Change-Id: I992141c7f30e5c2d5d77d1fcd6817d35bc6e5f6d Reviewed-on: https://go-review.googlesource.com/c/go/+/494191 Auto-Submit: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
-rw-r--r--src/runtime/mgcsweep.go2
-rw-r--r--src/runtime/runtime2.go10
-rw-r--r--src/runtime/trace.go44
3 files changed, 31 insertions, 25 deletions
diff --git a/src/runtime/mgcsweep.go b/src/runtime/mgcsweep.go
index a9ee2a9db6..4b0d655a9d 100644
--- a/src/runtime/mgcsweep.go
+++ b/src/runtime/mgcsweep.go
@@ -652,7 +652,7 @@ func (sl *sweepLocked) sweep(preserve bool) bool {
s.freeindex = 0 // reset allocation index to start of span.
s.freeIndexForScan = 0
if traceEnabled() {
- getg().m.p.ptr().traceReclaimed += uintptr(nfreed) * s.elemsize
+ getg().m.p.ptr().trace.reclaimed += uintptr(nfreed) * s.elemsize
}
// gcmarkBits becomes the allocBits.
diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go
index 0350052a25..314ab194e7 100644
--- a/src/runtime/runtime2.go
+++ b/src/runtime/runtime2.go
@@ -674,15 +674,7 @@ type p struct {
buf [128]*mspan
}
- tracebuf traceBufPtr
-
- // traceSweep indicates the sweep events should be traced.
- // This is used to defer the sweep start event until a span
- // has actually been swept.
- traceSweep bool
- // traceSwept and traceReclaimed track the number of bytes
- // swept and reclaimed by sweeping in the current sweep loop.
- traceSwept, traceReclaimed uintptr
+ trace pTraceState
palloc persistentAlloc // per-P to avoid mutex
diff --git a/src/runtime/trace.go b/src/runtime/trace.go
index 465e000c0e..8a2ef17f2b 100644
--- a/src/runtime/trace.go
+++ b/src/runtime/trace.go
@@ -174,6 +174,20 @@ type mTraceState struct {
startingTrace bool // this M is in TraceStart, potentially before traceEnabled is true
}
+// pTraceState is per-P state for the tracer.
+type pTraceState struct {
+ buf traceBufPtr
+
+ // inSweep indicates the sweep events should be traced.
+ // This is used to defer the sweep start event until a span
+ // has actually been swept.
+ inSweep bool
+
+ // swept and reclaimed track the number of bytes swept and reclaimed
+ // by sweeping in the current sweep loop (while inSweep was true).
+ swept, reclaimed uintptr
+}
+
// traceLockInit initializes global trace locks.
func traceLockInit() {
lockInit(&trace.bufLock, lockRankTraceBuf)
@@ -379,10 +393,10 @@ func StopTrace() {
// Loop over all allocated Ps because dead Ps may still have
// trace buffers.
for _, p := range allp[:cap(allp)] {
- buf := p.tracebuf
+ buf := p.trace.buf
if buf != 0 {
traceFullQueue(buf)
- p.tracebuf = 0
+ p.trace.buf = 0
}
}
if trace.buf != 0 {
@@ -429,7 +443,7 @@ func StopTrace() {
// The lock protects us from races with StartTrace/StopTrace because they do stop-the-world.
lock(&trace.lock)
for _, p := range allp[:cap(allp)] {
- if p.tracebuf != 0 {
+ if p.trace.buf != 0 {
throw("trace: non-empty trace buffer in proc")
}
}
@@ -650,8 +664,8 @@ func traceReaderAvailable() *g {
//
//go:systemstack
func traceProcFree(pp *p) {
- buf := pp.tracebuf
- pp.tracebuf = 0
+ buf := pp.trace.buf
+ pp.trace.buf = 0
if buf == 0 {
return
}
@@ -980,7 +994,7 @@ func traceAcquireBuffer() (mp *m, pid int32, bufp *traceBufPtr) {
mp = acquirem()
if p := mp.p.ptr(); p != nil {
- return mp, p.id, &p.tracebuf
+ return mp, p.id, &p.trace.buf
}
lock(&trace.bufLock)
return mp, traceGlobProc, &trace.buf
@@ -1480,10 +1494,10 @@ func traceGCSweepStart() {
// Delay the actual GCSweepStart event until the first span
// sweep. If we don't sweep anything, don't emit any events.
pp := getg().m.p.ptr()
- if pp.traceSweep {
+ if pp.trace.inSweep {
throw("double traceGCSweepStart")
}
- pp.traceSweep, pp.traceSwept, pp.traceReclaimed = true, 0, 0
+ pp.trace.inSweep, pp.trace.swept, pp.trace.reclaimed = true, 0, 0
}
// traceGCSweepSpan traces the sweep of a single page.
@@ -1492,23 +1506,23 @@ func traceGCSweepStart() {
// pair; however, it will not emit any trace events in this case.
func traceGCSweepSpan(bytesSwept uintptr) {
pp := getg().m.p.ptr()
- if pp.traceSweep {
- if pp.traceSwept == 0 {
+ if pp.trace.inSweep {
+ if pp.trace.swept == 0 {
traceEvent(traceEvGCSweepStart, 1)
}
- pp.traceSwept += bytesSwept
+ pp.trace.swept += bytesSwept
}
}
func traceGCSweepDone() {
pp := getg().m.p.ptr()
- if !pp.traceSweep {
+ if !pp.trace.inSweep {
throw("missing traceGCSweepStart")
}
- if pp.traceSwept != 0 {
- traceEvent(traceEvGCSweepDone, -1, uint64(pp.traceSwept), uint64(pp.traceReclaimed))
+ if pp.trace.swept != 0 {
+ traceEvent(traceEvGCSweepDone, -1, uint64(pp.trace.swept), uint64(pp.trace.reclaimed))
}
- pp.traceSweep = false
+ pp.trace.inSweep = false
}
func traceGCMarkAssistStart() {