Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 31 Jul 2012 18:57:09 +0000
From:      rudot@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r239963 - soc2012/rudot/sys/kern
Message-ID:  <20120731185709.13CF9106566C@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rudot
Date: Tue Jul 31 18:57:08 2012
New Revision: 239963
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239963

Log:
  use special way to calculate %cpu for short-lived processes. Work in progress.

Modified:
  soc2012/rudot/sys/kern/kern_racct.c

Modified: soc2012/rudot/sys/kern/kern_racct.c
==============================================================================
--- soc2012/rudot/sys/kern/kern_racct.c	Tue Jul 31 17:32:28 2012	(r239962)
+++ soc2012/rudot/sys/kern/kern_racct.c	Tue Jul 31 18:57:08 2012	(r239963)
@@ -282,7 +282,7 @@
  * work.
  */
 static u_int
-racct_getpcpu(struct proc *p)
+racct_getpcpu(struct proc *p, u_int pcpu)
 {
 	u_int swtime;
 #ifdef SCHED_4BSD
@@ -298,6 +298,14 @@
 	swtime = (ticks - p->p_swtick) / hz;
 	if ((swtime == 0) || ((p->p_flag & P_INMEM) == 0))
 		return (0);
+	if (swtime < 20) {
+		/*
+		 * For short-lived processes, the sched_pctcpu() returns small
+		 * values even for cpu intensive processes. Therefore we use
+		 * our own estimate in this case.
+		 */
+		return (pcpu);	
+	}
 
 	p_pctcpu = 0;
 	FOREACH_THREAD_IN_PROC(p, td) {
@@ -1002,7 +1010,7 @@
 	struct proc *p;
 	struct timeval wallclock;
 	uint64_t runtime;
-	u_int pct;
+	u_int pct, pct_estimate;
 	int over_limits;
 
 	for (;;) {
@@ -1036,7 +1044,10 @@
 				runtime = p->p_prev_runtime;
 #endif
 			p->p_prev_runtime = runtime;
-			pct = racct_getpcpu(p);
+			pct_estimate = (runtime * 100) /
+			    ((uint64_t)wallclock.tv_sec * 1000000 +
+			    wallclock.tv_usec);
+			pct = racct_getpcpu(p, pct_estimate);
 			mtx_lock(&racct_lock);
 			over_limits = racct_set_check_locked(p, RACCT_PCTCPU, pct);
 			if (over_limits) {



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