Measuring CPU load with cyclesoak

Although information on system idle time is available from oprofile and KPTrace, the simplest and most accurate way to measure the CPU load of an STLinux ST40 or ARM system is using cyclesoak.

cyclesoak is a tool for measuring system resource utilisation. It uses a "subtractive" algorithm: it measures how much system capacity is still available, rather than how much is consumed. This makes it much more accurate than tools such as top, which simply attempt to add up the CPU usage of separate user processes.

To use cyclesoak, it must first be calibrated. To do this, run it with the -C option on an unloaded system:

root@typhoo:~# cyclesoak -C
using 1 CPUs
calibrating: 10561832 loops/sec
calibrating: 10671135 loops/sec
calibrating: 10668440 loops/sec
calibrating: 10668936 loops/sec
calibrated OK.  10668936 loops/sec
 
root@typhoo:~#
This works out how many spare cycles are present on a totally unloaded system. This should be done immediately after boot, before any additional modules are loaded, with no other applications running. The system load figures produced will be relative to the system load at this time. From then on, running cyclesoak with no arguments gives the system load:
root@typhoo:~# cyclesoak
using 1 CPUs
System load:  0.9%
System load: -0.0%
System load: -0.0%
System load: -0.1%
System load: -0.0%
System load: -0.1%
System load: -0.1%
System load:  0.1%
System load: 75.7%
System load: 21.2%
System load: 11.8%
System load: 36.1%
System load: 62.0%
System load: -0.0%
System load:  0.0%
 
root@typhoo:~#

The tool continues to run until it is ended with a Ctrl+C. A value is output every second - this period is configurable with the -p (set period in seconds) and -m (set period in milliseconds) options.

To measure the load of one particular application or subsystem, recalibrate cyclesoak with everything else running, then run that application or enable that subsystem. The load figures, being relative, will then indicate the load that has been added.

The load figures produced by cyclesoak can also be written into the KPTrace trace buffer by running with the -k option. Because the output is then interleaved with the trace, this allows the load to be seen in the context of what was happening on the system at that time.