Subject: Re: clock(3) possible bug
To: <>
From: David Laight <david@l8s.co.uk>
List: netbsd-bugs
Date: 08/19/2003 09:45:08
On Tue, Aug 19, 2003 at 12:09:34AM +0100, Root wrote:
> 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.

I've commited a (slightly differnt) fix.

The returned value is still not necessarily monotonic.
But my tests are showing about 1 error per 1000 ticks rather than
errors on great tracts of boundaries.

The problem comes from the way time is apportioned - especially that
deemed to be 'interrupt time'

	David

-- 
David Laight: david@l8s.co.uk