Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Running mpstat -P ALL on one of our servers returns the following:

06:48:02 AM  CPU   %user    %nice   %sys    %iowait  %irq   %soft  %steal   %idle    intr/s
06:48:02 AM  all    15.61   0.08    84.09   7.20     0.56    0.01    0.00   13.97    763.27
06:48:02 AM    0    12.40   0.07    82.12   8.26     0.41    0.01    0.00   13.21    341.40
06:48:02 AM    1    18.82   0.04    86.06   6.15     0.72    0.01    0.00   14.73    421.87

So total CPU usage is;
all - 122.52%
CPU1 - 116.48%
CPU2 - 126.53%

Have I miss-understood how mpstat works? I thought the totals should always add up to 100%?

If it's relevant, the server is RHEL 5.5. CPU is Intel Xeon Dual Core L3406 2.26Ghz

share|improve this question

1 Answer 1

up vote 1 down vote accepted

From the mpstat manpage:

The interval parameter specifies the amount of time in seconds between each report. A value of 0 (or no parameters at all) indicates that processors statistics are to be reported for the time since system startup (boot)

Running mpstat once only gives you a log-term estimate of usage. Running mpstat with an interval argument will give you more precise numbers.

This discrepancy is an accumulation of rounding errors, which grows with system activity and uptime. The actual statistics dispayed are collected from /proc/stat and /proc/uptime. The statistics are counted in USER_HZ (usually 100Hz, getconf CLK_TCK will confirm this), so your resolution is only 1/100th of a second; and a CPU does a lot in .01 seconds.

As an example:

$ cat /proc/stat; cat /proc/uptime

cpu  414821 51578 226720 66535103 73932 0 4548 0 0 0
cpu0 205014 22950 114302 33188492 36369 0 2071 0 0 0
cpu1 209807 28628 112418 33346611 37563 0 2477 0 0 0
<...>
335694.91 665351.03

On my workstation, which has only been up for a few days, we get the above numbers. If we calculate the percentage of the total time for the cpu stats compared to uptime, we get

(414821 + 51578 + 226720 + 66535103 + 73932 + 4548) / 335694.91 / 2
100.25%

There's a (not very helpful) note about process statistics in the ps man page as well.

CPU usage is currently expressed as the percentage of time spent running during the entire lifetime of a process. This is not ideal, and it does not conform to the standards that ps otherwise conforms to. CPU usage is unlikely to add up to exactly 100%

share|improve this answer
    
That still doesn't explain why the CPU usage is over 100%, however long one samples for it should average out at under 100.01% should it not? –  sam Jun 15 '11 at 8:19
1  
@samarudge - I implied the reason by stating it was an "estimate", but I'll add more detail. –  JimB Jun 15 '11 at 13:24
    
Thanks, makes sense now =) –  sam Jun 15 '11 at 15:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.