akkartik / mu

Soul of a tiny new machine. More thorough tests → More comprehensible and rewrite-friendly software → More resilient society.
http://akkartik.name/akkartik-convivial-20200607.pdf
Other
1.38k stars 47 forks source link

Reduce idle cpu consumtion (using the hlt instruction) #53

Open copy opened 9 months ago

copy commented 9 months ago

This is a feature request: Currently, when waiting for keyboard input, Mu uses a busy loop (which you can tell by the high CPU usage in qemu, for example in the shell app).

On x86, idling is pretty simple, by using the HLT instruction.

akkartik commented 9 months ago

The issue here is that Mu doesn't use interrupts yet for the keyboard.. :thinking:

akkartik commented 9 months ago

Ohh, I think I see what you mean! It looks like all my test programs continue to work if I just hlt at the start of every call to read-key! This is the low-level non-blocking primitive and it continues to not block (maybe due to the timer interrupt?) even when I animate say apps/hest-life.mu.

However, when I make this change, running the game of life inside the tiny screen in the shell (following the quickstart and then pressing ctrl+s) slows down a lot. Does that sound right? This isn't insurmountable, I just need to adjust how frequently I check for a keypress when animating.

copy commented 9 months ago

However, when I make this change, running the game of life inside the tiny screen in the shell (following the quickstart and then pressing ctrl+s) slows down a lot. Does that sound right? This isn't insurmountable, I just need to adjust how frequently I check for a keypress when animating.

You may need to adjust the PIT reload value. The BIOS default is the maximum, which generates a timer interrupt roughly every 55ms.