NetBSD Problem Report #30115

From john@netreg-2.ait.iastate.edu  Mon May  2 14:49:55 2005
Return-Path: <john@netreg-2.ait.iastate.edu>
Received: from mailhub-5.iastate.edu (mailhub-5.iastate.edu [129.186.140.15])
	by narn.netbsd.org (Postfix) with ESMTP id 5E94863B117
	for <gnats-bugs@gnats.netbsd.org>; Mon,  2 May 2005 14:49:55 +0000 (UTC)
Message-Id: <200505021449.j42Enl514844@netreg-2.ait.iastate.edu>
Date: Mon, 2 May 2005 09:49:48 -0500 (CDT)
From: john@iastate.edu
To: gnats-bugs@netbsd.org
Subject: getrusage returns bogus ru_utime values
X-Send-Pr-Version: 3.95

>Number:         30115
>Category:       kern
>Synopsis:       getrusage returns bogus ru_utime values
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon May 02 14:50:00 +0000 2005
>Last-Modified:  Fri Apr 08 10:40:01 +0000 2011
>Originator:     john@iastate.edu
>Release:        NetBSD 1.6.1_STABLE
>Organization:
	Iowa State University
>Environment:
System: NetBSD netreg-2.ait.iastate.edu 1.6.1_STABLE NetBSD 1.6.1_STABLE (NETREG) #0: Mon May 10 14:59:57 CDT 2004 root@socrates.ait.iastate.edu:/tmp/compile/NETREG i386
Architecture: i386
Machine: i386
>Description:
	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.
	For example the first call might return 0 seconds, 913842 usecs
        and then second call might later return 0 seconds, 913803 usecs
        which would seem to indicate that the function used the cpu for
	a negative 39 usecs.  This does not always happen, and I
	have never seen it happen in the system time (ru_stime)
>How-To-Repeat:
	several times, call getrusage() around a function that does
	some small amount of work.  See if the second call shows a
	lower value than the first in ru_stime.
>Fix:

>Audit-Trail:
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."

From: "Jukka Ruohonen" <jruoho@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/30115 CVS commit: src/tests/syscall
Date: Wed, 6 Apr 2011 06:46:16 +0000

 Module Name:	src
 Committed By:	jruoho
 Date:		Wed Apr  6 06:46:15 UTC 2011

 Modified Files:
 	src/tests/syscall: t_getrusage.c

 Log Message:
 Add heuristic evaluation of PR kern/30115.


 To generate a diff of this commit:
 cvs rdiff -u -r1.2 -r1.3 src/tests/syscall/t_getrusage.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Jukka Ruohonen" <jruoho@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/30115 CVS commit: src/tests/syscall
Date: Fri, 8 Apr 2011 10:36:09 +0000

 Module Name:	src
 Committed By:	jruoho
 Date:		Fri Apr  8 10:36:09 UTC 2011

 Modified Files:
 	src/tests/syscall: t_getrusage.c

 Log Message:
 Adjust for the tracker PR kern/30115 for this over 15 year old bug.


 To generate a diff of this commit:
 cvs rdiff -u -r1.5 -r1.6 src/tests/syscall/t_getrusage.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.