Multitasking

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.
oib111
Member
Member
Posts: 55
Joined: Fri Sep 04, 2009 12:39 am

Multitasking

Post by oib111 »

So I just finished implementing the heap, and I'm trying to implement software multitasking, but I'm really confused. Does anybody have some good articles on it?
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Multitasking

Post by VolTeK »

yes, yes we do.
oib111
Member
Member
Posts: 55
Joined: Fri Sep 04, 2009 12:39 am

Re: Multitasking

Post by oib111 »

GhostXoPCorp wrote:yes, yes we do.
A link would be helpful :wink:
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Multitasking

Post by VolTeK »

sure would ;) lol im just being a jerk


try wiki.osdev.org look through there, or google, i promise u, ulll find a lot of info, trust me
oib111
Member
Member
Posts: 55
Joined: Fri Sep 04, 2009 12:39 am

Re: Multitasking

Post by oib111 »

I already checked the wiki. My problem is, I understand multitasking in theory, I just can't figure out how to implement it.
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Multitasking

Post by VolTeK »

welll everything ive ever messed with included single tasking. but look up things like task switching and how to get into multitasking for os development. or look up "how multitasking works os" or wait for osmeone more experienced, lol and thats not me
oib111
Member
Member
Posts: 55
Joined: Fri Sep 04, 2009 12:39 am

Re: Multitasking

Post by oib111 »

GhostXoPCorp wrote:welll everything ive ever messed with included single tasking. but look up things like task switching and how to get into multitasking for os development. or look up "how multitasking works os" or wait for osmeone more experienced, lol and thats not me
Oh, ok. Well I'm looking things up right now, but once again, any articles would still be great.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Multitasking

Post by Love4Boobies »

In preemptive multitasking, there's usually a timer that goes off (as an interrupt) and its handler performs the context switch, which will save the old state and load the new one.. The most common way to implement this on x86(-64) systems, is to change the return address on the stack to point to the new thread when IRET is executed. What thread you pick next is defined by your scheduling policy.

There are several common timers in x86(-64) systems (PIT/HPET, RTC, RDTSC, and LAPIC), and the one that would make most sense to use is the LAPIC (when present) because you get one per CPU core - you just need to make sure you calibrate it with another timer because there's no other way to reliably determine its operating frequency.

That said, you should aim for software multitasking instead of hardware multitasking - more about this on the wiki and other forum threads.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
oib111
Member
Member
Posts: 55
Joined: Fri Sep 04, 2009 12:39 am

Re: Multitasking

Post by oib111 »

That's what I was thinking, but since I don't plan on putting in SMP support for a while, I was just thinking of using the PIT instead of the LAPIC.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Multitasking

Post by Love4Boobies »

As far as the theory of it is concernet, I'm surprised you didn't consider looking through the wiki: You will find tutorials provided by JamesM here. In particular, you care about IRQs and the PIT and Multitasking.
Last edited by Love4Boobies on Tue Mar 23, 2010 9:30 pm, edited 3 times in total.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
oib111
Member
Member
Posts: 55
Joined: Fri Sep 04, 2009 12:39 am

Re: Multitasking

Post by oib111 »

I actually read his tutorial on Multitasking. I don't know if I'm missing something, but shouldn't he really be saving more than just ebp, esp, and eip for each task?
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Multitasking

Post by Love4Boobies »

That's done automatically by the IRQ handler (isr.c). I pointed you to tutorial 5 too for several reasons. :wink:

Also, notice that I've added some more links to my previous post.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
oib111
Member
Member
Posts: 55
Joined: Fri Sep 04, 2009 12:39 am

Re: Multitasking

Post by oib111 »

Love4Boobies wrote:That's done automatically by the IRQ handler (isr.c). I pointed you to tutorial 5 too for several reasons. :wink:

Also, notice that I've added some more links to my previous post.
Ah didn't notice that. I didn't look at JamesM article on the PIT when I was adding that functionality into my kernel. Thanks :)
oib111
Member
Member
Posts: 55
Joined: Fri Sep 04, 2009 12:39 am

Re: Multitasking

Post by oib111 »

Ah, a bit of a problem. I can't load in the new value for ebp without getting an invalid opcode exception.
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Re: Multitasking

Post by piranha »

oib111 wrote:Ah, a bit of a problem. I can't load in the new value for ebp without getting an invalid opcode exception.
Well, we're gonna need more information than that...

-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
Locked