]> Cypherpunks repositories - gostls13.git/commit
runtime: change mutex profile to count every blocked goroutine
authorRuss Cox <rsc@golang.org>
Mon, 26 Jun 2023 21:12:44 +0000 (17:12 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 17 Aug 2023 01:30:31 +0000 (01:30 +0000)
commit1c0035401358c8bfc2ff646b1d950da5fcd6b355
treeb446e570234778b0d89924fd70ab7a16b4542411
parent14a3ffc3d2165ef03c3ffd0037a4fa6dbb776026
runtime: change mutex profile to count every blocked goroutine

The pprof mutex profile was meant to match the Google C++ (now Abseil)
mutex profiler, originally designed and implemented by Mike Burrows.
When we worked on the Go version, pjw and I missed that C++ counts the
time each thread is blocked, even if multiple threads are blocked on a
mutex. That is, if 100 threads are blocked on the same mutex for the
same 10ms, that still counts as 1000ms of contention in C++. In Go, to
date, /debug/pprof/mutex has counted that as only 10ms of contention.
If 100 goroutines are blocked on one mutex and only 1 goroutine is
blocked on another mutex, we probably do want to see the first mutex
as being more contended, so the Abseil approach is the more useful one.

This CL adopts "contention scales with number of goroutines blocked",
to better match Abseil [1]. However, it still makes sure to attribute the
time to the unlock that caused the backup, not subsequent innocent
unlocks that were affected by the congestion. In this way it still gives
more accurate profiles than Abseil does.

[1] https://github.com/abseil/abseil-cpp/blob/lts_2023_01_25/absl/synchronization/mutex.cc#L2390

Fixes #61015.

Change-Id: I7eb9e706867ffa8c0abb5b26a1b448f6eba49331
Reviewed-on: https://go-review.googlesource.com/c/go/+/506415
Run-TryBot: Russ Cox <rsc@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/runtime/export_test.go
src/runtime/mprof.go
src/runtime/pprof/pprof_test.go
src/runtime/runtime2.go
src/runtime/sema.go