From owner-svn-soc-all@FreeBSD.ORG Mon Aug 13 12:09:41 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id A6200106566B for ; Mon, 13 Aug 2012 12:09:39 +0000 (UTC) (envelope-from rudot@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Mon, 13 Aug 2012 12:09:39 +0000 Date: Mon, 13 Aug 2012 12:09:39 +0000 From: rudot@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120813120939.A6200106566B@hub.freebsd.org> Cc: Subject: socsvn commit: r240321 - soc2012/rudot/sys/kern X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Aug 2012 12:09:41 -0000 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 +