Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for CPU pinning #615

Open
UtkarshVerma opened this issue Jan 20, 2023 · 9 comments
Open

feat: add support for CPU pinning #615

UtkarshVerma opened this issue Jan 20, 2023 · 9 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@UtkarshVerma
Copy link

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?

@philclifford
Copy link
Contributor

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 ...)

@flexiondotorg flexiondotorg added the enhancement New feature or request label Jan 23, 2023
@akarasulu
Copy link

@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.

@9SMTM6
Copy link

9SMTM6 commented Jan 27, 2023

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.

@philclifford
Copy link
Contributor

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

@9SMTM6
Copy link

9SMTM6 commented Jan 28, 2023

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
Copy link

9SMTM6 commented Jan 28, 2023

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.

@philclifford
Copy link
Contributor

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

@philclifford
Copy link
Contributor

philclifford commented Feb 3, 2023

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!

@UtkarshVerma
Copy link
Author

Will implementing something like this be possible?

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

@flexiondotorg flexiondotorg added the help wanted Extra attention is needed label Apr 20, 2024
@flexiondotorg flexiondotorg changed the title Support for CPU pinning feat: add support for CPU pinning May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants