Multi-tasking
-
DarylD
Re:Multi-Tasking!
I will have to give the standard answer:
*DON'T* even think about coding a scheduler without knowing how it theoretically works, you will get in a terrible mess.
Buy a good book!
Essentially though, the PIT ticks at 100/1000Hz, you switch tasks when this triggers (if you can), saving the state of the current task and loading the state of the next task (including stack/registers). You could use TSS based switching or software (which I am using because it is simpler and faster). You need to ensure that switching won't bugger things up so you may need critical sections protected and even delay switching if certain conditions are true (maybe certain locks held).
*DON'T* even think about coding a scheduler without knowing how it theoretically works, you will get in a terrible mess.
Buy a good book!
Essentially though, the PIT ticks at 100/1000Hz, you switch tasks when this triggers (if you can), saving the state of the current task and loading the state of the next task (including stack/registers). You could use TSS based switching or software (which I am using because it is simpler and faster). You need to ensure that switching won't bugger things up so you may need critical sections protected and even delay switching if certain conditions are true (maybe certain locks held).
-
Schol-R-LEA
Re:Multi-Tasking!
I have to concur with DarylD on this, but I'm sure you were expecting that. Even if you can't buy or borrow one, there is always the online version of Operating Systems Vade Mecum free for download.
I will say that you would be better off in the immediate term writing your task switching and scheduling code, and testing it in cooperative mode (i.e., task switches occur only when a task voluntarily cedes control, or when an interrupt is raised) first. Since pre-emptive multitasking is a superset of cooperative, it should be fairly easy to extend the system to pre-emptive operation once you're sure that the task switching and task scheduling are working correctly.
I will say that you would be better off in the immediate term writing your task switching and scheduling code, and testing it in cooperative mode (i.e., task switches occur only when a task voluntarily cedes control, or when an interrupt is raised) first. Since pre-emptive multitasking is a superset of cooperative, it should be fairly easy to extend the system to pre-emptive operation once you're sure that the task switching and task scheduling are working correctly.
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Multi-Tasking!
Here's what i can offer :
Clicker Threads programming : that's how i implemented multitasking in my OS
semaphores implementation
the dispatcher doing the job of executing things one after another
default scheduler adding/removing threads from the queues of the dispatcher.
Clicker Threads programming : that's how i implemented multitasking in my OS
semaphores implementation
the dispatcher doing the job of executing things one after another
default scheduler adding/removing threads from the queues of the dispatcher.
-
hanoi
Re:Multi-Tasking!
How does a program get stopped in the middle of execution? Wouldn't data get lost?
No, you put the registers to the stack and change the address-space like setCR3(Task.PageDirAddress);
And when the OS returns to the task - how does it know where to continue executing?
When the intterupt comes(from IRQ0), the flags and CS and EIP will be put to stack, if you do iret they'll be restored
No, you put the registers to the stack and change the address-space like setCR3(Task.PageDirAddress);
And when the OS returns to the task - how does it know where to continue executing?
When the intterupt comes(from IRQ0), the flags and CS and EIP will be put to stack, if you do iret they'll be restored
