[Simh] Simh processor usage.

Tim Riker Tim at Rikers.org
Thu Apr 7 02:31:05 EDT 2005


Bishop, Lewis wrote:
> http://threadmaster.tripod.com <http://threadmaster.tripod.com> . I can now

This will slowdown simh all the time, not just when idle. That's likely
ok for you needs anyway. I've done a simple hack to do this in the code.
This patch has only been tested on Linux, but similar code snippits
would work in the other OS sections:

--- simhv33-2/sim_console.c	2004-11-05 19:39:24.000000000 -0600
+++ sim_console.c	2005-04-07 00:52:13.000000000 -0500
@@ -977,7 +977,19 @@
 {
 int status;
 unsigned char buf[1];
+#if 1
+int sel_ret;
+struct timeval timeout;

+timeout.tv_sec = 0;
+timeout.tv_usec = 10000;
+
+fd_set setl;
+FD_ZERO(&setl);
+FD_SET(0, &setl);
+sel_ret = select(1, &setl, NULL, NULL, &timeout);
+if (sel_ret < 1) return SCPE_OK;
+#endif
 status = read (0, buf, 1);
 if (status != 1) return SCPE_OK;
 if (sim_brk_char && (buf[0] == sim_brk_char)) return SCPE_BREAK;


This just makes simh slow down. Changing the line that sets tv_usec to a
higher value will slow it down more, and lower will slow it down less.

It would be nice to have something like this configurable inside simh:

simh> set console sleep=1000

or something like that. Of course it would be nicer if it figured out
when the simulator is and is not busy, but that's a harder feature to add.

Word to the wise: that select() call is fast for console use because it
returns immediately on a use keypress. However, the call should include
all the telnet handles too, and it does not, so a high sleep time will
slowdown telnet connections more than console connections. It's still
very usable with the 1000 value above which inserts a 1 millisecond
delay every time the console is polled. This does NOT seem to happen
every instruction, but just every few instructions. I've not yet traced
the logic there.

It should be ok to put this code in sim_poll_kbd at present I would
think as I expect all platforms are reading from stdin, but this would
not be ok if someone ever added a gui interface. VMS might not handle
this presently, but the others should work fine.

This change on my ppc box slowed down some simple basic apps by aboue a
factor of 4. I suspect compute intensive ones would be effected even
more. It also lowered simh from 100% cpu usage to less than 3% usage.

-- 
Tim Riker - http://rikers.org/ - TimR at Debian.org
Embedded Linux Technologist
BZFlag maintainer - http://BZFlag.org/ - for fun!



More information about the Simh mailing list