Where to start with multitasking/userland

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
8infy
Member
Member
Posts: 185
Joined: Sun Apr 05, 2020 1:01 pm

Where to start with multitasking/userland

Post by 8infy »

Hi everyone!
I finally have a somewhat working memory manager that can allocate virtual memory, create new page directories, handle page faults, etc etc
Plus I have basic interrupt handlers and PIT up and running. I feel like I'm ready to start implementing multiprocessing/multitasking and start heading towards userland.
I found a bunch of cool tutorials that all approach things differently, but they're pretty old and its hard to tell, which one is the best at this time.
This is what I have found so far:
https://wiki.osdev.org/Brendan%27s_Mult ... g_Tutorial
http://www.brokenthorn.com/Resources/OSDev24.html
http://www.jamesmolloy.co.uk/tutorial_h ... sking.html
https://wiki.osdev.org/Kernel_Multitasking

Which one of those do you think is best in 2020? I don't want to take a hacky or intentionally simple/broken approach just to rewrite it later.

Also, while these tutorials talk about the implementation details, I was wondering if there were any other resources where I could read about multitasking (preferably modern) theory,
that explains different approaches and ways to do things and explains it more in depth. Any links other than the ones that I already found are also appreciated!

Thanks :)
Octocontrabass
Member
Member
Posts: 5575
Joined: Mon Mar 25, 2013 7:01 pm

Re: Where to start with multitasking/userland

Post by Octocontrabass »

I'm not aware of any major issues with either of these pages. However, care should be taken: OS development tutorials usually have mistakes in them.
Don't use this tutorial. Read this page if you want to know why.
Cooperative multitasking is the "intentionally simple" approach you want to avoid. Although looking at the code, perhaps this is meant to be an example of "one kernel stack per CPU"?
8infy wrote:Also, while these tutorials talk about the implementation details, I was wondering if there were any other resources where I could read about multitasking (preferably modern) theory, that explains different approaches and ways to do things and explains it more in depth.
All of the interesting theory is in the scheduling algorithms. The actual mechanics of switching from one task to another are pretty boring otherwise.
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Where to start with multitasking/userland

Post by bzt »

This part of the wiki is a real mess. I've tried to clean up a bit, any help would be appreciated.

Bredan's "tutorial" is not really a tutorial at all, it contains way too much theory for that. Besides, it is much more about scheduling than about multitasking imho. I haven't touched it, because some members think I have an issue with Brendan, but someone really should clean up this page (and probably rename it to scheduling).

Kernel Multitasking page had nothing to do with kernel multitasking, it's a simple tutorial on cooperative multitasking, therefore I've renamed it to "Cooperative Multitasking".

We also have a page https://wiki.osdev.org/Multitasking_Systems, which is about multitasking in general and classification. It had a section on implementation (called "How does it work", included code examples and talked about where to put the kernel stack), which had nothing to do with the classifications on Multitasking Systems, so I moved that section to the now empty "Kernel Multitasking" page. This new page is still short, I believe we should add more implementation details and more code samples to it.

Furthermore, there are lots of inaccuracies on the pages. For example, on Scheduling Algorithms page it reads:
Round Robin is the simplest algorithm for a preemptive scheduler.
Which makes absolutely no sense. A scheduler can't be preemptive (that's the type of multitasking), and also Round Robin can be used with cooperative multitask too.

Cheers,
bzt
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: Where to start with multitasking/userland

Post by nexos »

Brendan's tutorial looks good, as it lets you do a lot of problem solving.
Brokenthorn's is what I based my tasking code after. It is good, but it caters a lot to Visual Studio, hence when working with GCC, you half adapt a lot of stuff. Plus, it uses way to much inline assembly, and is a bit vague when it come to user stacks.
James Molloy's is pure wildness. It does some crazy stuff that probably will blow up after a while. It does give much help in turns of user process and multi-threading.
Kernel multitasking is very simple, as it supports only cooperative multitasking.
You should also look at some of the theory articles in the wiki.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
Post Reply