Latency issues with GPU passthrough


Recommended Posts

First off a huge thank you to Space Invader One's excellent video guides, His recent video on downgrading AMI BIOS's is the only reason I am able to use GPU passthrough in the first place.

 

I am having issues with stuttering in 3D applications, most notably in VR.  Here's the kicker, it's completely random whether I will have a butter smooth VR experience or a laggy hitchy mess.  Every day for the last week and a half I think I have it solved and the lag comes back.  Last night I thought I had fixed it for the final time, isolating cores from unraid (First four hyperthreaded cores to VM which worked fine then seven hyperthreaded cores for the VM which did improve performance).  I woke up this morning (and I wrote down this song...) and tried it again just to make sure I wasn't crazy for thinking it was fixed and the lag is back.  When I am troubleshooting this issue I have nothing else running, no other VM's or dockers.  It's not just VR, Firestrike also jumps between a smooth 100 FPS down to 20-30 FPS every few seconds, although I swear I once had a clean Firestrike run then immediately opened VR only to have lag.  I also have MSI enabled as per Space Invader One's recommendation.

 

I will continue to troubleshoot but it makes it much more difficult that it's only sometimes I experience the issue, It's maddening.  The only thing I know to try tonight is to isolate 6 HT cores to the VM leaving 2 for Unraid.  But I don't have much hope for this being the final solution since it worked fine last night and so horrible this morning.

 

I am very close to giving up and using my dedicated Ryzen 3600 machine for VR again, I like to play after work to blow off steam and get a slight workout before doing other PC projects but this is only increasing the steam production so far...

 

 

Specs:

ASROCK X370 Taichi downgraded to BIOS version 5.10

Ryzen 7 2700

32GB (2x16) Corsair 3000 DDR4 (XMP Enabled)

Zotac 1070ti mini

Renesas USB 3.0 PCIe card stubbed and passed through to VM

 

vrlag.thumb.png.aedc83f009f76bbc7807d63248c60c40.png

 

XML

 

 


<?xml version='1.0' encoding='UTF-8'?>
<domain type='kvm'>
  <name>Windows 10</name>
  <uuid>1f39d465-38b8-a19a-45bc-f1c881bd308b</uuid>
  <metadata>
    <vmtemplate xmlns="unraid" name="Windows 10" icon="windows.png" os="windows10"/>
  </metadata>
  <memory unit='KiB'>16777216</memory>
  <currentMemory unit='KiB'>16777216</currentMemory>
  <memoryBacking>
    <nosharepages/>
  </memoryBacking>
  <vcpu placement='static'>14</vcpu>
  <cputune>
    <vcpupin vcpu='0' cpuset='2'/>
    <vcpupin vcpu='1' cpuset='3'/>
    <vcpupin vcpu='2' cpuset='4'/>
    <vcpupin vcpu='3' cpuset='5'/>
    <vcpupin vcpu='4' cpuset='6'/>
    <vcpupin vcpu='5' cpuset='7'/>
    <vcpupin vcpu='6' cpuset='8'/>
    <vcpupin vcpu='7' cpuset='9'/>
    <vcpupin vcpu='8' cpuset='10'/>
    <vcpupin vcpu='9' cpuset='11'/>
    <vcpupin vcpu='10' cpuset='12'/>
    <vcpupin vcpu='11' cpuset='13'/>
    <vcpupin vcpu='12' cpuset='14'/>
    <vcpupin vcpu='13' cpuset='15'/>
  </cputune>
  <os>
    <type arch='x86_64' machine='pc-i440fx-3.1'>hvm</type>
    <loader readonly='yes' type='pflash'>/usr/share/qemu/ovmf-x64/OVMF_CODE-pure-efi.fd</loader>
    <nvram>/etc/libvirt/qemu/nvram/1f39d465-38b8-a19a-45bc-f1c881bd308b_VARS-pure-efi.fd</nvram>
  </os>
  <features>
    <acpi/>
    <apic/>
    <hyperv>
      <relaxed state='on'/>
      <vapic state='on'/>
      <spinlocks state='on' retries='8191'/>
      <vendor_id state='on' value='none'/>
    </hyperv>
  </features>
  <cpu mode='host-passthrough' check='none'>
    <topology sockets='1' cores='14' threads='1'/>
  </cpu>
  <clock offset='localtime'>
    <timer name='hypervclock' present='yes'/>
    <timer name='hpet' present='no'/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/local/sbin/qemu</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw' cache='writeback'/>
      <source file='/mnt/disks/VM_Storage/Windows 10/vdisk1.img'/>
      <target dev='hdc' bus='virtio'/>
      <boot order='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw' cache='writeback'/>
      <source file='/mnt/disks/VM_Storage2/iSpy/vdisk1.img'/>
      <target dev='hdd' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw' cache='writeback'/>
      <source file='/mnt/disks/Security/vdisk1.img'/>
      <target dev='hde' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='/mnt/user/isos/Windows 10 latest official.iso'/>
      <target dev='hda' bus='ide'/>
      <readonly/>
      <boot order='2'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='/mnt/user/isos/virtio-win-0.1.160-1.iso'/>
      <target dev='hdb' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
    </disk>
    <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='0x03' function='0x0'/>
    </controller>
    <controller type='usb' index='0' model='ich9-ehci1'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x7'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci1'>
      <master startport='0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0' multifunction='on'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci2'>
      <master startport='2'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x1'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci3'>
      <master startport='4'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x2'/>
    </controller>
    <interface type='bridge'>
      <mac address='52:54:00:ef:85:69'/>
      <source bridge='br0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' 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='unix'>
      <target type='virtio' name='org.qemu.guest_agent.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'/>
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <driver name='vfio'/>
      <source>
        <address domain='0x0000' bus='0x2d' slot='0x00' function='0x0'/>
      </source>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </hostdev>
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <driver name='vfio'/>
      <source>
        <address domain='0x0000' bus='0x2d' slot='0x00' function='0x1'/>
      </source>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </hostdev>
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <driver name='vfio'/>
      <source>
        <address domain='0x0000' bus='0x2e' slot='0x00' function='0x0'/>
      </source>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/>
    </hostdev>
    <memballoon model='none'/>
  </devices>
</domain>

 

Edited by Ibanez343
Link to comment
50 minutes ago, Ibanez343 said:

... isolating cores from unraid (First four hyperthreaded cores to VM which worked fine then seven hyperthreaded cores for the VM which did improve performance). ...

... The only thing I know to try tonight is to isolate 6 HT cores to the VM leaving 2 for Unraid....

 

By HT core, you mean physical core (i.e. a pair of connected "cpu" in Unraid)?

 

Now assuming your core assignment is 0 + 1 = 1 physical core (e.g. 2+3, 4+5 etc pairs - double check it on your Dashboard, it is not necessarily always the case e.g. it may be 0+8), then you might try isolating 2-7, 10-15 to use for your VM and it might actually improve your performance.

  • This is due to the Ryzen design which essentially, in Intel lingo, "glues" 2 CCX of 4-core each together (so 0-7 = CCX 0, 8-15 = CCX 1). Spreading the load evenly across CCX may actually improve performance. Based on my own test (albeit on Threadripper but it's a similar design), 7 core is just as fast as 6 core on some workloads!

Also perhaps obvious: you need to restart after changing CPU isolation for it to work.

While you are at it, add this bit before </cputune> in the VM template.

<emulatorpin cpuset='8,9'/>

It uses 8+9 for the emulator, which (a) saves your "main" VM cores from doing emulator work and (b) avoid core 0, which is preferred by Unraid.

 

Now if that does not improve on things then try these:

  • Install the tips and tweaks plugin and switch your CPU governor to High Performance (instead of the default On Demand). This should ensure your cores run at full all-core boost consistently, which improves fps consistency.
  • Update to Unraid 6.8.0-rc3 and start a fresh new template with Q35 4.1 machine type.
    • Start fresh template because the GUI can't handle the complicated switch from i440FX to Q35
    • Q35 because it helps with PCIe support
    • Unraid 6.8 because it has qemu 4.1 which again, improves PCIe support.
Link to comment

Thanks for the reply!

 

Sadly I don't think I'm going to go any further for now.  I spent the last hour trying various settings combinations and nothing seems to help.  I had already tried setting the CPU governor in tips and tweaks.  I tried setting the emulator pin to 2,3 (after removing those cores from the VM)  and when that didn't help I tried only the last 8 threads to the VM to try to isolate the CCX which was something I had considered and tested already.  Still major stuttering in VR.  My thread pairings are as follows and I've done quite a lot of searching and my best guess is that 0-7 = CCX1 and 8-15 = CCX2.

 

Pair 1:cpu 0 / cpu 1

Pair 2:cpu 2 / cpu 3

Pair 3:cpu 4 / cpu 5

Pair 4:cpu 6 / cpu 7

Pair 5:cpu 8 / cpu 9

Pair 6:cpu 10 / cpu 11

Pair 7:cpu 12 / cpu 13

Pair 8:cpu 14 / cpu 15

 

I'll attach a few screenshots of PC Mark vs. VR Mark to show the difference in frame rate fluctuation.  The tests were run consecutively with no settings changes or rebooting.

 

Firestrike.thumb.png.d9d7e434bf561d38df4128d5f1abc0ba.pngVRMark.thumb.png.66a6dc294e06d9eaebf0115555f8d5dc.png

 

At this point I really don't want to mess with Unraid updates and risk screwing something else up.  I'll just put the 1070ti back in my VR rig for now instead of selling it.  If anyone has any ideas as to why some firestrike would run fine (although not ALL the time) and VR mark would have issues I can always try again.  But for now this is exactly what I expected, some weird issue that I could chase indefinitely and probably never really find a solution.  But at least I got GPU passthrough working so I can make changes to my surveillance VM locally, You win some and lose some

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.