Scheduler(Multitasking) design

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
FlashBurn

Scheduler(Multitasking) design

Post by FlashBurn »

There was that idea in my head and I don?t know if I should use it in my OS. I want to hear your opinions on that!

This scheduler will be called when an irq 0 appears. This would look like this:

Code: Select all

pushad
push fs
push gs
push es
push ds

mov eax,10
mov ds,eax

mov [thread_esp],esp

mov esp,[scheduler_esp]

mov al,20h
out 20h,al

iret
The scheduler will now search for a new thread ready to run. So far normal ;)
But now it will take the time which the thread gets to run and would reprogram the pit to this time. So that the thread gets the whole time without that the pit will be firing at a given period!

Code: Select all

call search_new_thread_to_run

call reprogram_pit

mov esp,eax
mov cr3,ebx

pop ds
pop es
pop fs
pop gs
popad
ret                ;maybe an iret??
The problem which I see is that the reprogram of the pit could be slow?!

So now say what you are thinking about my idea!
BI lazy

Re:Scheduler(Multitasking) design

Post by BI lazy »

hm... at the end of the ISR, yes, indeed there shall be an IRET.

concerning your idea about reprogramming the PIT: in relation to simply decrement some counter (dec), comparing to zero and picking the next thread to run, the instructions you need for the reprogramming after each task switch --- I think they need more time. (only opinion, no proof) I tell why: communication with hardware (except of the cpu) takes always some time.

So, I'd rather go for some algorithm that decrements/increments a counter in the task and compares it with some other value (maybe max time/ ticks to run?)

Hope this helps

stay safe!
Therx

Re:Scheduler(Multitasking) design

Post by Therx »

I wouldn't waste time running the scheduler as a task my untested code below calls a C function in the form of void *task_scheduler(void *). The function stores the value of ESP passed to it and returns the new tasks ESP. If it decides to run the same task again it just returns the same value. The testing of the code below is limited to the C function always returning the same value as it takes in.

Code: Select all

pusha                      ; Store General Purpose Registers
           push ds                    ; Store Data Segment Selectors
           push es
           push fs
           push gs
           mov ax, KERN_DATA          ; Set Data Selectors to Kernel Data
           mov ds, ax
           mov es, ax
           mov fs, ax
           mov gs, ax
           mov eax, esp               ; Pass stack pointer to Scheduler
           push eax
           call _tasks_schedule       ; Call Kernel Scheduler
           mov ebx, eax
           pop eax
           mov al, 0x20               ; Send EOI to First PIC
           out 0x20, al
           mov esp, ebx
           pop gs                     ; Restore Data Segment Selectors
           pop fs
           pop es
           pop ds
           popa
           iretd
Pete
Post Reply