Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Jun 2012 14:48:58 +0000
From:      rudot@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r237691 - soc2012/rudot/sys/kern
Message-ID:  <20120614144858.68FC51065674@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rudot
Date: Thu Jun 14 14:48:57 2012
New Revision: 237691
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=237691

Log:
  When setting the pcpu resource in racctd, we both need to use the "force" version and need to know if we are past the limits.

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

Modified: soc2012/rudot/sys/kern/kern_racct.c
==============================================================================
--- soc2012/rudot/sys/kern/kern_racct.c	Thu Jun 14 13:55:52 2012	(r237690)
+++ soc2012/rudot/sys/kern/kern_racct.c	Thu Jun 14 14:48:57 2012	(r237691)
@@ -510,6 +510,48 @@
 	racct_add_cred(p->p_ucred, resource, amount);
 }
 
+/*
+ * This is basicly racct_set_force_locked(), but with the added
+ * benefit that if we are over limits, we let the caller know
+ * via the return value. But we stil do set the resource to the
+ * specified amount.
+ */
+static int
+racct_set_check_locked(struct proc *p, int resource, uint64_t amount)
+{
+	int64_t diff;
+	int over_limit;
+
+	SDT_PROBE(racct, kernel, rusage, set, p, resource, amount, 0, 0);
+
+	/*
+	 * We need proc lock to dereference p->p_ucred.
+	 */
+	PROC_LOCK_ASSERT(p, MA_OWNED);
+
+	/*
+	 * may be negative
+	 */
+	diff = amount - p->p_racct->r_resources[resource];
+#ifdef notyet
+	KASSERT(diff >= 0 || RACCT_IS_RECLAIMABLE(resource),
+	    ("racct_set: usage of non-reclaimable resource %d dropping",
+	     resource));
+#endif
+#ifdef RCTL
+	over_limit = rctl_enforce(p, resource, diff);
+#else
+	over_limit = 0;
+#endif
+	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);
+
+	return (over_limit);
+}
+
 static int
 racct_set_locked(struct proc *p, int resource, uint64_t amount)
 {
@@ -922,7 +964,7 @@
 	struct timeval wallclock;
 	uint64_t runtime;
 	u_int pct;
-	int error;
+	int over_limits;
 
 	for (;;) {
 		sx_slock(&allproc_lock);
@@ -949,8 +991,8 @@
 			p->p_prev_runtime = runtime;
 			pct = racct_getpcpu(p);
 			mtx_lock(&racct_lock);
-			error = racct_set_locked(p, RACCT_PCTCPU, pct);
-			if (error) {
+			over_limits = racct_set_check_locked(p, RACCT_PCTCPU, pct);
+			if (over_limits) {
 				racct_proc_disable(p);
 			} else if (racct_proc_disabled(p)) {
 				racct_proc_enable(p);

Modified: soc2012/rudot/sys/kern/kern_rctl.c
==============================================================================
--- soc2012/rudot/sys/kern/kern_rctl.c	Thu Jun 14 13:55:52 2012	(r237690)
+++ soc2012/rudot/sys/kern/kern_rctl.c	Thu Jun 14 14:48:57 2012	(r237691)
@@ -277,7 +277,7 @@
  * be denied, 0 otherwise.
  */
 int
-rctl_enforce(struct proc *p, int resource, uint64_t amount)
+rctl_enforce(struct proc *p, int resource, int64_t amount)
 {
 	struct rctl_rule *rule;
 	struct rctl_rule_link *link;



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