I haven't looked at the SIMH code, but the way I handled this problem on an Heathkit H89, should is fairly straight forward and was quite accurate. On the H89, it runs a Z80 processor at 2.048 MHz and had a 2 mSec timer. A real H89 would be able to run 4096 cycles between each timer interrupt. The Z80 code keeps track of the number of cycles each instruction takes to run. I gave the CPU thread 4096 cycles to run, when it ran out, the thread would sleep until the next timer interrupt. At the next timer interrupt another 4096 cycles would be given to the thread to run through. It would quickly run through it's cycles for the time slice, but then that allows the CPU to be idle most of the time (and doesn't require high overhead for each instruction). <br>
<br>Depending on how accurate you want the timing to be, you could just count instructions instead of clock ticks.<br><br>Mark<br> <br><br><div class="gmail_quote">On Tue, Apr 5, 2011 at 9:47 AM, Dalby, Jeremy R (GE Power & Water) <span dir="ltr"><<a href="mailto:jeremy.dalby@ge.com">jeremy.dalby@ge.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I am trying to figure out how to slow down the SIMH PDP-8 simulator such<br>
that the instructions are executed with similar timing to that of a real<br>
PDP-8.  I have found that that even with throttling set very low, the<br>
PDP-8 simulator executes much, much faster than a real PDP-8.<br>
<br>
>From what I have read, I believe the execution of a single PDP-8<br>
instruction can take anywhere from 1.2 - 4.6 microseconds, depending on<br>
the type of instruction and I/O device to which the instruction applies.<br>
<br>
I am running the PDP-8 simulator on a Windows XP host, which I<br>
unfortunately cannot change to a real-time environment.<br>
<br>
Some things I have considered:<br>
<br>
1.  Inserting a sleep() function after execution of each PDP-8<br>
instruction, but this won't work since the minimum sleep time is 1<br>
millisecond, and even a 1 ms sleep request is not likely to return for<br>
at least 20 ms due to Windows non-real-time scheduling.<br>
<br>
2. Inserting a loop that cycles for some number of times after execution<br>
of each PDP-8 instruction, in order to kill some time. The exact number<br>
of cycles required would depend on the host processor speed, so I would<br>
have to come up with some sort of calibration method to determine the<br>
number of cycles.  I don't really like this method because I would have<br>
to disable throttling and tie up the processor 100%, and I'm really not<br>
sure how I would go about calibrating the number of cycles.<br>
<br>
I am kind of thinking at this point that representative instruction<br>
timing on a Windows host is pretty much impossible, but I thought it<br>
might be worthwhile to throw the question out there to you guys and see<br>
what comes back.  Any thoughts or ideas would be much appreciated.<br>
<br>
Thanks,<br>
Jeremy Dalby<br>
<br>
_______________________________________________<br>
Simh mailing list<br>
<a href="mailto:Simh@trailing-edge.com">Simh@trailing-edge.com</a><br>
<a href="http://mailman.trailing-edge.com/mailman/listinfo/simh" target="_blank">http://mailman.trailing-edge.com/mailman/listinfo/simh</a><br>
</blockquote></div><br>