Subject: Re: kern/30115: getrusage returns bogus ru_utime values
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <mlelstv@serpens.de>
List: netbsd-bugs
Date: 05/02/2005 19:06:02
The following reply was made to PR kern/30115; it has been noted by GNATS.

From: mlelstv@serpens.de
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/30115: getrusage returns bogus ru_utime values
Date: Mon, 2 May 2005 21:05:33 +0200

 john@iastate.edu writes:
 
 >	Two calls of getrusage surround a function which does some amount
 >	of work.  Sometimes the second call indicates that the process has
 >	used less user time (ru_utime) than was used before the function.
 
 This is an artifact of the measurement and was reported in bin/10201.
 
 The reason is that the scheduler keeps a precise total cpu time of
 a process but the systime/usertime is only sampled by a much slower
 clock. The ratio systime/usertime is then used to return an approximation
 so that systime and usertime sum up to the total time(*).
 
 As a result it is possible that usertime or systime go backwards.
 
 FreeBSD has implemented a workaround by remembering reported
 usertime/systime values for a process and clamping getrusage()
 against these values. As a result the usertime/systime value
 is usually too high but it is monotonic.
 
 Another approach would be to round down the usertime/systime values,
 by not approximating 'measurments' that do not exist. The result
 would be that usertime/systime values that are too low and don't
 sum up to the total CPU time but are again monotonic.
 
 The approximation is done in kern_resource/calc().
 (*) The sampled interrupt time is also included.
 
 -- 
                                 Michael van Elst
 Internet: mlelstv@serpens.de
                                 "A potential Snark may lurk in every tree."