XML with qemu.conf

Hello,

I know that we can override qemu configuration using raw.qemu.conf, but I don’t know how to override them using XML.

i would like to override my conf using this snippet to test something but I don’t know how to convert it:

  <clock offset='utc'>
    <timer name='hpet' present='yes'/>
    <timer name='hypervclock' present='yes'/>
  </clock>

If somebody has a tip, thank you

QEMU doesn’t understand XML. I’m guessing your XML is in libvirt’s Domain XML. Porting it isn’t trivial, but you may want to have a look at the hpet bool of the machine definition, the hv-time of the cpu definition and other so-called Hyper-V enlightenments. This is outside of my expertise, but that’s the rough mapping I found.

Although I’m wondering why you want that, as we already have clock logic dedicated to Windows guests in our QEMU driver logic.

Yes, I’m talking about libvirt.

I want to do that because I have high CPU usage on my host despite the usage in VM is low (30% on host with 5% in the VM).

Some say that it would help (home assistant forum).

The VM are Linux guests

Incus doesn’t use libvirt, so you’ll need to convert your libvirt XML to either QEMU’s .conf format or to QMP commands.

Yes I noticed that thank for the hint.

Do you have an idea why the qemu process cpu consumption on host is way higher than the one reported in the vm ?

I have the same issue. Depending on the image used, when the guest is idle qemu on the host would use 5-20% CPU.

The fix is this: incus config set trixie-vm raw.qemu='-machine hpet=off'

Now CPU is down to 2-4% per VM.

There’s probably a reason why incus doesn’t disable hpet by default, though?

I found the second culprit: incus uses virtio-scsi instead of virtio-blk which causes the guest to constantly poll. This is the remaining 2-4% of CPU usage. I managed to force it by patching incus and it did fall to 0% (like proxmox/cockpit and libvirt do) instead of the 2-4% that we get after disabling hpet.

Unfortunately in another thread @stgraber mentioned that incus would stick with scsi because it is better supported by guests.

This is unfortunate but understandable. Though a way to override it would be nice (I couldn’t find one without patching incus itself).

In summary:

Default incus: 20% idle CPU usage

Default incus with raw.qemu override for machine hpet=off: 2-4% idle CPU usage

Patched incus with hpet by default, and virtio-blk: 0% idle CPU usage

You can just set io.bus=virtio-blk on your disk device.

Thank you that will definitely be useful to me! Also this is embarrassing and I’m sorry for invoking you unnecessarily: I was coming back to stealth edit my previous comment because I was wrong. I had changed two things at once, stupidly.

Removing ‘[device “qemu_gpu”]’ through raw.qemu.conf is what actually brought idle CPU usage down to zero. Libvirt has the exact same device definition of virtio-vga and yet achieves 0% idle so it might be something related to the gpu but not the gpu itself.

SPICE, perhaps? Libvirt uses VNC by default instead. That’s about all I can see. Or perhaps it’s a kernel config difference (in the guest).

I couldn’t find a way to disable SPICE to test, so I will patch it out of incus and try tomorrow. I’ve seen that 7.1 added feature detection for it so possibly I could remove support from my system and incus would simply not try to use it?

Edit:
This is the magic line for nearly 0% idling of guest, it has to be done for each vm container:
incus config set <vm-name> raw.qemu='-machine hpet=off' raw.qemu.conf='[device "qemu_gpu"]'

1 Like