Scheduler: track total CPU time of tasks

This commit is contained in:
apio 2022-09-25 17:49:51 +02:00
parent 3fd1b6773d
commit 19dff40ee2
2 changed files with 6 additions and 3 deletions

View File

@ -23,6 +23,8 @@ struct Task
uint64_t allocated_stack = 0; uint64_t allocated_stack = 0;
TaskState state; TaskState state;
uint64_t cpu_time = 0;
}; };
void set_context_from_task(Task& task, Context* ctx); void set_context_from_task(Task& task, Context* ctx);

View File

@ -25,7 +25,6 @@ static Task* end_task;
static void idle_task_function() static void idle_task_function()
{ {
Interrupts::enable();
while (1) asm volatile("hlt"); while (1) asm volatile("hlt");
} }
@ -123,7 +122,8 @@ void Scheduler::reap_task(Task* task)
void Scheduler::task_exit(Context* context) void Scheduler::task_exit(Context* context)
{ {
ASSERT(Interrupts::is_in_handler()); ASSERT(Interrupts::is_in_handler());
kdbgln("exit: task %ld finished running", sched_current_task->id); kdbgln("exit: task %ld finished running, used %ld ms of cpu time", sched_current_task->id,
sched_current_task->cpu_time);
sched_current_task->state = sched_current_task->Exited; sched_current_task->state = sched_current_task->Exited;
task_yield(context); task_yield(context);
} }
@ -131,7 +131,7 @@ void Scheduler::task_exit(Context* context)
void Scheduler::task_misbehave(Context* context) void Scheduler::task_misbehave(Context* context)
{ {
ASSERT(Interrupts::is_in_handler()); ASSERT(Interrupts::is_in_handler());
kdbgln("exit: task %ld misbehaved", sched_current_task->id); kdbgln("exit: task %ld misbehaved, used %ld ms of cpu time", sched_current_task->id, sched_current_task->cpu_time);
sched_current_task->state = sched_current_task->Exited; sched_current_task->state = sched_current_task->Exited;
task_yield(context); task_yield(context);
} }
@ -209,6 +209,7 @@ void Scheduler::task_tick(Context* context)
sched_decrement_sleep_times(); sched_decrement_sleep_times();
if (sched_current_task->id == 0) return task_yield(context); if (sched_current_task->id == 0) return task_yield(context);
sched_current_task->task_time -= frequency; sched_current_task->task_time -= frequency;
sched_current_task->cpu_time += frequency;
if (sched_current_task->task_time < 0) if (sched_current_task->task_time < 0)
{ {
sched_current_task->task_time = 0; sched_current_task->task_time = 0;