~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ WARNING 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 (http://lkml.org/lkml/2007/2/12/7) 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: http://lkml.org/lkml/2007/6/14/301 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 (Documentation/cpu-load.txt) Following thread describes a take on addressing the issue properly: http://marc.info/?t=117480935100001&r=1&w=2 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 depend on 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 red. 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 2.6.17.6 Linux 2.6.19.2 - AMD Athlon(tm)64 X2 Dual Core Processor 3800+ Linux 2.6.18 - AMD Athlon(tm)64 3800+ Linux 2.6.18.3 - PowerPC 7447A Linux 2.6.20.1 - 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 [3] http://cpu.rightmark.org/products/rmclock.shtml ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To build idlestat (boring console application) you will need: GCC - http://gcc.gnu.org/ Plus all what is required to build a kernel module. Process: $ 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 - http://caml.inria.fr/ocaml/ LablGL - http://wwwfun.kurims.kyoto-u.ac.jp/soft/lsl/lablgl.html (and by extension some OpenGL implementation) GLUT - http://www.opengl.org/resources/libraries/glut/ http://freeglut.sourceforge.net/ GCC - http://gcc.gnu.org/ Plus all what is required to build a kernel module. Process: $ 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. Workarounds 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" ======================================================================