mu icon indicating copy to clipboard operation
mu copied to clipboard

Reduce idle cpu consumtion (using the hlt instruction)

Open copy opened this issue 1 year ago • 3 comments

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.

copy avatar Dec 08 '23 03:12 copy

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

akkartik avatar Dec 08 '23 04:12 akkartik

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.

akkartik avatar Dec 08 '23 05:12 akkartik

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.

copy avatar Dec 08 '23 17:12 copy