Skip to content

Commit 1d9bea5

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 1d9bea5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

quickemu

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,26 @@ function vm_boot() {
16661666
-pidfile "${VMDIR}/${VMNAME}.pid")
16671667
fi
16681668

1669+
# TCG-specific optimisations for cross-architecture emulation
1670+
# Increases translation block cache size to reduce re-translation overhead
1671+
# and enables multi-threaded TCG for better SMP performance
1672+
if [ "${QEMU_ACCEL}" == "tcg" ]; then
1673+
local HOST_RAM_GB=0
1674+
if [ "${OS_KERNEL}" == "Darwin" ]; then
1675+
HOST_RAM_GB=$(($(sysctl -n hw.memsize) / (1024*1024*1024)))
1676+
else
1677+
HOST_RAM_GB=$(awk '/MemTotal/ {printf "%.0f", $2/1024/1024}' /proc/meminfo)
1678+
fi
1679+
# Use larger translation cache on hosts with 16GB+ RAM
1680+
if [ "${HOST_RAM_GB}" -ge 16 ]; then
1681+
TCG_TB_SIZE=512
1682+
else
1683+
TCG_TB_SIZE=256
1684+
fi
1685+
# shellcheck disable=SC2054,SC2206
1686+
args+=(-accel tcg,tb-size=${TCG_TB_SIZE},thread=multi)
1687+
fi
1688+
16691689
if [ "${guest_os}" == "windows" ] || [ "${guest_os}" == "windows-server" ] || [ "${guest_os}" == "reactos" ] || [ "${guest_os}" == "freedos" ]; then
16701690
# shellcheck disable=SC2054
16711691
args+=(-rtc base=localtime,clock=host,driftfix=slew)

0 commit comments

Comments
 (0)