Skip to content

Commit

Permalink
Set fastPathContextLimit after maxSysmsgThreads has been initialized.
Browse files Browse the repository at this point in the history
A recent change to the timing of initializing maxSysmsgThreads did not
account for fastPathContextLimit which depended on it.

Also set these globals only if they haven't been set already. We don't
expect there to be more than one instance of systrap, but just in case.

PiperOrigin-RevId: 633783350
  • Loading branch information
konstantin-s-bogom authored and gvisor-bot committed May 15, 2024
1 parent 54ea3e1 commit 6ab1a21
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 5 additions & 1 deletion pkg/sentry/platform/systrap/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,16 @@ var (
// deepSleepTimeout is much shorter than the Linux scheduler timeslice, so the
// only thing that matters here is whether the Sentry handles syscall faster
// than the overhead of scheduling another stub thread.
fastPathContextLimit = uint32(maxSysmsgThreads * 2)
//
// It is set after maxSysmsgThreads is initialized.
fastPathContextLimit = uint32(0)
)

// controlFastPath is used to spawn a goroutine when creating the Systrap
// platform.
func controlFastPath() {
fastPathContextLimit = uint32(maxSysmsgThreads * 2)

for {
time.Sleep(recordingPeriod)

Expand Down
14 changes: 8 additions & 6 deletions pkg/sentry/platform/systrap/systrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,14 @@ func (*Systrap) MinUserAddress() hostarch.Addr {

// New returns a new seccomp-based implementation of the platform interface.
func New() (*Systrap, error) {
// CPUID information has been initialized at this point.
archState.Init()
// GOMAXPROCS has been set at this point.
maxSysmsgThreads = runtime.GOMAXPROCS(0)
// Account for syscall thread.
maxChildThreads = maxSysmsgThreads + 1
if maxSysmsgThreads == 0 {
// CPUID information has been initialized at this point.
archState.Init()
// GOMAXPROCS has been set at this point.
maxSysmsgThreads = runtime.GOMAXPROCS(0)
// Account for syscall thread.
maxChildThreads = maxSysmsgThreads + 1
}

mf, err := createMemoryFile()
if err != nil {
Expand Down

0 comments on commit 6ab1a21

Please sign in to comment.