]> Cypherpunks repositories - gostls13.git/commit
runtime: make trace.lock not reentrant
authorMichael Anthony Knyszek <mknyszek@google.com>
Thu, 18 May 2023 14:21:05 +0000 (14:21 +0000)
committerMichael Knyszek <mknyszek@google.com>
Fri, 19 May 2023 20:47:57 +0000 (20:47 +0000)
commit94a948d1b114982ddfa3f38a40442c166f52fa32
tree0cec3c41610c4db141a7dd3214acab615de84949
parent7c91e1e568fff5667419257d2654d5362dd89536
runtime: make trace.lock not reentrant

Currently trace.lock is reentrant in a few cases. AFAICT, this was
necessary a long time ago when the trace reader would goparkunlock, and
might flush a trace buffer while parking the goroutine. Today, that's no
longer true, since that always happens without the trace.lock held.

However, traceReadCPU does still rely on this behavior, since it could
get called either with trace.lock held, or without it held. The silver
lining here is that it doesn't *need* trace.lock to be held, so the
trace reader can just drop the lock to call traceReadCPU (this is
probably also nice for letting other goroutines flush while the trace
reader is reading from the CPU log).

Stress-tested with

$ stress ./trace.test -test.run="TestTraceCPUProfile|TestTraceStress|TestTraceStressStartStop"
...

42m0s: 24520 runs so far, 0 failures

Change-Id: I2016292c17fe7384050fcc0c446f5797c4e46437
Reviewed-on: https://go-review.googlesource.com/c/go/+/496296
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/runtime/trace.go