Thanks for your replies

Code: Select all
[bits 32]
; null_loop - an example of a kernel null process
; This code is an example only, and has not been tested
null_loop:
sti ; Ensure that interrupts are enabled, or you'll have
; a looong wait for the loop to finish ;-)
hlt ; shuts down the processor until the next interrupt
jmp short null_loop ; when the process returns, loop back to the beginning
ret ; can't happen, but put it here anyway in case
; things go very, very wrong
Code: Select all
while (true)
__asm__("hlt");
Code: Select all
while (true)
; /* do nothing */
While applying unused cycles to such activites may be a worthwhile practice, you wouldn't use the null process for it. Even very low-priority processes like those have occasional need to wait on something (e.g., when save a result). The null process exists solely to run when there is no process active. Even the lowest priority background process will run in preference to the null process. The null process should never be more than a backstop for times when every other process is waiting on something - period. You can spawn all the low-priority threads you wish to try and ensure that every available cycle is used, but they won't be the null process.kaos wrote: Some people have this idea that you could use the idle loop to process previously recorded data to train decision trees, perceptrons, etc to define system policies on scheduling, swapping, etc instead of halting. I don't know how good of an idea that is, but someone might want to look into it.
As schol-R-lea said, what speaks against doing things in the idle thread is that the idle thread should *never* be blocked (i mean unable to run because it waits for something). The best way to make sure it will be the case is not to do anything in it.BI lazy wrote: and what speaks *against* having the idle thread do some wake up stuff, so that these low level processes can come into play?
Well, if you just want a task to be done in the background when there is nothing else to do, the best way would be to have a 'background task' queue or to assign those tasks a priority such as it will always be lower than any user operation thread.Why not waking it up when there is really nothing to do except waiting for disk io or the user?
Any other execution than waking up some threads I can't imagine in the idle thread.