PERFORCE change 127628 for review
Marko Zec
zec at FreeBSD.org
Wed Oct 17 06:48:54 PDT 2007
http://perforce.freebsd.org/chv.cgi?CH=127628
Change 127628 by zec at zec_tpx32 on 2007/10/17 13:48:29
Improve accuracy of per process group CPU average usage
accounting and reporting, and slightly increase deccay
periods.
Affected files ...
.. //depot/projects/vimage/src/sys/kern/kern_clock.c#11 edit
.. //depot/projects/vimage/src/sys/kern/kern_vimage.c#46 edit
.. //depot/projects/vimage/src/usr.sbin/vimage/vimage.c#6 edit
Differences ...
==== //depot/projects/vimage/src/sys/kern/kern_clock.c#11 (text+ko) ====
@@ -484,21 +484,25 @@
tot_acc_statcalls++;
if (!TD_IS_IDLETHREAD(td))
V_acc_statcalls++;
+
+ /* Deccay processing every 1/16 seconds */
if (last_acc_ticks + (hz >> 4) <= ticks) {
u_int weight_fixp;
u_int avg0;
last_acc_ticks = ticks;
/*
- * 0x10000 == 1.0 in 16:16 fixed point notation;
- * a few extra LS bits are added in an attempt to
- * compensate for truncation errors.
+ * avg0, avg1 and avg2 are stored in 16.16 fixed point format.
+ * weight_fixp is in 1.31 format for better accuracy.
+ *
+ * avg1 loses half of its value in roughly 150 ms.
+ * avg2 loses half of its value in roughly 1350 ms.
*/
- weight_fixp = 0x010007 / tot_acc_statcalls;
+ weight_fixp = 0x80000000 / tot_acc_statcalls;
LIST_FOREACH(vcpu, &vcpu_head, vcpu_le) {
- avg0 = weight_fixp * V_acc_statcalls;
- V_avg1_fixp = (V_avg1_fixp + avg0 + 1) >> 1;
- V_avg2_fixp = (15 * V_avg2_fixp + avg0 + 15) >> 4;
+ avg0 = (weight_fixp * V_acc_statcalls) >> 15;
+ V_avg1_fixp = (3 * V_avg1_fixp + avg0) >> 2;
+ V_avg2_fixp = (31 * V_avg2_fixp + avg0) >> 5;
V_acc_statcalls = 0;
}
tot_acc_statcalls = 0;
==== //depot/projects/vimage/src/sys/kern/kern_vimage.c#46 (text+ko) ====
@@ -504,8 +504,7 @@
vi_req->vi_proc_count = vip_r->v_procg->nprocs;
vi_req->vi_if_count = vip_r->v_vnet->ifccnt;
vi_req->vi_sock_count = vip_r->v_vnet->sockcnt;
- vi_req->cp_time_avg =
- (vip_r->v_cpu->_avg2_fixp * 10000 + 0x8000) >> 16;
+ vi_req->cp_time_avg = vip_r->v_cpu->_avg2_fixp;
break;
case SIOCSPVIMAGE:
==== //depot/projects/vimage/src/usr.sbin/vimage/vimage.c#6 (text+ko) ====
@@ -72,7 +72,7 @@
lf * vi_req->averunnable.ldavg[1],
lf * vi_req->averunnable.ldavg[2]);
- printf(" CPU usage: %3.2f%%\n", 0.01 * vi_req->cp_time_avg);
+ printf(" CPU usage: %3.2f%%\n", vi_req->cp_time_avg / 655.04);
printf(" Sockets (cur/max): %d/%d;", vi_req->vi_sock_count,
vi_req->vi_maxsockets);
More information about the p4-projects
mailing list