Skip to content

Commit ae9996f

Browse files
mknyszekgopherbot
authored andcommitted
[release-branch.go1.22] 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 #71146. 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/+/641356 Auto-Submit: Michael Pratt <[email protected]>
1 parent 223260b commit ae9996f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/runtime/proc.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -3762,23 +3762,23 @@ func injectglist(glist *gList) {
37623762
if glist.empty() {
37633763
return
37643764
}
3765-
trace := traceAcquire()
3766-
if trace.ok() {
3767-
for gp := glist.head.ptr(); gp != nil; gp = gp.schedlink.ptr() {
3768-
trace.GoUnpark(gp, 0)
3769-
}
3770-
traceRelease(trace)
3771-
}
37723765

37733766
// Mark all the goroutines as runnable before we put them
37743767
// on the run queues.
37753768
head := glist.head.ptr()
37763769
var tail *g
37773770
qsize := 0
3771+
trace := traceAcquire()
37783772
for gp := head; gp != nil; gp = gp.schedlink.ptr() {
37793773
tail = gp
37803774
qsize++
37813775
casgstatus(gp, _Gwaiting, _Grunnable)
3776+
if trace.ok() {
3777+
trace.GoUnpark(gp, 0)
3778+
}
3779+
}
3780+
if trace.ok() {
3781+
traceRelease(trace)
37823782
}
37833783

37843784
// Turn the gList into a gQueue.

0 commit comments

Comments
 (0)