From owner-svn-soc-all@FreeBSD.ORG Sat Jul 14 13:00:14 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 EF113106566B for ; Sat, 14 Jul 2012 13:00:12 +0000 (UTC) (envelope-from rudot@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Sat, 14 Jul 2012 13:00:12 +0000 Date: Sat, 14 Jul 2012 13:00:12 +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: <20120714130012.EF113106566B@hub.freebsd.org> Cc: Subject: socsvn commit: r239377 - 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: Sat, 14 Jul 2012 13:00:14 -0000 Author: rudot Date: Sat Jul 14 13:00:12 2012 New Revision: 239377 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239377 Log: supporting both schedulers - fixing %cpu calculations Modified: soc2012/rudot/sys/kern/kern_racct.c Modified: soc2012/rudot/sys/kern/kern_racct.c ============================================================================== --- soc2012/rudot/sys/kern/kern_racct.c Sat Jul 14 12:15:20 2012 (r239376) +++ soc2012/rudot/sys/kern/kern_racct.c Sat Jul 14 13:00:12 2012 (r239377) @@ -145,10 +145,13 @@ RACCT_IN_MILLIONS, [RACCT_PCTCPU] = RACCT_RECLAIMABLE | RACCT_DENIABLE }; +#ifdef SCHED_4BSD /* * Contains intermediate values for %cpu calculations to avoid using floating * point in the kernel. - * ccpu_exp[k] = FSCALE * exp(-k/20) + * ccpu_exp[k] = FSCALE * (ccpu/FSCALE)^k = FSCALE * exp(-k/20) + * It is needed only for the 4BSD scheduler, because in ULE, the ccpu equals to + * zero so the calculations are more straightforward. */ fixpt_t ccpu_exp[] = { [0] = FSCALE * 1, @@ -263,9 +266,18 @@ [109] = FSCALE * 0.00429630469075234057, [110] = FSCALE * 0.00408677143846406699, }; +#endif #define CCPU_EXP_MAX 110 +/* + * This function is analogical to the getpcpu() function in the ps(1) command. + * 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 + * work. + */ u_int racct_getpcpu(struct proc *p) { @@ -290,14 +302,22 @@ pctcpu_next += sched_pctcpu_delta(td); p_pctcpu += max(pctcpu, pctcpu_next); #else + /* + * In ULE the %cpu statistics are updated on every + * sched_pctcpu() call. So special calculations to + * account for the latest (unfinished) second are + * not needed. + */ p_pctcpu += sched_pctcpu(td); #endif thread_unlock(td); } +#ifdef SCHED_4BSD if (swtime <= CCPU_EXP_MAX) { return ((100 * p_pctcpu) / (FSCALE - ccpu_exp[swtime])); } +#endif return ((100 * p_pctcpu) / FSCALE); }