aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/trace.go
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2020-12-23 15:05:37 -0500
committerMichael Pratt <mpratt@google.com>2021-03-05 22:09:52 +0000
commitd85083911d6ea742901933a544467dad55bb381f (patch)
treef8f826d01c3ff45af5908c8a1d71befe4439f97c /src/runtime/trace.go
parent39bdd41d03725878f1fd6f8b500ba6700f03bdad (diff)
downloadgo-d85083911d6ea742901933a544467dad55bb381f.tar.gz
go-d85083911d6ea742901933a544467dad55bb381f.zip
runtime: encapsulate access to allgs
Correctly accessing allgs is a bit hairy. Some paths need to lock allglock, some don't. Those that don't are safest using atomicAllG, but usage is not consistent. Rather than doing this ad-hoc, move all access* through forEachG / forEachGRace, the locking and atomic versions, respectively. This will make it easier to ensure safe access. * markroot is the only exception, as it has a far-removed guarantee of safe access via an atomic load of allglen far before actual use. Change-Id: Ie1c7a8243e155ae2b4bc3143577380c695680e89 Reviewed-on: https://go-review.googlesource.com/c/go/+/279994 Trust: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/runtime/trace.go')
-rw-r--r--src/runtime/trace.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/runtime/trace.go b/src/runtime/trace.go
index bcd0b9d56c..bfaa00ee58 100644
--- a/src/runtime/trace.go
+++ b/src/runtime/trace.go
@@ -221,7 +221,8 @@ func StartTrace() error {
stackID := traceStackID(mp, stkBuf, 2)
releasem(mp)
- for _, gp := range allgs {
+ // World is stopped, no need to lock.
+ forEachGRace(func(gp *g) {
status := readgstatus(gp)
if status != _Gdead {
gp.traceseq = 0
@@ -241,7 +242,7 @@ func StartTrace() error {
} else {
gp.sysblocktraced = false
}
- }
+ })
traceProcStart()
traceGoStart()
// Note: ticksStart needs to be set after we emit traceEvGoInSyscall events.