mirror of
https://codeberg.org/sethm/symon.git
synced 2026-11-08 19:22:23 +00:00
revert back to busy waiting for CPU speed emulation to have a less bursty CPU behavior
This commit is contained in:
1 parent
44bfbc17ab
commit
a49c0d40d8
1 file changed
+5
-16
@@ -78,9 +78,8 @@ public class Cpu implements InstructionTable {
|
|||||||
private int lo = 0, hi = 0; // Used in address calculation
|
private int lo = 0, hi = 0; // Used in address calculation
|
||||||
private int tmp; // Temporary storage
|
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 opBeginTime;
|
||||||
private long surplusTime;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new CPU.
|
* Construct a new CPU.
|
||||||
@@ -1331,20 +1330,10 @@ public class Cpu implements InstructionTable {
|
|||||||
if (clockSteps == 0) {
|
if (clockSteps == 0) {
|
||||||
clockSteps = 1;
|
clockSteps = 1;
|
||||||
}
|
}
|
||||||
long opFinishTime = System.nanoTime();
|
long opScheduledEnd = opBeginTime + clockSteps;
|
||||||
long timeSpent = opFinishTime - opBeginTime;
|
long now = System.nanoTime();
|
||||||
if(timeSpent < clockSteps) {
|
while(now < opScheduledEnd) {
|
||||||
surplusTime += clockSteps - timeSpent;
|
now = System.nanoTime();
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user