Page 1 of 3
how 2 start multitasking?
Posted: Thu May 19, 2005 12:47 pm
by viral
Hi..
I am working on an 32 - bit OS in c++. My os got:
1. Setup GDT.
2. IDT.
3. Video driver.
3. Keyboard driver.
Now I want to start multitasking, I have read many tuts but i guess they dint help me. My questions are:
1. How to start a task?
2. How to store info about all task?
3. How to switch them by just software side? (no tss plz i am a kidd..)
Re:how 2 start multitasking?
Posted: Fri May 20, 2005 1:40 am
by Pype.Clicker
How to store info about all task?
- the "ancient unix way": have a table of N "tasks control block" and sweep that table to see what's the next task to be run (each control block should at least have a 'state' information telling if it's ready, running, sleeping, zombie, etc.)
- the "more modern way": have a set (e.g. a binary tree) of threads for each process so that you can kill all of them when requested to kill the process and find one thread efficiently; have a set/table of processes so that you can list them all ; have a queue of "ready" thread in the scheduler structure.
If that sounds totally dark-side to you, i suggest you read deeper about dynamic structures like AVL trees, hash tables and linked lists first.
How to switch them just by software ?
http://www.osdev.org/osfaq2/index.php/C ... 0Switching should carry all the information you need. Basically you have
- to convince you that you can keep all the information you need on your stack
- have a single function that will pick the current stack pointer, move it to the current task control block and then load the stack pointer of the new task control block into the cpu
- convince yourself that, by the previous operation, you've now entered a new task state and that letting the CPU go will gently resume suspended operations.
- check that your implementation is "irq-safe" (e.g. the IRQs are re-enabled iff an IRQ caused the switch)
how do i start a task ?
The nicest way is to prepare a new Thread Control Block and a corresponding stack so that the task switcher code will not even notice that the stack is new.
You can do this by faking "what would happen if there were a call for switch right before the first instruction of my new task is executed".
Re:how 2 start multitasking?
Posted: Sat May 21, 2005 1:34 pm
by viral
Really thanks 4 that...
I am learning at a snail-speed. Can u please better explain in other word (if possible). I am trying to make things work. But still not gettin what to do now... can u plz give me steps to impliment?
Re:how 2 start multitasking?
Posted: Sun May 22, 2005 3:28 pm
by Pype.Clicker
i'm abroad for now, so i'll leave that to someone else. BI tutorial (on distantvoices) should give you those steps, though.
Re:how 2 start multitasking?
Posted: Mon May 23, 2005 1:02 pm
by viral
Thanks for the reply...
Can anyone really know:
* How to start a task?
* Where the Stack of all task lies?
Re:how 2 start multitasking?
Posted: Mon May 23, 2005 4:26 pm
by Kemp
If by stack you mean the stack the tasks use, then usually they'll be given a stack each that you can stick anywhere you wnat within their memory space. If you mean the list of tasks running, then that's up to you to keep track of, I personally use a series of linked lists.
Re:how 2 start multitasking?
Posted: Tue May 24, 2005 2:36 pm
by viral
So that means I have to assign Stack for every Process by myself (If I am wrong then plz do correct me). I had gone through the tutorial by BlueIllusionOS at
http://www.distantvoices.org/html/multitasking.html
I dint get some terms..
1. What is &kstack[d][KSTACKTOP] ?
Re:how 2 start multitasking?
Posted: Tue May 24, 2005 8:44 pm
by AR
kstack appears to be an array of pointers to kernel stacks, each task has its own kernel stack, what he's doing is getting a pointer to the top of the task's stack.
Re:how 2 start multitasking?
Posted: Sat May 28, 2005 1:33 pm
by viral
Thanks for reply..
I am still trying to work it out....
Re:how 2 start multitasking?
Posted: Thu Jun 02, 2005 10:40 am
by Poseidon
maybe a look at
www.codezen.org/viridis helps... it made a lot of things clear to me (both the whitepapers and the source code).
Re:how 2 start multitasking?
Posted: Thu Jun 02, 2005 1:58 pm
by Warrior
Thx Poseidon, a lot of good articles there.
Re:how 2 start multitasking?
Posted: Fri Jun 03, 2005 4:07 am
by viral
Thnx a lot....
wonderfull links..............
Re:how 2 start multitasking?
Posted: Fri Jun 03, 2005 5:53 am
by Neo
Pype.Clicker wrote:
- the "more modern way": have a set (e.g. a binary tree) of threads for each process so that you can kill all of them when requested to kill the process and find one thread efficiently; have a set/table of processes so that you can list them all ; have a queue of "ready" thread in the scheduler structure.
.............
@Pype: One thing that I wanted to know.
Did you mean a tree in general or binary trees in particular?
I mean if a parent has more than 2 children processes then ....?
Re:how 2 start multitasking?
Posted: Fri Jun 03, 2005 6:43 am
by Pype.Clicker
well, it could be whatever tree you want provided that
- it's fast to search
- it's quick to adjust for insertions/deletions
- it has fair memory usage.
Most people pick binary trees for this because there are plenty of well-known implementations with provable performances, but you could go for B+tree if you prefer ...
Re:how 2 start multitasking?
Posted: Fri Jun 03, 2005 1:05 pm
by viral
Ya right..
binary trees are easy to implement.. but then a parent can have atmost 2 childs .. if we restrict to binary trees