4
Tuning
KosiehBarter edited this page 2026-04-19 13:35:42 +01:00

Potential troubles and how to resolve them

Caution

If you encounter stability troubles: Consult your journalctl -u libvirtd and /var/log/libvirt/qemu/<your_vm>.log .

CPU pinning can cause virtual machine to abruptly power off:

  • Disable CPU pinning completely.
  • Set your CPU to 1 core, 1 thread, after installation return to normal (Based on observation with Windows 11 installer).

Note

You can use bash cpuset.sh to give you CPU pinning based on your /sys/devices/system/cpu/cpu$CPU_INDEX/topology/thread_siblings_list. You can follow steps below if for some reason need manual control.

CPU Pinning

  • Notice the "CORE" column. It tells you which logical CPUs belong to the same physical core.
  • CPUs sharing the same CORE value are SMT/HT siblings and should usually be treated as a pair.
  • It will vary per CPU, so consult your lscpu -e, as I do below:
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE    MAXMHZ   MINMHZ       MHZ
  0    0      0    0 0:0:0:0          yes 4654.2881 560.7580 3609.5791
  1    0      0    1 1:1:1:0          yes 4654.2881 560.7580 3471.4089
  2    0      0    2 2:2:2:0          yes 4654.2881 560.7580 3447.0750
  3    0      0    3 3:3:3:0          yes 4654.2881 560.7580 3950.7229
  4    0      0    4 4:4:4:0          yes 4654.2881 560.7580 1738.3490
  5    0      0    5 5:5:5:0          yes 4654.2881 560.7580 3591.7510
  6    0      0    0 0:0:0:0          yes 4654.2881 560.7580 3596.5920
  7    0      0    1 1:1:1:0          yes 4654.2881 560.7580 3442.9810
  8    0      0    2 2:2:2:0          yes 4654.2881 560.7580 3518.6599
  9    0      0    3 3:3:3:0          yes 4654.2881 560.7580 3845.2971
 10    0      0    4 4:4:4:0          yes 4654.2881 560.7580 3591.1069
 11    0      0    5 5:5:5:0          yes 4654.2881 560.7580 1738.3490
  1. Notice the "CORE" column. It basically tells you what CPU "index" you need to use for your vcpupin.
  2. Here I have a pattern, where essentially my vCPU will have to be paired with physical core and it's SMT/HT counterpart.
  3. Example: For my pair, this indicates core 0 and core 6, however, I have to "map" them as vcpupin indexed 0-n.
  4. For a full example:
vCPU 0: 0   # Pair 0
vCPU 1: 6   # Pair 0
vCPU 2: 1   # Pair 1
vCPU 3: 7   # Pair 1
vCPU 4: 2   # Pair 2
vCPU 5: 8   # Pair 2
vCPU 6: 3   # Pair 3
vCPU 7: 9   # Pair 3
  1. So my resulting XML for my virtual machine's XML settings will be:
  <!-- Feel free to copy, but adjust accordingly to your `lscpu -e` output -->
  <!-- Please do not copy blindly. -->
  <vcpu placement="static">8</vcpu>
  <cputune>
    <vcpupin vcpu="0" cpuset="0"/><!-- pair 0 -->
    <vcpupin vcpu="1" cpuset="6"/><!-- pair 0 -->
    <vcpupin vcpu="2" cpuset="1"/><!-- pair 1 -->
    <vcpupin vcpu="3" cpuset="7"/><!-- pair 1 -->
    <vcpupin vcpu="4" cpuset="2"/><!-- pair 2 -->
    <vcpupin vcpu="5" cpuset="8"/><!-- pair 2 -->
    <vcpupin vcpu="6" cpuset="3"/><!-- pair 3 -->
    <vcpupin vcpu="7" cpuset="9"/><!-- pair 3 -->
    <!-- This you have to alter to your remaining CPU cores/threads! -->
    <emulatorpin cpuset="4-5,10-11"/>
  </cputune>

Also, do not forget to set your CPU according to your real-world CPU, minus some cores + threads for your host system.

Clock times.

I have used this snippet, originating from this Git, by briansteiner (located here: https://github.com/bryansteiner/gpu-passthrough-tutorial?tab=readme-ov-file:

  <clock offset="localtime">
    <timer name="rtc" tickpolicy="catchup"/>
    <timer name="pit" tickpolicy="delay"/>
    <timer name="hpet" present="no"/>
    <timer name="hypervclock" present="yes"/>
  </clock>

Hiding KVM inside the VM:

  • Append this to your machine's XML to hide it:
<kvm>
      <hidden state="on"/>
</kvm>
  • also, recommended for nVidia drivers, within the <features> set:
<ioapic driver="kvm"/>

L3 Cache passthrough:

  • Adding this instruction within your <cpu...> could also help:
<cache mode="passthrough"/>

Hyper-V Replay (STIMER)

  • It might be also beneficial to add this to your <hyperv> section as well:
<stimer state='on'>
  <direct state='on'/>
</stimer>
<vendor_id state="on" value="AuthenticAMD"/><!-- Replace with "GenuineIntel"  for Intel CPUs.-->