<div dir="ltr">Thanks for all of that. Things are running much smoother now.<div><br></div><div>Another question: Does my CPU (i7-4820k) overclock carry over into the VM? My Windows guest reports that the CPU is running at 3.7GHz under load, while both my Linux host and separate Windows partition say 4.6GHz. How is fan control handled? Does the VM have a separate set of UEFI firmware settings? Sorry if this is more of a question about virtualization in general -- my research hasn't turned up much.</div><div><br></div><div>Thanks</div></div><br><div class="gmail_quote"><div dir="ltr">On Sat, Aug 29, 2015 at 8:40 AM Mark Nipper <<a href="mailto:nipsy@bitgnome.net">nipsy@bitgnome.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 29 Aug 2015, Bradley Davis wrote:<br>
> Pin your CPUs<br>
<br>
        Related to Bradley's suggestion, I have my script pin the<br>
CPU's (using output from qmp-shell) and set the CPU frequency<br>
governor to performance.  You can also choose whether you want to<br>
pass isolcpus=... to the kernel to reserve cores for specifically<br>
qemu use.  I initially did this but it annoyed me that my Linux<br>
host couldn't use every single core on the system, so I stopped<br>
doing it and just risk the possible performance hit.<br>
<br>
        Anyway, here is my script for doing the rest:<br>
---<br>
#!/bin/zsh<br>
<br>
keyboard_id="04d9:0169"<br>
mouse_id="046d:c24a"<br>
<br>
keyboard=$(lsusb | grep "${keyboard_id}" | cut -d ' ' -f 2,4 | grep -Eo '[[:digit:]]+' | sed -e 's/^0*//' | xargs -n 2 | sed -e 's/ /./')<br>
mouse=$(lsusb | grep "${mouse_id}" | cut -d ' ' -f 2,4 | grep -Eo '[[:digit:]]+' | sed -e 's/^0*//' | xargs -n 2 | sed -e 's/ /./')<br>
<br>
if [[ -z "${keyboard}" || -z "${mouse}" ]]; then<br>
        echo "keyboard (${keyboard}) or mouse (${mouse}) cannot be found; exiting"<br>
        exit 1<br>
fi<br>
<br>
for i in {4..7}; do<br>
        echo performance > /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_governor<br>
done<br>
<br>
taskset -ac 4-7 qemu-system-x86_64 \<br>
        -qmp unix:/run/qmp-sock,server,nowait \<br>
        -display none \<br>
        -enable-kvm \<br>
        -M q35,accel=kvm \<br>
        -m 8192 \<br>
        -cpu host,kvm=off \<br>
        -smp 4,sockets=1,cores=4,threads=1 \<br>
        -mem-path /dev/hugepages \<br>
        -rtc base=localtime,driftfix=slew \<br>
        -device ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root \<br>
        -device vfio-pci,host=02:00.0,bus=root,addr=00.0,multifunction=on,x-vga=on -vga none \<br>
        -device vfio-pci,host=02:00.1,bus=root,addr=00.1 \<br>
        -usb -usbdevice host:${keyboard} -usbdevice host:${mouse} \<br>
        -device virtio-scsi-pci,id=scsi \<br>
        -drive if=none,file=/dev/win/cdrive,format=raw,cache=none,id=win-c -device scsi-hd,drive=win-c \<br>
        -drive if=none,format=raw,file=/dev/sr0,id=blu-ray -device scsi-block,drive=blu-ray \<br>
        -device virtio-net-pci,netdev=net0 -netdev bridge,id=net0,helper=/usr/lib/qemu/qemu-bridge-helper &<br>
<br>
sleep 5<br>
<br>
cpuid=4<br>
for threadpid in $(echo 'query-cpus' | qmp-shell /run/qmp-sock | grep '^(QEMU) {"return":' | sed -e 's/^(QEMU) //' | jq -r '.return[].thread_id'); do<br>
        taskset -p -c ${cpuid} ${threadpid}<br>
        ((cpuid+=1))<br>
done<br>
<br>
wait<br>
<br>
for i in {4..7}; do<br>
        echo ondemand > /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_governor<br>
done<br>
---<br>
<br>
        I'm also limiting any other qemu threads to cores 4-7 on<br>
my physical processor through the first taskset command.  I'm not<br>
sure if people here typically run the other, non-vCPU threads<br>
elsewhere on the host or just don't usually specify anything.<br>
And I put in some extra magic to find my second keyboard and<br>
mouse automatically, regardless of where they appear on the USB<br>
bus, so I wouldn't have to change anything if one of them gets<br>
unplugged and enumerated at a new location on the bus.<br>
<br>
        Oh, and I use zsh by default for everything.  I'm fairly<br>
certain there isn't anything zsh specific in the above though, so<br>
you could probably just use bash.<br>
<br>
        Finally, I'm not sure if the suggestion to use threads=1<br>
is still valid.  I know I saw something along the way that said<br>
performance was worse trying to emulate the layout of a real CPU<br>
by specifying multiple sockets or threads instead of simply<br>
specifying how many cores you want.  This might be something else<br>
for you to try though.<br>
<br>
--<br>
Mark Nipper<br>
<a href="mailto:nipsy@bitgnome.net" target="_blank">nipsy@bitgnome.net</a> (XMPP)<br>
+1 979 575 3193<br>
-<br>
"Long live the fighters!"<br>
 -- Paul Muad'Dib, "Dune", 1984<br>
</blockquote></div>