Skip to content

Commit 1dde0b4

Browse files
mknyszekgopherbot
authored andcommitted
[release-branch.go1.23] runtime: hold traceAcquire across casgstatus in injectglist
Currently injectglist emits all the trace events before actually calling casgstatus on each goroutine. This is a problem, since tracing can observe an inconsistent state (gstatus does not match tracer's 'emitted an event' state). This change fixes the problem by having injectglist do what every other scheduler function does, and that's wrap each call to casgstatus in traceAcquire/traceRelease. For #70883. Fixes #71147. Change-Id: I857e96cec01688013597e8efc0c4c3d0b72d3a70 Reviewed-on: https://go-review.googlesource.com/c/go/+/638558 Reviewed-by: Michael Pratt <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> (cherry picked from commit f025d19) Reviewed-on: https://go-review.googlesource.com/c/go/+/641378 Auto-Submit: Michael Pratt <[email protected]>
1 parent 3417000 commit 1dde0b4

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/runtime/proc.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3873,23 +3873,23 @@ func injectglist(glist *gList) {
38733873
if glist.empty() {
38743874
return
38753875
}
3876-
trace := traceAcquire()
3877-
if trace.ok() {
3878-
for gp := glist.head.ptr(); gp != nil; gp = gp.schedlink.ptr() {
3879-
trace.GoUnpark(gp, 0)
3880-
}
3881-
traceRelease(trace)
3882-
}
38833876

38843877
// Mark all the goroutines as runnable before we put them
38853878
// on the run queues.
38863879
head := glist.head.ptr()
38873880
var tail *g
38883881
qsize := 0
3882+
trace := traceAcquire()
38893883
for gp := head; gp != nil; gp = gp.schedlink.ptr() {
38903884
tail = gp
38913885
qsize++
38923886
casgstatus(gp, _Gwaiting, _Grunnable)
3887+
if trace.ok() {
3888+
trace.GoUnpark(gp, 0)
3889+
}
3890+
}
3891+
if trace.ok() {
3892+
traceRelease(trace)
38933893
}
38943894

38953895
// Turn the gList into a gQueue.

0 commit comments

Comments
 (0)