aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/trace2runtime.go
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2024-02-08 17:16:49 +0000
committerGopher Robot <gobot@golang.org>2024-03-08 19:58:29 +0000
commit52b5f164ae65b96ce9bd0fb7d06c609bf62c3d30 (patch)
treede8e085374346157a116e3e9ffc58ae6530a4359 /src/runtime/trace2runtime.go
parente38be310a4f725ce9167b3444eedcd3b15a6e683 (diff)
downloadgo-52b5f164ae65b96ce9bd0fb7d06c609bf62c3d30.tar.xz
runtime: make checking if tracing is enabled non-atomic
Tracing is currently broken when using iter.Pull from the rangefunc experiment partly because the "tracing is off" fast path in traceAcquire was deemed too expensive to check (an atomic load) during the coroutine switch. This change adds trace.enabled, a non-atomic indicator of whether tracing is enabled. It doubles trace.gen, which is the source of truth on whether tracing is enabled. The semantics around trace.enabled are subtle. When tracing is enabled, we need to be careful to make sure that if gen != 0, goroutines enter the tracer on traceAcquire. This is enforced by making sure trace.enabled is published atomically with trace.gen. The STW takes care of synchronization with most Ms, but there's still sysmon and goroutines exiting syscalls. We need to synchronize with those explicitly anyway, which luckily takes care of trace.enabled as well. When tracing is disabled, it's always OK for trace.enabled to be stale, since traceAcquire will always double-check gen before proceeding. For #61897. Change-Id: I47c2a530fb5339c15e419312fbb1e22d782cd453 Reviewed-on: https://go-review.googlesource.com/c/go/+/565935 Auto-Submit: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime/trace2runtime.go')
-rw-r--r--src/runtime/trace2runtime.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/runtime/trace2runtime.go b/src/runtime/trace2runtime.go
index 512e53907e..7b88c258ba 100644
--- a/src/runtime/trace2runtime.go
+++ b/src/runtime/trace2runtime.go
@@ -141,7 +141,7 @@ var traceGoStopReasonStrings = [...]string{
//
//go:nosplit
func traceEnabled() bool {
- return trace.gen.Load() != 0
+ return trace.enabled
}
// traceShuttingDown returns true if the trace is currently shutting down.