mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
platform/systrap: never enable fast paths if only one cpu is avaliable
Fast paths here is when one process is spinning to wait for another one. It definitely can't work on one cpu. Before: BM_GetpidOpt 28491 ns 28586 ns 24138 After: BM_GetpidOpt 7578 ns 7600 ns 100000 PiperOrigin-RevId: 629518277
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user