]> Cypherpunks.ru repositories - gostls13.git/blob - src/internal/trace/v2/testdata/generators/go122-syscall-steal-proc-ambiguous.go
internal/trace/v2: resolve syscall parsing ambiguity
[gostls13.git] / src / internal / trace / v2 / testdata / generators / go122-syscall-steal-proc-ambiguous.go
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 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.
13
14 package main
15
16 import (
17         "internal/trace/v2"
18         "internal/trace/v2/event/go122"
19         testgen "internal/trace/v2/internal/testgen/go122"
20 )
21
22 func main() {
23         testgen.Main(gen)
24 }
25
26 func gen(t *testgen.Trace) {
27         t.DisableTimestamps()
28
29         g := t.Generation(1)
30
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")
40
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))
46 }