Advanced Virtual Box Technique – Hotpluggable CPU

By Kwok WhyeNo Comments

With virtual machines running modern server operating systems, VirtualBox supports CPU hot-plugging.Whereas on a physical computer this would mean that a CPU can be added or removed while the machine is running, VirtualBox supports adding and removing virtual CPUs while a virtual machine is running.

CPU hot-plugging works only with guest operating systems that support it. So far this applies only to Linux and Windows Server 2008 x64 Data Center Edition. Windows supports only hot-add while Linux supports hot-add and hot-remove but to use this feature with more than 8 CPUs a 64bit Linux guest is required.

At this time, CPU hot-plugging requires using the VBoxManage command-line interface. First, hot-plugging needs to be enabled for a virtual machine:

VBoxManage modifyvm <vmname> –cpuhotplug on

After that, the –cpus option specifies the maximum number of CPUs that the virtual machine can have:

VBoxManage modifyvm <vmname> –cpus 8

When the VM is off, you can then add and remove virtual CPUs with the modifyvm –plugcpu and –unplugcpu subcommands, which take the number of the virtual CPU as a parameter, like this:

VBoxManage modifyvm <vmname> –plugcpu 3
VBoxManage modifyvm <vmname> –unplugcpu 3

Note that CPU 0 can never be removed.
While the VM is running, CPUs can be added with the controlvm plugcpu/unplugcpu commands instead:

VBoxManage controlvm <vmname> plugcpu 3
VBoxManage controlvm <vmname> unplugcpu 3

Hotplug CPU Testing
Tested the hotplug CPU feature on one of the virtualbox with original config as following.

One Intel(R) Xeon(R) CPU E5506 @ 2.13GHz CPU assigned to VirtualBox
1024MB RAM

Run Unixbench to measure current system score first. The score is 799.5.

Run the following command to enable hotplug cpu and allow CPUs up to 3 CPU.

VBoxManage modifyvm DB –cpuhotplug on
VBoxManage modifyvm DB –cpus 3

Start the DB Guest.

Run the following command on host OS after Guest is running.

VBoxManage controlvm DB plugcpu 1

Run mpstat on Guest and you will see one CPU added as the following.

[root@s-db ~]# mpstat -P ALL
Linux 2.6.18-194.17.1.el5 (s-db)        10/12/2011

04:11:43 PM  CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s
04:11:43 PM  all    0.19    0.22    2.93    0.00    1.68   12.84    0.00   82.14   1011.35
04:11:43 PM    0    0.18    0.22    2.92    0.00    1.69   12.95    0.00   82.03   1011.23
04:11:43 PM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00      0.00

But you can see for CPU1 , the usage is still 0, because the linux guest does not recognize it yet.
At this moment, if you run cat /proc/cpuinfo. You will only see one CPU there.

Run the following command to make CPU1 online.

echo 1 > /sys/devices/system/cpu/cpu1/online

After it online, run again mpstat and you will see CPU 1 are being used now. You will see two CPU in /proc/cpuinfo as well.

[root@s-db ~]# mpstat -P ALL
Linux 2.6.18-194.17.1.el5 (s-db)        10/12/2011

04:19:00 PM  CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s
04:19:00 PM  all    1.13    0.08    3.59    0.27    0.27    0.81    0.00   93.85   1044.33
04:19:00 PM    0    1.02    0.14    4.22    0.22    0.29    1.22    0.00   92.88   1032.23
04:19:00 PM    1    1.23    0.01    2.95    0.32    0.25    0.41    0.00   94.83     12.11

After two CPU are assigned, run unixbench again and the score for this is 936.0.

To make the hotplug cpu offline, run the following command.

echo 0 > /sys/devices/system/cpu/cpu1/online

One problem you might see  is when you try to unplug the CPU on host OS, you might  face the following error.

[root@testbed64 ~]# VBoxManage controlvm DB unplugcpu 1
Oracle VM VirtualBox Command Line Management Interface Version 3.2.8
(C) 2005-2010 Oracle Corporation
All rights reserved.

ERROR: Hot-Remove was aborted because the CPU may still be used by the guest
Details: code VBOX_E_VM_ERROR (0x80bb0003), component Console, interface IConsole, callee nsISupports
Context: “HotUnplugCPU(n)” at line 125 of file VBoxManageControlVM.cpp
Based on the virtual box manual as following, we need guest addition installed to manage the hot-remove event.

With Linux guests, the following applies: To .prevent ejection while the CPU is still used it has to be ejected from within the guest before. The Linux Guest Additions contain a service which receives hot-remove events and ejects the CPU

Virtual Box

Leave your Comment

Your email address will not be published. Required fields are marked *


seven − 2 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Blue Taste Theme created by Jabox