Skip to content

Commit 502b605

Browse files
committed
runtime: add mayAcquire annotation for trace.lock
Now that we've moved the trace locks to the leaf of the lock graph, we can safely annotate that any trace event may acquire trace.lock even if dynamically it turns out a particular event doesn't need to flush and acquire this lock. This reveals a new edge where we can trace while holding the mheap lock, so we add this to the lock graph. For #53789. Updates #53979. Change-Id: I13e2f6cd1b621cca4bed0cc13ef12e64d05c89a7 Reviewed-on: https://go-review.googlesource.com/c/go/+/418720 Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
1 parent cc8bac8 commit 502b605

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

Diff for: src/runtime/lockrank.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/runtime/mklockrank.go

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ mheap, mheapSpecial < globalAlloc;
159159
160160
# Execution tracer events (with a P)
161161
hchan,
162+
mheap,
162163
root,
163164
sched,
164165
traceStrings,

Diff for: src/runtime/trace.go

+15
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,11 @@ func traceStackID(mp *m, buf []uintptr, skip int) uint64 {
883883

884884
// traceAcquireBuffer returns trace buffer to use and, if necessary, locks it.
885885
func traceAcquireBuffer() (mp *m, pid int32, bufp *traceBufPtr) {
886+
// Any time we acquire a buffer, we may end up flushing it,
887+
// but flushes are rare. Record the lock edge even if it
888+
// doesn't happen this time.
889+
lockRankMayTraceFlush()
890+
886891
mp = acquirem()
887892
if p := mp.p.ptr(); p != nil {
888893
return mp, p.id, &p.tracebuf
@@ -899,6 +904,16 @@ func traceReleaseBuffer(pid int32) {
899904
releasem(getg().m)
900905
}
901906

907+
// lockRankMayTraceFlush records the lock ranking effects of a
908+
// potential call to traceFlush.
909+
func lockRankMayTraceFlush() {
910+
owner := trace.lockOwner
911+
dolock := owner == nil || owner != getg().m.curg
912+
if dolock {
913+
lockWithRankMayAcquire(&trace.lock, getLockRank(&trace.lock))
914+
}
915+
}
916+
902917
// traceFlush puts buf onto stack of full buffers and returns an empty buffer.
903918
//
904919
// This must run on the system stack because it acquires trace.lock.

0 commit comments

Comments
 (0)