• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 where a thread 'steals'
8// a P from itself. It's just a ProcStop with extra steps when
9// it happens on the same P.
10
11package main
12
13import (
14	"internal/trace"
15	"internal/trace/event/go122"
16	testgen "internal/trace/internal/testgen/go122"
17)
18
19func main() {
20	testgen.Main(gen)
21}
22
23func gen(t *testgen.Trace) {
24	t.DisableTimestamps()
25
26	g := t.Generation(1)
27
28	// A goroutine execute a syscall and steals its own P, then starts running
29	// on that P.
30	b0 := g.Batch(trace.ThreadID(0), 0)
31	b0.Event("ProcStatus", trace.ProcID(0), go122.ProcRunning)
32	b0.Event("GoStatus", trace.GoID(1), trace.ThreadID(0), go122.GoRunning)
33	b0.Event("GoSyscallBegin", testgen.Seq(1), testgen.NoStack)
34	b0.Event("ProcSteal", trace.ProcID(0), testgen.Seq(2), trace.ThreadID(0))
35	b0.Event("ProcStart", trace.ProcID(0), testgen.Seq(3))
36	b0.Event("GoSyscallEndBlocked")
37}
38