diff options
| author | Rhys Hiltner <rhys.hiltner@gmail.com> | 2024-04-19 22:12:18 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-04-22 14:29:04 +0000 |
| commit | 4bb67bc21eea06afadceec239bae6e5e40a9e759 (patch) | |
| tree | c6a2329b64053275ae75435ec4ffee2248b28a18 /src/runtime/proc.go | |
| parent | 2dddc7ef881669276c96356ec44c4e46ec20b1e9 (diff) | |
| download | go-4bb67bc21eea06afadceec239bae6e5e40a9e759.tar.xz | |
runtime: always acquire M when acquiring locks by rank
Profiling of runtime-internal locks checks gp.m.locks to see if it's
safe to add a new record to the profile, but direct use of
acquireLockRank can change the list of the M's active lock ranks without
updating gp.m.locks to match. The runtime's internal rwmutex
implementation makes a point of calling acquirem/releasem when
manipulating the lock rank list, but the other user of acquireLockRank
(the GC's Gscan bit) relied on the GC's invariants to avoid deadlocks.
Codify the rwmutex approach by renaming acquireLockRank to
acquireLockRankAndM and having it include a call to aquirem. Do the same
for release.
Fixes #64706
Fixes #66004
Change-Id: Ib76eaa0cc1c45b64861d03345e17e1e843c19713
GitHub-Last-Rev: 160577bdb2bb2a4e869c6fd7e53e3be8fb819182
GitHub-Pull-Request: golang/go#66276
Reviewed-on: https://go-review.googlesource.com/c/go/+/571056
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Rhys Hiltner <rhys.hiltner@gmail.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime/proc.go')
| -rw-r--r-- | src/runtime/proc.go | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/runtime/proc.go b/src/runtime/proc.go index cb5a80455d..54408dbab7 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -1067,7 +1067,7 @@ func casfrom_Gscanstatus(gp *g, oldval, newval uint32) { dumpgstatus(gp) throw("casfrom_Gscanstatus: gp->status is not in scan state") } - releaseLockRank(lockRankGscan) + releaseLockRankAndM(lockRankGscan) } // This will return false if the gp is not in the expected status and the cas fails. @@ -1081,7 +1081,7 @@ func castogscanstatus(gp *g, oldval, newval uint32) bool { if newval == oldval|_Gscan { r := gp.atomicstatus.CompareAndSwap(oldval, newval) if r { - acquireLockRank(lockRankGscan) + acquireLockRankAndM(lockRankGscan) } return r @@ -1110,8 +1110,7 @@ func casgstatus(gp *g, oldval, newval uint32) { }) } - acquireLockRank(lockRankGscan) - releaseLockRank(lockRankGscan) + lockWithRankMayAcquire(nil, lockRankGscan) // See https://golang.org/cl/21503 for justification of the yield delay. const yieldDelay = 5 * 1000 @@ -1245,7 +1244,7 @@ func casGToPreemptScan(gp *g, old, new uint32) { if old != _Grunning || new != _Gscan|_Gpreempted { throw("bad g transition") } - acquireLockRank(lockRankGscan) + acquireLockRankAndM(lockRankGscan) for !gp.atomicstatus.CompareAndSwap(_Grunning, _Gscan|_Gpreempted) { } } |
