feat: CPU features

This commit is contained in:
Kroese 2023-12-16 06:31:43 +01:00 committed by GitHub
parent a2e55c5dda
commit f93f870626
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,15 +2,15 @@
set -Eeuo pipefail set -Eeuo pipefail
# Docker environment variables # Docker environment variables
: ${HOST_CPU:=''} : ${HOST_CPU:=''}
: ${CPU_MODEL:='host'} : ${CPU_MODEL:='host'}
: ${QEMU_CPU:='qemu64,+ssse3,+sse4,+sse4.1,+sse4.2'} : ${CPU_FEATURES:='+ssse3,+sse4.1,+sse4.2'}
KVM_ERR="" KVM_ERR=""
KVM_OPTS="" KVM_OPTS=""
if [ "$ARCH" == "amd64" ] && [[ "$KVM" != [Nn]* ]]; then if [[ "$ARCH" == "amd64" && "$KVM" != [Nn]* ]]; then
if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then
if ! grep -q -e vmx -e svm /proc/cpuinfo; then if ! grep -q -e vmx -e svm /proc/cpuinfo; then
@ -24,40 +24,36 @@ if [ "$ARCH" == "amd64" ] && [[ "$KVM" != [Nn]* ]]; then
error "KVM acceleration not detected $KVM_ERR, this will cause a major loss of performance." error "KVM acceleration not detected $KVM_ERR, this will cause a major loss of performance."
error "See the FAQ on how to enable it, or skip this error by setting KVM=N (not recommended)." error "See the FAQ on how to enable it, or skip this error by setting KVM=N (not recommended)."
[[ "$DEBUG" != [Yy1]* ]] && exit 88 [[ "$DEBUG" != [Yy1]* ]] && exit 88
[ "$CPU_MODEL" == "host"* ] && CPU_MODEL="$QEMU_CPU" [[ "$CPU_MODEL" == "host"* ]] && CPU_MODEL="max,$CPU_FEATURES"
else else
KVM_OPTS=",accel=kvm -enable-kvm" KVM_OPTS=",accel=kvm -enable-kvm"
fi fi
if [ "$CPU_MODEL" == "host" ]; then if [[ "$CPU_MODEL" != *"$CPU_FEATURES"* ]]; then
if ! grep -qE '^flags.* (sse4_2)' /proc/cpuinfo; then if ! grep -qE '^flags.* (sse4_2)' /proc/cpuinfo; then
info "Your CPU does not have the SSE4.2 instruction set, it will be emulated.." info "Your CPU does not have the SSE4.2 instruction set that DSM needs, it will be emulated.."
CPU_MODEL="host,+ssse3,+sse4,+sse4.1,+sse4.2" CPU_MODEL="host,$CPU_FEATURES"
fi fi
fi fi
else else
[ "$CPU_MODEL" == "host"* ] && CPU_MODEL="$QEMU_CPU" [[ "$CPU_MODEL" == "host"* ]] && CPU_MODEL="max,$CPU_FEATURES"
fi fi
if [ -z "$HOST_CPU" ] && [ "$CPU_MODEL" == "host"* ]; then if [ -z "$HOST_CPU" ]; then
HOST_CPU=$(lscpu | grep 'Model name' | cut -f 2 -d ":" | awk '{$1=$1}1' | sed 's# @.*##g' | sed s/"(R)"//g | sed 's/[^[:alnum:] ]\+/ /g' | sed 's/ */ /g') HOST_CPU=$(lscpu | grep 'Model name' | cut -f 2 -d ":" | awk '{$1=$1}1' | sed 's# @.*##g' | sed s/"(R)"//g | sed 's/[^[:alnum:] ]\+/ /g' | sed 's/ */ /g')
fi fi
if [ -n "$HOST_CPU" ]; then if [ -n "$HOST_CPU" ]; then
HOST_CPU="${HOST_CPU%%,*},," HOST_CPU="${HOST_CPU%%,*},,"
else else
if [ "$CPU_MODEL" == "host"* ] || [ "$CPU_MODEL" == "qemu"* ]; then HOST_CPU="QEMU, Virtual CPU,"
HOST_CPU="QEMU"
else
HOST_CPU="${CPU_MODEL%%,*}"
fi
if [ "$ARCH" == "amd64" ]; then if [ "$ARCH" == "amd64" ]; then
HOST_CPU="${HOST_CPU%%,*}, Virtual CPU, X86_64" HOST_CPU="$HOST_CPU X86_64"
else else
HOST_CPU="${HOST_CPU%%,*}, Virtual CPU, $ARCH" HOST_CPU="$HOST_CPU $ARCH"
fi fi
fi fi