You are here: Home / Projects / OSADL Linux Add-on Patch / 
2018-12-17 - 03:38
OSADL Projects

OSADL Linux Add-on Patch: Precise load measurement

Ping SysRqNMI SysRqLatency histogramsBuilt-in kernel patchset - Precise load measurement

Why another load measurement?

The standard load measurement of the Linux kernel has the disadvantage that it is collecting load data at discrete points in time, but the load may be completely different some time before and some time after the data were collected.

A more precise per-CPU load measurement can be obtained, if the time is recorded a particular CPU core spends in idle processing and this time is compared against the total time.

How does it work?

The related patch (configuration with CONFIG_CPU_IDLERUNTIME=y) adds entries for every CPU in /proc/idleruntime/cpuX/data in the format "<idletime> <runtime>". The counters can be reset by writing to /proc/idleruntime/cpuN/reset. To calculate the per-core CPU usage since the most recent reset, divide the runtime by the sum of runtime plus idletime, e.g. on a 4-core processor:
for i in `ls -1d /proc/idleruntime/cpu* | sort -nk1.22`
> do
>   echo "$i: `awk '{ print (100.0*$2) / ($1+$2)"%" }' <$i/data`"
>   echo 1 >$i/reset
> done

/proc/idleruntime/cpu0: 72.0048%
/proc/idleruntime/cpu1: 5.49522%
/proc/idleruntime/cpu2: 0.27916%
/proc/idleruntime/cpu3: 32.3493%


In addition, summed up data of all present CPUs are available in /proc/idleruntime/ all in the same format as above. Thus, to calculate the overall CPU usage since the most recent reset, the following command may be used:
awk '{ print (100.0*$2) / ($1+$2)"%" }' </proc/idleruntime/all/data

Download patch