Idle loop

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
pini

Idle loop

Post by pini »

Could someone help me figuring out where should the idle loop be located (eg : Should it be in a specific task ?)

Another related question : if I put the Idle loop in ring 3, how is it possible to use 'hlt' ? Is it necessary to switch down to ring 0 ?
BI lazy

Re:Idle loop

Post by BI lazy »

I'd put the idle task in ring 0 for the sake of 'hlt'

And yes, it is a seperate task (I've put it in the kernel main.c and say 'create_task(entry,priority,nice)' where entry is a pointer to a function of the kind void (* entry)(void). ), which sole purpose is said to be spinning in an endless while loop around the 'hlt'.

stay safe.
Tim

Re:Idle loop

Post by Tim »

I say that the thread responsible for kernel initialisation becomes the idle thread once it is done. That is, my KernelMain function ends in while (1) ArchProcessorIdle();

However, this then means that none of the functions that KernelMain calls can block, so to get around that I put the high-level initialisation code (loading drivers) into a separate thread.
DarylD

Re:Idle loop

Post by DarylD »

I agree with Tim, my main kernel thread becomes the idle thread, which is literally a hlt in a while loop. My loop actually has a boolean check to see whether the kernel is shutting down and then it goes through the final non-multitasking shutdown code.

And again, I spawn threads for various initialisation tasks. One reason being is in future I want a method to kill an initialisation task that has locked for some reason.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Idle loop

Post by Pype.Clicker »

i personnally have a dedicated "sleeper" thread that is mainly a while (1) asm("sti;hlt") too ...

Its handling by the dispatcher is a bit specific, in the sense that it is never pushed in any queue, but rather consist itself of a sort of 'lowest-priority' single item queue.

There is another thread for the initial thread, so i do not have problems like no blocking until kinit() is done ... And the initial thread normally goes in 'sleep' mode (thus leaving the sleeper thread "running") when final init level is reached. Stopping the system actually implies that you wakeup the initializer thread, so that it can stop everything ...
Post Reply