I'm looking for an explanation to how /proc/stat reports CPU usage. It is the basis for ex. the top command.
I have a 2 core ARMv7 processor running Linux kernel 4.14.34 with RT preempt patches.
It s my understanding that /proc/stat is counting ticks. My kernel is running 100 HZ, thus there would be 100 jiffies/s
Now I have made an observation on CPU1 that /proc/stat it may count more than 100 jiffies during a second. Usually the value is less than 100, also on a PC with Ubuntu.
This script shows how I do the calculation
Code:
b=`awk /cpu1/'{print $2+$3+$4+$5+$6+$7+$8+$9+$10+$11}' /proc/stat`
sleep 1
a=`awk /cpu1/'{print $2+$3+$4+$5+$6+$7+$8+$9+$10+$11}' /proc/stat`
expr $a - $b
Every time I boot I get a new value. It typically varies from 40 to 140 jiffies/s
And with every new value, busybox top applet show a new percentage of load.
Hope that somebody knows a good article on how this works.