aboutsummaryrefslogtreecommitdiff
path: root/kernel/proc/sched.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/proc/sched.c')
-rw-r--r--kernel/proc/sched.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/kernel/proc/sched.c b/kernel/proc/sched.c
index d0e634f..0461279 100644
--- a/kernel/proc/sched.c
+++ b/kernel/proc/sched.c
@@ -74,6 +74,7 @@ void sched_queue_init(ktqueue_t *queue)
*/
static void ktqueue_enqueue(ktqueue_t *queue, kthread_t *thr)
{
+ // TODO: ask in mentor meeting about what causes this assertion error
KASSERT(!thr->kt_wchan);
list_assert_sanity(&queue->tq_list);
@@ -229,19 +230,19 @@ void sched_switch(ktqueue_t *queue)
{
// NOT_YET_IMPLEMENTED("PROCS: sched_switch");
- KASSERT(intr_getipl == IPL_HIGH);
+ // KASSERT(intr_getipl == IPL_HIGH);
intr_disable();
+ int oldIPL = intr_setipl(IPL_LOW); // allow interrupts to wake up the idling core
KASSERT(curthr->kt_state != KT_ON_CPU);
- ktqueue_enqueue(queue, curthr);
curcore.kc_queue = queue;
last_thread_context = &curthr->kt_ctx;
- intr_setipl(IPL_LOW); // allow interrupts to wake up the idling core
- intr_enable();
context_switch(&curthr->kt_ctx, &curcore.kc_ctx);
+ intr_enable();
+ intr_setipl(oldIPL);
// TODO: ask about why we need the old thread context
}
@@ -271,11 +272,11 @@ void sched_make_runnable(kthread_t *thr)
// NOT_YET_IMPLEMENTED("PROCS: sched_make_runnable");
dbg(DBG_SCHED, "Making thread with proc pid %d runnable\n in thread\n", thr->kt_proc->p_pid);
- if (curthr == NULL)
+ if (curthr)
{
- dbg(DBG_SCHED, "I did this ^^ with a null thread!\n");
- } else {
dbg(DBG_SCHED, "I did this ^^ with thread %d\n", curthr->kt_proc->p_pid);
+ } else {
+ dbg(DBG_SCHED, "I did this ^^ with a null thread!\n");
}
KASSERT(thr != curthr);
@@ -307,9 +308,8 @@ void sched_sleep_on(ktqueue_t *q)
int oldIPL = intr_setipl(IPL_HIGH);
curthr->kt_state = KT_SLEEP;
-
sched_switch(q);
- // intr_setipl(oldIPL); not called, hold the lock into the sched_switch call
+ intr_setipl(oldIPL);
}
/*
@@ -433,6 +433,9 @@ void core_switch()
KASSERT(mapped_paddr == expected_paddr);
curthr = next_thread;
+
+ dbg(DBG_THR, "Switching to curthr thread %d\n", curthr->kt_proc->p_pid);
+
curthr->kt_state = KT_ON_CPU;
curproc = curthr->kt_proc;
context_switch(&curcore.kc_ctx, &curthr->kt_ctx);