Repository navigation
feat(main): warn at startup when the kernel clocksource is slow - #1682
Merged
Merged
Conversation
Sōzu calls Instant::now() throughout the request path. When the kernel clocksource has no vDSO mode (hpet, acpi_pm, jiffies), every call is a clock_gettime syscall; the profile in #500 shows ~59% of CPU time in sys_clock_gettime -> read_hpet. The main process now reads /sys/devices/system/clocksource/clocksource0/current_clocksource once at startup and logs one warning, with the commands to check and change it, unless the source is one that can set a vdso_clock_mode other than VDSO_CLOCKMODE_NONE: tsc, kvm-clock, xen, hyperv_clocksource_tsc_page, arch_sys_counter or riscv_clocksource. An unreadable file is logged at debug level only; non-Linux targets skip the check. The decision lives in the pure slow_clocksource_warning function, unit tested for fast sources, slow sources and sysfs whitespace trimming. Closes #500 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 29, 2026 12:45
This was referenced Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses #500 the way @Geal proposed there: a configuration check at startup. Sōzu calls
Instant::now()throughout the request path (246 call sites inlib/src). When the kernel clocksource has no vDSO mode, each call becomes aclock_gettimesyscall; the profile in #500 shows ~59% of CPU time undersys_clock_gettime -> read_hpet.The main process now reads
/sys/devices/system/clocksource/clocksource0/current_clocksourceonce, right after logging is set up inbegin_main_process(bin/src/command/mod.rs), and emits onewarn!with the commands to check and change it when the source is not vDSO-capable. Workers are not checked: the clocksource is system-wide, so one check per start is enough. An unreadable file is logged at debug level only, and non-Linux targets compile the check to a no-op.slow_clocksource_warning(&str) -> Option<String>(bin/src/util.rs): pure decision, trims the sysfs newline, empty input yields no verdict.warn_on_slow_clocksource()(bin/src/util.rs): thin I/O wrapper.doc/debugging_strategies.md: new "Slow kernel clocksource" section;CHANGELOG.mdUnreleased entry.No new dependency. No protocol or security impact: one sysfs read and one log line at startup.
Why this list of fast clocksources
A clocksource is read from the vDSO only when it sets
vdso_clock_modeto something other thanVDSO_CLOCKMODE_NONE. Checked against Linux master at72d3fcf802c4:tscVDSO_CLOCKMODE_TSC(L1163, L1186)kvm-clockVDSO_CLOCKMODE_PVCLOCK, only withPVCLOCK_TSC_STABLE_BIT(L270-279)xenVDSO_CLOCKMODE_PVCLOCK, only withPVCLOCK_TSC_STABLE_BIT(L470-485)hyperv_clocksource_tsc_pageVDSO_CLOCKMODE_HVCLOCKwhere the arch has it (L409-413)arch_sys_counterVDSO_CLOCKMODE_ARCHTIMERunless an erratum disables it (L59, L497)riscv_clocksourceVDSO_CLOCKMODE_ARCHTIMER(L101)hpetvdso_clock_modein the file)acpi_pmxenis in the fast list because it has the same conditional vDSO path askvm-clock; flagging it would warn on modern Xen guests with a stable TSC. The classification is by name, so it is a heuristic: a listed source that lost its vDSO mode at runtime (unstable TSC, arm64 erratum) is not flagged.Tests (red, then green)
Tests written first against a stub returning
Nonewith an empty fast list:After the implementation:
Commands run (all exit 0)
cargo build --all-features --lockedcargo clippy --all-features --all-targets --locked -- -D warningscargo +nightly fmt --all -- --checkcargo test -p sozu --locked(119 passed in the lib and bin test targets)python3 .github/scripts/check_doc_citations.py --self-test,--root .,--base origin/main,--audit --root .Closes #500