descriptionCPU load monitor
last changeSun, 27 Jul 2014 17:15:12 +0000 (27 21:15 +0400)
content tags

The kernel module part of this program messes with internal affairs of
the kernel, while best effort was put into making it safe, there are:

                       NO GUARANTEES WHATSOEVER

Furthermore  removing the  previous    versions  of the  module   (via
rmmod(8))      caused  one  particular      kernel   version to  panic
(2.6.8-2-686-SMP  form Debian), to  the best  of  my current knowledge
panics are only possible on SMP machines (and with maxcpus > 1).  Pair
of safety nets were added and this  particular kernel no longer panics
upon module removal, but, again, three words in caps above apply.

The module expects certain things not to happen at particular point in
execution, otherwise the information kernel  module exports can not be
trusted.   Those `things' did  happen on aforementioned Debian kernel,
so if you need to run APC there you might want to uncomment first line
of `mod/itc-mod.c'.

2.4 series of kernels were never tested on SMP as such the module will
refuse to build for them.

               This is APC - graphical CPU load meter.

It is more suitable/accurate in situations where applications generate
"short" periodic bursts of activity.

It works by measuring the time spent in  the kernels idle handler. CPU
load time is taken to mean:

     time spent in idle handler
1 -  --------------------------
        total time elapsed

Con Kolivas  in  his post on   LKML (
described  the way   Linux  gathers information   that it exports   to
`/proc/stat' (at least for "boring"  architectures), this method is by
no means accurate and can "lie" in either direction.

You can witness this  by running the `hog'  example and, if  stars are
aligned  correctly, you will notice  that something is wrong with what
`/proc/stat' claims. Since most of the CPU monitoring applications use
`/proc/stat' they will produce incorrect results too.

Note that  dyntick  kernels  will most   likely produce  different but
still incorrect accounting. 
(For more information: and bellow)

Kernel (starting with version 2.6.21) comes with a document describing
the  way accounting is currently  done and problems with this approach

Following thread describes a take on addressing the issue properly:

Apart    from   being inaccurate,  `/proc/stat'  exports monotonically
increasing load times but _NOT_  real time[1], so there's omni-present
sub-jiffy error. Not to mention that jiffy resolution is somewhat low.

If you are  not running RT kernel  and  need sorta-kinda, semi-correct
load meter in situation when `/proc/stat' is disconnected with reality
APC might present a better choice.

The kernel  module part  of APC   tries to insert  itself  as  a power
management idle  handler and when  invoked measure  how  much time  is
spent executing previous/default one - this information is represented
by yellow color, values  obtained via `/proc/stat' are represented  by

You  can use `-help' command  line option to   get a brief overview of
tunable parameters.

Tested on[2]:

Linux 2.4.30   - AMD Athlon(tm) Processor (1.4 Ghz)
Linux - AMD Athlon(tm)64 X2 Dual Core Processor  3800+
Linux 2.6.18   - AMD Athlon(tm)64 3800+
Linux - PowerPC 7447A
Linux - PowerPC 7447A
Linux 2.6.19   - [some Core 2 Duo]

It's possible  that RMClock[3]  does something similar(load  measuring
wise) on Microsoft Windows.

[1] Unlike `/proc/uptime'. But this one is useless for SMP
[2] SMP not tested on 2.4 kernels, nor QUIRK mode. SMP on PPC wasn't
    tested either

To build idlestat (boring console application) you will need:

GCC    -

Plus all what is required to build a kernel module.


$ gcc -o idlestat idlestat.c
$ cd mod && make

Idlestat (as well as APC) requires kernel module to be loaded in order
for it to operate. Module loading is described below.

To build APC (graphical application with bells etc) you will need:

OCaml  -
LablGL -
         (and by extension some OpenGL implementation)
GLUT   -
GCC    -

Plus all what is required to build a kernel module.


<untar and go to directory with sources>
$ sh build.linux

# if following step fails(on X86) read next section before trying to
# execute mknod
$ su -c 'insmod mod/itc.ko' - 2.6 Kernels
$ su -c 'insmod mod/itc.o'  - 2.4 Kernels

$ su -c "chmod +r /dev/itc"

[make sure you are in X]
$ ./apc

Following applies only to Linux running on X86.

If the module fails to load consult dmesg(8). Most likely cause is the
lack of exported `default_idle'  function. Few workarounds follow.


    Variant 1
        Add `idle=halt' to the  kernel command line (method depends on
        the boot-loader) and reboot.

    Variant 2 (DANGEROUS)
        Kernel 2.6
        $ func=$(awk '/default_idle$/ {print "0x" $1}' /proc/kallsyms)
        $ su -c "/sbin/insmod mod/itc.ko idle_func=$func"

        Kernel 2.4
        $ func=$(awk '/default_idle$/ {print "0x" $1}' /proc/ksyms)
        $ su -c "/sbin/insmod mod/itc.o idle_func=$func"

2014-07-27 malchmmphmaster
2014-07-27 malcdarn
2014-07-27 malcuh
2014-07-27 malcyeah well
2014-07-27 malcErm...
2013-03-03 malcSample wall clock before idle time
2013-03-03 malcRemove unused variable
2013-03-03 malcMake sure idle times are properly initialized for all...
2013-03-03 malcEh?
2012-04-26 malcShrug
2012-04-26 malcModule for 3.x kernels
2012-04-26 malcModule for 3.x kernels
2011-05-06 malcDrop ioctl
2011-04-12 malcShrug
2010-06-15 malcUgly hack for NVidia drivers
2010-06-15 malcAdd modules.order
8 years ago v1.02
8 years ago v1.01
8 years ago v1.00b
8 years ago v1.00a
8 years ago v1.00
8 years ago v0.99
8 years ago v0.98b
8 years ago v0.98a
8 years ago v0.98
8 years ago v0.97c
8 years ago v0.97b
8 years ago v0.97a
8 years ago v0.97
8 years ago v0.96
8 years ago v0.95
8 years ago v0.94
16 months ago master