Having random lag spikes & Audio switching on KVM

Hey everyone, I’m setting up my first kvm to game on, It’s GPU passthrough but having some issues when playing games it will give random lagspikes or sometimes even my audio completely changes to another input making the game completely crash till i change it back properly. Does anyone happen to know a fix for this?

My specs :
CPU: Intel Core i9-7920X
GPU: GTX 2080 ti & GTX 960
Ram : 32 gb ddr4

Host is Arch linux
I’m passing through the 2080ti together with 8 cores, 16 threads & 16gb of ram.

My XML config :

XML Config
<domain type="kvm">
<name>awaaa</name>
  <uuid>5ba0bef0-09a2-4a2a-ba4f-54b67bdf9f52</uuid>
  <metadata>
    <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
      <libosinfo:os id="http://microsoft.com/win/10"/>
    </libosinfo:libosinfo>
  </metadata>
  <memory unit="KiB">16777216</memory>
  <currentMemory unit="KiB">16777216</currentMemory>
  <vcpu placement="static">16</vcpu>
  <iothreads>1</iothreads>
  <cputune>
    <vcpupin vcpu="0" cpuset="2"/>
    <vcpupin vcpu="1" cpuset="8"/>
    <vcpupin vcpu="2" cpuset="3"/>
    <vcpupin vcpu="3" cpuset="9"/>
    <vcpupin vcpu="4" cpuset="4"/>
    <vcpupin vcpu="5" cpuset="10"/>
    <vcpupin vcpu="6" cpuset="5"/>
    <vcpupin vcpu="7" cpuset="11"/>
    <vcpupin vcpu="8" cpuset="6"/>
    <vcpupin vcpu="9" cpuset="12"/>
    <vcpupin vcpu="10" cpuset="7"/>
    <vcpupin vcpu="11" cpuset="13"/>
    <vcpupin vcpu="12" cpuset="8"/>
    <vcpupin vcpu="13" cpuset="14"/>
    <vcpupin vcpu="14" cpuset="9"/>
    <vcpupin vcpu="15" cpuset="15"/>
    <emulatorpin cpuset="0"/>
    <iothreadpin iothread="1" cpuset="0"/>
  </cputune>
  <sysinfo type="smbios">
    <bios>
      <entry name="vendor">METICK</entry>
    </bios>
    <system>
      <entry name="manufacturer">METICK</entry>
      <entry name="product">Metick</entry>
      <entry name="version">1.0.1</entry>
      <entry name="serial">Metick</entry>
      <entry name="uuid">5ba0bef0-09a2-4a2a-ba4f-54b67bdf9f52</entry>
      <entry name="sku">SHEESH</entry>
      <entry name="family">Metick</entry>
    </system>
    <baseBoard>
      <entry name="manufacturer">METICK</entry>
      <entry name="product">MetickV</entry>
      <entry name="version">1.0</entry>
      <entry name="serial">metick</entry>
    </baseBoard>
    <chassis>
      <entry name="manufacturer">METICK</entry>
      <entry name="version">1.01</entry>
      <entry name="serial">metick</entry>
      <entry name="asset">9010004</entry>
      <entry name="sku">typeMetick</entry>
    </chassis>
  </sysinfo>
  <os>
    <type arch="x86_64" machine="pc-i440fx-6.0">hvm</type>
    <loader readonly="yes" type="pflash">/usr/share/edk2-ovmf/x64/OVMF_CODE.fd</loader>
    <nvram>/var/lib/libvirt/qemu/nvram/awaaa_VARS.fd</nvram>
    <boot dev="hd"/>
    <smbios mode="sysinfo"/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <hyperv>
      <relaxed state="on"/>
      <vapic state="on"/>
      <spinlocks state="on" retries="8191"/>
      <vpindex state="on"/>
      <synic state="on"/>
      <stimer state="on"/>
      <reset state="on"/>
      <vendor_id state="on" value="cAb6Z9623a9"/>
      <frequencies state="on"/>
    </hyperv>
    <kvm>
      <hidden state="on"/>
    </kvm>
    <vmport state="off"/>
    <ioapic driver="kvm"/>
  </features>
  <cpu mode="host-passthrough" check="partial" migratable="on">
    <topology sockets="1" dies="1" cores="8" threads="2"/>
  </cpu>
  <clock offset="localtime">
    <timer name="rtc" tickpolicy="catchup"/>
    <timer name="pit" tickpolicy="delay"/>
    <timer name="hpet" present="no"/>
    <timer name="hypervclock" present="yes"/>
    <timer name="tsc" present="yes" mode="native"/>
  </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/qemu-system-x86_64</emulator>
    <disk type="file" device="disk">
      <driver name="qemu" type="qcow2"/>
      <source file="/var/lib/libvirt/images/awaaa.qcow2"/>
      <target dev="sda" bus="sata"/>
      <serial>metickACutie</serial>
      <address type="drive" controller="0" bus="0" target="0" unit="0"/>
    </disk>
    <controller type="usb" index="0" model="qemu-xhci" ports="15">
      <address type="pci" domain="0x0000" bus="0x00" slot="0x05" function="0x0"/>
    </controller>
    <controller type="pci" index="0" model="pci-root"/>
    <controller type="sata" index="0">
      <address type="pci" domain="0x0000" bus="0x00" slot="0x06" function="0x0"/>
    </controller>
    <controller type="virtio-serial" index="0">
      <address type="pci" domain="0x0000" bus="0x00" slot="0x07" function="0x0"/>
    </controller>
    <interface type="network">
      <mac address="52:54:00:b0:5c:43"/>
      <source network="default"/>
      <model type="e1000e"/>
      <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>
    <input type="evdev">
      <source dev="/dev/input/by-id/usb-Corsair_Corsair_Gaming_GLAIVE_RGB_Mouse_0A013018AF08984858ADF5D7F5001946-event-mouse"/>
    </input>
    <input type="evdev">
      <source dev="/dev/input/by-id/usb-Razer_Razer_BlackWidow_X_Chroma-event-kbd" grab="all" repeat="on"/>
    </input>
    <input type="mouse" bus="virtio">
      <address type="pci" domain="0x0000" bus="0x00" slot="0x04" function="0x0"/>
    </input>
    <input type="keyboard" bus="virtio">
      <address type="pci" domain="0x0000" bus="0x00" slot="0x0c" function="0x0"/>
    </input>
    <input type="mouse" bus="ps2"/>
    <input type="keyboard" bus="ps2"/>
    <audio id="1" type="spice"/>
    <hostdev mode="subsystem" type="pci" managed="yes">
      <source>
        <address domain="0x0000" bus="0x17" 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="0x17" 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="0x17" 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="0x17" slot="0x00" function="0x3"/>
      </source>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x0e" function="0x0"/>
    </hostdev>
    <hostdev mode="subsystem" type="usb" managed="yes">
      <source>
        <vendor id="0x1220"/>
        <product id="0x8fe0"/>
      </source>
      <address type="usb" bus="0" port="1"/>
    </hostdev>
    <hostdev mode="subsystem" type="usb" managed="yes">
      <source>
        <vendor id="0x1038"/>
        <product id="0x1294"/>
      </source>
      <address type="usb" bus="0" port="5"/>
    </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>

pls cleanup that post…

I’m trying to, but lmao it doesnt want me to post my XML for some reason.

EDIT: Cleaned it up

12 core CPU right?

why all cores to the VM? try 8 or 10 only maybe?

I am passing 8 cores to the VM as i stated above.

I found the sound emulation in Qemu caused me some issues. I ended up going with Scream: GitHub - duncanthrax/scream: Virtual network sound card for Microsoft Windows

It allows you to install a Windows device driver and then stream to your Linux audio system over the network. Supports full surround sound as well. I use a Host Only connection and you don’t even notice any latency in the audio.

1 Like

your xml says something else…

    <vcpupin vcpu="0" cpuset="2"/>
    <vcpupin vcpu="1" cpuset="8"/>
    <vcpupin vcpu="2" cpuset="3"/>
    <vcpupin vcpu="3" cpuset="9"/>
    <vcpupin vcpu="4" cpuset="4"/>
    <vcpupin vcpu="5" cpuset="10"/>
    <vcpupin vcpu="6" cpuset="5"/>
    <vcpupin vcpu="7" cpuset="11"/>
    <vcpupin vcpu="8" cpuset="6"/>
    <vcpupin vcpu="9" cpuset="12"/>
    <vcpupin vcpu="10" cpuset="7"/>
    <vcpupin vcpu="11" cpuset="13"/>
    <vcpupin vcpu="12" cpuset="8"/>
    <vcpupin vcpu="13" cpuset="14"/>
    <vcpupin vcpu="14" cpuset="9"/>
    <vcpupin vcpu="15" cpuset="15"/>

You might want to try only passing six cores instead of eight. The idea I am trying to get across is only using half of the available cores for your virtual machine. It has been my experience using more than half of the available CPU cores for virtual machines introduces stability issues into the virtual machines.

Don’t you also have to pass through the threads? since they’re seen as cpus orsmth? might be wrong, but that’s the example i got shown from the guide i was reading. although I did find out i was pinning it wrong but that didn’t fix the issue.

and correct me if i’m wrong.

<cputune>
    <vcpupin vcpu="0" cpuset="0"/>
    <vcpupin vcpu="1" cpuset="1"/>
    <vcpupin vcpu="2" cpuset="2"/>
    <vcpupin vcpu="3" cpuset="3"/>
    <vcpupin vcpu="4" cpuset="4"/>
    <vcpupin vcpu="5" cpuset="5"/>
    <vcpupin vcpu="6" cpuset="6"/>
    <vcpupin vcpu="7" cpuset="7"/>
    <vcpupin vcpu="8" cpuset="8"/>
    <vcpupin vcpu="9" cpuset="9"/>
    <vcpupin vcpu="10" cpuset="10"/>
    <vcpupin vcpu="11" cpuset="11"/>
    <vcpupin vcpu="12" cpuset="0"/>
    <vcpupin vcpu="13" cpuset="1"/>
    <vcpupin vcpu="14" cpuset="2"/>
    <vcpupin vcpu="15" cpuset="3"/>
    <emulatorpin cpuset="16-23"/>
    <iothreadpin iothread="1" cpuset="16-23"/>
  </cputune>

Thanks! this fixed my audio issue.