Idle time
Hi,
When GRUB is idle (for example, waiting for keyboard input) it is very active with busy waiting. This has some problems and besides that, we can make good use of this time.
First the problems. One GRUB user on some IRC channel I am in was complaining that GRUB on qemu consumed a lot of CPU power. He was entering GRUB commands on the GRUB console and his machine got slow. With a timeout GRUB will consume power on laptops. Perhaps it's not much, but it would be nice if we could fix this somehow.
My main motivation is that it would be nice if sometimes events can be handled. For example, Okuji and Vincent were talking about the play command and how it should keep playing music in the background. My motivation to ask this is to handle network events (ARP and ICMP).
Although it is not very important to handle those events, it can be nice and is efficient and easy to do. Here is some proposed function and interface:
void grub_idle (int msec);
When this function is called, GRUB will be idle for about MSEC milliseconds. When nothing can be sanely done with this time, some machine specific function is called instead of an idle loop. Otherwise some functions will be called that can be registered to run during idle time. But the next function will not be called it MSECS have passed.
So we need some functions to register and deregister callback functions. And in input loops we have to add grub_idle. That's all and it will fix the problems above and give us a nice feature (one that should be handled with a *LOT* of care).
Please let me know if you have problems with such interface.
--
Marco
Quoted 4 lines · Marco Gerards
Although it is not very important to handle those events, it can be nice and is efficient and easy to do. Here is some proposed function and interface:
Quoted 8 lines
void
grub_idle(int msec);When this function is called, GRUB will be idle for about MSEC milliseconds. When nothing can be sanely done with this time, some machine specific function is called instead of an idle loop. Otherwise some functions will be called that can be registered to run during idle time. But the next function will not be called it MSECS have passed.
In my opinion, the essential function would be something similar to pause in POSIX, since the timer itself is an event.
If you want to stop CPU while waiting, the events must be hardware interrupts, or triggered by hardware interrupts (such as a timer). Probably the most difficult architecture is PC in this case, because the interrupt handling is different between protected mode and real mode, and we may not interfere with BIOS. Looking at Etherboot's experience, this should be feasible but not trivial.
However, it is easy to make a fake component for this, so I don't object to this. For example:
voidgrub_pause (void)
{
grub_event_start ();
while (1)
if (grub_event_poll ())
break; grub_event_stop ();
}
grub_uint32_t start_time;
unsigned long sleep_usecs;
voidgrub_timer_event_start (void)
{
start_time = grub_get_rtc ();
}
intgrub_timer_event_poll (void)
{
grub_uint32_t duration;
duration = grub_get_rtc () - start_time;
if (duration * GRUB_TICKS_PER_SECOND * 1000000 >= sleep_usecs)
return 1;
return 0;
}
voidgrub_timer_event_stop (void)
{
}
voidgrub_usleep (unsigned long usecs)
{
sleep_usecs = usecs;
grub_pause ();
}
Okuji
Quoted 9 lines · Yoshinori K. Okuji
In my opinion, the essential function would be something similar to pause in POSIX, since the timer itself is an event.
If you want to stop CPU while waiting, the events must be hardware interrupts, or triggered by hardware interrupts (such as a timer). Probably the most difficult architecture is PC in this case, because the interrupt handling is different between protected mode and real mode, and we may not interfere with BIOS. Looking at Etherboot's experience, this should be feasible but not trivial.
I think there is some CPU based functionality for this as well.
Quoted 2 lines
However, it is easy to make a fake component for this, so I don't object to this. For example:
I had a slightly different model in mind, although it looks like yours. How about me start getting coding, submit a patch and we can talk about that?
After this I can do some networking hacking. Which I want to submit within a month or so.
Thanks,
Marco
Quoted 3 lines · Marco Gerards
I had a slightly different model in mind, although it looks like yours. How about me start getting coding, submit a patch and we can talk about that?
No problem.
Okuji