CPU time mismeasurement

John Summerfield (summer@os2.ami.com.au)
Fri, 19 Jun 1998 14:47:15 +0800 (WST)


I began thinking this is definitely a kernel bug. Now I'm not so sure. I'm
running a 2.0 kernel but have a 2.1 source tree in place and libraries are
those versions required for recent 2.1 kernels.

I have a program that used to report its CPU usage (or at least a
believable approximation). I made a few changes to other areas and the CPU
time measurement's broken.

When I began this I thought CLOCK_PER_SEC must have changed recently but I
now see that's not so,
Let me explain the program output:
[summer@possum indexes]$ ls /home/summer/*/bin/dircon
-rwxrwxr-x 1 summer summer 22290 Jun 19 13:49
/home/summer/r/bin/dircon
-rwxrwxr-x 1 summer summer 22252 Jun 19 1998
/home/summer/s/bin/dircon
[summer@possum indexes]$ ls -lR /mnt/cdrom/ | /home/summer/r/bin/dircon
-d /mnt/cdrom -h possum >rep
Init stime(0.000000)
host(possum) dir(/mnt/cdrom/) basedir(/mnt/cdrom/) ifile()
Records(1550) Elapsed(4s) cpu(600.000000s)
s(0.000000) e(60000.000000), C(100)
[summer@possum indexes]$ ls -lR /mnt/cdrom/ | /home/summer/s/bin/dircon
-d /mnt/cdrom -h possum >rep
Init stime(0.000000)
host(possum) dir(/mnt/cdrom/) basedir(/mnt/cdrom/) ifile()
Records(1550) Elapsed(1s) cpu(0.050000s)
s(0.000000) e(5.000000), C(100)

On the last line above, s(..) lists the value returned by clock() on the
first call, e(..) reports the final value and C(..) the value of
CLOCKS_PER_SEC.

When I saw this
/* CAE XSH, Issue 4, Version 2: <time.h>
The value of CLOCKS_PER_SEC is required to be 1 million on all
XSI-conformant systems. */
# define CLOCKS_PER_SEC 1000000

in /usr/include/timebits.h I figured that time.h was broken. however, I
see that my rh 4.2 system has CLOCKS_PER_SEC set to 100 just as it is on
RH5.
(I've just compiled & run on emu with standard Rh5 runtime and kernel
2.0.34 postbeta:
s(0.000000) e(30000.000000), C(1000000))

The CPU times reported by this version seem reasonable.

/home/summer/r is my home directory structure on emu, a P133 with Rh5.
/home/summer/s is my home directory structure on quokka, an i486 with
Rh4.2.

My workstation is possum, PII-233, RH5 plus
-rwxr-xr-x 1 root root 3057702 Apr 19 03:01 /lib/libc-2.0.7.so
lrwxrwxrwx 1 root root 14 May 12 04:09 /lib/libc.so.5 ->
libc.so.5.4.44
-rwxr-xr-x 1 root root 35500 May 12 04:09 /lib/libc.so.5.4.44
lrwxrwxrwx 1 root root 13 May 12 02:54 /lib/libc.so.6 ->
libc-2.0.7.so
lrwxrwxrwx 1 root root 17 Sep 7 1997
/lib/libcom_err.so.2 -> libcom_err.so.2.0
-rwxr-xr-x 1 root root 6233 Oct 15 1997
/lib/libcom_err.so.2.0
-rwxr-xr-x 1 root root 181956 Apr 19 03:06
/lib/libcrypt-2.0.7.so
lrwxrwxrwx 1 root root 17 May 9 16:29 /lib/libcrypt.so.1
-> libcrypt-2.0.7.so

[summer@possum indexes]$ gcc --version
2.7.2.3

Linux version 2.0.33 (root@possum.my.ami.com.au) (gcc version 2.7.2.3)

Oh,
[summer@possum indexes]$ ls /usr/src
total 11
lrwxrwxrwx 1 summer summer 13 Jun 12 09:16 linux ->
linux-2.1.105
drwxr-xr-x 7 summer summer 1024 May 8 17:49 linux-2.0.30
drwxr-xr-x 16 summer summer 1024 May 23 09:38 linux-2.0.32
drwxr-xr-x 15 summer summer 1024 Jun 4 13:05 linux-2.0.33
drwxr-xr-x 15 summer summer 1024 Jun 13 21:06 linux-2.1.105
drwxr-xr-x 15 summer summer 1024 Mar 26 18:15 linux-2.1.90
drwxr-xr-x 3 josu josu 1024 Jan 5 11:50 pgsql
drwxr-xr-x 7 root root 1024 Nov 1 1997 redhat

I'm using glibc libraries on 5.0, libc on 4.2.
Here are the relevant lines of source code:
[summer@possum source]$ grep cputime dircon.cpp
double scputime=(double)clock(),ecputime, ccputime;
fprintf(stderr,"Init stime(%f)\n",scputime);
ecputime=(double)clock();
ccputime=(ecputime-scputime)/CLOCKS_PER_SEC;
count,(long) (etime-stime),ccputime);
fprintf(stderr,"s(%f) e(%f),
C(%d)\n",scputime,ecputime,CLOCKS_PER_SEC);

Cheers
John Summerfield
http://os2.ami.com.au/os2/ for OS/2 support.
Configuration, networking, combined IBM ftpsites index.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu