feat: Detect clock source (#923)

This commit is contained in:
Kroese 2025-03-14 14:16:10 +01:00 committed by GitHub
parent beadfe720c
commit 5e6f931433
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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