socsvn commit: r240321 - soc2012/rudot/sys/kern
rudot at FreeBSD.org
rudot at FreeBSD.org
Mon Aug 13 12:09:41 UTC 2012
Author: rudot
Date: Mon Aug 13 12:09:39 2012
New Revision: 240321
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240321
Log:
cosmetic changes - adding some comments, some adjustments to comply with the coding style.
Modified:
soc2012/rudot/sys/kern/kern_racct.c
Modified: soc2012/rudot/sys/kern/kern_racct.c
==============================================================================
--- soc2012/rudot/sys/kern/kern_racct.c Mon Aug 13 08:16:30 2012 (r240320)
+++ soc2012/rudot/sys/kern/kern_racct.c Mon Aug 13 12:09:39 2012 (r240321)
@@ -308,17 +308,21 @@
fixpt_t p_pctcpu;
struct thread *td;
+ /*
+ * If the process is swapped out, we count its %cpu usage as zero.
+ * This behaviour is consistent with the userland ps(1) tool.
+ */
if ((p->p_flag & P_INMEM) == 0)
return (0);
swtime = (ticks - p->p_swtick) / hz;
- if (swtime < RACCT_PCPU_SECS) {
- /*
- * For short-lived processes, the sched_pctcpu() returns small
- * values even for cpu intensive processes. Therefore we use
- * our own estimate in this case.
- */
- return (pcpu);
- }
+
+ /*
+ * For short-lived processes, the sched_pctcpu() returns small
+ * values even for cpu intensive processes. Therefore we use
+ * our own estimate in this case.
+ */
+ if (swtime < RACCT_PCPU_SECS)
+ return (pcpu);
p_pctcpu = 0;
FOREACH_THREAD_IN_PROC(p, td) {
@@ -355,9 +359,8 @@
}
#ifdef SCHED_4BSD
- if (swtime <= CCPU_EXP_MAX) {
+ if (swtime <= CCPU_EXP_MAX)
return ((100 * p_pctcpu) / (FSCALE - ccpu_exp[swtime]));
- }
#endif
return ((100 * p_pctcpu) / FSCALE);
@@ -462,7 +465,7 @@
/*
* Increase consumption of 'resource' by 'amount' for 'racct'
- * and all its parents. Differently from other cases, 'amount' here
+ * and all its parents. Differently from other cases, 'amount' here
* may be less than zero.
*/
static void
@@ -480,11 +483,18 @@
racct->r_resources[resource] = 0;
}
- if (resource == RACCT_PCTCPU) {
- if (racct->r_resources[RACCT_PCTCPU] > 100) {
- racct->r_resources[RACCT_PCTCPU] = 100;
- }
- }
+ /*
+ * 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
+ * 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%.
+ */
+ if ((resource == RACCT_PCTCPU) &&
+ (racct->r_resources[RACCT_PCTCPU] > 100))
+ racct->r_resources[RACCT_PCTCPU] = 100;
}
static int
@@ -609,9 +619,8 @@
if (RACCT_IS_DECAYING(resource)) {
decayed_amount = old_amount * RACCT_DECAY_FACTOR / FSCALE;
diff_cred = amount - decayed_amount;
- } else {
+ } else
diff_cred = diff_proc;
- }
available = INT64_MAX;
racct_alloc_resource(p->p_racct, resource, diff_proc);
@@ -650,9 +659,8 @@
if (RACCT_IS_DECAYING(resource)) {
decayed_amount = old_amount * RACCT_DECAY_FACTOR / FSCALE;
diff_cred = amount - decayed_amount;
- } else {
+ } else
diff_cred = diff_proc;
- }
#ifdef notyet
KASSERT(diff_proc >= 0 || RACCT_CAN_DROP(resource),
("racct_set: usage of non-droppable resource %d dropping",
@@ -726,7 +734,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
@@ -743,7 +751,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
@@ -1059,7 +1067,7 @@
int resource;
int64_t r_old, r_new;
- resource = *(int *) res;
+ resource = *(int *)res;
r_old = racct->r_resources[resource];
/* If there is nothing to decay, just exit. */
@@ -1130,11 +1138,10 @@
mtx_lock(&racct_lock);
over_limits = racct_set_check_locked(p, RACCT_PCTCPU,
pct);
- if (over_limits) {
+ if (over_limits)
racct_proc_disable(p);
- } else if (racct_proc_disabled(p)) {
+ else if (racct_proc_disabled(p))
racct_proc_enable(p);
- }
racct_set_locked(p, RACCT_CPU, runtime);
racct_set_locked(p, RACCT_WALLCLOCK,
(uint64_t)wallclock.tv_sec * 1000000 +
More information about the svn-soc-all
mailing list