CPU on Linux/Intel

 

I am running Linux on my notebook in a VirtualBox with 1 dedicated CPU
 Linux 2.6.39-200.24.1.el6uek.x86_64 (ol6-112-rac1.localdomain)  02/25/2017      _x86_64_        (1 CPU)

My CPU hog script is utilizing bc (binary counter) to generate load on the machine. 
We will observe CPU utilization numbers from time, top, and mpstat. 

# the loop is calibrated to run for about 10 seconds
time -p echo "scale=12;for(x=0;x<10000000;++x){1+1.243;}" | bc >/dev/null

real 10.64	<- utilization is 0.9=(8.3+1.31)/10.64
user 8.30
sys 1.31

top showed my process with 92% for %CPU, it is matching time output

top1thread


I only have 1 CPU on my virtual box.
We see around 8% CPU used before I started the script, and 100% utilization while the script was running.
Therefore hog script used around 92% of the CPU, a good match with both time and top.

mpstat 5 10000
06:29:28 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle
06:30:23 PM  all    3.61    0.00    1.80    2.40    0.00    0.00    0.00    0.00   92.18
06:30:28 PM  all   84.60    0.00   15.00    0.00    0.00    0.40    0.00    0.00    0.00
06:30:33 PM  all   85.97    0.00   13.83    0.00    0.00    0.20    0.00    0.00    0.00
06:30:38 PM  all    8.47    0.00    2.82    1.61    0.00    0.00    0.00    0.00   87.10

If we execute 2 hogs, each hog will run two times longer - they are sharing my only CPU.
While executing, top showed both processes were using 45%.

# 2 hogs, time is matching top
time -p echo "scale=12;for(x=0;x<10000000;++x){1+1.243;}" | bc >/dev/null &
time -p echo "scale=12;for(x=0;x<10000000;++x){1+1.243;}" | bc >/dev/null &

real 20.75	<- 0.46=(8.24+1.34)/20.75
user 8.24
sys 1.34
real 20.78
user 8.25
sys 1.36
Advertisements