sar: Compute global CPU stats as the sum of individual ones
sar used to get statistics for CPU "all" from the first line of the
/proc/stat file giving global CPU utilization.
There are several problems with this:
1) With recent kernels (problem detected on a 4.4.14 kernel), the number
of jiffies spent in idle and iowait modes given by this file for global
CPU utilization goes crazy when a CPU is set offline or comes back
online. These counters may even not be monotonic, resulting in wrong
results being displayed by sar.
E.g.:
cat /proc/stat |grep "cpu "
cpu 8123 235 3359
1099139 15985 0 14 0 0 0
(Set a CPU offline)
cat /proc/stat |grep "cpu "
cpu 8146 235 3374
1168377 18919 0 14 0 0 0
(Set the CPU back online)
cat /proc/stat |grep "cpu "
cpu 8169 236 3391
1033989 15978 0 14 0 0 0
2) The updating of the /proc/stat global and individual values is not
done atomically. As a result there can be skew between the global and
individual values reported by sar.
E.g.:
01:46:12 CPU %user %nice %system %iowait %steal %idle
01:46:13 all 0.25 0.00 10.89 0.00 0.00 88.86
01:46:13 0 0.00 0.00 84.80 0.00 0.00 15.20
01:46:13 1 0.00 0.00 89.65 0.00 0.00 10.35
01:46:13 2 0.17 0.00 83.33 0.00 0.00 16.50
01:46:13 3 0.00 0.00 83.64 0.00 0.00 16.36
In the above case, the %system and %idle for "all" is wrongly
reported as 10.89%.
This patch fixes those problems by calculating the statistics for CPU
"all" (global CPU utilization) as the sum of each individual CPU.
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>