Skip to content

Commit 98fd8f5

Browse files
prattmicgopherbot
authored andcommitted
runtime: rename GODEBUG=profileruntimelocks to runtimecontentionstacks
profileruntimelocks is new in CL 544195, but the name is deceptive. Even with profileruntimelocks=0, runtime-internal locks are still profiled. The actual difference is that call stacks are not collected. Instead all contention is reported at runtime._LostContendedLock. Rename this setting to runtimecontentionstacks to make its name more aligned with its behavior. In addition, for this release the default is profileruntimelocks=0, meaning that users are fairly likely to encounter runtime._LostContendedLock. Rename it to runtime._LostContendedRuntimeLock in an attempt to make it more intuitive that these are runtime locks, not locks in application code. For #57071. Change-Id: I38aac28b2c0852db643d53b1eab3f3bc42a43393 Reviewed-on: https://go-review.googlesource.com/c/go/+/547055 Reviewed-by: Michael Knyszek <[email protected]> Auto-Submit: Michael Pratt <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Rhys Hiltner <[email protected]>
1 parent 6e33a63 commit 98fd8f5

File tree

5 files changed

+39
-38
lines changed

5 files changed

+39
-38
lines changed

Diff for: src/runtime/extern.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,14 @@ It is a comma-separated list of name=val pairs setting these named variables:
152152
risk in that scenario. Currently not supported on Windows, plan9 or js/wasm. Setting this
153153
option for some applications can produce large traces, so use with care.
154154
155-
profileruntimelocks: setting profileruntimelocks=1 includes call stacks related to
156-
contention on runtime-internal locks in the "mutex" profile, subject to the
157-
MutexProfileFraction setting. The call stacks will correspond to the unlock call that
158-
released the lock. But instead of the value corresponding to the amount of contention that
159-
call stack caused, it corresponds to the amount of time the caller of unlock had to wait
160-
in its original call to lock. A future release is expected to align those and remove this
161-
setting.
155+
runtimecontentionstacks: setting runtimecontentionstacks=1 enables inclusion of call stacks
156+
related to contention on runtime-internal locks in the "mutex" profile, subject to the
157+
MutexProfileFraction setting. When runtimecontentionstacks=0, contention on
158+
runtime-internal locks will report as "runtime._LostContendedRuntimeLock". When
159+
runtimecontentionstacks=1, the call stacks will correspond to the unlock call that released
160+
the lock. But instead of the value corresponding to the amount of contention that call
161+
stack caused, it corresponds to the amount of time the caller of unlock had to wait in its
162+
original call to lock. A future release is expected to align those and remove this setting.
162163
163164
invalidptr: invalidptr=1 (the default) causes the garbage collector and stack
164165
copier to crash the program if an invalid pointer value (for example, 1)

Diff for: src/runtime/metrics_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -956,12 +956,12 @@ func TestRuntimeLockMetricsAndProfile(t *testing.T) {
956956
{
957957
before := os.Getenv("GODEBUG")
958958
for _, s := range strings.Split(before, ",") {
959-
if strings.HasPrefix(s, "profileruntimelocks=") {
959+
if strings.HasPrefix(s, "runtimecontentionstacks=") {
960960
t.Logf("GODEBUG includes explicit setting %q", s)
961961
}
962962
}
963963
defer func() { os.Setenv("GODEBUG", before) }()
964-
os.Setenv("GODEBUG", fmt.Sprintf("%s,profileruntimelocks=1", before))
964+
os.Setenv("GODEBUG", fmt.Sprintf("%s,runtimecontentionstacks=1", before))
965965
}
966966

967967
t.Logf("NumCPU %d", runtime.NumCPU())

Diff for: src/runtime/mprof.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ func saveblockevent(cycles, rate int64, skip int, which bucketType) {
552552
// previous lock call took (like the user-space "block" profile).
553553
//
554554
// Thus, reporting the call stacks of runtime-internal lock contention is
555-
// guarded by GODEBUG for now. Set GODEBUG=profileruntimelocks=1 to enable.
555+
// guarded by GODEBUG for now. Set GODEBUG=runtimecontentionstacks=1 to enable.
556556
//
557557
// TODO(rhysh): plumb through the delay duration, remove GODEBUG, update comment
558558
//
@@ -644,7 +644,7 @@ func (prof *mLockProfile) recordLock(cycles int64, l *mutex) {
644644
if prev := prof.cycles; prev > 0 {
645645
// We can only store one call stack for runtime-internal lock contention
646646
// on this M, and we've already got one. Decide which should stay, and
647-
// add the other to the report for runtime._LostContendedLock.
647+
// add the other to the report for runtime._LostContendedRuntimeLock.
648648
prevScore := uint64(cheaprand64()) % uint64(prev)
649649
thisScore := uint64(cheaprand64()) % uint64(cycles)
650650
if prevScore > thisScore {
@@ -690,8 +690,8 @@ func (prof *mLockProfile) captureStack() {
690690
}
691691
prof.pending = 0
692692

693-
if debug.profileruntimelocks.Load() == 0 {
694-
prof.stack[0] = abi.FuncPCABIInternal(_LostContendedLock) + sys.PCQuantum
693+
if debug.runtimeContentionStacks.Load() == 0 {
694+
prof.stack[0] = abi.FuncPCABIInternal(_LostContendedRuntimeLock) + sys.PCQuantum
695695
prof.stack[1] = 0
696696
return
697697
}
@@ -733,7 +733,7 @@ func (prof *mLockProfile) store() {
733733
saveBlockEventStack(cycles, rate, prof.stack[:nstk], mutexProfile)
734734
if lost > 0 {
735735
lostStk := [...]uintptr{
736-
abi.FuncPCABIInternal(_LostContendedLock) + sys.PCQuantum,
736+
abi.FuncPCABIInternal(_LostContendedRuntimeLock) + sys.PCQuantum,
737737
}
738738
saveBlockEventStack(lost, rate, lostStk[:], mutexProfile)
739739
}

Diff for: src/runtime/proc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5279,7 +5279,7 @@ func _ExternalCode() { _ExternalCode() }
52795279
func _LostExternalCode() { _LostExternalCode() }
52805280
func _GC() { _GC() }
52815281
func _LostSIGPROFDuringAtomic64() { _LostSIGPROFDuringAtomic64() }
5282-
func _LostContendedLock() { _LostContendedLock() }
5282+
func _LostContendedRuntimeLock() { _LostContendedRuntimeLock() }
52835283
func _VDSO() { _VDSO() }
52845284

52855285
// Called if we receive a SIGPROF signal.

Diff for: src/runtime/runtime1.go

+23-23
Original file line numberDiff line numberDiff line change
@@ -307,28 +307,28 @@ type dbgVar struct {
307307
// existing int var for that value, which may
308308
// already have an initial value.
309309
var debug struct {
310-
cgocheck int32
311-
clobberfree int32
312-
disablethp int32
313-
dontfreezetheworld int32
314-
efence int32
315-
gccheckmark int32
316-
gcpacertrace int32
317-
gcshrinkstackoff int32
318-
gcstoptheworld int32
319-
gctrace int32
320-
invalidptr int32
321-
madvdontneed int32 // for Linux; issue 28466
322-
profileruntimelocks atomic.Int32
323-
scavtrace int32
324-
scheddetail int32
325-
schedtrace int32
326-
tracebackancestors int32
327-
asyncpreemptoff int32
328-
harddecommit int32
329-
adaptivestackstart int32
330-
tracefpunwindoff int32
331-
traceadvanceperiod int32
310+
cgocheck int32
311+
clobberfree int32
312+
disablethp int32
313+
dontfreezetheworld int32
314+
efence int32
315+
gccheckmark int32
316+
gcpacertrace int32
317+
gcshrinkstackoff int32
318+
gcstoptheworld int32
319+
gctrace int32
320+
invalidptr int32
321+
madvdontneed int32 // for Linux; issue 28466
322+
runtimeContentionStacks atomic.Int32
323+
scavtrace int32
324+
scheddetail int32
325+
schedtrace int32
326+
tracebackancestors int32
327+
asyncpreemptoff int32
328+
harddecommit int32
329+
adaptivestackstart int32
330+
tracefpunwindoff int32
331+
traceadvanceperiod int32
332332

333333
// debug.malloc is used as a combined debug check
334334
// in the malloc function and should be set
@@ -355,7 +355,7 @@ var dbgvars = []*dbgVar{
355355
{name: "gctrace", value: &debug.gctrace},
356356
{name: "invalidptr", value: &debug.invalidptr},
357357
{name: "madvdontneed", value: &debug.madvdontneed},
358-
{name: "profileruntimelocks", atomic: &debug.profileruntimelocks},
358+
{name: "runtimecontentionstacks", atomic: &debug.runtimeContentionStacks},
359359
{name: "sbrk", value: &debug.sbrk},
360360
{name: "scavtrace", value: &debug.scavtrace},
361361
{name: "scheddetail", value: &debug.scheddetail},

0 commit comments

Comments
 (0)