From 0c74201eb41484061c4ad33decc3f422f4cdf04f Mon Sep 17 00:00:00 2001 From: Kroese Date: Sun, 21 Jan 2024 20:52:53 +0100 Subject: [PATCH] feat: CPU flags (#586) --- src/config.sh | 4 ++-- src/proc.sh | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/config.sh b/src/config.sh index 98ade00..b31422d 100644 --- a/src/config.sh +++ b/src/config.sh @@ -3,8 +3,8 @@ set -Eeuo pipefail DEF_OPTS="-nodefaults -boot strict=on" RAM_OPTS=$(echo "-m $RAM_SIZE" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g') -CPU_OPTS="-cpu $CPU_MODEL -smp $CPU_CORES,sockets=1,dies=1,cores=$CPU_CORES,threads=1" -MAC_OPTS="-machine type=q35,usb=off,dump-guest-core=off,hpet=off${KVM_OPTS}" +CPU_OPTS="-cpu $CPU_FLAGS -smp $CPU_CORES,sockets=1,dies=1,cores=$CPU_CORES,threads=1" +MAC_OPTS="-machine type=q35,usb=off,vmport=off,dump-guest-core=off,hpet=off${KVM_OPTS}" DEV_OPTS="-device virtio-balloon-pci,id=balloon0,bus=pcie.0,addr=0x4" DEV_OPTS="$DEV_OPTS -object rng-random,id=objrng0,filename=/dev/urandom" DEV_OPTS="$DEV_OPTS -device virtio-rng-pci,rng=objrng0,id=rng0,bus=pcie.0,addr=0x1c" diff --git a/src/proc.sh b/src/proc.sh index 3c81892..dc5b04d 100644 --- a/src/proc.sh +++ b/src/proc.sh @@ -5,8 +5,8 @@ set -Eeuo pipefail : "${KVM:="Y"}" : "${HOST_CPU:=""}" +: "${CPU_FLAGS:=""}" : "${CPU_MODEL:="host"}" -: "${CPU_FEATURES:="+ssse3,+sse4.1,+sse4.2"}" [ "$ARCH" != "amd64" ] && KVM="N" @@ -37,6 +37,7 @@ fi if [[ "$KVM" != [Nn]* ]]; then + CPU_FEATURES="kvm=on" KVM_OPTS=",accel=kvm -enable-kvm" if ! grep -qE '^flags.* (sse4_2)' /proc/cpuinfo; then @@ -48,15 +49,23 @@ if [[ "$KVM" != [Nn]* ]]; then else KVM_OPTS="" + CPU_FEATURES="+ssse3,+sse4.1,+sse4.2" + + if [[ "${CPU_MODEL,,}" == "host"* ]]; then - if [[ "$CPU_MODEL" == "host"* ]]; then if [[ "$ARCH" == "amd64" ]]; then - CPU_MODEL="max,$CPU_FEATURES" + CPU_MODEL="max" else - CPU_MODEL="qemu64,$CPU_FEATURES" + CPU_MODEL="qemu64" fi - fi + fi +fi + +if [ -z "$CPU_FLAGS" ]; then + CPU_FLAGS="$CPU_MODEL,$CPU_FEATURES" +else + CPU_FLAGS="$CPU_MODEL,$CPU_FEATURES,$CPU_FLAGS" fi if [ -z "$HOST_CPU" ]; then