quickemu icon indicating copy to clipboard operation
quickemu copied to clipboard

feat: add support for CPU pinning

Open UtkarshVerma opened this issue 2 years ago • 9 comments
trafficstars

I wish to be able to pin some cores of my processor to the QEMU process. Would it be possible to get that done with quickemu?

UtkarshVerma avatar Jan 20 '23 03:01 UtkarshVerma

You can add additional qemu arguments via a parameter in the VM.conf. So you can already achieve that I believe, but you should do a bit of research, consider the goals you are aiming for, be aware of the impact of your CPU architecture and numa arrangements... You might also need to tweak settings on your host if that is necessary to, say, reserve some cores/threads for exclusive VM use (as opposed to forcing the VM virtual cores/threads to specific physical cores/threads (/chiplets/CPUs ...)

philclifford avatar Jan 20 '23 22:01 philclifford

@philclifford Which parameters should we use specifically within the VM.conf to pass through CPU pinning information.

Performance is terrible WITHOUT CPU pinning especially in macOS and Windows. This should certainly be addressed. In fact CPU pinning should be enabled out of the box or you're looking at inordinate amounts of time in both OS installations.

There's a lot of greatness in quickemu however this problem draws away from that. Should be high priority to solve for baseline usability.

akarasulu avatar Jan 24 '23 09:01 akarasulu

I did look around a decent bit. AFAICT from man quickemu and man quickemu_conf (also as provided in this very repo) you can not provide generic arguments to qemu-system-XXX, which is of course what you'd need to do.

You cant even provide the number of threads, which is easy enough with raw qemu.

How to do what is commonly referred to as cpu-pinning with the raw commandline isnt very well documented in secondary documentation (articles etc, they mostly suggest using libvirt with qemu/kvm, sometimes additionally wrapped in something like virt-manager). But as far as I can tell we should be able to do it or at least something very similar with qemu-system-x86_64 -numa (one can read the fitting section in man qemu-system-... as reference). In the end libvirt uses qemu/kvm in that config so it should be possible.

But as it stands, as far as I can tell, quickemu does NOT support this even indirectly by providing a way to pass through parameters.

The best way we can currently use quickemu with it, as far as I can tell, is to make it generate a windows machine, calling it once with quickemu, and then afterwards copy and manipulate the generated <VM>.sh instead.

My use-case to want this is that I currently use a laptop with mobile Intel 12th Gen and little enough battery life. When I use quickemu it burns through my battery. But I believe that if I can only use like 6 of the efficiency cores that 12th gen introduced (which also only have 1 thread each, but even my low power one has 8 of them) then I might have a VM with decent enough performance but without burning so much energy.

9SMTM6 avatar Jan 27 '23 16:01 9SMTM6

extra_args="-whatever you -want" in the VM.conf will put extra parameters in the regenerated VM.sh for you

philclifford avatar Jan 28 '23 00:01 philclifford

Oh wow, yeah, that should do it. Shouldnt have overlooked that, though, in fairness, it doesnt appear to be documented in the manpage, only in quickemu --help.

Gonna experiment a bit if I can also override the number of threads with that invocation, that would depend on where its placed in the invocation of qemu.

9SMTM6 avatar Jan 28 '23 10:01 9SMTM6

Hmm. Quickemu Adds these parameters to the end of the invocation. I tried to override the smp for starters. qemu actually validated these parameters when I provided a faulty config, but it doesnt appear to override the earlier provided parameters. On my machine quickemu defaulted to -smp cores=4,threads=2,sockets=1, which means it'll take all the high performance cores my machine has, me using quickemu --display spice --extra_args '-smp cores=6,threads=1,sockets=1' --vm windows-11.conf -- minimal change to avoid other inferference -- indeed did add that parameter to the end, but it still resulted in a 4 cores 2 threads configuration.

quickemu --display spice --extra_args '-numa [...]' --vm windows-11.conf probably still works for others that dont have such a ...weird CPU as me, but for me without being able to change to one thread per core this likely isnt going to work. As I've got an exam on monday I think I'll rather learn than spend time on these experiments, for the moment.

9SMTM6 avatar Jan 28 '23 10:01 9SMTM6

Ok @9SMTM6 thanks for the valuable feedback. And best wishes for the exam!

philclifford avatar Jan 30 '23 00:01 philclifford

Oh wow, yeah, that should do it. Shouldnt have overlooked that, though, in fairness, it doesnt appear to be documented in the manpage, only in quickemu --help.

Added in #626 The documentation should be updated in the next release - thanks for the heads-up!

philclifford avatar Feb 03 '23 19:02 philclifford

Will implementing something like this be possible?

https://github.com/zegelin/qemu-affinity

UtkarshVerma avatar Jun 30 '23 05:06 UtkarshVerma