socsvn commit: r236507 - in soc2012/rudot: aux sys/kern

rudot at FreeBSD.org rudot at FreeBSD.org
Sat May 26 17:18:53 UTC 2012


Author: rudot
Date: Sat May 26 17:18:50 2012
New Revision: 236507
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=236507

Log:
  rctl can add rule specifying per process %cpu limit. The rules do take effect.
  The scheduler pauses processes that are over limit. This will probably change.

Added:
  soc2012/rudot/aux/enter_kdb.sh   (contents, props changed)
Modified:
  soc2012/rudot/aux/add.sh
  soc2012/rudot/aux/build_kernel.sh
  soc2012/rudot/aux/dummy_process.c
  soc2012/rudot/sys/kern/sched_4bsd.c

Modified: soc2012/rudot/aux/add.sh
==============================================================================
--- soc2012/rudot/aux/add.sh	Sat May 26 16:42:47 2012	(r236506)
+++ soc2012/rudot/aux/add.sh	Sat May 26 17:18:50 2012	(r236507)
@@ -1,8 +1,14 @@
-if [ ! $# == 1 ]; then
-	echo "Usage: $0 pid"
+if [ $# == 0 ]; then
+	echo "Usage: $0 pid [pct]"
 	exit
 fi
 
 PID=$1
 
-rctl -a process:${PID}:pcpu:deny=50
+if [ -z $2 ]; then
+	PCT=50
+else
+	PCT=$2
+fi
+
+rctl -a process:${PID}:pcpu:deny=${PCT}

Modified: soc2012/rudot/aux/build_kernel.sh
==============================================================================
--- soc2012/rudot/aux/build_kernel.sh	Sat May 26 16:42:47 2012	(r236506)
+++ soc2012/rudot/aux/build_kernel.sh	Sat May 26 17:18:50 2012	(r236507)
@@ -1,5 +1,9 @@
 # check http://www.mail-archive.com/freebsd-hackers@freebsd.org/msg23424.html
 
+if [ `hostname` != "target" ]; then
+	echo "You can run it only on the target machine."
+	exit
+fi
+
 cd /usr/src
-make buildkernel -DNO_MODULES KERNCONF=RCTL
-make installkernel -DNO_MODULES KERNCONF=RCTL
+make buildkernel -DNO_MODULES -DNO_CLEAN KERNCONF=RCTL && make installkernel -DNO_MODULES KERNCONF=RCTL

Modified: soc2012/rudot/aux/dummy_process.c
==============================================================================
--- soc2012/rudot/aux/dummy_process.c	Sat May 26 16:42:47 2012	(r236506)
+++ soc2012/rudot/aux/dummy_process.c	Sat May 26 17:18:50 2012	(r236507)
@@ -8,7 +8,14 @@
 	pid_t myPid = getpid();
 	printf("%d\n", myPid);
 
-	pause();
+	// pause();
+
+	int i = 75;
+	for (;;) {
+		i++;
+		if (i % 48 == 13)
+			i++;
+	}
 
 	return (0);
 }

Added: soc2012/rudot/aux/enter_kdb.sh
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2012/rudot/aux/enter_kdb.sh	Sat May 26 17:18:50 2012	(r236507)
@@ -0,0 +1 @@
+sysctl debug.kdb.enter=1

Modified: soc2012/rudot/sys/kern/sched_4bsd.c
==============================================================================
--- soc2012/rudot/sys/kern/sched_4bsd.c	Sat May 26 16:42:47 2012	(r236506)
+++ soc2012/rudot/sys/kern/sched_4bsd.c	Sat May 26 17:18:50 2012	(r236507)
@@ -511,9 +511,6 @@
 #endif
 				ts->ts_cpticks = 0;
 			}
-#ifdef RACCT
-			racct_set(p, RACCT_PCTCPU, ts->ts_pctcpu);
-#endif						
 			/*
 			 * If there are ANY running threads in this process,
 			 * then don't count it as sleeping.
@@ -677,18 +674,6 @@
 	return (sched_quantum);
 }
 
-#ifdef RACCT
-static int
-sched_racct_pcpu_deny(struct thread *td)
-{
-	struct proc *p;
-
-	p = td->td_proc;
-
-	return (0);
-}
-#endif
-
 /*
  * We adjust the priority of the current process.  The priority of
  * a process gets worse as it accumulates CPU time.  The cpu usage
@@ -708,6 +693,12 @@
 {
 	struct pcpuidlestat *stat;
 	struct td_sched *ts;
+#ifdef RACCT
+	int error;
+	int pct_human;
+	fixpt_t pctcpu;
+	struct thread *tdp;
+#endif
 
 	THREAD_LOCK_ASSERT(td, MA_OWNED);
 	ts = td->td_sched;
@@ -727,15 +718,26 @@
 	    ticks - PCPU_GET(switchticks) >= sched_quantum)
 		td->td_flags |= TDF_NEEDRESCHED;
 
-#ifdef RACCT
-	if (!TD_IS_IDLETHREAD(td) &&
-	    sched_racct_pcpu_deny(td))
-		td->td_flags |= TDF_NEEDRESCHED;
-#endif
-
 	stat = DPCPU_PTR(idlestat);
 	stat->oldidlecalls = stat->idlecalls;
 	stat->idlecalls = 0;
+
+#ifdef RACCT
+	pctcpu = sched_pctcpu(td);
+	FOREACH_THREAD_IN_PROC(td->td_proc, tdp) {
+		if (td == tdp)
+		    continue;
+		thread_lock(tdp);
+		pctcpu += sched_pctcpu(tdp);
+		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))) {
+		pause("racct", hz);
+	}
+#endif
 }
 
 /*


More information about the svn-soc-all mailing list