From 59cac783f5ba12a47308b05b87d5cfa769473a49 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Wed, 11 Jul 2018 05:38:01 +1000 Subject: Modified the tick_handler interrupt routine in timer.s so that it no longer calls reschedule() directly. It now calls sched_tick() so that the scheduler can make it's own decisions relating to handling the timer interrupt. The reschedule() function now *actually* implements a basic round-robin scheduling algorithm that iterates through the list of tasks. This is still a temporary algorithm but at least it now includes *all* runnable processes instead of switching back and forth between process 1 and 2. --- kernel/sched.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'kernel/sched.c') diff --git a/kernel/sched.c b/kernel/sched.c index dd75d47..8469005 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -48,6 +48,7 @@ struct task_state { } __attribute__((packed)); struct task_struct *ctask; +uint32_t ctaskn; struct task_state *cstate; static struct task_struct tasks[NRTASKS]; @@ -192,6 +193,7 @@ void sched_init(void) { ctask = NULL; cstate = NULL; + create_proc(&_usrbin_start, (size_t) &_usrbin_size); create_proc(&_usrbin_start, (size_t) &_usrbin_size); create_proc(&_usrbin_start, (size_t) &_usrbin_size); @@ -221,12 +223,20 @@ void save_state(void) { } void reschedule(void) { + int i; + uint32_t n; + if(ctask == NULL) return; - if(ctask == &tasks[0]) { - switch_to(1, &tasks[1]); - } else { - switch_to(0, &tasks[0]); + n = ctaskn; + for(i = 0; i < NRTASKS; i++) { + n = (n + 1) % NRTASKS; + if(tasks[n].pid) + switch_to(n, &tasks[n]); } } + +void sched_tick(void) { + reschedule(); +} -- cgit v1.3