Debian Codegraph @

src/internal/trace/testdata/generators/go122-syscall-steal-proc-ambiguous.go

raw
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.
4
5 // Tests syscall P stealing.
6 //
7 // Specifically, it tests a scenario 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.
13
14 package main
15
16 import (
17 "internal/trace"
18 "internal/trace/internal/testgen"
19 "internal/trace/tracev2"
20 "internal/trace/version"
21 )
22
23 func main() {
24 testgen.Main(version.Go122, gen)
25 }
26
27 func gen(t *testgen.Trace) {
28 t.DisableTimestamps()
29
30 g := t.Generation(1)
31
32 // One goroutine does a syscall without blocking, then another one where
33 // it's P gets stolen.
34 b0 := g.Batch(trace.ThreadID(0), 0)
35 b0.Event("ProcStatus", trace.ProcID(0), tracev2.ProcRunning)
36 b0.Event("GoStatus", trace.GoID(1), trace.ThreadID(0), tracev2.GoRunning)
37 b0.Event("GoSyscallBegin", testgen.Seq(1), testgen.NoStack)
38 b0.Event("GoSyscallEnd")
39 b0.Event("GoSyscallBegin", testgen.Seq(2), testgen.NoStack)
40 b0.Event("GoSyscallEndBlocked")
41
42 // A running goroutine steals proc 0.
43 b1 := g.Batch(trace.ThreadID(1), 0)
44 b1.Event("ProcStatus", trace.ProcID(2), tracev2.ProcRunning)
45 b1.Event("GoStatus", trace.GoID(2), trace.ThreadID(1), tracev2.GoRunning)
46 b1.Event("ProcSteal", trace.ProcID(0), testgen.Seq(3), trace.ThreadID(0))
47 }