From 52b5f164ae65b96ce9bd0fb7d06c609bf62c3d30 Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Thu, 8 Feb 2024 17:16:49 +0000 Subject: 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 LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Pratt --- src/runtime/trace2runtime.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/runtime/trace2runtime.go') 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. -- cgit v1.3-5-g9baa