From a3ee159ebfd2d088432e386e8809840784f697e7 Mon Sep 17 00:00:00 2001 From: Miguel Date: Wed, 12 Sep 2018 02:10:11 +0200 Subject: working on smp scheduler --- kernel/scheduler.c | 361 ++++++++++++++++++++++++++++------------------------- 1 file changed, 192 insertions(+), 169 deletions(-) (limited to 'kernel/scheduler.c') diff --git a/kernel/scheduler.c b/kernel/scheduler.c index cac5ba7..d0b4b68 100644 --- a/kernel/scheduler.c +++ b/kernel/scheduler.c @@ -2,6 +2,7 @@ #include "kernel.h" #include "gdt.h" +#include "smp.h" #include "mem.h" #include "fs/elf.h" #include "asm_x86.h" @@ -16,9 +17,10 @@ #define NO_TASK 0xffffffff -static volatile uint32_t current_task=NO_TASK; +// we hold this stuff per cpu +static volatile uint32_t current_task[SMP_MAX_PROC]; -// TODO: per cpu! +// we hold this stuff per cpu static volatile struct task_list_struct { volatile bool active; // is this slot used (Y/N) @@ -37,11 +39,142 @@ static volatile struct task_list_struct volatile uint32_t ecx; volatile uint32_t edx; -}task_list[MAX_TASKS]; +}task_list[SMP_MAX_PROC][MAX_TASKS]; + +// init tasks // +volatile void scheduler_init(uint32_t cpu, void *dir) +{ + for(int i=0;i-1) - { - int pid=force_pid; - current_task=pid; - install_tss(0,task_list[pid].esp0); - - x86_set_page_directory(task_list[pid].vmem); - return task_list[pid].esp; - } - - for(int i=0;i [%d] (free blocks remaining: %d )", pid, ret,0); return ret; } volatile uint32_t task_clone(uint32_t pid) { + uint32_t cpu=smp_get(SMP_APIC_ID); //TODO: what will happen if we get rescheduled!?!?! - int ret=add_task(pid,vmem_new_space_dir(task_list[pid].vmem,true)); + int ret=add_task(pid,vmem_new_space_dir(task_list[cpu][pid].vmem,true)); klog("[%d] cloned -> [%d] (free blocks remaining: %d )", pid, ret,0); return ret; } -// init task (root of all other tasks / processes) // -volatile void scheduler_init(void *dir) -{ - for(int i=0;i