From b3cada1dbf6f9477ea43f6ced5b0df6f8fa9421f Mon Sep 17 00:00:00 2001 From: Jim Wilcoxson Date: Sun, 19 Apr 2020 01:14:15 +0000 Subject: [PATCH] em.c: add a small benchmark loop to set the initial value of instpermsec to a reasonable value. This avoids clock anomolies during startup. --- em.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/em.c b/em.c index 0511c8f..f48c4f4 100644 --- a/em.c +++ b/em.c @@ -4412,7 +4412,10 @@ int main (int argc, char **argv) { NOTE: if instpermsec is off by more than a factor of 2, it causes some minor clock skew problems during the first few seconds of - system boot. There is debug code in emdev.h/devcp to see this. */ + system boot. There is debug code in emdev.h/devcp to see this. + To remedy, a small benchmark is run after initialization to set a + "close" value based on empirical testing, then the clock process + adjusts it periodically. */ gv.intvec = -1; gv.instcount = 0; @@ -4706,6 +4709,33 @@ int main (int argc, char **argv) { } bzero(MEM, 64*1024*2); /* zero first 64K words */ + /* run a short benchmark to help determine initial MIPS rating. For + a system with an actual Prime MIPS rating of 58, this benchmark + returns numbers around 160, so divide by 3-ish with -DFAST or + 7-ish without -DFAST*/ + + { + #define BENCHINST 10000000 + #ifdef FAST + #define BENCHFACTOR 2.9 + #else + #define BENCHFACTOR 7.0 + #endif + struct timeval start_tv, tv; + int elapsedms; + + if (gettimeofday(&start_tv, NULL) != 0) + fatal("em: gettimeofday failed"); + for (templ=0; templ < BENCHINST; templ++) { + add16(1, 2, 3, 0); + } + if (gettimeofday(&tv, NULL) != 0) + fatal("em: gettimeofday failed"); + elapsedms = (tv.tv_sec-start_tv.tv_sec)*1000.0 + (tv.tv_usec-start_tv.tv_usec)/1000.0; + gv.instpermsec = BENCHINST * 1.0 / elapsedms / BENCHFACTOR; + printf("=== %d Prime MIPS ===\n", gv.instpermsec / 1000); + } + /* if no maps were specified on the command line, look for ring0.map and ring3.map in the current directory and read them */