Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Nov 2012 11:29:08 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r242957 - head/sys/kern
Message-ID:  <201211131129.qADBT8pG038301@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trasz
Date: Tue Nov 13 11:29:08 2012
New Revision: 242957
URL: http://svnweb.freebsd.org/changeset/base/242957

Log:
  Don't divide by zero.
  
  Tested by:	swills

Modified:
  head/sys/kern/kern_racct.c

Modified: head/sys/kern/kern_racct.c
==============================================================================
--- head/sys/kern/kern_racct.c	Tue Nov 13 08:35:25 2012	(r242956)
+++ head/sys/kern/kern_racct.c	Tue Nov 13 11:29:08 2012	(r242957)
@@ -921,9 +921,12 @@ racct_proc_exit(struct proc *p)
 #endif
 	microuptime(&wallclock);
 	timevalsub(&wallclock, &p->p_stats->p_start);
-	pct_estimate = (1000000 * runtime * 100) /
-	    ((uint64_t)wallclock.tv_sec * 1000000 +
-	    wallclock.tv_usec);
+	if (wallclock.tv_sec > 0 || wallclock.tv_usec > 0) {
+		pct_estimate = (1000000 * runtime * 100) /
+		    ((uint64_t)wallclock.tv_sec * 1000000 +
+		    wallclock.tv_usec);
+	} else
+		pct_estimate = 0;
 	pct = racct_getpcpu(p, pct_estimate);
 
 	mtx_lock(&racct_lock);
@@ -1136,9 +1139,12 @@ racctd(void)
 				runtime = p->p_prev_runtime;
 #endif
 			p->p_prev_runtime = runtime;
-			pct_estimate = (1000000 * runtime * 100) /
-			    ((uint64_t)wallclock.tv_sec * 1000000 +
-			    wallclock.tv_usec);
+			if (wallclock.tv_sec > 0 || wallclock.tv_usec > 0) {
+				pct_estimate = (1000000 * runtime * 100) /
+				    ((uint64_t)wallclock.tv_sec * 1000000 +
+				    wallclock.tv_usec);
+			} else
+				pct_estimate = 0;
 			pct = racct_getpcpu(p, pct_estimate);
 			mtx_lock(&racct_lock);
 			racct_set_force_locked(p, RACCT_PCTCPU, pct);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201211131129.qADBT8pG038301>