git: 9front

Download patch

ref: 88b9fbdb3a14de36aa269bb88857f70164b09afd
parent: 9754248d915b32aa99485a7db579cc7736163ad1
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Sep 27 22:42:33 EDT 2014

devcons: avoid division by zero reading Qsysstat

alexchandel got the kernel to crash with divide error
on qemu 2.1.2/macosx at this location. probably
caused by perfticks()/tsc being wrong or accounttime()
not having been called yet from timer interrupt yet for
some reason.

--- a/sys/src/9/port/devcons.c
+++ b/sys/src/9/port/devcons.c
@@ -581,13 +581,14 @@
 				bp += NUMSIZE;
 				readnum(0, bp, NUMSIZE, mp->load, NUMSIZE);
 				bp += NUMSIZE;
+				l = mp->perf.period;
+				if(l == 0)
+					l = 1;
 				readnum(0, bp, NUMSIZE,
-					(mp->perf.avg_inidle*100)/mp->perf.period,
-					NUMSIZE);
+					(mp->perf.avg_inidle*100)/l, NUMSIZE);
 				bp += NUMSIZE;
 				readnum(0, bp, NUMSIZE,
-					(mp->perf.avg_inintr*100)/mp->perf.period,
-					NUMSIZE);
+					(mp->perf.avg_inintr*100)/l, NUMSIZE);
 				bp += NUMSIZE;
 				*bp++ = '\n';
 			}
--