21

I've installed Ubuntu in a virtual environment using Oracle VM VirtualBox Manager and it works great.

However I'd like to enable multiple cores - as seen in the image below my Windows machine has 2 cores:

enter image description here

Now when I run the lscpu in Ubuntu I get the following info revealing that only 1 core is being utilized:

enter image description here

I've tried changing the settings of the virtual box to enable multiple processors but it won't allow me to do so as shown in the image below:

Image

How do I enable multiple cores (processors) in my virtual enviroment?

0

4 Answers 4

20

To enable more than 1 CPU in your VM the following settings are needed in addition:

  • 64-bit virtual guest hardware in General settings tab (for 64-bit guests)

    enter image description here

  • enable I/O APIC in the Motherboard settings tab

    enter image description here

  • enable hardware virtualization (VT-x/AMD-V) in the Acceleration tab

    enter image description here

Note that if your run your VM on all cores available you may experience a better host performance when assigning an execution cap to the CPU.

If you had not enabled hot-plug CPU feature of virtualbox changing of the number of cores can only be done on a machine that was shut down.

A performance boost in the guest is only to be expected for software that makes use of several cores. Only then giving all cores with an execution cap makes sense.

3
  • so this is not possible on a 32 bit Ubuntu?
    – user47206
    Oct 9, 2014 at 15:44
  • 1
    @cipricus thanks for the notice, 64-bit is only required for a 64-bit guest, of course.
    – Takkat
    Oct 9, 2014 at 17:48
  • @Takkat I am using 32 bit Ubuntu as guest OS. How can I enable multiple cpus? May 9, 2015 at 9:56
16

If your VM is currently running (or "Saved") you can't change that value. Power off your VM first.

2
  • Though it would be really cool if we could swap processors at runtime. That would give CPU throttling a new dimension. Oct 2, 2015 at 11:12
  • 2
    Virtualbox supports CPU hot-plugging
    – bbigras
    Dec 18, 2015 at 18:35
1

I was working on a multithreaded program which executed in sequential order on virtual machine. I had similar problem as you had. I fixed it by :

  1. Stop virtual machine or exit.
  2. Launch VMWare --> Select machine -->Click System --> Click Processor --> Change number processors.
  3. Start Virtual Machine.

Earlier std::thread::hardware_concurrency() from standard thread returned 1, but, after changes it returns the number of CPU's on the settings of Virtual Machine.

Now, I was able to run my multithreaded programs on VM successfully.

0

The other answers didn't work for me, so I'm sharing my solution which is based on VirtualBox manual §2.4 CPU Hot-Plugging.

The GUI allowed me to add 32 vCPUs, but when the Linux guest booted nproc and cat /proc/cpuinfo would only show a single CPU/core/thread. I could see in dmesg that 32 vCPUs were detected:

# dmesg | grep -E 'smp:|smpboot:'
[    0.000000] smpboot: Allowing 32 CPUs, 31 hotplug CPUs
[    0.192151] smpboot: CPU0: Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz (family: 0x6, model: 0x55, stepping: 0x4)
[    0.193848] smp: Bringing up secondary CPUs ...
[    0.193850] smp: Brought up 1 node, 1 CPU
[    0.193852] smpboot: Max logical packages: 32
[    0.193854] smpboot: Total of 1 processors activated (4788.97 BogoMIPS)

Seems hotplug is enabled, but the CPUs are not online for some reason.

Run the following on the host:

for i in {1..31}; do VBoxManage controlvm $VM plugcpu $i; done

From within the guest I can see the CPUs have been hotplugged, but they are not automatically put online:

# dmesg | grep 'has been hot-added'
[  317.236099] CPU1 has been hot-added
[  317.289383] CPU2 has been hot-added
[  317.341704] CPU3 has been hot-added
[  317.393434] CPU4 has been hot-added
[  317.602969] CPU5 has been hot-added
[  317.603570] CPU6 has been hot-added
[  317.603810] CPU7 has been hot-added
[  317.604031] CPU8 has been hot-added
[  317.780191] CPU9 has been hot-added
[  317.780498] CPU10 has been hot-added
[  317.780745] CPU11 has been hot-added
[  317.817875] CPU12 has been hot-added
[  317.870629] CPU13 has been hot-added
[  317.911276] CPU14 has been hot-added
[  317.962533] CPU15 has been hot-added
[  318.012838] CPU16 has been hot-added
[  318.063693] CPU17 has been hot-added
[  318.116346] CPU18 has been hot-added
[  318.167847] CPU19 has been hot-added
[  318.232230] CPU20 has been hot-added
[  318.284266] CPU21 has been hot-added
[  318.344941] CPU22 has been hot-added
[  318.373422] CPU23 has been hot-added
[  318.501419] CPU24 has been hot-added
[  318.501714] CPU25 has been hot-added
[  318.535717] CPU26 has been hot-added
[  318.652636] CPU27 has been hot-added
[  318.653046] CPU28 has been hot-added
[  318.689386] CPU29 has been hot-added
[  318.739736] CPU30 has been hot-added
[  318.790743] CPU31 has been hot-added

# nproc
6

But you can bring the CPUs online manually from within the guest by running:

# for CPU in /sys/devices/system/cpu/cpu*/online; do echo 1 | sudo tee $CPU >/dev/null; done

Healthy:

# nproc
32

This appear to persist when the guest is rebooted:

# dmesg | grep -E 'smp:|smpboot:'
[    0.000000] smpboot: Allowing 32 CPUs, 0 hotplug CPUs
[    0.189487] smpboot: CPU0: Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz (family: 0x6, model: 0x55, stepping: 0x4)
[    0.191502] smp: Bringing up secondary CPUs ...
[    0.278723] smp: Brought up 1 node, 32 CPUs
[    0.278723] smpboot: Max logical packages: 1
[    0.278723] smpboot: Total of 32 processors activated (153236.67 BogoMIPS)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .