Score:0

Why sum of all process CPU(%) is not equal to total cpu(%) utilisation in top output

sg flag

In the attached image of top command output, you can see the idle is 96.8% means CPU utilisation is 3.2% but, sum of CPU% of all the process listed (Image cropped for CPU% > 0.0) is more than the total utilised (3.2%)

TOP Command output

And in another top instance, the CPU utilisation (100-idle) was 14% but the top most process shown "Chrome" alone consumes 253%. I am unsure of how the chrome process consumes CPU more than 100%

Help me with the interpretation of top output if I am wrong

terdon avatar
cn flag
Please [don't post images of text](https://meta.askubuntu.com/q/8713/85695). Instead, copy/paste the text into your question and use the [formatting tools](https://askubuntu.com/help/formatting) to format it as code.
Score:4
cn flag

That isn't what the "CPU(s)" column shows. From man top:

   Line 2 shows CPU state percentages based on  the  interval  since  the
   last refresh.

   As   a  default,  percentages  for  these  individual  categories  are
   displayed.  Where two labels are shown below, those  for  more  recent
   kernel versions are shown first.
       us, user    : time running un-niced user processes
       sy, system  : time running kernel processes
       ni, nice    : time running niced user processes
       id, idle    : time spent in the kernel idle handler
       wa, IO-wait : time waiting for I/O completion
       hi : time spent servicing hardware interrupts
       si : time spent servicing software interrupts
       st : time stolen from this vm by the hypervisor

So when you see that 98.8%, that doesn't mean 98.8% of available CPU power. It is telling you what percentage of time the CPU spent in each of those categories since the last time top polled the system. By default, top polls the system every 2 seconds. So your line is telling you that your CPU spent most of the last 2 seconds in an idle state.

I have posted a fuller description of how top works here: https://superuser.com/a/575330/151431.

Score:2
vn flag

It is my (very basic) understanding that the CPU consumption in the header is percentage of total CPU (all CPUs/cores), whereas the %CPU in the table is (by default) percentage per CPU/core.

This means that the sum of the percentages in the table divided by the number of CPUs/cores in your system should roughly match the CPU consumption in the header.

Further, the man page states:

1. %CPU  --  CPU Usage
   The  task's share of the elapsed CPU time since the last screen update, expressed as a
   percentage of total CPU time.

   In a true SMP environment, if a process is multi-threaded and top is not operating  in
   Threads mode, amounts greater than 100% may be reported.  You toggle Threads mode with
   the `H' interactive command.

   Also for multi-processor environments, if Irix  mode  is  Off,  top  will  operate  in
   Solaris  mode  where  a  task's cpu usage will be divided by the total number of CPUs.
   You toggle Irix/Solaris modes with the `I' interactive command.

You can see in the last paragraph that if you press I (Shift+i), you switch to a mode where the CPU time for each process is divided by the number of CPUs/cores. In this mode, the total of the table should match the number in the header.

Examples from my own system with 4 cores

Irix mode on (default) - sum in the table is roughly 4 times total in header.

enter image description here

Irix mode off (Solaris mode) - sum in the table is roughly the same as in header.

enter image description here

Also, see @terdon's answer as to why the numbers aren't exactly the same - and add to that rounding of fractions etc.

Disabling Irix mode in batch operation

To disable Irix mode in batch operation, do the following:

  1. Run top in normal mode
  2. Disable Irix mode with: Shift+i
  3. Save a configuration file for the current user: Shift+w

The configuration file will be located at $HOME/.config/procps

Now, when you run top for this user (including batch mode), Irix mode will be disabled.

To make this the default for the root user, switch to root (with sudo -s) and run the 3 steps above.

Since top is a relatively simple program, it's not possible to run with a custom config file. If you require custom config or CPU metrics, consider using another method than top output.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.