socsvn commit: r239377 - soc2012/rudot/sys/kern
rudot at FreeBSD.org
rudot at FreeBSD.org
Sat Jul 14 13:00:14 UTC 2012
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);
}
More information about the svn-soc-all
mailing list