Unverified Commit 7b491b3c authored by Kroese's avatar Kroese Committed by GitHub
Browse files

feat: Verify clocksource is set to TSC (#759)

parent 2ece8654
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -142,14 +142,16 @@ kubectl apply -f kubernetes.yml

* ### How do I verify if my system supports KVM?

  To verify if your system supports KVM, run the following commands:
  To verify that your system supports KVM, run the following commands:

  ```bash
  sudo apt install cpu-checker
  sudo kvm-ok
  ```

  If you receive an error from `kvm-ok` indicating that KVM acceleration can't be used, check the virtualization settings in the BIOS.
  If you receive an error from `kvm-ok` indicating that KVM acceleration can't be used, check whether the virtualization extensions (`Intel VT-x` or `AMD SVM`) are enabled in your BIOS. If you are running the container inside a VM instead of directly on the host, you will also need to enable nested virtualization in its settings. If you are using a cloud provider, you may be out of luck as most of them do not allow nested virtualization for their VPS's. If you are using Windows 10 or MacOS, you are also out of luck, as only Linux and Windows 11 support KVM.

  If you don't receive any error from `kvm-ok` at all, but the container still complains that `/dev/kvm` is missing, it might help to add `privileged: true` to your compose file (or `--privileged` to your `run` command), to rule out any permission issue.

* ### How do I assign an individual IP address to the container?

+11 −12
Original line number Diff line number Diff line
@@ -379,7 +379,8 @@ createDevice () {
      ;;
    "ide" )
      result+=",if=none \
      -device ide-hd,drive=${DISK_ID},bus=ide.$DISK_INDEX,rotation_rate=$DISK_ROTATION${index}"
      -device ich9-ahci,id=ahci${DISK_INDEX},addr=$DISK_ADDRESS,iothread=io2 \
      -device ide-hd,drive=${DISK_ID},bus=ahci$DISK_INDEX.0,rotation_rate=$DISK_ROTATION${index}"
      echo "$result"
      ;;
    "blk" | "virtio-blk" )
@@ -466,8 +467,7 @@ addDisk () {

  fi

  OPTS=$(createDevice "$DISK_FILE" "$DISK_TYPE" "$DISK_INDEX" "$DISK_ADDRESS" "$DISK_FMT" "$DISK_IO" "$DISK_CACHE")
  DISK_OPTS+=" $OPTS"
  DISK_OPTS+=$(createDevice "$DISK_FILE" "$DISK_TYPE" "$DISK_INDEX" "$DISK_ADDRESS" "$DISK_FMT" "$DISK_IO" "$DISK_CACHE")

  return 0
}
@@ -482,19 +482,19 @@ addDevice () {
  [ -z "$DISK_DEV" ] && return 0
  [ ! -b "$DISK_DEV" ] && error "Device $DISK_DEV cannot be found! Please add it to the 'devices' section of your compose file." && exit 55

  local OPTS
  OPTS=$(createDevice "$DISK_DEV" "$DISK_TYPE" "$DISK_INDEX" "$DISK_ADDRESS" "raw" "$DISK_IO" "$DISK_CACHE")
  DISK_OPTS+=" $OPTS"
  DISK_OPTS+=$(createDevice "$DISK_DEV" "$DISK_TYPE" "$DISK_INDEX" "$DISK_ADDRESS" "raw" "$DISK_IO" "$DISK_CACHE")

  return 0
}

html "Initializing disks..."

[ -z "${DISK_OPTS:-}" ] && DISK_OPTS=""
[ -z "${DISK_TYPE:-}" ] && DISK_TYPE="scsi"

case "${DISK_TYPE,,}" in
  "" ) DISK_TYPE="scsi" ;;
  "auto" | "ide" | "usb" | "blk" | "scsi" ) ;;
  * ) error "Invalid DISK_TYPE, value \"$DISK_TYPE\" is unrecognized!" && exit 80 ;;
  "ide" | "usb" | "scsi" | "blk" | "auto" ) ;;
  * ) error "Invalid DISK_TYPE specified, value \"$DISK_TYPE\" is unrecognized!" && exit 80 ;;
esac

if [ -z "$ALLOCATE" ]; then
@@ -513,9 +513,8 @@ else
  DISK_ALLOC="preallocation=falloc"
fi

DISK_OPTS=$(createDevice "$BOOT" "$DISK_TYPE" "1" "0xa" "raw" "$DISK_IO" "$DISK_CACHE")
OPTS=$(createDevice "$SYSTEM" "$DISK_TYPE" "2" "0xb" "raw" "$DISK_IO" "$DISK_CACHE")
DISK_OPTS="$DISK_OPTS $OPTS"
DISK_OPTS+=$(createDevice "$BOOT" "$DISK_TYPE" "1" "0xa" "raw" "$DISK_IO" "$DISK_CACHE")
DISK_OPTS+=$(createDevice "$SYSTEM" "$DISK_TYPE" "2" "0xb" "raw" "$DISK_IO" "$DISK_CACHE")

DISK1_FILE="$STORAGE/data"
if [[ ! -f "$DISK1_FILE.img" ]] && [[ -f "$STORAGE/data${DISK_SIZE}.img" ]]; then
+11 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ if [[ "$KVM" != [Nn]* ]]; then
        warn "you are using Windows 10 which has no KVM support, this will cause a major loss of performance."
      else
        error "KVM acceleration not available $KVM_ERR, this will cause a major loss of performance."
        error "See the FAQ on how to enable it, or continue without KVM by setting KVM=N (not recommended)."
        error "See the FAQ on how to diagnose the cause, or continue without KVM by setting KVM=N (not recommended)."
        [[ "$DEBUG" != [Yy1]* ]] && exit 88
      fi
    fi
@@ -51,6 +51,7 @@ fi
if [[ "$KVM" != [Nn]* ]]; then

  CPU_FEATURES="kvm=on,l3-cache=on,+hypervisor"
  CLOCK="/sys/devices/system/clocksource/clocksource0/current_clocksource"
  KVM_OPTS=",accel=kvm -enable-kvm -global kvm-pit.lost_tick_policy=discard"

  if ! grep -qw "sse4_2" <<< "$flags"; then
@@ -64,6 +65,15 @@ if [[ "$KVM" != [Nn]* ]]; then
    CPU_FEATURES+=",migratable=no"
  fi

  if [ -f "$CLOCK" ]; then
    CLOCK=$(<"$CLOCK")
    if [[ "${CLOCK,,}" != "tsc" ]]; then
      warn "unexpected clocksource: $CLOCK"
    fi
  else
    warn "file \"$CLOCK\" cannot not found?"
  fi

  if grep -qw "svm" <<< "$flags"; then

    # AMD processor