Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 18 Jul 2010 17:00:41 GMT
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 181146 for review
Message-ID:  <201007181700.o6IH0fjl085158@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@181146?ac=10

Change 181146 by trasz@trasz_victim on 2010/07/18 17:00:13

	CPU time accounting.  Display doesn't work yet, for some weird reason.

Affected files ...

.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#17 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#89 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_resource.c#41 edit

Differences ...

==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#17 (text+ko) ====

@@ -226,7 +226,10 @@
 	KASSERT(container != NULL, ("NULL container"));
 
 	for (i = 0; i <= RUSAGE_MAX; i++) {
-		if (container->c_resources[i] != 0)
+		/*
+		 * XXX: The RUSAGE_CPU thing should be done in a better way.
+		 */
+		if (container->c_resources[i] != 0 && i != RUSAGE_CPU)
 			printf("destroying non-empty container: "
 			    "%ju allocated for resource %d",
 			    container->c_resources[i], i);

==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#89 (text+ko) ====

@@ -1290,6 +1290,15 @@
 	    rule->hr_subject_type != HRL_SUBJECT_TYPE_UNDEFINED)
 		rule->hr_per = rule->hr_subject_type;
 
+	/*
+	 * Some rules just don't make sense.
+	 */
+	if (rule->hr_resource == RUSAGE_CPU &&
+	    rule->hr_action == HRL_ACTION_DENY) {
+		error = EINVAL;
+		goto out;
+	}
+
 	if (!hrl_rule_fully_specified(rule)) {
 		error = EINVAL;
 		goto out;

==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_resource.c#41 (text+ko) ====

@@ -43,6 +43,7 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/sysproto.h>
+#include <sys/container.h>
 #include <sys/file.h>
 #include <sys/hrl.h>
 #include <sys/kernel.h>
@@ -618,9 +619,13 @@
 static void
 lim_cb(void *arg)
 {
-	struct rlimit rlim;
 	struct thread *td;
 	struct proc *p;
+#ifdef CONTAINERS
+	int error;
+#else
+	struct rlimit rlim;
+#endif
 
 	p = arg;
 	PROC_LOCK_ASSERT(p, MA_OWNED);
@@ -635,6 +640,10 @@
 		ruxagg(p, td);
 	}
 	PROC_SUNLOCK(p);
+#ifdef CONTAINERS
+	error = rusage_set(p, RUSAGE_CPU, p->p_rux.rux_runtime / cpu_tickrate());
+	KASSERT(error == 0, ("rusage_set(p, RUSAGE_CPU, ...) returned error"));
+#else
 	if (p->p_rux.rux_runtime > p->p_cpulimit * cpu_tickrate()) {
 		lim_rlimit(p, RLIMIT_CPU, &rlim);
 		if (p->p_rux.rux_runtime >= rlim.rlim_max * cpu_tickrate()) {
@@ -645,6 +654,7 @@
 			psignal(p, SIGXCPU);
 		}
 	}
+#endif
 	if ((p->p_flag & P_WEXIT) == 0)
 		callout_reset(&p->p_limco, hz, lim_cb, p);
 }
@@ -726,11 +736,22 @@
 	 */
 	if (rule->hr_action != HRL_ACTION_DENY) {
 		rule2 = hrl_rule_duplicate(rule, M_WAITOK);
-		rule2->hr_action = HRL_ACTION_DENY;
+
+		/*
+		 * The "deny" action doesn't make sense for some resources,
+		 * such as RUSAGE_CPU.
+		 */
+		if (rule2->hr_resource == RUSAGE_CPU)
+			rule2->hr_action = HRL_ACTION_SIGKILL;
+		else
+			rule2->hr_action = HRL_ACTION_DENY;
 		hrl_rule_remove(rule2);
 
 		if (lim->rlim_cur != RLIM_INFINITY) {
-			rule2->hr_amount = lim->rlim_cur;
+			if (rule2->hr_resource == RUSAGE_CPU)
+				rule2->hr_amount = lim->rlim_max;
+			else
+				rule2->hr_amount = lim->rlim_cur;
 			error = hrl_rule_add(rule2);
 			KASSERT(error == 0, ("hrl_rule_add failed"));
 		}



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