feat(darwin): check if SMT is enabled on darwin

This commit is contained in:
Martin Wimpress 2024-05-14 16:09:26 +01:00 committed by Martin Wimpress
parent e1ee983245
commit c30c4612b5
1 changed files with 16 additions and 2 deletions

View File

@ -315,9 +315,23 @@ function configure_cpu() {
done
fi
# Account for Hyperthreading/SMT.
if [ -e /sys/devices/system/cpu/smt/control ] && [ "${GUEST_CPU_CORES}" -ge 2 ]; then
if [ ${DARWIN} -eq 1 ]; then
# Get the number of physical cores
physicalcpu=$(sysctl -n hw.physicalcpu)
# Get the number of logical processors
logicalcpu=$(sysctl -n hw.logicalcpu)
# Check if Hyper-Threading is enabled
if [ "${logicalcpu}" -gt "${physicalcpu}" ]; then
HOST_CPU_SMT="on"
else
HOST_CPU_SMT="off"
fi
elif [ -e /sys/devices/system/cpu/smt/control ]; then
HOST_CPU_SMT=$(cat /sys/devices/system/cpu/smt/control)
fi
# Account for Hyperthreading/SMT.
if [ "${GUEST_CPU_CORES}" -ge 2 ]; then
case ${HOST_CPU_SMT} in
on) GUEST_CPU_THREADS=2
GUEST_CPU_LOGICAL_CORES=$(( GUEST_CPU_CORES / GUEST_CPU_THREADS ));;