Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 May 2012 20:51:20 +0000
From:      rudot@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r236685 - in soc2012/rudot: aux sys/kern
Message-ID:  <20120529205120.A7052106567D@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rudot
Date: Tue May 29 20:51:19 2012
New Revision: 236685
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=236685

Log:
  set the pcpu racct resource in the racctd while enumerating all procs. Thus also processes that start sleeping for a longer time have their pcpu resource updated.

Added:
  soc2012/rudot/aux/list_changes.sh   (contents, props changed)
Modified:
  soc2012/rudot/sys/kern/kern_racct.c
  soc2012/rudot/sys/kern/sched_4bsd.c

Added: soc2012/rudot/aux/list_changes.sh
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2012/rudot/aux/list_changes.sh	Tue May 29 20:51:19 2012	(r236685)
@@ -0,0 +1,40 @@
+usage()
+{
+	echo "Usage: $0 [-v] [-w]"
+}
+
+VERBOSE=
+WRITE=
+
+while getopts "vw" OPTION
+do
+	case $OPTION in
+		v)
+			VERBOSE=1
+			;;
+		w)
+			WRITE=1
+			;;
+		?)
+			usage
+			exit
+			;;
+	esac
+done
+
+FILES=`find ../sys -name "*.[ch]"`
+
+for file in $FILES
+do
+	tree_file=/usr/src/${file#*/}
+	if [ -n "$WRITE" ]; then
+		if ! diff -q $file $tree_file > /dev/null; then
+			echo "Copying $tree_file to $file"
+			cp "$tree_file" "$file"
+		fi
+	elif [ -z "$VERBOSE" ]; then
+		diff -q "$file" "$tree_file"
+	else
+		diff -u "$file" "$tree_file"
+	fi
+done

Modified: soc2012/rudot/sys/kern/kern_racct.c
==============================================================================
--- soc2012/rudot/sys/kern/kern_racct.c	Tue May 29 19:55:07 2012	(r236684)
+++ soc2012/rudot/sys/kern/kern_racct.c	Tue May 29 20:51:19 2012	(r236685)
@@ -413,8 +413,8 @@
 	return (error);
 }
 
-void
-racct_set_force(struct proc *p, int resource, uint64_t amount)
+static void
+racct_set_force_locked(struct proc *p, int resource, uint64_t amount)
 {
 	int64_t diff;
 
@@ -425,13 +425,19 @@
 	 */
 	PROC_LOCK_ASSERT(p, MA_OWNED);
 
-	mtx_lock(&racct_lock);
 	diff = amount - p->p_racct->r_resources[resource];
 	racct_alloc_resource(p->p_racct, resource, diff);
 	if (diff > 0)
 		racct_add_cred_locked(p->p_ucred, resource, diff);
 	else if (diff < 0)
 		racct_sub_cred_locked(p->p_ucred, resource, -diff);
+}
+
+void
+racct_set_force(struct proc *p, int resource, uint64_t amount)
+{
+	mtx_lock(&racct_lock);
+	racct_set_force_locked(p, resource, amount);
 	mtx_unlock(&racct_lock);
 }
 
@@ -696,6 +702,8 @@
 	struct proc *p;
 	struct timeval wallclock;
 	uint64_t runtime;
+	fixpt_t pctcpu;
+	int pct_human;
 
 	for (;;) {
 		sx_slock(&allproc_lock);
@@ -706,10 +714,15 @@
 
 			microuptime(&wallclock);
 			timevalsub(&wallclock, &p->p_stats->p_start);
+			pctcpu = 0;
 			PROC_LOCK(p);
 			PROC_SLOCK(p);
-			FOREACH_THREAD_IN_PROC(p, td)
+			FOREACH_THREAD_IN_PROC(p, td) {
 				ruxagg(p, td);
+				thread_lock(td);
+				pctcpu += sched_pctcpu(td);
+				thread_unlock(td);
+			}
 			runtime = cputick2usec(p->p_rux.rux_runtime);
 			PROC_SUNLOCK(p);
 #ifdef notyet
@@ -720,7 +733,14 @@
 				runtime = p->p_prev_runtime;
 #endif
 			p->p_prev_runtime = runtime;
+			pct_human = (100 * pctcpu) / FSCALE;
 			mtx_lock(&racct_lock);
+			/*
+			 * I use _force_ here because we always want to have
+			 * the real value in the RACCT_PCTCPU resource
+			 * regardless of the limits set.
+			 */
+			racct_set_force_locked(p, RACCT_PCTCPU, pct_human);
 			racct_set_locked(p, RACCT_CPU, runtime);
 			racct_set_locked(p, RACCT_WALLCLOCK,
 			    (uint64_t)wallclock.tv_sec * 1000000 +

Modified: soc2012/rudot/sys/kern/sched_4bsd.c
==============================================================================
--- soc2012/rudot/sys/kern/sched_4bsd.c	Tue May 29 19:55:07 2012	(r236684)
+++ soc2012/rudot/sys/kern/sched_4bsd.c	Tue May 29 20:51:19 2012	(r236685)
@@ -694,7 +694,6 @@
 	struct pcpuidlestat *stat;
 	struct td_sched *ts;
 #ifdef RACCT
-	int error;
 	int pct_human;
 	fixpt_t pctcpu;
 	struct thread *tdp;
@@ -732,9 +731,8 @@
 		thread_unlock(tdp);
 	}
 	pct_human = (100 * pctcpu) / FSCALE;
-	error = racct_set(td->td_proc, RACCT_PCTCPU, pct_human);
-	if ((error != 0) ||
-	    (pct_human >= racct_get_limit(td->td_proc, RACCT_PCTCPU))) {
+	racct_set_force(td->td_proc, RACCT_PCTCPU, pct_human);
+	if (pct_human >= racct_get_limit(td->td_proc, RACCT_PCTCPU)) {
 		pause("racct", hz);
 	}
 #endif



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