Page 1 of 2

High cpu usage on linux

PostPosted: 14. Jul 2008, 14:31
by panz3r
I have virtual box v1.6.2 running on fedora core 8 -
Intel(R) Core(TM)2 Duo CPU E6550 @ 2.33GHz.
The problem is one cpu seems to be constantly used.
The guest is windows xp with sp2.

Any idea why the "select" system calls take so long ?
Code: Select all   Expand viewCollapse view
top - 14:17:56 up  3:31,  3 users,  load average: 0.65, 0.22, 0.42
Tasks: 147 total,   1 running, 146 sleeping,   0 stopped,   0 zombie
Cpu(s):  1.2%us, 49.2%sy,  1.0%ni, 48.3%id,  0.3%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   5110472k total,  1937920k used,  3172552k free,   820228k buffers
Swap:   522104k total,        0k used,   522104k free,   417040k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                             
 6789 root      20   0  468m 270m  15m S  100  5.4   0:50.93 VirtualBox         

The usage seems to be in kernel system calls:
vmstat 1
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0      0 2362684 818416 409380    0    0    93    75  440  504  5 41 53  1  0
 1  0      0 2355120 818416 409380    0    0     0     0 1044 1421  3 50 46  0  0
 1  0      0 2362684 818416 409380    0    0     0     0 1011 2095  5 51 44  0  0
 1  0      0 2354996 818428 409368    0    0     0     0 1017 1155  3 50 47  0  0
 1  0      0 2354500 818460 409348    0    0    32     0  950  691  3 51 47  0  0
running strace for about 5 sec:

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
100.00    5.131674       42764       120           select
  0.00    0.000000           0       119       113 read
  0.00    0.000000           0       214           gettimeofday
  0.00    0.000000           0        10           writev
  0.00    0.000000           0        12           futex
------ ----------- ----------- --------- --------- ----------------
100.00    5.131674                   475       113 total
This is some strace output that seems to repeat.

select(29, [21 22 23 28], [], [], {0, 49016}) = 0 (Timeout)
gettimeofday({1216038606, 443904}, NULL) = 0
read(21, 0x9e364b8, 4096)               = -1 EAGAIN (Resource temporarily unavailable)
gettimeofday({1216038606, 444013}, NULL) = 0
select(29, [21 22 23 28], [], [], {0, 49022}) = 0 (Timeout)
gettimeofday({1216038606, 493911}, NULL) = 0
read(21, 0x9e364b8, 4096)               = -1 EAGAIN (Resource temporarily unavailable)
gettimeofday({1216038606, 494028}, NULL) = 0
select(29, [21 22 23 28], [], [], {0, 49007}) = 0 (Timeout)
gettimeofday({1216038606, 543931}, NULL) = 0
read(21, 0x9e364b8, 4096)               = -1 EAGAIN (Resource temporarily unavailable)
gettimeofday({1216038606, 544058}, NULL) = 0
select(29, [21 22 23 28], [], [], {0, 48977}) = 0 (Timeout)
gettimeofday({1216038606, 592903}, NULL) = 0
read(21, 0x9e364b8, 4096)               = -1 EAGAIN (Resource temporarily unavailable)
gettimeofday({1216038606, 592997}, NULL) = 0
select(29, [21 22 23 28], [], [], {0, 38}) = 0 (Timeout)
gettimeofday({1216038606, 593867}, NULL) = 0
read(21, 0x9e364b8, 4096)               = -1 EAGAIN (Resource temporarily unavailable)
gettimeofday({1216038606, 593958}, NULL) = 0
select(29, [21 22 23 28], [], [], {0, 49077}) = 0 (Timeout)
gettimeofday({1216038606, 643906}, NULL) = 0
read(21, 0x9e364b8, 4096)               = -1 EAGAIN (Resource temporarily unavailable)
gettimeofday({1216038606, 644017}, NULL) = 0
select(29, [21 22 23 28], [], [], {0, 49018}) = 0 (Timeout)
gettimeofday({1216038606, 693910}, NULL) = 0
read(21, 0x9e364b8, 4096)               = -1 EAGAIN (Resource temporarily unavailable)
gettimeofday({1216038606, 694030}, NULL) = 0
select(29, [21 22 23 28], [], [], {0, 49005}) = 0 (Timeout)
gettimeofday({1216038606, 743911}, NULL) = 0
read(21, 0x9e364b8, 4096)               = -1 EAGAIN (Resource temporarily unavailable)
gettimeofday({1216038606, 744030}, NULL) = 0
select(29, [21 22 23 28], [], [], {0, 49005}) = 0 (Timeout)
gettimeofday({1216038606, 794490}, NULL) = 0

PostPosted: 15. Jul 2008, 13:44
by panz3r
It doesn;t make any difference if windows is runned from real partition or virtualbox disk image.

The cpu usage in windows is close to 0.

PostPosted: 21. Jul 2008, 11:00
by panz3r
It is the same if i try to boot a linux in the Virtual box. It looks strange to me that the select system calls take so long. When in grub the cpu is used in used space but soon afer os start booting it move to system.
Please tell if you have any ideea how to workaround this.

PostPosted: 31. Jul 2008, 20:57
by philippe44
Used from another thread

The problem is not activating support in the VM manager -- you need to swap out the Windows kernel for one that doesn't use ACPI.

Your CPU will, by default, prompt Windows to load the ACPI-enabled SMP kernel. So when you switch to having Windows virtualized, this kernel remains and uses some ACPI registers that have severe virtualzation penalties (it talks to the BIOS). The solution is to force Windows to stop doing that. You can do this by going to Device Manager (right click on My Computer -> Hardware -> Device Manager), expanding 'Comptuer', right-clicking 'ACPI Multiprocessor PC', select 'Update Driver...', choose manual installation, from a list, and select 'Standard PC'.

PostPosted: 9. Aug 2008, 08:47
by NoraaC
Same problem with Win2K guest - Ubuntu Hardy Host - Quad Core - One core always at 100% (VirtualBox 1.6.4 NOT OSE)

Tried changing to standard PC in Device Manager. Windows hangs just before desktop starts to show normal color on bootup.

Safe mode to change back & boot up OK.

Any other ideas ?

PostPosted: 10. Aug 2008, 12:07
by philippe44
Sorry - my mistake ! it does crash with "standard PC" but it works with "PC with advanced energy and configuration interface (ACPI)" - or something similar, I don't know the exact translation as mine is in french - I'm using it every day on my PC

PostPosted: 11. Aug 2008, 18:02
by NoraaC
Thanks for the reply.

The driver that was being used by default was:
"Advanced Configuration Power Interface (ACPI) PC"

My other choices are:
ACPI Multiprocessor PC
ACPI Uniprocessor PC
MPS Multiprocessor PC
MPS Uniprocessor PC
Standard PC

I decided to try "ACPI Multiprocessor PC" to see what would happen.

Unfortunately this causes Windows to hang on the Starting Windows screen and I am unable to get to safe mode.

This is a new install and like an idiot I hadn't got around to making a snapshot of the working install.

I have a limited amount of time to mess with this so I guess I'll think about it for a while and if I can't come up with an easy way to get it booted up again I will just reinstall and start over.

Thanks again for your willingness to help.

Intel Quad Core - ASUS P5Q - Ubuntu 8.04 Host - Win2K guest

PostPosted: 13. Aug 2008, 04:11
by NoraaC
In case anyone is following this:

I reinstalled Win2K and the cpu usage seemed to be fairly normal right after the install.

What I am noticing is that as I am setting up Windows by doing updates and installing Java, Flash etc., the cpu is usage is starting to become excessive again when there is nothing running (at least not in the foreground).

I just installed Quickbooks 2006 which also installs Flash 7 & .Net 1.1 and now one of the cores is constantly spiking from a low of 20% up to 100% with no applications open. Not sure why it insisted on installing flash when I already had the latest version installed.

Before I started mucking around in device manager and hosed the first Win2K install one of the cores would never go below 80% and was mostly at 100% - So things are different so far but I don't know why.

Also looking at Task Manager in Windows shows cpu usage at 0 to 2%

PostPosted: 13. Aug 2008, 04:32
by btanoue

I turned off USB and now all is well.

Let me know if that worked for you as well.


100% CPU util

PostPosted: 13. Aug 2008, 23:16
by rober1s
Turning off USB did not help me. Linux Kubuntu 8.04 host, Windows XP guest, SMP AMD x86_64 dual core cpu.


PostPosted: 19. Aug 2008, 22:16
by philippe44
I'm really sorry you had to re-install. I was off for some days so not able to follow-up.
Normally, when you mess-up with this kind of things (or switch motherboard eg), you have to re-install the HAL (did that many times) so you can just bootup your Windows CD and choose "install" then it will see that you have an existing XP installation and will offer a repair - again, don't chose the "repair" on the initial boot screen, choose install THEN choose repair.
After this you have erased all the windows updates, various SP etc -so just need to redo them) but you have killed nothing of your existing apps. The install process might claim that some DLL are missing, but it is due to inconsistencies in case you have installed SP2, so just go over them and re-install SP2 later, it will be fine
To be back to your question, the right setup is to force ACPI Uniprocessor PC, to prevent XP from trying to use both cores. My config is exactly the same as yours and it is with this setup although it WAS using 50+% CPU when idle before
As you said, doing a disk image is always better, but I think nobody can pretend to never have made the mistake ;-)

PostPosted: 28. Aug 2008, 23:15
by philippe44
Found a more decent way to solve the problem because in what I described before, you had only one core, wether you boot native or under linux + VB. The idea is to have the right HAL and NTKERNEL to be loaded at boot time
Initially, I was hoping that these where part of the hardware profile, but they are not, so XP uses the same HAL and NTKERNEL across all of them.
  • Make a copy of \windows\system32\hal???.dll and \windows\system32\ntkernl???.exe to whatever names you want.
  • Change the processor type in hardware profile to ACPI single core. Do not reboot, but copy the new \windows\system32\hal???.dll and \windows\system32\ntkrnl???.exe to whatever names you want.
  • However for the following to work, all these file names must be 8.3 based.
  • Switch back to ACPI multicore - although this is not strictly needed, but in case in the future you do something wrong with your boot.ini, at least the default-named HAL and NTKERNEL will be there.
  • Change your boot.ini to have two systems to boot (basically duplicate the existing one, change the name) and add the /KERNEL and /HAL options. Here is my example (See MS Kb83372):
    Code: Select all   Expand viewCollapse view
    [boot loader]
    [operating systems]
    multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP  Professional (multicore)" /fastdetect /NoExecute=OptIn /kernel=ntkrnlmp.exe /hal=halamp.dll
    multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional (singlecore)" /fastdetect /NoExecute=OptIn /kernel=ntkrnl.exe /hal=hala.dll
  • Note that boot.ini is a hidden System file in the root directory of your system partition so it is typically C:\boot.ini. Changing this file incorrectly can leave your VM unbootable, so take great care in editing it. Here is an example of how to do this:
    Code: Select all   Expand viewCollapse view
    attrib -h -s -r c:\boot.ini
    notepad c:\boot.ini
    attrib +h +s +r c:\boot.ini
Now it works, you have multicore in native and no more 50% CPU usage in Linux+VB when you choose the single core HAL/NTKERNEL. The trade-off is that when you boot, you have to press 2 or 3 keys before the computer actually boots (choose Linux/Windows, then in Windows Multi/Single core the the Hardware Profile) - I think this is minor.

BTW, I tried in boot.ini to have /onecpu or /numcore=1, but this does not work, still 50% in Linux+VB

PostPosted: 28. Aug 2008, 23:23
by Sasquatch
Philippe, this is a very good explaination. I will add this to the FAQ. Credits to you of course ;). If you have anything more to add, please mention this in the FAQ discussion topic.

PostPosted: 29. Aug 2008, 01:01
by TerryE
Philippe, If you don't mind and especially since I suspect that this topic will get browsed a lot, I've enhanced the BBcode to make it more readable. I have also added a clause to explain how to edit the boot.ini, since most users will have the "hide protected operating system files" option checked and go "boot.ini, what boot.ini??", plus a KB reference.

I was wondering whether to recommend using MSCONFIG to make this change? However, AFIAR this adds an extra prompt to the boot sequence.

The other thing is that typically this will be used when the same image is used for dual boot in a VM and on bare metal. Normally you would also have two profiles one for each to enable / disable the appropriate device drivers to match the VM and bare H/W configs.

PostPosted: 29. Aug 2008, 06:10
by philippe44
your are right, I was mixing this with another thread I was involed in. Here is what I wrote in this one

/************ **********/
- Create another hardware profile in windows (under "hardware" of "system properties") - I recommend, although optional that you boot this profile natively and remove at least the native video driver as it might create problems while booting the windows in the VM. BTW, using no timeout in chosing hardware profile at boot time is better to avoid silly mistakes of booting the wrong profile ...
- Next, create a .vdmk container in Linux, so boot your Linux host and
- I recommend you don't use the whole disk access, but only the partitions you really need (see fdisk /dev/[your partition] to list them)
- I also recommend to use another IPL, not the original disk boot loader otherwise it will ask you if you want to boot Linux or Windows when you boot your VM, which is obviously stupid. For this, use any IPL (you can extract it yourself using (eg) MBRFix - if you have problems, tell me and I'll send you one, this is a tiny file). With this trick, you will directly boot your windows partition in the VM and will be asked for the hardware profile you want
- So, to create the .vdmk container : VBoxManage internalcommands createrawvmdk -filename [/path/to/file.vmdk] -rawdisk /dev/[your device eg :sda] -partitions [your windows partition(s) eg 1,5] -mbr winxp.mbr
- Don't forget to have the current user member of the group "disk" otherwise the above mentionned command will not work
- In your virtualbox, choose IO APIC, otherwise your windows will not be happy when booting as I assume it has previously started with IO APIC.
/************ here is the link ***********/
- Finally, I experienced problems with my virtualmachine using a lot of CPU (50%) running windows guest, even while idle. To solve this, I had to
force (in hardware device manager) the "computer" device properties to be "ACPI only", not the default on (sorry, can't remember the exact english translation, tell me if this is not clear)