Multitasking Tutorial
Multitasking Tutorial
Well, I decided that multitasking is fresh in my head. So I wrote a tutorial on it. I'd like suggestions, criticism, etc. right now before I submit it anywhere. Also I'm not 100% on that exact code working, as I haven't had a chance to test it, but it should work. I checked it to the intel manuals twice .
http://hosted.cjmovie.net/TutMultitask.htm
http://hosted.cjmovie.net/TutMultitask.htm
Re:Multitasking Tutorial
Very good tutorial, Cjmovie!
It is the simplest multi-tasking tutorial I've ever read.
It is the simplest multi-tasking tutorial I've ever read.
Re:Multitasking Tutorial
very nice, i wish i had something like this when i was trying to figure out stack swapping. Seems you took the advice given in here to you and really took it in and tried to understand it, well done.
only one comment (not an error just an optimization)
instead of
you could just do:
where 2 is the number of tasks you have, this way your round robin will scale nicely to having more threads. Also, next thing you need to figure out is how to block a thread
it's really not hard, you just need to mark it as "non-runnable" somehow and make your taskSwitch function skip over any threads which are not-runnable until it find a runnable one...falling back on an idle thread if none found of course.
good job and good luck.
proxy
only one comment (not an error just an optimization)
instead of
Code: Select all
if(CurrentTask == 0)CurrentTask = 1;
else CurrentTask = 0;
Code: Select all
currentTask = (currentTask + 1) % 2;
it's really not hard, you just need to mark it as "non-runnable" somehow and make your taskSwitch function skip over any threads which are not-runnable until it find a runnable one...falling back on an idle thread if none found of course.
good job and good luck.
proxy
Re:Multitasking Tutorial
Nice job, this should come in handy. Never seen such a detailed explination.
Re:Multitasking Tutorial
or move them to a separate "blocked" list.and make your taskSwitch function skip over any threads which are not-runnable until it find a runnable one...
Re:Multitasking Tutorial
As I said, it was intended to be super-simple. However, now that I see the other little things I could add, it seems dumb NOT to add them.
IDK, Maybe I will add an explanation for keeping track of entire processes and not just threads, different scheduling methods, or even some other things like preparing the kernel for multitasking (Try calling the same kpritnf function in two threads at once - Not pretty!)
So I do have some things to add. But really, nobody had any trouble with it? Maybe I should get somebody who doesn't know what's going on to read it .
IDK, Maybe I will add an explanation for keeping track of entire processes and not just threads, different scheduling methods, or even some other things like preparing the kernel for multitasking (Try calling the same kpritnf function in two threads at once - Not pretty!)
So I do have some things to add. But really, nobody had any trouble with it? Maybe I should get somebody who doesn't know what's going on to read it .
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Multitasking Tutorial
you don't really need a "cli" in your interrupt handler, right ? ...
... or do you ?
... or do you ?
Re:Multitasking Tutorial
Actually we don't, but in most tutorials (which I've found people usually just copy and paste code....) it has the 'cli', and I figured, it won't hurt anything. Better KISS.
Re:Multitasking Tutorial
Here are some suggestions: (no offence - I am a lot better at bitching about other people's writing than at writing my own)
Protected Mode isn't mentioned, maybe add it to the prerequisites (there are real-mode "Hello, World" OSes out there) I wasn't sure if you're using it or not from the first glance.
Maybe you can state your assumptions about the reader's knowledge?
You might want to explain what flavor of multitasking _you_ describe, its properties, advantages and limitations, alternatives, etc. Here's an actual question from a newbie (me):
---
small, irrelevant details:
2. Command-Line Interface, maybe? (as opposed to GUI) "Interpreter" may be valid anyway.
I'll shut up now.
How about naming the method, and providing a brief description of it, so the reader can see what is coming up without reading the whole document, and decide if this is what they want, or they already know that, etc. It also helps to remember things when you come back. (an "abstract" of the document)To use the method I try to describe here, which is among the simplest,
Protected Mode isn't mentioned, maybe add it to the prerequisites (there are real-mode "Hello, World" OSes out there) I wasn't sure if you're using it or not from the first glance.
Maybe you can state your assumptions about the reader's knowledge?
You might want to explain what flavor of multitasking _you_ describe, its properties, advantages and limitations, alternatives, etc. Here's an actual question from a newbie (me):
Will this method work with privileges and separate address spaces, and why?You should now have enough understanding to bring your OS from the DOS age of mono tasking...to the modern age of multi-tasking, multi-threaded operating systems!
---
small, irrelevant details:
1. linux is not CLI-based, CLI may be linux-based. You can start X11 at any time, if you have it.Even the CLI (Command Line Interpreter) based linux (using bash, or the like)
2. Command-Line Interface, maybe? (as opposed to GUI) "Interpreter" may be valid anyway.
I assume you mean Alt+F* - that switches consoles (terminals), not processes. You switch between processes (jobs) in shell using fg, bg and ctrl+z to move processes to and from background execution or suspension.is multitasking - You can switch between processes with F1, F2, F3 and F4 on debian, for instance.
I'll shut up now.
Re:Multitasking Tutorial
Yes, that would make my life easier. But it would also make my life more boring, more useless, and less of a lot of other things. This is exactly why I posted - I was hoping for improvements.I'll shut up now.
I will do as such.
-
- Member
- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:Multitasking Tutorial
You might as well have a look at my Multitasking text:
www.distantvoices.org/html/multitasking.html
Just compare, maybe we can come up with a good text.
Oh and btw - the blocked tasks: just don't insert them into a runable queue of any priority. I insert them to a blocked queue for the sake of having them collected at a handy place for statistics - but as well you can mark them blocked (which I'm doing also - for the sake of scrutinizng the tcb table.
stay safe.
www.distantvoices.org/html/multitasking.html
Just compare, maybe we can come up with a good text.
Oh and btw - the blocked tasks: just don't insert them into a runable queue of any priority. I insert them to a blocked queue for the sake of having them collected at a handy place for statistics - but as well you can mark them blocked (which I'm doing also - for the sake of scrutinizng the tcb table.
stay safe.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
Re:Multitasking Tutorial
I don't know if this is an intentional challenge to the reader but you forgot to reset the master PIC by outportb(0x20,0x20).
Re:Multitasking Tutorial
Very very nice multitasking tutorial, just what i was looking for.
Could you please give me some insight on the AllocPage() function?
Thanks again for the great tutorial, keep up the good work.
Could you please give me some insight on the AllocPage() function?
Code: Select all
Threads[id].esp0 = AllocPage() + 4096;
Re:Multitasking Tutorial
It simply gives out chunks of memory in 4KB and the 4096 is to get to the very end of it since the stack grows downward.
Re:Multitasking Tutorial
You might want to read this:
http://www.osdev.org/osfaq2/index.php/A ... g%20Memory
or maybe:
http://osdever.net/tutorials/memory1.php?the_id=44
If you don't understand AllocPage. As it says at the beginning, you MUST already have a memory manager to use the 'exact' code in the tutorial, sure you could 'fudge' a little, but It's not a good idea unless you know you'll always be running exactly 1 or exactly 5 tasks or something...
http://www.osdev.org/osfaq2/index.php/A ... g%20Memory
or maybe:
http://osdever.net/tutorials/memory1.php?the_id=44
If you don't understand AllocPage. As it says at the beginning, you MUST already have a memory manager to use the 'exact' code in the tutorial, sure you could 'fudge' a little, but It's not a good idea unless you know you'll always be running exactly 1 or exactly 5 tasks or something...