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.
This commit is contained in:
cinap_lenrek 2014-09-28 02:42:33 +02:00
parent c8cf0cee47
commit eb6a4fc1a4

View file

@ -581,13 +581,14 @@ consread(Chan *c, void *buf, long n, vlong off)
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';
}