[vfio-users] Stuttering in guest

Blank Field ihatethisfield at gmail.com
Sun Aug 30 19:43:09 UTC 2015


Do not trust the guest hardware tools, they all lie.
For example, on AMD CPUs to know the temperature you must read PCI config.
space of a device 18 function 4. To do that from the guest, you should
pass-through that device, but you can't do that because it's a system
device and it's too important for the host. BKDG(the datasheet) for the CPU
says that there are some control bits, and no one knows for sure how they
are managed.
I suppose, since Intel too have Processor Function devices, it works more
or less the same way.

That said, the fact that your i7 CPU shows some strange frequency in the
guest system can be ignored.
The only true cpu speed measuring tool is host Tick State Counter, or TSC:
[user at crossfire ~]$ dmesg | grep tsc
[    0.000000] tsc: Fast TSC calibration using PIT
[    0.000000] tsc: Detected 3999.734 MHz processor
[    1.872491] tsc: Refined TSC clocksource calibration: 3999.999 MHz
[    1.872605] clocksource tsc: mask: 0xffffffffffffffff max_cycles:
0x7350b79871d, max_idle_ns: 881591110622 ns
[    2.873296] Switched to clocksource tsc
As you can see, it's very precise.

Since motherboard manufacturers LOVE to implement same things different, to
know the voltage that is supplied to your CPU, you must:
a). write a linux device driver for the host system.
b). get into the UEFI setup menu and check it there.
c). boot windows and install proprietary, manufacturer and hardware
specific software, available from that manufacturer.
d). solder a voltmeter somewhere on the motherboard(not recommended due to
it's possible impact on power lanes and bad precision)

The core idea of VM is that the virtualized(guest) OS runs on the same CPU
as the host one, so the frequencies will be the same.They may fluctuate
from host's actions (cpufreq). Different cores may or may not have
different clocks depending on the turbo, P-state and all that other
energy-saving stuff. I think, the only way the clocks may be different is
running in NoHZ mode, but i'm not all that familiar with that topic.


2015-08-30 4:36 GMT+03:00 Garrett Powell <garretttracypowell at gmail.com>:

> Thanks for all of that. Things are running much smoother now.
>
> 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.
>
> Thanks
>
> On Sat, Aug 29, 2015 at 8:40 AM Mark Nipper <nipsy at bitgnome.net> wrote:
>
>> 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
>>
>
> _______________________________________________
> vfio-users mailing list
> vfio-users at redhat.com
> https://www.redhat.com/mailman/listinfo/vfio-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/vfio-users/attachments/20150830/77321231/attachment.htm>


More information about the vfio-users mailing list