How to Modify QEMU Source Code to Increase GTK Display Refresh Rate in libvirtd?

Hello everyone,

I’m currently running NixOS with libvirt for virtualization. I have encountered a problem where the refresh rate of the GTK display in my QEMU virtual machine is capped at 33Hz. I would like to increase this to 60Hz to improve the smoothness of the display.

After some research, I’ve found that I need to modify a value in the QEMU source code (GUI_REFRESH_INTERVAL_DEFAULT in include/ui/console.h) from 30 to 16. However, I’m having trouble figuring out how to apply this change in NixOS.

I’ve tried to create an overlay as follows:

self: super: {
  qemu = super.qemu.overrideAttrs (oldAttrs: {
    postPatch = ''
      sed -i 's/GUI_REFRESH_INTERVAL_DEFAULT 30/GUI_REFRESH_INTERVAL_DEFAULT 16/g' include/ui/console.h

I also have tried:

  virtualisation.libvirtd.qemu.package = pkgs.qemu_full;

  nixpkgs.overlays = with pkgs; [
    (self: super: {
      qemu_full = super.qemu_full.overrideAttrs (oldAttrs: {
        postPatch = oldAttrs.postPatch + ''
          sed -i 's/GUI_REFRESH_INTERVAL_DEFAULT 30/GUI_REFRESH_INTERVAL_DEFAULT 16/g' include/ui/console.h

But it still can’t work.

But I’m not sure if this is actually modifying the QEMU package used by libvirt, or even if this is the correct way to apply such a modification. As far as I tried, my win10 vm still display with a low frame rate.

Could anyone provide guidance on how to properly apply this modification to the QEMU source code used by libvirt in NixOS? Any help or pointers in the right direction would be greatly appreciated.

Thanks in advance.

Certainly looks like that could work.

First obvious thing to check is whether your changes have actually resulted in a different qemu binary being used.

  1. Did a nixos-rebuild result in qemu being built?
    If not: then your changes didn’t do anything

  2. When running the VM with/without the overlay, check the qemu store path in ps output. Did it change?
    If not: then your changes didn’t do anything.

If it does change: then at least your changes have made it to the right derivation (which doesn’t guarantee it actually affects the build). I suggest stepping through the build to inspect the source pre-buildPhase.

Or: note the qemu store path while performing the steps outlined above, and then binary diff or disassemble the qemu executables to make sure the number has changed.

Thank you for your reply, As your say, the Nixos-rebuild has compile a qemu binary, but as ps shows, my vm was running by another qemu package.

It’s weired, maybe is the virtualisation.libvirtd.qemu.package = pkgs.qemu_full; doesn’t work.

I’ll try to firgure it out.

Sorry for my pool english, Thank you!

After reboot, the qemu was successfully replaced by my ‘overlay version’, but the vm frame rate is still low.

Maybe something else going wrong caused my vm get low fps.