Unverified Commit 5e6f9314 authored by Kroese's avatar Kroese Committed by GitHub
Browse files

feat: Detect clock source (#923)

parent beadfe72
Loading
Loading
Loading
Loading
+17 −10
Original line number Diff line number Diff line
@@ -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