Few small adjustments to the scheduler
This commit is contained in:
parent
1c12cf016e
commit
ddbe9b8b8b
@ -1,6 +1,7 @@
|
|||||||
#define MODULE "sched"
|
#define MODULE "sched"
|
||||||
|
|
||||||
#include "thread/Scheduler.h"
|
#include "thread/Scheduler.h"
|
||||||
|
#include "assert.h"
|
||||||
#include "interrupts/Interrupts.h"
|
#include "interrupts/Interrupts.h"
|
||||||
#include "log/Log.h"
|
#include "log/Log.h"
|
||||||
#include "memory/KernelMemoryManager.h"
|
#include "memory/KernelMemoryManager.h"
|
||||||
@ -45,7 +46,7 @@ void Scheduler::init()
|
|||||||
end_task = base_task;
|
end_task = base_task;
|
||||||
sched_current_task = base_task;
|
sched_current_task = base_task;
|
||||||
sched_current_task->id = free_tid++;
|
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;
|
sched_current_task->next_task = nullptr;
|
||||||
// the other registers will be saved next task switch
|
// 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.cs = 0x08;
|
||||||
new_task->regs.ds = 0x10;
|
new_task->regs.ds = 0x10;
|
||||||
asm volatile("pushfq; movq (%%rsp), %%rax; movq %%rax, %0; popfq;" : "=m"(new_task->regs.rflags)::"%rax");
|
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_sleep = 0;
|
||||||
new_task->task_time = 0;
|
new_task->task_time = 0;
|
||||||
end_task->next_task = new_task;
|
end_task->next_task = new_task;
|
||||||
@ -88,6 +89,7 @@ static void sched_decrement_sleep_times()
|
|||||||
|
|
||||||
void Scheduler::task_tick(Context* context)
|
void Scheduler::task_tick(Context* context)
|
||||||
{
|
{
|
||||||
|
ASSERT(Interrupts::is_in_handler());
|
||||||
sched_decrement_sleep_times();
|
sched_decrement_sleep_times();
|
||||||
sched_current_task->task_time -= frequency;
|
sched_current_task->task_time -= frequency;
|
||||||
if (sched_current_task->task_time < 0)
|
if (sched_current_task->task_time < 0)
|
||||||
@ -99,6 +101,7 @@ void Scheduler::task_tick(Context* context)
|
|||||||
|
|
||||||
void Scheduler::task_yield(Context* context)
|
void Scheduler::task_yield(Context* context)
|
||||||
{
|
{
|
||||||
|
ASSERT(Interrupts::is_in_handler());
|
||||||
get_context_to_task(*sched_current_task, context);
|
get_context_to_task(*sched_current_task, context);
|
||||||
bool was_idle = false;
|
bool was_idle = false;
|
||||||
if (sched_current_task->id == 0) // idle task
|
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) { sched_current_task = base_task; }
|
||||||
if (sched_current_task->task_sleep == 0)
|
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);
|
set_context_from_task(*sched_current_task, context);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -123,8 +126,7 @@ void Scheduler::task_yield(Context* context)
|
|||||||
if (!was_idle) { set_context_from_task(*sched_current_task, context); }
|
if (!was_idle) { set_context_from_task(*sched_current_task, context); }
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
kinfoln("Resuming current task %ld", original_task->id);
|
original_task->task_time = 20; // grant 30 more ms, there is no other task available
|
||||||
original_task->task_time = 30; // grant 30 more ms, there is no other task available
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user