Date: Sun, 29 Oct 1995 12:57:47 +0100 (MET) From: Andreas Klemm <andreas@knobel.gun.de> To: hackers@freebsd.org, current@freebsd.org, jkh@freebsd.org Subject: time -l, floating point exeption, division through '0'. trace + FIX ! Message-ID: <199510291157.MAA00781@knobel.gun.de>
next in thread | raw e-mail | index | archive | help
Hi !
The problem is, that calling '/usr/bin/time -l' often results in a
floating point exception, caused by a division through zero (long ticks) !
This works seems to be, that the value computed for ticks is ok here (>=1).
knobel# /usr/bin/time -l du
1 ./.tin/.news
1 ./.tin/.save
14 ./.tin
1 ./Mail
1 ./News
1 ./.elm
62 .
0.06 real 0.00 user 0.02 sys
508 maximum resident set size
12 average shared memory size
20 average unshared data size
192 average unshared stack size
96 page reclaims
0 page faults
0 swaps
6 block input operations
0 block output operations
0 messages sent
0 messages received
0 signals received
6 voluntary context switches
5 involuntary context switches
But look at the following:
knobel# /usr/bin/time -l /bin/ls
.cshrc .history .newsrc Mail
.elm .klogin .profile News
.gopherrc .login .tin xxx
.gopherrc~ .ncrecent .xboing-scores xxx.c
0.01 real 0.00 user 0.00 sys
216 maximum resident set size
Floating exception (core dumped)
Here what happens:
Program terminated with signal 8, Floating point exception.
#0 0x1af0 in main (argc=1, argv=0xefbfd9f8)
at /local/FreeBSD/src-stable/usr.bin/time/time.c:112
112 fprintf(stderr, "%10ld %s\n",
(gdb) list
107
108 ticks = hz * (ru.ru_utime.tv_sec + ru.ru_stime.tv_sec) +
109 hz * (ru.ru_utime.tv_usec + ru.ru_stime.tv_usec) / 1000000;
110 fprintf(stderr, "%10ld %s\n",
111 ru.ru_maxrss, "maximum resident set size");
112 fprintf(stderr, "%10ld %s\n",
113 ru.ru_ixrss / ticks, "average shared memory size");
114 fprintf(stderr, "%10ld %s\n",
115 ru.ru_idrss / ticks, "average unshared data size");
116 fprintf(stderr, "%10ld %s\n",
(gdb) r -l /bin/ls
Starting program: /usr/bin/time -l /bin/ls
.cshrc .history .newsrc Mail xxx.c
.elm .klogin .profile News
.gopherrc .login .tin time.core
.gopherrc~ .ncrecent .xboing-scores xxx
0.02 real 0.00 user 0.00 sys
0 maximum resident set size
Program received signal SIGFPE, Arithmetic exception.
0x1af0 in main (argc=1, argv=0xefbfd9f8)
at /local/FreeBSD/src-stable/usr.bin/time/time.c:112
112 fprintf(stderr, "%10ld %s\n",
(gdb) display ru.ru_ixrss, ticks
1: ru.ru_ixrss, ticks = 0
(gdb) display ru.ru_ixrss
2: ru.ru_ixrss = 0
(gdb) display ticks
3: ticks = 0
When ticks is equal to zero, then the program dumps core....
ticks (long) will be computed as follows:
ticks = hz * (ru.ru_utime.tv_sec + ru.ru_stime.tv_sec) +
hz * (ru.ru_utime.tv_usec + ru.ru_stime.tv_usec) / 1000000;
ticks = 100 * ( 0 + 0 ) +
100 * ( 0 + 7415 ) / 1000000;
In this case ticks would be 0.74, but because of long ticks -> 0.
A simple hack would be, to force ticks to be at least '1'. This could be
done by simply adding '1'....
What do you think ?????
*** time.c.orig Fri May 27 14:32:52 1994
--- time.c Sun Oct 29 12:50:26 1995
***************
*** 105,112 ****
int hz = 100; /* XXX */
long ticks;
! ticks = hz * (ru.ru_utime.tv_sec + ru.ru_stime.tv_sec) +
! hz * (ru.ru_utime.tv_usec + ru.ru_stime.tv_usec) / 1000000;
fprintf(stderr, "%10ld %s\n",
ru.ru_maxrss, "maximum resident set size");
fprintf(stderr, "%10ld %s\n",
--- 105,113 ----
int hz = 100; /* XXX */
long ticks;
! ticks = hz * (ru.ru_utime.tv_sec + ru.ru_stime.tv_sec)
! + hz * (ru.ru_utime.tv_usec + ru.ru_stime.tv_usec)
! / 1000000 + 1; /* XXX avoid division through zero */
fprintf(stderr, "%10ld %s\n",
ru.ru_maxrss, "maximum resident set size");
fprintf(stderr, "%10ld %s\n",
--
$$ apsfilter - magic print filter 4lpd @home : andreas@knobel.gun.de
$$ ftp://sunsite.unc.edu @work : andreas@sunny.wup.de
$$ /pub/Linux/system/Printing/aps-491.tgz knobel: >>> powered by FreeBSD <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199510291157.MAA00781>
