1
0
mirror of https://github.com/sethm/symon.git synced 2024-06-02 14:41:33 +00:00

revert back to busy waiting for CPU speed emulation to have a less bursty CPU behavior

This commit is contained in:
Maik Merten 2014-07-20 21:55:01 +02:00
parent 44bfbc17ab
commit a49c0d40d8

View File

@ -78,9 +78,8 @@ public class Cpu implements InstructionTable {
private int lo = 0, hi = 0; // Used in address calculation
private int tmp; // Temporary storage
/* Accounting for non-busy CPU waiting */
/* start time of op execution, needed for speed simulation */
private long opBeginTime;
private long surplusTime;
/**
* Construct a new CPU.
@ -1331,20 +1330,10 @@ public class Cpu implements InstructionTable {
if (clockSteps == 0) {
clockSteps = 1;
}
long opFinishTime = System.nanoTime();
long timeSpent = opFinishTime - opBeginTime;
if(timeSpent < clockSteps) {
surplusTime += clockSteps - timeSpent;
// look if a reasonable amount of time has accumulated
if(surplusTime > 1000 * 1000 * 10) {
try {
// sleep away the surplus time
Thread.sleep(surplusTime / (1000 * 1000));
} catch (InterruptedException ex) {
Logger.getLogger(Cpu.class.getName()).log(Level.SEVERE, "Trouble putting the CPU to sleep", ex);
}
surplusTime = 0;
}
long opScheduledEnd = opBeginTime + clockSteps;
long now = System.nanoTime();
while(now < opScheduledEnd) {
now = System.nanoTime();
}
}