diff --git a/kernel/src/thread/Scheduler.cpp b/kernel/src/thread/Scheduler.cpp index 34c1518a..dc085af9 100644 --- a/kernel/src/thread/Scheduler.cpp +++ b/kernel/src/thread/Scheduler.cpp @@ -1,6 +1,7 @@ #define MODULE "sched" #include "thread/Scheduler.h" +#include "assert.h" #include "interrupts/Interrupts.h" #include "log/Log.h" #include "memory/KernelMemoryManager.h" @@ -45,7 +46,7 @@ void Scheduler::init() end_task = base_task; sched_current_task = base_task; sched_current_task->id = free_tid++; - sched_current_task->task_time = 30; // gets 30 ms of cpu time before next switch + sched_current_task->task_time = 20; // gets 20 ms of cpu time before next switch sched_current_task->next_task = nullptr; // the other registers will be saved next task switch @@ -63,7 +64,7 @@ void Scheduler::add_kernel_task(void (*task)(void)) new_task->regs.cs = 0x08; new_task->regs.ds = 0x10; asm volatile("pushfq; movq (%%rsp), %%rax; movq %%rax, %0; popfq;" : "=m"(new_task->regs.rflags)::"%rax"); - new_task->regs.rflags |= 0x200; + new_task->regs.rflags |= 0x200; // enable interrupts new_task->task_sleep = 0; new_task->task_time = 0; end_task->next_task = new_task; @@ -88,6 +89,7 @@ static void sched_decrement_sleep_times() void Scheduler::task_tick(Context* context) { + ASSERT(Interrupts::is_in_handler()); sched_decrement_sleep_times(); sched_current_task->task_time -= frequency; if (sched_current_task->task_time < 0) @@ -99,6 +101,7 @@ void Scheduler::task_tick(Context* context) void Scheduler::task_yield(Context* context) { + ASSERT(Interrupts::is_in_handler()); get_context_to_task(*sched_current_task, context); bool was_idle = false; if (sched_current_task->id == 0) // idle task @@ -112,7 +115,7 @@ void Scheduler::task_yield(Context* context) if (!sched_current_task) { sched_current_task = base_task; } if (sched_current_task->task_sleep == 0) { - sched_current_task->task_time = 30; + sched_current_task->task_time = 20; set_context_from_task(*sched_current_task, context); return; } @@ -123,8 +126,7 @@ void Scheduler::task_yield(Context* context) if (!was_idle) { set_context_from_task(*sched_current_task, context); } return; } - kinfoln("Resuming current task %ld", original_task->id); - original_task->task_time = 30; // grant 30 more ms, there is no other task available + original_task->task_time = 20; // grant 30 more ms, there is no other task available return; }