From 8e36d125dae4f84e2e747d11d9704dd1679fc78c Mon Sep 17 00:00:00 2001 From: Jamie Liu Date: Tue, 28 Nov 2023 14:46:07 -0800 Subject: [PATCH] Change gopark()'s fourth argument type to traceBlockReason. This follows https://go-review.googlesource.com/c/go/+/494185. PiperOrigin-RevId: 586109546 --- pkg/sleep/sleep_unsafe.go | 2 +- pkg/sync/BUILD | 1 + pkg/sync/gate_unsafe.go | 4 ++-- pkg/sync/runtime_constants.go | 7 ------- pkg/sync/runtime_exectracer1.go | 27 +++++++++++++++++++++++++++ pkg/sync/runtime_unsafe.go | 9 ++++++--- pkg/syncevent/waiter_unsafe.go | 4 ++-- 7 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 pkg/sync/runtime_exectracer1.go diff --git a/pkg/sleep/sleep_unsafe.go b/pkg/sleep/sleep_unsafe.go index 822c0f423..ca7ee6576 100644 --- a/pkg/sleep/sleep_unsafe.go +++ b/pkg/sleep/sleep_unsafe.go @@ -206,7 +206,7 @@ func (s *Sleeper) nextWaker(block, wakepOrSleep bool) *Waker { // See:runtime2.go in the go runtime package for // the values to pass as the waitReason here. const waitReasonSelect = 9 - sync.Gopark(commitSleep, unsafe.Pointer(&s.waitingG), sync.WaitReasonSelect, sync.TraceEvGoBlockSelect, 0) + sync.Gopark(commitSleep, unsafe.Pointer(&s.waitingG), sync.WaitReasonSelect, sync.TraceBlockSelect, 0) } // Pull the shared list out and reverse it in the local diff --git a/pkg/sync/BUILD b/pkg/sync/BUILD index e38df4cd1..ad01e913e 100644 --- a/pkg/sync/BUILD +++ b/pkg/sync/BUILD @@ -27,6 +27,7 @@ go_library( "runtime.go", "runtime_amd64.go", "runtime_constants.go", + "runtime_exectracer1.go", "runtime_go121_unsafe.go", "runtime_not_go121_unsafe.go", "runtime_other.go", diff --git a/pkg/sync/gate_unsafe.go b/pkg/sync/gate_unsafe.go index 1f7a03309..0f3b58dc7 100644 --- a/pkg/sync/gate_unsafe.go +++ b/pkg/sync/gate_unsafe.go @@ -140,8 +140,8 @@ func (g *Gate) Close() { // The last call to Leave arrived while we were setting up closingG. return } - // WaitReasonSemacquire/TraceEvGoBlockSync are consistent with WaitGroup. - gopark(gateCommit, gohacks.Noescape(unsafe.Pointer(&g.closingG)), WaitReasonSemacquire, TraceEvGoBlockSync, 0) + // WaitReasonSemacquire/TraceBlockSync are consistent with WaitGroup. + gopark(gateCommit, gohacks.Noescape(unsafe.Pointer(&g.closingG)), WaitReasonSemacquire, TraceBlockSync, 0) } //go:norace diff --git a/pkg/sync/runtime_constants.go b/pkg/sync/runtime_constants.go index 9a5a47a82..d6eef328e 100644 --- a/pkg/sync/runtime_constants.go +++ b/pkg/sync/runtime_constants.go @@ -20,10 +20,3 @@ const ( WaitReasonChanReceive uint8 = 14 // +checkconst runtime waitReasonChanReceive WaitReasonSemacquire uint8 = 18 // +checkconst runtime waitReasonSemacquire ) - -// Values for the traceEv argument to gopark, from Go's src/runtime/trace.go. -const ( - TraceEvGoBlockRecv byte = 23 // +checkconst runtime traceEvGoBlockRecv - TraceEvGoBlockSelect byte = 24 // +checkconst runtime traceEvGoBlockSelect - TraceEvGoBlockSync byte = 25 // +checkconst runtime traceEvGoBlockSync -) diff --git a/pkg/sync/runtime_exectracer1.go b/pkg/sync/runtime_exectracer1.go new file mode 100644 index 000000000..33af525bd --- /dev/null +++ b/pkg/sync/runtime_exectracer1.go @@ -0,0 +1,27 @@ +// Copyright 2023 The gVisor Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package sync + +// TraceBlockReason constants, from Go's src/runtime/trace.go. +const ( + TraceBlockSelect TraceBlockReason = traceEvGoBlockSelect // +checkconst runtime traceBlockSelect + TraceBlockSync = traceEvGoBlockSync // +checkconst runtime traceBlockSync +) + +// Tracer event types, from Go's src/runtime/trace.go. +const ( + traceEvGoBlockSelect = 24 // +checkconst runtime traceEvGoBlockSelect + traceEvGoBlockSync = 25 // +checkconst runtime traceEvGoBlockSync +) diff --git a/pkg/sync/runtime_unsafe.go b/pkg/sync/runtime_unsafe.go index a298bddbc..5bc0a92e0 100644 --- a/pkg/sync/runtime_unsafe.go +++ b/pkg/sync/runtime_unsafe.go @@ -29,12 +29,15 @@ func Goyield() { // splitting and race context are not available where it is called. // //go:nosplit -func Gopark(unlockf func(uintptr, unsafe.Pointer) bool, lock unsafe.Pointer, reason uint8, traceEv byte, traceskip int) { - gopark(unlockf, lock, reason, traceEv, traceskip) +func Gopark(unlockf func(uintptr, unsafe.Pointer) bool, lock unsafe.Pointer, reason uint8, traceReason TraceBlockReason, traceskip int) { + gopark(unlockf, lock, reason, traceReason, traceskip) } //go:linkname gopark runtime.gopark -func gopark(unlockf func(uintptr, unsafe.Pointer) bool, lock unsafe.Pointer, reason uint8, traceEv byte, traceskip int) +func gopark(unlockf func(uintptr, unsafe.Pointer) bool, lock unsafe.Pointer, reason uint8, traceReason TraceBlockReason, traceskip int) + +// TraceBlockReason is equivalent to runtime.traceBlockReason. +type TraceBlockReason uint8 //go:linkname wakep runtime.wakep func wakep() diff --git a/pkg/syncevent/waiter_unsafe.go b/pkg/syncevent/waiter_unsafe.go index 7c6b1b19f..650967faf 100644 --- a/pkg/syncevent/waiter_unsafe.go +++ b/pkg/syncevent/waiter_unsafe.go @@ -93,7 +93,7 @@ func (w *Waiter) WaitFor(es Set) Set { // If w.g is still preparingG (i.e. w.NotifyPending() has not been // called or has not reached atomic.SwapUintptr()), go to sleep until // w.NotifyPending() => goready(). - sync.Gopark(waiterCommit, unsafe.Pointer(&w.g), sync.WaitReasonSelect, sync.TraceEvGoBlockSelect, 0) + sync.Gopark(waiterCommit, unsafe.Pointer(&w.g), sync.WaitReasonSelect, sync.TraceBlockSelect, 0) } } @@ -139,7 +139,7 @@ func (w *Waiter) WaitAndAckAll() Set { // If w.g is still preparingG (i.e. w.NotifyPending() has not been // called or has not reached atomic.SwapUintptr()), go to sleep until // w.NotifyPending() => goready(). - sync.Gopark(waiterCommit, unsafe.Pointer(&w.g), sync.WaitReasonSelect, sync.TraceEvGoBlockSelect, 0) + sync.Gopark(waiterCommit, unsafe.Pointer(&w.g), sync.WaitReasonSelect, sync.TraceBlockSelect, 0) // Check for pending events. We call PendingAndAckAll() directly now since // we only expect to be woken after events become pending.