aboutsummaryrefslogtreecommitdiff
path: root/src/sync
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2022-08-30 22:18:01 +0000
committerGopher Robot <gobot@golang.org>2022-09-16 16:32:27 +0000
commita2c396ce00df96f66246aab7a63f3ce5b7ad8753 (patch)
tree0efc1501bd5ac11506acc96c181eacf1dd249b01 /src/sync
parentb7c28f484ddbc8267273c997e1bcc83a1391b5f7 (diff)
downloadgo-a2c396ce00df96f66246aab7a63f3ce5b7ad8753.tar.gz
go-a2c396ce00df96f66246aab7a63f3ce5b7ad8753.zip
runtime: make the wait reason for a g blocked on a mutex more specific
This change adds 3 new waitReasons that correspond to sync.Mutex.Lock, sync.RWMutex.RLock, and sync.RWMutex.Lock that are plumbed down into semacquire1 by exporting new functions to the sync package from the runtime. Currently these three functions show up as "semacquire" in backtraces which isn't very clear, though the stack trace itself should reveal what's really going on. This represents a minor improvement to backtrace readability, though blocking on an RWMutex.w.Lock will still show up as blocking on a regular mutex (I suppose technically it is). This is a step toward helping the runtime identify when a goroutine is blocked on a mutex of some kind. For #49881. Change-Id: Ia409b4d27e117fe4bfdc25fa541e9c58d6d587b9 Reviewed-on: https://go-review.googlesource.com/c/go/+/427616 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/sync')
-rw-r--r--src/sync/runtime.go8
-rw-r--r--src/sync/rwmutex.go4
2 files changed, 9 insertions, 3 deletions
diff --git a/src/sync/runtime.go b/src/sync/runtime.go
index de2b0a3ccd..5a90813585 100644
--- a/src/sync/runtime.go
+++ b/src/sync/runtime.go
@@ -13,11 +13,17 @@ import "unsafe"
// library and should not be used directly.
func runtime_Semacquire(s *uint32)
-// SemacquireMutex is like Semacquire, but for profiling contended Mutexes.
+// Semacquire(RW)Mutex(R) is like Semacquire, but for profiling contended
+// Mutexes and RWMutexes.
// If lifo is true, queue waiter at the head of wait queue.
// skipframes is the number of frames to omit during tracing, counting from
// runtime_SemacquireMutex's caller.
+// The different forms of this function just tell the runtime how to present
+// the reason for waiting in a backtrace, and is used to compute some metrics.
+// Otherwise they're functionally identical.
func runtime_SemacquireMutex(s *uint32, lifo bool, skipframes int)
+func runtime_SemacquireRWMutexR(s *uint32, lifo bool, skipframes int)
+func runtime_SemacquireRWMutex(s *uint32, lifo bool, skipframes int)
// Semrelease atomically increments *s and notifies a waiting goroutine
// if one is blocked in Semacquire.
diff --git a/src/sync/rwmutex.go b/src/sync/rwmutex.go
index e7d95181d5..ad52951311 100644
--- a/src/sync/rwmutex.go
+++ b/src/sync/rwmutex.go
@@ -68,7 +68,7 @@ func (rw *RWMutex) RLock() {
}
if rw.readerCount.Add(1) < 0 {
// A writer is pending, wait for it.
- runtime_SemacquireMutex(&rw.readerSem, false, 0)
+ runtime_SemacquireRWMutexR(&rw.readerSem, false, 0)
}
if race.Enabled {
race.Enable()
@@ -149,7 +149,7 @@ func (rw *RWMutex) Lock() {
r := rw.readerCount.Add(-rwmutexMaxReaders) + rwmutexMaxReaders
// Wait for active readers.
if r != 0 && rw.readerWait.Add(r) != 0 {
- runtime_SemacquireMutex(&rw.writerSem, false, 0)
+ runtime_SemacquireRWMutex(&rw.writerSem, false, 0)
}
if race.Enabled {
race.Enable()