--------------------------------------------------------------------------------
README file - Linux kernel 2.0.14 patch to add per-cpu usage information to
              /proc/stat
--------------------------------------------------------------------------------

This patch is provided in the hope it will be helpful, but with no warranty of
any kind.

--------------------------------------------------------------------------------

1) Purpose of this patch

Under the current versions of the Linux kernel, it is not possible to get
detailed cpu times for each processor of an SMP system (i.e. user/nice/system
/idle time spent on each processor).

The /proc/stat pseudo-file only provides global time information.

This patch creates new entries in /proc/stat so that time spend in various
system states appears for each processor.

I decided to make this patch when I compiled the 'xosview' utility and realized
that it could not display detailed cpu activity for each processor on an SMP
system.

2) Changes made in /proc/stat

Before the patch, a typical /proc/stat dump would look like :

cpu  7942 5410 2591 185661
disk 8768 0 0 0
disk_rio 7166 0 0 0
disk_wio 1602 0 0 0
disk_rblk 10486 0 0 0
disk_wblk 4206 0 0 0
page 19359 5003
swap 72 367
intr 256109 201604 3934 0 0 41763 1 2 0 0 8804 0 0 0 1 0 0
ctxt 214658
btime 848340657
processes 298

With the patch applied on a 2-cpu system, it would look like :

cpu  7942 5410 2591 371322
cpu0  4354 3182 1811 185661
cpu1  3588 2228 780 185661
disk 8768 0 0 0
disk_rio 7166 0 0 0
disk_wio 1602 0 0 0
disk_rblk 10486 0 0 0
disk_wblk 4206 0 0 0
page 19359 5003
swap 72 367
intr 256109 201604 3934 0 0 41763 1 2 0 0 8804 0 0 0 1 0 0
ctxt 214658
btime 848340657
processes 298

The first line still displays the total times for the system (the idle time is
multiplied by the number of cpus, I believe this field was incorrect in
2.0.14. See the 'array.c.diff' file.).

The following lines give the times for each cpu present in the system (n lines
for n processors). Each processor is identified by the string 'cpu<i>', i being
an integer between 0 and (smp_num_cpus-1).

3) The modified files

/usr/src/linux/fs/proc/array.c
/usr/src/linux/kernel/sched.c
/usr/src/linux/include/kernel_stat.h

The 'diff -u' files are : array.c.diff, sched.c.diff, kernel_stat.h.diff. To
apply the patch, simply copy each .diff file to the corresponding directory,
and do a 'patch <filename>.diff'.

4) Remarks

First of all, I developped this little patch on a SuperMicro P6D0F PentiumPro
mainboard equipped with only 1 processor. So it is not very useful for me
up to now (it will be as soon as I can afford another P6-200 ! :-}).
Therefore, I could not test this patch as much as I would like to.

I read in Linux-related newsgroups that the time spent on other processors than
cpu#0 is considered to be always 100% system (or 100% user, don't remember). I
suppose this problem will show up clearly with this patch :-}. Maybe I will
try to know more about that if I get a 2nd cpu.

There should be no major problem, however, except one thing: the changes in the
format of /proc/stat may break some programs that rely on the fact that, say,
the swap info are in the 8th line of that file. I believe that, for efficiency
reasons, many programs do not check the content of the first field to find the
correct /proc/stat line.

As for now, I've been using the patched version for about 2 months without any 
problem. I compiled a modified version of 'xosview' that displays several cpu
bars, one for the total time and one for each cpu. Total and cpu0 show the
same thing on my 1-cpu system, so up to that point everything seems to be OK...

If you have remarks about this patch you can e-mail me. I will appreciate
feedback.

---
Jerome Forissier
ISIA
Ecole des Mines de Paris - Sophia Antipolis - France
<forissie@isia.cma.fr>
