-----
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 kernels).
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
To apply the patch, simply copy the smp_cpu_usage_patch.diff file to
/usr/src/linux, 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...
You can find the xosview patch at :
http://www-isia.cma.fr/~forissie/smp_kernel_patch/
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
--
Michael Meissner, Cygnus Solutions (Massachusetts office)
4th floor, 955 Massachusetts Avenue, Cambridge, MA 02139, USA