Return to Level1Techs.com

[CLOSED] - LIBVIRT - Multiple cpus/threads in one guest vcore

Hi there,

I’m wonder if it is possible to pin 1 virtual core on several host cores. The idea is to add several cpu clocks in one virtual core to optimize single thread apps.

I read the RedHat cpu pinning doc but nothing seems to match my need. Maybe it’s impossible, I don’t know. Thank’s in advance !

OS Debian testing/bullseye up to date
I’m using libvirt 7.0.0-3 with qemu 5.2.0

If this was possible, don’t you think that every OS would already have this feature?

Yes I guess, but since we are on a virtual machine, I was like … maybe :). So the answer would be no. Necronomicon thanks for your quick feedback.

This does not work, unfortunately, or at least not with how CPUs are currently designed.

There are a couple of issues with this:

  • Each CPU core (normally) has it’s own level 1 cache, which would take a lot more than one clock cycle to move to another core. So, yes it can move, and processes often do get moved, but more on human timescales rather than every clock.
  • Modern CPUs use pipelines, so a single instruction is not actually completed in one clock cycle, but rather in several cycles. So it moves through each step in a cycle, so the throughput is good, but the latency for each instruction is more than a cycle. So it would be impossible to switch between multiple cores each cycle because nothing would get finished.
  • Modern x86 CPUs use things called branch prediction and speculative execution to help mitigate the long pipeline latency, so switching cores would throw out all that work.
  • For AMD chipsets, I think (but could be wrong) that there is multiple clock cycles of latency to communicate between chiplets.

It is a lovely idea in theory, and you are not the first to think of it, but it just doesn’t work like that in practice unfortunately.

4 Likes

Thanks for your time TheCakeIsNaOH, it’s clear to me now. Subject close.

It’s definitly not possible the way you think. Libvirt(or QEMU for that matter) can’t do it “that way”, because of the aforementioned reasons.

But for the sake of discussion, some work of a single-threaded VM can be offloaded on multiple cores, e.g. most Kernels can storage operations on multiple threads, or at least not always on the same core as the “virtualized” core.