From 5e6f9314331c0abedecd54f1a21806bcc9daafe1 Mon Sep 17 00:00:00 2001 From: Kroese Date: Fri, 14 Mar 2025 14:16:10 +0100 Subject: [PATCH] feat: Detect clock source (#923) --- src/proc.sh | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/proc.sh b/src/proc.sh index 34d8013..56b2466 100644 --- a/src/proc.sh +++ b/src/proc.sh @@ -9,6 +9,23 @@ set -Eeuo pipefail : "${CPU_MODEL:=""}" : "${DEF_MODEL:="qemu64"}" +CLOCKSOURCE="tsc" +[[ "${ARCH,,}" == "arm64" ]] && CLOCKSOURCE="arch_sys_counter" +CLOCK="/sys/devices/system/clocksource/clocksource0/current_clocksource" + +if [ ! -f "$CLOCK" ]; then + warn "file \"$CLOCK\" cannot not found?" +else + result=$(<"$CLOCK") + case "${result,,}" in + "${CLOCKSOURCE,,}" ) ;; + "kvm-clock" ) info "Nested KVM virtualization detected.." ;; + "hyperv_clocksource_tsc_page" ) info "Nested Hyper-V virtualization detected.." ;; + "hpet" ) warn "unsupported clock source detected: '$result'. Please set host clock source to '$CLOCKSOURCE'" ;; + *) warn "unexpected clock source detected: '$result'. Please set host clock source to '$CLOCKSOURCE'" ;; + esac +fi + if [[ "${ARCH,,}" != "amd64" ]]; then KVM="N" warn "your CPU architecture is ${ARCH^^} and cannot provide KVM acceleration for x64 instructions, this will cause a major loss of performance." @@ -60,16 +77,6 @@ if [[ "$KVM" != [Nn]* ]]; then CPU_FEATURES+=",migratable=no" fi - CLOCK="/sys/devices/system/clocksource/clocksource0/current_clocksource" - if [ -f "$CLOCK" ]; then - result=$(<"$CLOCK") - if [[ "${result,,}" != "tsc" ]]; then - warn "unexpected clocksource: $result" - fi - else - warn "file \"$CLOCK\" cannot not found?" - fi - if grep -qw "svm" <<< "$flags"; then # AMD processor