44

enter image description here

I have ubuntu running on a multi-core CPU with 32 cores. When I check the cpu usage using top command, sometime it shows more than 100 %, like 340%, 650% etc. I did some investigation and found that its actually a sum of usages across different cores. For example if 1st cpu usages is 20% , 2nd is 30%, 3rd is 40% and remaining are 0% then ‘top’ shows 20+30+40=90%.

Its bit confusing and misleading. I believe the top command should display the CPU usages between 0 to 100 by calculating the usages across all the cores. In my example above, I would expect -(90*100)/3200 =2.8125% . Is this a bug with top command ? should it be considered as an enhancement for future releases? please advise

muru
  • 193,181
  • 53
  • 473
  • 722
Poonam Srivatava
  • 461
  • 1
  • 4
  • 5
  • It is not a bug, this is standard `top` behavior, and it is probably too lte to change it. Nothing stops you from using another command with a different reporting convention however :) – 0xF2 Dec 08 '15 at 04:47
  • 1
    Out of curiosity, what CPU is this? One of those newfangled ARM64 systems? – 0xF2 Dec 08 '15 at 04:48
  • CPU1 & CPU2 - Intel(R) Xeon(R) CPU E5-2670 @2.60 GHz (8 Cores) – Poonam Srivatava Dec 08 '15 at 18:28

3 Answers3

60

By default, top displays CPU usage as a percentage of a single CPU. On multi-core systems, you can see percentages of CPU usage are greater than 100%. You can toggle this behavior by hitting Shift + i while top is running to show the overall percentage of available CPUs in use.

htop is a better alternative of top. In htop, you can see how your programs consuming all of the 32 cores.

Tung Tran
  • 3,905
  • 1
  • 17
  • 27
  • Hello - thanks for this insight. I'm new to working on a multi-core system, so I'm wondering why all cores are being used in this case. I have similar behavior sometimes when I am not doing parallelized operations. It seems dependent on the size of my operation and memory required (I'm working with R). Everything seems to slow down when this spillover to other CPUs occurs. – Marc in the box Sep 02 '19 at 14:38
  • Cross site reference: [Understanding %CPU while running top command (duplicate)](https://unix.stackexchange.com/a/145249/53670) – Sourav Ghosh Jul 14 '21 at 05:34
2

looks like I found a way :-) if I switch to solaris mode while running the top command it shows the correct cpu usage. To switch to the solaris mode first run the top command then press shift+i

reference articles

https://help.gnome.org/users/gnome-system-monitor/stable/solaris-mode.html.en https://unix.stackexchange.com/questions/15733/why-process-cpu-usage-larger-than-total-cpu-time

Poonam Srivatava
  • 461
  • 1
  • 4
  • 5
0
  1. You have to use the "-H" option to get the actual CPU usage of threads. Let's take I have a program "load", this program creates three threads. Each thread is in an infinite loop to make CPU utilization 100%.
  2. Here parent has ID = 181906, thread-1 ID = 181907, thread-2 ID = 181908 and thread-3 ID = 181909.
  3. Using the top command, I see load with ID = 181906 has 300% CPU.
  4. After using top -H -p 181906 then, load ID = 181906 0 %CPU thread1 ID = 181907 99 %CPU thread2 ID = 181908 99 %CPU thread3 ID = 181909 99 %CPU

So, final word, use the -H option along with the top -p option to get actual CPU utilization.