Skip to content

Commit 43bbbf7

Browse files
committed
perf(quickemu): tune TCG translation cache and enable multithreaded TCG
- Add TCG-specific runtime optimisations in vm_boot for cross-architecture VMs - Detect host RAM and set tb-size to 512 for hosts with >=16GB, otherwise 256 - Append -accel tcg,tb-size=${TCG_TB_SIZE},thread=multi to QEMU args - Improve TCG translation cache behaviour and SMP performance for TCG guests Signed-off-by: Martin Wimpress <martin@wimpress.org>
1 parent d8b27e8 commit 43bbbf7

File tree

1 file changed

+51
-13
lines changed

1 file changed

+51
-13
lines changed

quickemu

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,20 +1650,58 @@ function vm_boot() {
16501650
# SMM (System Management Mode) is an x86-specific CPU mode used for firmware operations
16511651
# and is required for Secure Boot. ARM64 uses different mechanisms for firmware security.
16521652
# vmport emulates VMware's I/O port for guest tools, which is also x86-specific.
1653-
if [ "${ARCH_VM}" == "aarch64" ]; then
1654-
# ARM64 uses 'virt' machine type without x86-specific options
1655-
# shellcheck disable=SC2054,SC2206,SC2140
1656-
args+=(-machine ${MACHINE_TYPE},accel=${QEMU_ACCEL} ${GUEST_TWEAKS}
1657-
${CPU} ${SMP}
1658-
-m ${RAM_VM} ${BALLOON}
1659-
-pidfile "${VMDIR}/${VMNAME}.pid")
1653+
#
1654+
# TCG-specific optimisations for cross-architecture emulation:
1655+
# - Use -accel tcg,... to specify tb-size and thread options
1656+
# - QEMU does not allow both -machine accel= and -accel simultaneously
1657+
# - For KVM/HVF, continue using -machine accel= (simpler, no extra options needed)
1658+
if [ "${QEMU_ACCEL}" == "tcg" ]; then
1659+
local HOST_RAM_GB=0
1660+
if [ "${OS_KERNEL}" == "Darwin" ]; then
1661+
HOST_RAM_GB=$(($(sysctl -n hw.memsize) / (1024*1024*1024)))
1662+
else
1663+
HOST_RAM_GB=$(awk '/MemTotal/ {printf "%.0f", $2/1024/1024}' /proc/meminfo)
1664+
fi
1665+
# Use larger translation cache on hosts with 16GB+ RAM
1666+
local TCG_TB_SIZE=256
1667+
if [ "${HOST_RAM_GB}" -ge 16 ]; then
1668+
TCG_TB_SIZE=512
1669+
fi
1670+
# shellcheck disable=SC2054,SC2206
1671+
args+=(-accel tcg,tb-size=${TCG_TB_SIZE},thread=multi)
1672+
1673+
if [ "${ARCH_VM}" == "aarch64" ]; then
1674+
# ARM64 uses 'virt' machine type without x86-specific options
1675+
# shellcheck disable=SC2054,SC2206,SC2140
1676+
args+=(-machine ${MACHINE_TYPE} ${GUEST_TWEAKS}
1677+
${CPU} ${SMP}
1678+
-m ${RAM_VM} ${BALLOON}
1679+
-pidfile "${VMDIR}/${VMNAME}.pid")
1680+
else
1681+
# x86_64 includes SMM (System Management Mode) and vmport options
1682+
# shellcheck disable=SC2054,SC2206,SC2140
1683+
args+=(-machine ${MACHINE_TYPE},smm=${SMM},vmport=off ${GUEST_TWEAKS}
1684+
${CPU} ${SMP}
1685+
-m ${RAM_VM} ${BALLOON}
1686+
-pidfile "${VMDIR}/${VMNAME}.pid")
1687+
fi
16601688
else
1661-
# x86_64 includes SMM (System Management Mode) and vmport options
1662-
# shellcheck disable=SC2054,SC2206,SC2140
1663-
args+=(-machine ${MACHINE_TYPE},smm=${SMM},vmport=off,accel=${QEMU_ACCEL} ${GUEST_TWEAKS}
1664-
${CPU} ${SMP}
1665-
-m ${RAM_VM} ${BALLOON}
1666-
-pidfile "${VMDIR}/${VMNAME}.pid")
1689+
# KVM/HVF: use -machine accel= (no extra options needed)
1690+
if [ "${ARCH_VM}" == "aarch64" ]; then
1691+
# ARM64 uses 'virt' machine type without x86-specific options
1692+
# shellcheck disable=SC2054,SC2206,SC2140
1693+
args+=(-machine ${MACHINE_TYPE},accel=${QEMU_ACCEL} ${GUEST_TWEAKS}
1694+
${CPU} ${SMP}
1695+
-m ${RAM_VM} ${BALLOON}
1696+
-pidfile "${VMDIR}/${VMNAME}.pid")
1697+
else
1698+
# x86_64 includes SMM (System Management Mode) and vmport options
1699+
# shellcheck disable=SC2054,SC2206,SC2140
1700+
args+=(-machine ${MACHINE_TYPE},smm=${SMM},vmport=off,accel=${QEMU_ACCEL} ${GUEST_TWEAKS}
1701+
${CPU} ${SMP}
1702+
-m ${RAM_VM} ${BALLOON}
1703+
-pidfile "${VMDIR}/${VMNAME}.pid")
1704+
fi
16671705
fi
16681706

16691707
if [ "${guest_os}" == "windows" ] || [ "${guest_os}" == "windows-server" ] || [ "${guest_os}" == "reactos" ] || [ "${guest_os}" == "freedos" ]; then

0 commit comments

Comments
 (0)