shithub: riscv

Download patch

ref: 2604bc360347176323dd6706362186b97c49662c
parent: 19a8f66eecda455b56c6c07bd1ce75be8d2cbb82
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Sep 20 14:06:59 EDT 2014

stats: handle /dev/sysstat 32bit overflow in delta calculation

the numbers from /dev/sysstat overflow on 32bit, so have
to do subtraction modulo 2^32 as we calculate with 64bit
integers.

thanks mischief for reporting this.

--- a/sys/src/cmd/stats.c
+++ b/sys/src/cmd/stats.c
@@ -353,6 +353,10 @@
 			y = (y+2.)/3.;
 		}
 	}
+	if(y >= 1.)
+		y = 1;
+	if(y <= 0.)
+		y = 0;
 	p.y = g->r.max.y - Dy(g->r)*y - Dot;
 	if(p.y < g->r.min.y)
 		p.y = g->r.min.y;
@@ -830,7 +834,7 @@
 void
 contextval(Machine *m, uvlong *v, uvlong *vmax, int init)
 {
-	*v = m->devsysstat[Context]-m->prevsysstat[Context];
+	*v = (m->devsysstat[Context]-m->prevsysstat[Context])&0xffffffff;
 	*vmax = sleeptime*m->nproc;
 	if(init)
 		*vmax = sleeptime;
@@ -842,7 +846,7 @@
 void
 intrval(Machine *m, uvlong *v, uvlong *vmax, int init)
 {
-	*v = m->devsysstat[Interrupt]-m->prevsysstat[Interrupt];
+	*v = (m->devsysstat[Interrupt]-m->prevsysstat[Interrupt])&0xffffffff;
 	*vmax = sleeptime*m->nproc*10;
 	if(init)
 		*vmax = sleeptime*10;
@@ -851,7 +855,7 @@
 void
 syscallval(Machine *m, uvlong *v, uvlong *vmax, int init)
 {
-	*v = m->devsysstat[Syscall]-m->prevsysstat[Syscall];
+	*v = (m->devsysstat[Syscall]-m->prevsysstat[Syscall])&0xffffffff;
 	*vmax = sleeptime*m->nproc;
 	if(init)
 		*vmax = sleeptime;
@@ -860,7 +864,7 @@
 void
 faultval(Machine *m, uvlong *v, uvlong *vmax, int init)
 {
-	*v = m->devsysstat[Fault]-m->prevsysstat[Fault];
+	*v = (m->devsysstat[Fault]-m->prevsysstat[Fault])&0xffffffff;
 	*vmax = sleeptime*m->nproc;
 	if(init)
 		*vmax = sleeptime;
@@ -869,7 +873,7 @@
 void
 tlbmissval(Machine *m, uvlong *v, uvlong *vmax, int init)
 {
-	*v = m->devsysstat[TLBfault]-m->prevsysstat[TLBfault];
+	*v = (m->devsysstat[TLBfault]-m->prevsysstat[TLBfault])&0xffffffff;
 	*vmax = (sleeptime/1000)*10*m->nproc;
 	if(init)
 		*vmax = (sleeptime/1000)*10;
@@ -878,7 +882,7 @@
 void
 tlbpurgeval(Machine *m, uvlong *v, uvlong *vmax, int init)
 {
-	*v = m->devsysstat[TLBpurge]-m->prevsysstat[TLBpurge];
+	*v = (m->devsysstat[TLBpurge]-m->prevsysstat[TLBpurge])&0xffffffff;
 	*vmax = (sleeptime/1000)*10*m->nproc;
 	if(init)
 		*vmax = (sleeptime/1000)*10;