diff --git a/pkg/sentry/platform/systrap/metrics.go b/pkg/sentry/platform/systrap/metrics.go index 9a2f17f89..de6555ea5 100644 --- a/pkg/sentry/platform/systrap/metrics.go +++ b/pkg/sentry/platform/systrap/metrics.go @@ -60,6 +60,10 @@ const ( minNecessaryRecordings = 5 ) +// neverEnableFastPath is used for completely disabling the fast path. +// It is set once so doesn't need any synchronizations. +var neverEnableFastPath bool + // latencyRecorder is used to collect latency metrics. type latencyRecorder struct { stubBound latencyBuckets @@ -414,6 +418,9 @@ func (s *fastPathState) shouldDisableStubFP(stubMedian, sentryMedian cpuTicks) b // fastpath state machine described above. func sentryOffStubOff(s *fastPathState) { + if neverEnableFastPath { + return + } periodStubBoundMedian := latencies.stubBound.getMedian() s.stubBoundBaselineLatency.merge(&latencies.stubBound) latencies.stubBound.reset() diff --git a/pkg/sentry/platform/systrap/systrap.go b/pkg/sentry/platform/systrap/systrap.go index 6292eb192..7a5310f7a 100644 --- a/pkg/sentry/platform/systrap/systrap.go +++ b/pkg/sentry/platform/systrap/systrap.go @@ -51,6 +51,7 @@ package systrap import ( "fmt" "os" + "runtime" "sync" "golang.org/x/sys/unix" @@ -324,6 +325,9 @@ func New() (*Systrap, error) { } stubInitialized.Do(func() { + // Don't use sentry and stub fast paths if here is just one cpu. + neverEnableFastPath = min(runtime.NumCPU(), runtime.GOMAXPROCS(0)) == 1 + // Initialize the stub. stubInit()