From c30c4612b55000d4957026c889212857cd3577ef Mon Sep 17 00:00:00 2001 From: Martin Wimpress Date: Tue, 14 May 2024 16:09:26 +0100 Subject: [PATCH] feat(darwin): check if SMT is enabled on darwin --- quickemu | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/quickemu b/quickemu index 447c8c6..3aca4ce 100755 --- a/quickemu +++ b/quickemu @@ -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 ));;