]> Cypherpunks repositories - gostls13.git/commit
runtime: profile contended lock calls
authorRhys Hiltner <rhys@justin.tv>
Tue, 21 Nov 2023 16:03:54 +0000 (16:03 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 21 Nov 2023 21:02:20 +0000 (21:02 +0000)
commit450ecbe90508f56684b69e39823d4da155846932
tree05c96f583157666fead2c8987757e5a71fd0b880
parent539b4d8d5bb91f74f580a1bc6e8e28b9de38aedd
runtime: profile contended lock calls

Add runtime-internal locks to the mutex contention profile.

Store up to one call stack responsible for lock contention on the M,
until it's safe to contribute its value to the mprof table. Try to use
that limited local storage space for a relatively large source of
contention, and attribute any contention in stacks we're not able to
store to a sentinel _LostContendedLock function.

Avoid ballooning lock contention while manipulating the mprof table by
attributing to that sentinel function any lock contention experienced
while reporting lock contention.

Guard collecting real call stacks with GODEBUG=profileruntimelocks=1,
since the available data has mixed semantics; we can easily capture an
M's own wait time, but we'd prefer for the profile entry of each
critical section to describe how long it made the other Ms wait. It's
too late in the Go 1.22 cycle to make the required changes to
futex-based locks. When not enabled, attribute the time to the sentinel
function instead.

Fixes #57071

This is a roll-forward of https://go.dev/cl/528657, which was reverted
in https://go.dev/cl/543660

Reason for revert: de-flakes tests (reduces dependence on fine-grained
timers, correctly identifies contention on big-endian futex locks,
attempts to measure contention in the semaphore implementation but only
uses that secondary measurement to finish the test early, skips tests on
single-processor systems)

Change-Id: I31389f24283d85e46ad9ba8d4f514cb9add8dfb0
Reviewed-on: https://go-review.googlesource.com/c/go/+/544195
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Auto-Submit: Rhys Hiltner <rhys@justin.tv>
Run-TryBot: Rhys Hiltner <rhys@justin.tv>
13 files changed:
src/runtime/debug.go
src/runtime/export_test.go
src/runtime/extern.go
src/runtime/lock_futex.go
src/runtime/lock_js.go
src/runtime/lock_sema.go
src/runtime/lock_wasip1.go
src/runtime/metrics.go
src/runtime/metrics_test.go
src/runtime/mprof.go
src/runtime/proc.go
src/runtime/runtime1.go
src/runtime/runtime2.go