Page 1 of 1

question about CPU allocation and usage

Posted: 26. Jan 2015, 20:42
by ljwobker
Host machine is windows7, i7-4600U, 2 cores/4 threads @ 2.1Ghz, 12GB of memory.
Guest machine is (in this case) Ubuntu 14.04.1.

I've followed the advice given here and allocated only 2 CPUs to the guest, but when I run CPU intensive applications (such as compiling code with jobserver working) I've noticed that the guest CPU shows two cores, both running at/near 100% during the build. However, on the host machine the CPU utilization is only reported as ~50%.

This implies, at least to a casual observer, that the guest machine is only getting access to half the processing power of the host. But if you change the number of CPUs to four, the guest machine now sees all four, and the host machine now runs at near 100% CPU during builds.

That said, the compile times on my (somewhat limited) build aren't substantially faster - if that many cycles are indeed being wasted, where are they going?

Re: question about CPU allocation and usage

Posted: 26. Jan 2015, 20:55
by loukingjr
If you aren't doing much on the host you could try assigning 3 cores to the guest and see if compile times are faster.

Re: question about CPU allocation and usage

Posted: 26. Jan 2015, 21:28
by scottgus1
ljwobker wrote:Host machine is windows7, i7-4600U, 2 cores/4 threads . . . if you change the number of CPUs to four . . . the compile times on my (somewhat limited) build aren't substantially faster
It sounds like you are proving the scuttlebutt around here that hyperthreading doesn't help when counting cores for guests. Hyperthreading is supposed to allow two dissimilar threads to get through the core at the same time if they use different parts of the core guts. If the two threads being assigned to two hyperthreading channels on one core are too similar, one thread will have to wait for the other to get done before it can run through, since they both need the same parts of the core to calculate.

Quite likely the processing being done by your program is rather similar on each thread, so hyperthreading can't really work as good as it claims it can, and your times aren't getting much better.

Re: question about CPU allocation and usage

Posted: 26. Jan 2015, 21:42
by loukingjr
Just to add, unless the OS and/or the application that's being run is optimized to multi-core/hyperthreading it really isn't much of an advantage. It's similar to the 32bit vs 64bit argument.

An exaggerated analogy woud be, adding 2+2 on an Intel i7 is not going to be all that much slower than on a Cray if at all.

Re: question about CPU allocation and usage

Posted: 29. Jan 2015, 19:43
by mpack
Basically, it's a marketing scam. It's like Ford saying "hey, we put two engines in a car, it now has twice the horsepower!" - so the buyer will expect the car to go twice as fast, right? There's so many things wrong with that logic that it's hard to know where to start.

Returning to CPUs: my understanding is that every time context is switched between host and VM, the CPU context has to be saved and restored, which is relatively slow. If you allocate multiple CPUs then multiple contexts need to be swapped. If the app isn't actually designed for multiprocessing then it won't benefit, but it still has the switching overhead. Result: the VM gets slower as you add CPUs, not faster.