KVM(内核虚拟机)Ubuntu 18.04 MSI MPG x570 Gaming Plus Ryzen 5 3600 Nvidia RTX 2070 Super
我正在使用 GPU 直通,此设置的目的是让我在游戏中获得最佳性能,同时保持将 Ubuntu 作为我的主要平台的能力。这将使我能够在发行版之间切换并在更难的发行版上测试我的技能,而无需进行核对和铺平。
我所遇到的问题是,我主要用于游戏的 Windows 10 客户机没有看到任何超线程,我正在研究这个问题,因为我注意到帧速率比虚拟化之前下降了 50-70 fps,而且大的帧丢失几乎表现为小型延迟峰值,我知道我会看到性能损失,但我想尽我所能获得最佳性能。
当我使用默认容器 qemu 时,我在更改 xml 文件中的设置后收到错误,内容如下
qemu-system-x86_64: AMD CPU doesn't support hyperthreading. Please configure -smp options properly.
当我更新到 qemu 4.1.0 时,这个错误消失了,尽管在我的 Windows 客户机中,我可以通过使用命令来确认没有看到超线程
wmic
CPU GET NumberOfCores,NumberOfLogicalProcessors /Format:List
核心数和逻辑处理器数匹配,表明 Windows 将所有线程视为真实核心。
过去几天,我在网上找到了大量文章,试图找到一些可行的方法,但尚未成功。
我最初关注的是指导
此后,我所做的所有进一步的编辑要么是为了解决错误代码 43,要么主要是解决 CPU 固定问题。
我的主板有 3 个独立的 SATA 控制器,因此我让其中一个 SATA 控制器(2 个驱动器,SSD 和 HDD)直接通过。GPU 直接通过,许多 USB 也直接通过。我的主机运行的是 2GB Nvidia Quadro 卡。
任何指导都会非常有帮助。
XML 配置文件
<domain type='kvm'>
<name>Windows10</name>
<uuid>de7e92c8-cde1-4722-a20d-a3c791db265e</uuid>
<memory unit='KiB'>12386304</memory>
<currentMemory unit='KiB'>12386304</currentMemory>
<vcpu placement='static'>8</vcpu>
<iothreads>4</iothreads>
<cputune>
<vcpupin vcpu='0' cpuset='4'/>
<vcpupin vcpu='1' cpuset='5'/>
<vcpupin vcpu='2' cpuset='6'/>
<vcpupin vcpu='3' cpuset='7'/>
<vcpupin vcpu='4' cpuset='8'/>
<vcpupin vcpu='5' cpuset='9'/>
<vcpupin vcpu='6' cpuset='10'/>
<vcpupin vcpu='7' cpuset='11'/>
<iothreadpin iothread='1' cpuset='4-5'/>
<iothreadpin iothread='2' cpuset='6-7'/>
<iothreadpin iothread='3' cpuset='8-9'/>
<iothreadpin iothread='4' cpuset='10-11'/>
</cputune>
<os>
<type arch='x86_64' machine='pc-i440fx-bionic'>hvm</type>
<loader readonly='yes' type='pflash'>/usr/share/OVMF/OVMF_CODE.fd</loader>
<nvram>/var/lib/libvirt/qemu/nvram/Windows10_VARS.fd</nvram>
<bootmenu enable='no'/>
</os>
<features>
<acpi/>
<apic/>
<hyperv>
<relaxed state='on'/>
<vapic state='on'/>
<spinlocks state='on' retries='8191'/>
<vendor_id state='on' value='1234567890ab'/>
</hyperv>
<kvm>
<hidden state='on'/>
</kvm>
<vmport state='off'/>
</features>
<cpu mode='host-passthrough' check='none'>
<topology sockets='1' cores='4' threads='2'/>
<cache level='3' mode='emulate'/>
<feature policy='require' name='topoext'/>
</cpu>
<clock offset='localtime'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
<timer name='hypervclock' present='yes'/>
</clock>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<pm>
<suspend-to-mem enabled='no'/>
<suspend-to-disk enabled='no'/>
</pm>
<devices>
<emulator>/usr/bin/kvm-spice</emulator>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='/home/terry/Downloads/Win10_1903_V1_English_x64.iso'/>
<target dev='hdb' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='0' target='0' unit='1'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='/home/terry/.kvm/virtio/virtio-win-0.1.141.iso'/>
<target dev='hdc' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='1' target='0' unit='0'/>
</disk>
<controller type='usb' index='0' model='ich9-ehci1'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x7'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci1'>
<master startport='0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0' multifunction='on'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci2'>
<master startport='2'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x1'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci3'>
<master startport='4'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<controller type='virtio-serial' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</controller>
<interface type='network'>
<mac address='52:54:00:fb:32:91'/>
<source network='default'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='pty'>
<target type='isa-serial' port='0'>
<model name='isa-serial'/>
</target>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<channel type='spicevmc'>
<target type='virtio' name='com.redhat.spice.0'/>
<address type='virtio-serial' controller='0' bus='0' port='1'/>
</channel>
<input type='tablet' bus='usb'>
<address type='usb' bus='0' port='1'/>
</input>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<sound model='ich6'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</sound>
<hostdev mode='subsystem' type='pci' managed='yes'>
<source>
<address domain='0x0000' bus='0x2d' slot='0x00' function='0x0'/>
</source>
<address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
</hostdev>
<hostdev mode='subsystem' type='pci' managed='yes'>
<source>
<address domain='0x0000' bus='0x2d' slot='0x00' function='0x1'/>
</source>
<address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/>
</hostdev>
<hostdev mode='subsystem' type='pci' managed='yes'>
<source>
<address domain='0x0000' bus='0x2d' slot='0x00' function='0x2'/>
</source>
<address type='pci' domain='0x0000' bus='0x00' slot='0x0b' function='0x0'/>
</hostdev>
<hostdev mode='subsystem' type='pci' managed='yes'>
<source>
<address domain='0x0000' bus='0x2d' slot='0x00' function='0x3'/>
</source>
<address type='pci' domain='0x0000' bus='0x00' slot='0x0c' function='0x0'/>
</hostdev>
<hostdev mode='subsystem' type='pci' managed='yes'>
<source>
<address domain='0x0000' bus='0x2a' slot='0x00' function='0x1'/>
</source>
<address type='pci' domain='0x0000' bus='0x00' slot='0x0d' function='0x0'/>
</hostdev>
<hostdev mode='subsystem' type='pci' managed='yes'>
<source>
<address domain='0x0000' bus='0x2a' slot='0x00' function='0x3'/>
</source>
<address type='pci' domain='0x0000' bus='0x00' slot='0x0e' function='0x0'/>
</hostdev>
<hostdev mode='subsystem' type='pci' managed='yes'>
<source>
<address domain='0x0000' bus='0x26' slot='0x00' function='0x0'/>
</source>
<boot order='1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x0f' function='0x0'/>
</hostdev>
<redirdev bus='usb' type='spicevmc'>
<address type='usb' bus='0' port='2'/>
</redirdev>
<redirdev bus='usb' type='spicevmc'>
<address type='usb' bus='0' port='3'/>
</redirdev>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
</memballoon>
</devices>
</domain>
以下是我迄今为止发现并在一定程度上参考的研究。
http://mathiashueber.com/cpu-pinning-on-amd-ryzen/#comments
https://www.reddit.com/r/VFIO/comments/9iukj5/whats_best_practice_for_ryzen_1800x_cpu_pinning/
这表明由于 numa 已经处于自动状态,因此 emulatorpin 不是必需的,因此我从我的 xml 中删除了 emulatorpin。
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/virtualization_tuning_and_optimization_guide/sect-Virtualization_Tuning_Optimization_Guide-NUMA-NUMA_and_libvirt#sect-Virtualization_Tuning_Optimization_Guide-NUMA-NUMA_and_libvirt-Using_emulatorpin
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/virtualization_tuning_and_optimization_guide/sect-virtualization_tuning_optimization_guide-numa-numa_and_libvirt
我已经尝试过 Epyc 的 CPU 模型以及主机模型,得到了类似的结果
答案1
好吧,我确实围绕我的答案跑了好几英里。
正如我最初的指南在构建 qemu 3.1 部分底部所说的那样
When this is done you can later use:
<os>
...
<type arch='x86_64' machine='pc-q35-3.1'>hvm</type>
...
</os>
and
<devices>
...
<emulator>/usr/local/bin/qemu3.1-system-x86_64</emulator>
...
</devices>
不过我不明白这些东西是什么意思,所以机器类型末尾带有“3.1”,因为他安装的是 3.1 版本,在互联网上进一步搜索后,我发现人们说这是修补后的启动版本,默认情况下不应用它,也不在虚拟管理器中列出。我没有使用 q35,而是通过运行
/usr/local/bin/qemu-system-x86_64 -machine help
这给了我支持的机器类型,我看到了我的机器类型并使用了相应的 4.1。
下一步是指定模拟器。我们现在想要模拟新下载的 4.1 qemu-system-x86_64。因此这也需要定义。
如果你注重细节,他的这一份指南基本上可以把所有事情都安排好,但我觉得我没有做到这一点。
我希望这能在未来帮助其他人。祝你好运