From bw@exile.desync.com  Thu Sep 20 15:56:15 2012
Return-Path: <bw@exile.desync.com>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 85B4E106566B
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 20 Sep 2012 15:56:15 +0000 (UTC)
	(envelope-from bw@exile.desync.com)
Received: from exile.desync.com (exile.desync.com [IPv6:2607:f178::167])
	by mx1.freebsd.org (Postfix) with ESMTP id 0F2378FC0A
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 20 Sep 2012 15:56:14 +0000 (UTC)
Received: by exile.desync.com (Postfix, from userid 666)
	id 0B46B2D92; Thu, 20 Sep 2012 11:56:15 -0400 (EDT)
Message-Id: <20120920155615.0B46B2D92@exile.desync.com>
Date: Thu, 20 Sep 2012 11:56:15 -0400 (EDT)
From: Ben Wilber <ben@desync.com>
Reply-To: Ben Wilber <ben@desync.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] rctl(8) cputime is too high
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         171811
>Category:       kern
>Synopsis:       [patch] rctl(8) cputime is too high
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    trasz
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 20 16:00:22 UTC 2012
>Closed-Date:    
>Last-Modified:  Mon Feb 03 11:16:31 UTC 2014
>Originator:     Ben Wilber
>Release:        FreeBSD 10.0-CURRENT amd64
>Organization:
>Environment:
System: FreeBSD exile 10.0-CURRENT FreeBSD 10.0-CURRENT #1 r240178M: Thu Sep 6 19:25:33 EDT 2012 bw@exodus:/usr/obj/usr/src/sys/COMRADE amd64

>Description:

rctl's idea of cputime is unreasonably high with lots of process turnover.

>How-To-Repeat:

# jail -c command=sh
jail# while true; do id > /dev/null; done

meanwhile:

# dtrace -n 'rusage:add-cred/args[0]->cr_prison->pr_id != 0 && args[1] == 0/{printf("%d: jail %d cputime %d", pid, args[0]->cr_prison->pr_id, args[2])}'
5  57139                  rusage:add-cred 37375: jail 5 cputime 124211
5  57139                  rusage:add-cred 37375: jail 5 cputime 6330
5  57139                  rusage:add-cred 37375: jail 5 cputime 51237828
5  57139                  rusage:add-cred 37375: jail 5 cputime 173602
5  57139                  rusage:add-cred 37375: jail 5 cputime 6834680
(...)

>Fix:

Attached patch seems to help.

--- kern_racct.diff begins here ---
Index: kern_racct.c
===================================================================
diff --git a/head/sys/kern/kern_racct.c b/head/sys/kern/kern_racct.c
--- a/head/sys/kern/kern_racct.c	(revision 240705)
+++ b/head/sys/kern/kern_racct.c	(working copy)
@@ -607,7 +607,9 @@
 	/*
 	 * We don't need to calculate rux, proc_reap() has already done this.
 	 */
+	PROC_SLOCK(p);
 	runtime = cputick2usec(p->p_rux.rux_runtime);
+	PROC_SUNLOCK(p);
 #ifdef notyet
 	KASSERT(runtime >= p->p_prev_runtime, ("runtime < p_prev_runtime"));
 #else
--- kern_racct.diff ends here ---

>Release-Note:
>Audit-Trail:

From: ben wilber <ben@desync.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/171811: [patch] rctl(8) cputime is too high
Date: Fri, 21 Sep 2012 03:51:18 -0400

 Sorry, please ignore my patch; I guess the problem is just that =
 p_prev_runtime is never initialized.  I'm not sure why it exists, but =
 removing it makes things work as expected.=
Responsible-Changed-From-To: freebsd-bugs->trasz 
Responsible-Changed-By: trasz 
Responsible-Changed-When: Mon Feb 3 11:16:30 UTC 2014 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=171811 
>Unformatted:
