-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement execution throttling when over 100% #20
Comments
Indeed! Actually, I have some prototype for this already, this is what the code looks like: async execute(callback: (cpu: CPU) => void) {
this.stopped = false;
let workUnitCycles = 500000;
let nextTick = this.cpu.cycles + workUnitCycles;
for (;;) {
avrInstruction(this.cpu);
this.timer.tick();
this.usart.tick();
if (this.cpu.cycles >= nextTick) {
const speed = this.performance.update();
callback(this.cpu);
if (speed < 0.95) {
workUnitCycles = Math.min(500000, Math.floor(workUnitCycles * 1.05));
} else if (speed < 0.98) {
workUnitCycles = Math.min(500000, Math.floor(workUnitCycles * 1.01));
} else if (speed > 1.1) {
workUnitCycles = Math.max(10000, Math.floor(workUnitCycles / 1.05));
} else if (speed > 1.02) {
workUnitCycles = Math.max(10000, Math.floor(workUnitCycles / 1.01));
}
await new Promise(resolve => setTimeout(resolve, 0));
if (this.stopped) {
break;
}
nextTick += workUnitCycles;
}
}
} |
Ah right, that make sense. I like the gradual threshold approach. |
This week I studied a little about execution throttling when over 100% |
Thanks for sharing it @arcostasi |
A great issue to write 😄
So now that the simulation runs faster than the simulated CPU, it would be nice to have the possibility to throttle at 100% speed
Similar to how application target a specific number of Frame Per Second, we could target CPU Freq instructions per second, not more.
This would be implemented in the execute runner function.
Not a priority but nice to have.
The text was updated successfully, but these errors were encountered: