]> Cypherpunks repositories - gostls13.git/commit
runtime: emit a ProcSteal from entersyscall_gcwait
authorMichael Anthony Knyszek <mknyszek@google.com>
Tue, 21 Nov 2023 03:23:05 +0000 (03:23 +0000)
committerMichael Knyszek <mknyszek@google.com>
Tue, 21 Nov 2023 22:29:44 +0000 (22:29 +0000)
commitb6b72c775ab562c632abf5d93e8c541385edfffc
tree7506945c2e8db6348c694688af9ed6a492e9b6d6
parentff05cdbd2bdc28ab545a5964f7f772e2ea4c5fd1
runtime: emit a ProcSteal from entersyscall_gcwait

Currently entersyscall_gcwait always emits a ProcStop event. Most of the
time, this is correct, since the thread that just put the P into
_Psyscall is the same one that is putting it into _Pgcstop. However it's
possible for another thread to steal the P, start running a goroutine,
and then enter another syscall, putting the P back into _Psyscall. In
this case ProcStop is incorrect; the P is getting stolen. This leads to
broken traces.

Fix this by always emitting a ProcSteal event from entersyscall_gcwait.
This means that most of the time a thread will be 'stealing' the proc
from itself when it enters this function, but that's theoretically fine.
A ProcSteal is really just a fancy ProcStop.

Well, it would be if the parser correctly handled a self-steal. This is
a minor bug that just never came up before, but it's an update order
error (the mState is looked up and modified, but then it's modified
again at the end of the function to match newCtx). There's really no
reason a self-steal shouldn't be allowed, so fix that up and add a test.

Change-Id: Iec3d7639d331e3f2d127f92ce50c2c4a7818fcd3
Reviewed-on: https://go-review.googlesource.com/c/go/+/544215
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/internal/trace/v2/order.go
src/internal/trace/v2/testdata/generators/go122-syscall-steal-proc-self.go [new file with mode: 0644]
src/internal/trace/v2/testdata/tests/go122-syscall-steal-proc-self.test [new file with mode: 0644]
src/runtime/proc.go
src/runtime/trace2runtime.go