diff --git a/pkg/sentry/platform/systrap/BUILD b/pkg/sentry/platform/systrap/BUILD index cb0bbceb7..d90633c8f 100644 --- a/pkg/sentry/platform/systrap/BUILD +++ b/pkg/sentry/platform/systrap/BUILD @@ -53,6 +53,8 @@ go_library( "lib_amd64.s", "lib_arm64.s", "shared_context.go", + "shared_context_norace.go", + "shared_context_race.go", "stub_amd64.s", "stub_arm64.s", "stub_defs.go", diff --git a/pkg/sentry/platform/systrap/shared_context.go b/pkg/sentry/platform/systrap/shared_context.go index e4b106432..1616ab658 100644 --- a/pkg/sentry/platform/systrap/shared_context.go +++ b/pkg/sentry/platform/systrap/shared_context.go @@ -23,7 +23,6 @@ import ( "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/sentry/platform" "gvisor.dev/gvisor/pkg/sentry/platform/systrap/sysmsg" - gsync "gvisor.dev/gvisor/pkg/sync" "gvisor.dev/gvisor/pkg/syncevent" ) @@ -351,7 +350,7 @@ func (q *fastPathDispatcher) loop(target *sharedContext) { // q.list has to be empty at the end. continue } - gsync.Goyield() + yield() } } } diff --git a/pkg/sentry/platform/systrap/shared_context_norace.go b/pkg/sentry/platform/systrap/shared_context_norace.go new file mode 100644 index 000000000..354d58c24 --- /dev/null +++ b/pkg/sentry/platform/systrap/shared_context_norace.go @@ -0,0 +1,26 @@ +// 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. + +//go:build !race +// +build !race + +package systrap + +import ( + "gvisor.dev/gvisor/pkg/sync" +) + +func yield() { + sync.Goyield() +} diff --git a/pkg/sentry/platform/systrap/shared_context_race.go b/pkg/sentry/platform/systrap/shared_context_race.go new file mode 100644 index 000000000..5cf3df58b --- /dev/null +++ b/pkg/sentry/platform/systrap/shared_context_race.go @@ -0,0 +1,22 @@ +// 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. + +//go:build race +// +build race + +package systrap + +// yield is just a stub because sync.Goyield() is very expensive with the race +// detector. +func yield() {}