summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorJake Mannens <jake72360@gmail.com>2018-07-11 05:38:01 +1000
committerJake Mannens <jake72360@gmail.com>2018-07-11 05:38:01 +1000
commit59cac783f5ba12a47308b05b87d5cfa769473a49 (patch)
tree35e14bb57fa7fdbaf1573f409c3289e1ddb9c0c1 /kernel
parent99d16e98e04c73e108160d7d70244bafdb33b6fc (diff)
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.
Diffstat (limited to 'kernel')
-rw-r--r--kernel/asm.s5
-rw-r--r--kernel/sched.c18
-rw-r--r--kernel/timer.s4
3 files changed, 20 insertions, 7 deletions
diff --git a/kernel/asm.s b/kernel/asm.s
index 0bf9067..6d35334 100644
--- a/kernel/asm.s
+++ b/kernel/asm.s
@@ -3,6 +3,7 @@ global switch_to
global set_tss
extern cstate
extern ctask
+extern ctaskn
extern gdt
extern save_state
@@ -27,9 +28,11 @@ switch_to:
ltr ax
; copy the saved state into the previous TSS
call save_state
- ; update ctask
+ ; update ctask and ctaskn
mov ebx, [ebp+12]
mov [ctask], ebx
+ mov ebx, [ebp+8]
+ mov [ctaskn], ebx
; calculate the task segment index and jump to it
mov ebx, [ebp+8]
add ebx, 5
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];
@@ -194,6 +195,7 @@ void sched_init(void) {
create_proc(&_usrbin_start, (size_t) &_usrbin_size);
create_proc(&_usrbin_start, (size_t) &_usrbin_size);
+ create_proc(&_usrbin_start, (size_t) &_usrbin_size);
switch_to(0, &tasks[0]);
}
@@ -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();
+}
diff --git a/kernel/timer.s b/kernel/timer.s
index c84a847..12ea9d0 100644
--- a/kernel/timer.s
+++ b/kernel/timer.s
@@ -2,7 +2,7 @@ global ticks
global timer_init
extern cstate
extern register_isr
-extern reschedule
+extern sched_tick
ticks: dd 0
@@ -26,7 +26,7 @@ tick_handler:
out 0x20, al
; call the scheduler
- call reschedule
+ call sched_tick
; restore the data segment selectors
pop ax