feat: refactor virtualisation accelerators

This commit is contained in:
Martin Wimpress 2024-05-15 17:42:51 +01:00 committed by Martin Wimpress
parent 587d218f14
commit b7ab6f6d36
1 changed files with 6 additions and 5 deletions

View File

@ -287,33 +287,34 @@ function configure_cpu() {
HOST_CPU_VENDOR=$(get_cpu_info 'Vendor') HOST_CPU_VENDOR=$(get_cpu_info 'Vendor')
CPU_MODEL="host" CPU_MODEL="host"
QEMU_ACCEL="tcg"
# Configure appropriately for the host platform # Configure appropriately for the host platform
if [ "${OS_KERNEL}" == "Darwin" ]; then if [ "${OS_KERNEL}" == "Darwin" ]; then
MANUFACTURER=$(ioreg -l | grep -e Manufacturer | grep -v iMan | cut -d'"' -f4 | sort -u) MANUFACTURER=$(ioreg -l | grep -e Manufacturer | grep -v iMan | cut -d'"' -f4 | sort -u)
CPU_KVM_UNHALT="" CPU_KVM_UNHALT=""
KVM_GUEST_TWEAKS="" KVM_GUEST_TWEAKS=""
QEMU_ACCEL=",accel=hvf" QEMU_ACCEL="hvf"
# QEMU for macOS from Homebrew does not support SMM # QEMU for macOS from Homebrew does not support SMM
SMM="off" SMM="off"
else else
MANUFACTURER=$(head -1 /sys/class/dmi/id/sys_vendor) MANUFACTURER=$(head -1 /sys/class/dmi/id/sys_vendor)
CPU_KVM_UNHALT=",kvm_pv_unhalt" CPU_KVM_UNHALT=",kvm_pv_unhalt"
KVM_GUEST_TWEAKS="-global kvm-pit.lost_tick_policy=discard " KVM_GUEST_TWEAKS="-global kvm-pit.lost_tick_policy=discard "
QEMU_ACCEL=",accel=kvm" QEMU_ACCEL="kvm"
fi fi
# If the architecture of the VM is different from the host, disable acceleration # If the architecture of the VM is different from the host, disable acceleration
if [ "${ARCH_VM}" != "${ARCH_HOST}" ]; then if [ "${ARCH_VM}" != "${ARCH_HOST}" ]; then
QEMU_ACCEL=""
CPU_MODEL="qemu64" CPU_MODEL="qemu64"
CPU_KVM_UNHALT="" CPU_KVM_UNHALT=""
KVM_GUEST_TWEAKS="" KVM_GUEST_TWEAKS=""
QEMU_ACCEL="tcg"
fi fi
# Detect if running in a VM # Detect if running in a VM
case ${MANUFACTURER,,} in case ${MANUFACTURER,,} in
qemu|virtualbox) CPU_MODEL="qemu64" qemu|virtualbox) CPU_MODEL="qemu64"
QEMU_ACCEL="" QEMU_ACCEL="tcg"
HYPERVISOR="${MANUFACTURER,,}";; HYPERVISOR="${MANUFACTURER,,}";;
*) HYPERVISOR="";; *) HYPERVISOR="";;
esac esac
@ -1133,7 +1134,7 @@ function vm_boot() {
args+=(-name ${VMNAME},process=${VMNAME}) args+=(-name ${VMNAME},process=${VMNAME})
fi fi
# shellcheck disable=SC2054,SC2206,SC2140 # shellcheck disable=SC2054,SC2206,SC2140
args+=(-machine ${MACHINE_TYPE},smm=${SMM},vmport=off${QEMU_ACCEL} ${GUEST_TWEAKS} args+=(-machine ${MACHINE_TYPE},smm=${SMM},vmport=off,accel=${QEMU_ACCEL} ${GUEST_TWEAKS}
${CPU} ${SMP} ${CPU} ${SMP}
-m ${RAM_VM} ${BALLOON} -m ${RAM_VM} ${BALLOON}
-rtc base=localtime,clock=host,driftfix=slew -rtc base=localtime,clock=host,driftfix=slew