Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Sep 2012 18:09:04 +0000
From:      rudot@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r241842 - in soc2012/rudot/sys: kern sys
Message-ID:  <20120918180904.B73EA1065676@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rudot
Date: Tue Sep 18 18:09:04 2012
New Revision: 241842
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=241842

Log:
  Adapt comments to the coding style + some new comments

Modified:
  soc2012/rudot/sys/kern/kern_racct.c
  soc2012/rudot/sys/kern/kern_rctl.c
  soc2012/rudot/sys/kern/sched_4bsd.c
  soc2012/rudot/sys/sys/racct.h

Modified: soc2012/rudot/sys/kern/kern_racct.c
==============================================================================
--- soc2012/rudot/sys/kern/kern_racct.c	Tue Sep 18 17:30:08 2012	(r241841)
+++ soc2012/rudot/sys/kern/kern_racct.c	Tue Sep 18 18:09:04 2012	(r241842)
@@ -68,7 +68,7 @@
 FEATURE(racct, "Resource Accounting");
 
 /*
- * Do not block processes that have their %cpu usage <= pcpu_threshold
+ * Do not block processes that have their %cpu usage <= pcpu_threshold.
  */
 static int pcpu_threshold = 1;
 
@@ -77,9 +77,9 @@
     0, "Processes with higher %cpu usage than this value can be throttled.");
 
 /*
- * How many seconds it takes to use the scheduler %cpu calculations. When a
+ * How many seconds it takes to use the scheduler %cpu calculations.  When a
  * process starts, we compute its %cpu usage by dividing its runtime by the
- * process wall clock time. After RACCT_PCPU_SECS pass, we use the value
+ * process wall clock time.  After RACCT_PCPU_SECS pass, we use the value
  * provided by the scheduler.
  */
 #define RACCT_PCPU_SECS		3
@@ -297,7 +297,7 @@
  * They should both calculate in the same way so that the racct %cpu
  * calculations are consistent with the values showed by the ps(1) tool.
  * The calculations are more complex in the 4BSD scheduler because of the value
- * of the ccpu variable. In ULE it is defined to be zero which saves us some
+ * of the ccpu variable.  In ULE it is defined to be zero which saves us some
  * work.
  */
 static uint64_t
@@ -324,7 +324,7 @@
 
 	/*
 	 * For short-lived processes, the sched_pctcpu() returns small
-	 * values even for cpu intensive processes. Therefore we use
+	 * values even for cpu intensive processes.  Therefore we use
 	 * our own estimate in this case.
 	 */
 	if (swtime < RACCT_PCPU_SECS)
@@ -355,7 +355,7 @@
 #else
 		/*
 		 * In ULE the %cpu statistics are updated on every
-		 * sched_pctcpu() call. So special calculations to
+		 * sched_pctcpu() call.  So special calculations to
 		 * account for the latest (unfinished) second are
 		 * not needed.
 		 */
@@ -494,10 +494,10 @@
 	 * There are some cases where the racct %cpu resource would grow
 	 * beyond 100%.
 	 * For example in racct_proc_exit() we add the process %cpu usage
-	 * to the ucred racct containers. If too many processes terminated
+	 * to the ucred racct containers.  If too many processes terminated
 	 * in a short time span, the ucred %cpu resource could grow too much.
 	 * Also, the 4BSD scheduler sometimes returns for a thread more than
-	 * 100% cpu usage. So we set a boundary here to 100%.
+	 * 100% cpu usage.  So we set a boundary here to 100%.
 	 */
 	if ((resource == RACCT_PCTCPU) &&
 	    (racct->r_resources[RACCT_PCTCPU] > 100 * 1000000))
@@ -601,7 +601,7 @@
 /*
  * 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 still do set the resource to the
+ * via the return value.  But we still do set the resource to the
  * specified amount.
  */
 static int
@@ -620,7 +620,7 @@
 
 	old_amount = p->p_racct->r_resources[resource];
 	/*
-	 * the diffs may be negative
+	 * The diffs may be negative.
 	 */
 	diff_proc = amount - old_amount;
 	if (RACCT_IS_DECAYING(resource)) {
@@ -660,7 +660,7 @@
 
 	old_amount = p->p_racct->r_resources[resource];
 	/*
-	 * the diffs may be negative
+	 * The diffs may be negative.
 	 */
 	diff_proc = amount - old_amount;
 	if (RACCT_IS_DECAYING(resource)) {
@@ -741,7 +741,7 @@
 /*
  * Returns amount of 'resource' the process 'p' can keep allocated.
  * Allocating more than that would be denied, unless the resource
- * is marked undeniable. Amount of already allocated resource does
+ * is marked undeniable.  Amount of already allocated resource does
  * not matter.
  */
 uint64_t
@@ -758,7 +758,7 @@
 /*
  * Returns amount of 'resource' the process 'p' can keep allocated.
  * Allocating more than that would be denied, unless the resource
- * is marked undeniable. Amount of already allocated resource does
+ * is marked undeniable.  Amount of already allocated resource does
  * matter.
  */
 uint64_t
@@ -855,8 +855,9 @@
 		goto out;
 #endif
 
-	/* Init process cpu time */
+	/* Init process cpu time. */
 	child->p_prev_runtime = 0;
+	child->p_throttled = 0;
 
 	/*
 	 * Inherit resource usage.
@@ -1019,7 +1020,7 @@
 	PROC_LOCK_ASSERT(p, MA_OWNED);
 
 	/*
-	 * Do not block kernel processes. Also do not block processes with
+	 * Do not block kernel processes.  Also do not block processes with
 	 * low %cpu utilization to improve interactivity.
 	 */
 	if (((p->p_flag & (P_SYSTEM | P_KTHREAD)) != 0) ||
@@ -1030,11 +1031,21 @@
 	FOREACH_THREAD_IN_PROC(p, td) {
 		switch (td->td_state) {
 		case TDS_RUNQ:
+			/*
+			 * If the thread is on the scheduler run-queue, we can
+			 * not just remove it from there.  So we set the flag
+			 * TDF_NEEDRESCHED for the thread, so that once it is
+			 * running, it is taken off the cpu as soon as possible.
+			 */
 			thread_lock(td);
 			td->td_flags |= TDF_NEEDRESCHED;
 			thread_unlock(td);
 			break;
 		case TDS_RUNNING:
+			/*
+			 * If the thread is running, we request a context
+			 * switch for it by setting the TDF_NEEDRESCHED flag.
+			 */
 			thread_lock(td);
 			td->td_flags |= TDF_NEEDRESCHED;
 #ifdef SMP

Modified: soc2012/rudot/sys/kern/kern_rctl.c
==============================================================================
--- soc2012/rudot/sys/kern/kern_rctl.c	Tue Sep 18 17:30:08 2012	(r241841)
+++ soc2012/rudot/sys/kern/kern_rctl.c	Tue Sep 18 18:09:04 2012	(r241842)
@@ -305,7 +305,7 @@
 
 	/*
 	 * Return slightly less than actual value of the available
-	 * %cpu resource. This makes %cpu throttling more agressive
+	 * %cpu resource.  This makes %cpu throttling more agressive
 	 * and lets us act sooner than the limits are already exceeded.
 	 */
 	if (limit != 0) {

Modified: soc2012/rudot/sys/kern/sched_4bsd.c
==============================================================================
--- soc2012/rudot/sys/kern/sched_4bsd.c	Tue Sep 18 17:30:08 2012	(r241841)
+++ soc2012/rudot/sys/kern/sched_4bsd.c	Tue Sep 18 18:09:04 2012	(r241842)
@@ -1564,6 +1564,10 @@
 }
 
 #ifdef	RACCT
+/*
+ * Calculates the contribution to the thread cpu usage for the latest
+ * (unfinished) second.
+ */
 fixpt_t
 sched_pctcpu_delta(struct thread *td)
 {

Modified: soc2012/rudot/sys/sys/racct.h
==============================================================================
--- soc2012/rudot/sys/sys/racct.h	Tue Sep 18 17:30:08 2012	(r241841)
+++ soc2012/rudot/sys/sys/racct.h	Tue Sep 18 18:09:04 2012	(r241842)
@@ -91,7 +91,7 @@
 #define	RACCT_IS_IN_MILLIONS(X)	(racct_types[X] & RACCT_IN_MILLIONS)
 
 /*
- * Resource usage can drop, as opposed to only grow. When the process
+ * Resource usage can drop, as opposed to only grow.  When the process
  * terminates, its resource usage is freed from the respective
  * per-credential racct containers.
  */
@@ -118,7 +118,7 @@
 
 /*
  * When a process terminates, its resource usage is not automatically
- * subtracted from per-credential racct containers. Instead, the resource
+ * subtracted from per-credential racct containers.  Instead, the resource
  * usage of per-credential racct containers decays in time.
  * Resource usage can olso drop for such resource.
  * So far, the only such resource is RACCT_PCTCPU.
@@ -141,9 +141,6 @@
 	LIST_HEAD(, rctl_rule_link)	r_rule_links;
 };
 
-/* Flags kept in r_pflags. */
-#define	R_PCPUEXCEEDED	0x00001 /* Process %cpu limits have been exceeded. */
-
 int	racct_add(struct proc *p, int resource, uint64_t amount);
 void	racct_add_cred(struct ucred *cred, int resource, uint64_t amount);
 void	racct_add_force(struct proc *p, int resource, uint64_t amount);



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