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:
Andrei Vagin
2024-04-30 13:53:23 -07:00
committed by gVisor bot
parent 98f3211aeb
commit d71608fc03
2 changed files with 11 additions and 0 deletions
+7
View File
@@ -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()
+4
View File
@@ -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()