diff options
Diffstat (limited to 'kernel/scheduler.c')
| -rw-r--r-- | kernel/scheduler.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/kernel/scheduler.c b/kernel/scheduler.c index 20b69ed..0c24f94 100644 --- a/kernel/scheduler.c +++ b/kernel/scheduler.c @@ -35,6 +35,7 @@ static uint32_t nextPID() // we hold this stuff per cpu static volatile uint32_t current_task[SMP_MAX_PROC]; +static volatile uint32_t last_task[SMP_MAX_PROC]; // last non ring1 task // we hold this stuff per cpu static volatile struct task_list_struct @@ -69,6 +70,7 @@ volatile void scheduler_init(uint32_t cpu, void *dir) } current_task[cpu]=0; + last_task[cpu]=0; // need to make space on the esp stacks for pushing vals vias task_pusha @@ -117,6 +119,8 @@ static uint32_t scheduler_schedule(uint32_t idx) uint32_t cpu=smp_get(SMP_APIC_ID); if(task_list[cpu][idx].active && !task_list[cpu][idx].syscall) { + if(current_task[cpu]!=0)last_task[cpu]=current_task[cpu]; + current_task[cpu]=idx; install_tss(cpu,task_list[cpu][idx].esp0); x86_set_page_directory(task_list[cpu][idx].vmem); @@ -150,19 +154,21 @@ volatile uint32_t scheduler_run(uint32_t oldesp,uint32_t preference) uint32_t esp; esp=scheduler_schedule(preference); // try preference + if(esp)return esp; for(int i=0;i<MAX_TASKS;i++) { - int idx=(current_task[cpu]+1+i)%MAX_TASKS; // schedule round robin style - if(idx==2)continue;// skip sleeper here + int idx=(last_task[cpu]+1+i)%MAX_TASKS; // schedule round robin style - esp=scheduler_schedule(idx); // try preference - if(esp)return esp; + if(idx==preference||idx==2)continue;// skip sleeper and preferred tasks here. + esp=scheduler_schedule(idx); + + if(esp)return esp; } - // force the sleeper task + // force the sleeper task... return scheduler_schedule(2); } @@ -455,5 +461,5 @@ void task_exit(uint32_t pid) task_list[cpu][i].active=false; } - vmem_free_space_dir(task_list[cpu][idx].vmem,false); + vmem_free_space_dir(task_list[cpu][idx].vmem,task_list[cpu][idx].thread); } |
