Files
lyphyserandHanzo Dev 26b6f703f1 systrap: express spin/deep-sleep timeouts as durations, fix arm64 idle CPU
The deepSleepTimeout/handshakeTimeout thresholds bound how long stub
threads and the dispatcher spin before deep-sleeping. They were hardcoded
in cputicks() units tuned for the amd64 TSC (~2GHz), e.g. 40000 ticks for
"20µs". But cputicks() advances at a platform-specific rate unrelated to
the CPU clock: on arm64 it reads CNTVCT_EL0, which runs at CNTFRQ_EL0 --
anywhere from tens of MHz up to ~1GHz depending on the core -- so a fixed
tick count maps to a different wall-clock duration there. On a tens-of-MHz
part, 40000 ticks is ~2ms (~100x the intended 20µs), so idle stub threads
and the dispatcher spin far too long before sleeping, burning CPU on
otherwise idle containers (issue #13361).

Neither RDTSC nor CNTVCT_EL0 is an instruction/cycle counter; both are
constant-rate time references at frequencies that differ per platform, so
the timeouts are fundamentally durations. Express them once as nanosecond
durations and convert to cputicks() units via a new per-arch
cputicksFreq():
  - arm64 reads CNTFRQ_EL0 (exact, no calibration).
  - amd64 returns the nominal 2GHz the constants were tuned against, so
    amd64 behavior is unchanged.

initSleepTimeouts() performs the conversion once in New(), before
stubInit() copies deepSleepTimeout into the stub.

Co-authored-by: Hanzo Dev <[email protected]>
2026-06-16 19:38:17 +00:00

33 lines
938 B
ArmAsm

// Copyright 2022 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.
#include "funcdata.h"
#include "textflag.h"
TEXT ·spinloop(SB),NOSPLIT,$0
YIELD
RET
TEXT ·cputicks(SB),NOSPLIT,$0-8
ISB $15
WORD $0xd53be040 //MRS CNTVCT_EL0, R0
MOVD R0, ret+0(FP)
RET
TEXT ·getCNTFRQ(SB),NOSPLIT,$0-8
// Get the virtual counter frequency.
WORD $0xd53be000 //MRS CNTFRQ_EL0, R0
MOVD R0, ret+0(FP)
RET