Skip to content

Commit 342ea34

Browse files
craig[bot]tbg
andcommitted
Merge #143514
143514: rac2: introduce tokenCounterMu r=tbg a=tbg This gives the mutex acquisitions a dedicated call frame which helps look for only this mutex in mutex profiles. This follows the same pattern that we already apply for ReplicaMutex. Epic: CRDB-42584 Release note: None Co-authored-by: Tobias Grieger <[email protected]>
2 parents 424e966 + ac6d299 commit 342ea34

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

pkg/kv/kvserver/kvflowcontrol/rac2/token_counter.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,43 @@ func (f TokenType) SafeFormat(p redact.SafePrinter, _ rune) {
181181
}
182182
}
183183

184+
// Wrapper type to give mutex contention events in mutex profiles a leaf frame
185+
// that references tokenCounterMu. This makes it easier to look at contention
186+
// on this mutex specifically.
187+
type tokenCounterMu syncutil.RWMutex
188+
189+
func (mu *tokenCounterMu) Lock() {
190+
(*syncutil.RWMutex)(mu).Lock()
191+
}
192+
193+
func (mu *tokenCounterMu) TryLock() {
194+
(*syncutil.RWMutex)(mu).TryLock()
195+
}
196+
197+
func (mu *tokenCounterMu) Unlock() {
198+
(*syncutil.RWMutex)(mu).Unlock()
199+
}
200+
201+
func (mu *tokenCounterMu) RLock() {
202+
(*syncutil.RWMutex)(mu).RLock()
203+
}
204+
205+
func (mu *tokenCounterMu) TryRLock() {
206+
(*syncutil.RWMutex)(mu).TryRLock()
207+
}
208+
209+
func (mu *tokenCounterMu) RUnlock() {
210+
(*syncutil.RWMutex)(mu).RUnlock()
211+
}
212+
213+
func (mu *tokenCounterMu) AssertHeld() {
214+
(*syncutil.RWMutex)(mu).AssertHeld()
215+
}
216+
217+
func (mu *tokenCounterMu) AssertRHeld() {
218+
(*syncutil.RWMutex)(mu).AssertRHeld()
219+
}
220+
184221
// tokenCounter holds flow tokens for {regular,elastic} traffic over a
185222
// kvflowcontrol.Stream. It's used to synchronize handoff between threads
186223
// returning and waiting for flow tokens.
@@ -194,7 +231,7 @@ type tokenCounter struct {
194231
tokenType TokenType
195232

196233
mu struct {
197-
syncutil.RWMutex
234+
tokenCounterMu
198235

199236
counters [admissionpb.NumWorkClasses]tokenCounterPerWorkClass
200237
}

0 commit comments

Comments
 (0)