Navigation Menu

Skip to content

Commit

Permalink
runtime: add mayAcquire annotation for trace.lock
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
aclements committed Aug 11, 2022
1 parent cc8bac8 commit 502b605
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/runtime/lockrank.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/runtime/mklockrank.go
Expand Up @@ -159,6 +159,7 @@ mheap, mheapSpecial < globalAlloc;
# Execution tracer events (with a P)
hchan,
mheap,
root,
sched,
traceStrings,
Expand Down
15 changes: 15 additions & 0 deletions src/runtime/trace.go
Expand Up @@ -883,6 +883,11 @@ func traceStackID(mp *m, buf []uintptr, skip int) uint64 {

// traceAcquireBuffer returns trace buffer to use and, if necessary, locks it.
func traceAcquireBuffer() (mp *m, pid int32, bufp *traceBufPtr) {
// Any time we acquire a buffer, we may end up flushing it,
// but flushes are rare. Record the lock edge even if it
// doesn't happen this time.
lockRankMayTraceFlush()

mp = acquirem()
if p := mp.p.ptr(); p != nil {
return mp, p.id, &p.tracebuf
Expand All @@ -899,6 +904,16 @@ func traceReleaseBuffer(pid int32) {
releasem(getg().m)
}

// lockRankMayTraceFlush records the lock ranking effects of a
// potential call to traceFlush.
func lockRankMayTraceFlush() {
owner := trace.lockOwner
dolock := owner == nil || owner != getg().m.curg
if dolock {
lockWithRankMayAcquire(&trace.lock, getLockRank(&trace.lock))
}
}

// traceFlush puts buf onto stack of full buffers and returns an empty buffer.
//
// This must run on the system stack because it acquires trace.lock.
Expand Down

0 comments on commit 502b605

Please sign in to comment.