Subject: clock(3) possible bug
To: None <netbsd-bugs@netbsd.org>
From: Root <root@theforest.plus.com>
List: netbsd-bugs
Date: 08/19/2003 00:09:34
Sometime clock() will appear to lose a tick when really abused (I was
porting TiLP, and timeouts were occuring regularly).

I tested using getrusage() which clock() calls. The way that the
system/user cpu times are added allow for values to be lost enough to drop
a single (CLOCKS_PER_SEC).

When the timeval tv_usec/tv_sec values are added separately, it works
ok. e.g.

etv.tv_sec=ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
etv.tv_usec=ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;
etv.tv_sec+=etv.tv_usec / 1000000;
etv.tv_usec=etv.tv_usec % 1000000;

return((clock_t)(CONVTCK(etv)));

It is certainly a minor thing, just thought I'd mention it.

Richard Smith