1 // Copyright 2023 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Tests syscall P stealing.
7 // Specifically, it tests a scenerio wherein, without a
8 // P sequence number of GoSyscallBegin, the syscall that
9 // a ProcSteal applies to is ambiguous. This only happens in
10 // practice when the events aren't already properly ordered
11 // by timestamp, since the ProcSteal won't be seen until after
12 // the correct GoSyscallBegin appears on the frontier.
18 "internal/trace/v2/event/go122"
19 testgen "internal/trace/v2/internal/testgen/go122"
26 func gen(t *testgen.Trace) {
31 // One goroutine does a syscall without blocking, then another one where
32 // it's P gets stolen.
33 b0 := g.Batch(trace.ThreadID(0), 0)
34 b0.Event("ProcStatus", trace.ProcID(0), go122.ProcRunning)
35 b0.Event("GoStatus", trace.GoID(1), trace.ThreadID(0), go122.GoRunning)
36 b0.Event("GoSyscallBegin", testgen.Seq(1), testgen.NoStack)
37 b0.Event("GoSyscallEnd")
38 b0.Event("GoSyscallBegin", testgen.Seq(2), testgen.NoStack)
39 b0.Event("GoSyscallEndBlocked")
41 // A running goroutine steals proc 0.
42 b1 := g.Batch(trace.ThreadID(1), 0)
43 b1.Event("ProcStatus", trace.ProcID(2), go122.ProcRunning)
44 b1.Event("GoStatus", trace.GoID(2), trace.ThreadID(1), go122.GoRunning)
45 b1.Event("ProcSteal", trace.ProcID(0), testgen.Seq(3), trace.ThreadID(0))