[vfio-users] Stuttering in guest

Mark Nipper nipsy at bitgnome.net
Sat Aug 29 12:40:55 UTC 2015


On 29 Aug 2015, Bradley Davis wrote:
> Pin your CPUs

	Related to Bradley's suggestion, I have my script pin the
CPU's (using output from qmp-shell) and set the CPU frequency
governor to performance.  You can also choose whether you want to
pass isolcpus=... to the kernel to reserve cores for specifically
qemu use.  I initially did this but it annoyed me that my Linux
host couldn't use every single core on the system, so I stopped
doing it and just risk the possible performance hit.

	Anyway, here is my script for doing the rest:
---
#!/bin/zsh

keyboard_id="04d9:0169"
mouse_id="046d:c24a"

keyboard=$(lsusb | grep "${keyboard_id}" | cut -d ' ' -f 2,4 | grep -Eo '[[:digit:]]+' | sed -e 's/^0*//' | xargs -n 2 | sed -e 's/ /./')
mouse=$(lsusb | grep "${mouse_id}" | cut -d ' ' -f 2,4 | grep -Eo '[[:digit:]]+' | sed -e 's/^0*//' | xargs -n 2 | sed -e 's/ /./')

if [[ -z "${keyboard}" || -z "${mouse}" ]]; then
        echo "keyboard (${keyboard}) or mouse (${mouse}) cannot be found; exiting"
        exit 1
fi

for i in {4..7}; do
        echo performance > /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_governor
done

taskset -ac 4-7 qemu-system-x86_64 \
        -qmp unix:/run/qmp-sock,server,nowait \
        -display none \
        -enable-kvm \
        -M q35,accel=kvm \
        -m 8192 \
        -cpu host,kvm=off \
        -smp 4,sockets=1,cores=4,threads=1 \
        -mem-path /dev/hugepages \
        -rtc base=localtime,driftfix=slew \
        -device ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root \
        -device vfio-pci,host=02:00.0,bus=root,addr=00.0,multifunction=on,x-vga=on -vga none \
        -device vfio-pci,host=02:00.1,bus=root,addr=00.1 \
        -usb -usbdevice host:${keyboard} -usbdevice host:${mouse} \
        -device virtio-scsi-pci,id=scsi \
        -drive if=none,file=/dev/win/cdrive,format=raw,cache=none,id=win-c -device scsi-hd,drive=win-c \
        -drive if=none,format=raw,file=/dev/sr0,id=blu-ray -device scsi-block,drive=blu-ray \
        -device virtio-net-pci,netdev=net0 -netdev bridge,id=net0,helper=/usr/lib/qemu/qemu-bridge-helper &

sleep 5

cpuid=4
for threadpid in $(echo 'query-cpus' | qmp-shell /run/qmp-sock | grep '^(QEMU) {"return":' | sed -e 's/^(QEMU) //' | jq -r '.return[].thread_id'); do
        taskset -p -c ${cpuid} ${threadpid}
        ((cpuid+=1))
done

wait

for i in {4..7}; do
        echo ondemand > /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_governor
done
---

	I'm also limiting any other qemu threads to cores 4-7 on
my physical processor through the first taskset command.  I'm not
sure if people here typically run the other, non-vCPU threads
elsewhere on the host or just don't usually specify anything.
And I put in some extra magic to find my second keyboard and
mouse automatically, regardless of where they appear on the USB
bus, so I wouldn't have to change anything if one of them gets
unplugged and enumerated at a new location on the bus.

	Oh, and I use zsh by default for everything.  I'm fairly
certain there isn't anything zsh specific in the above though, so
you could probably just use bash.

	Finally, I'm not sure if the suggestion to use threads=1
is still valid.  I know I saw something along the way that said
performance was worse trying to emulate the layout of a real CPU
by specifying multiple sockets or threads instead of simply
specifying how many cores you want.  This might be something else
for you to try though.

-- 
Mark Nipper
nipsy at bitgnome.net (XMPP)
+1 979 575 3193
-
"Long live the fighters!"
 -- Paul Muad'Dib, "Dune", 1984




More information about the vfio-users mailing list