ppos

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 049015a681d6c5ea61f275c79faff40b0b08325e
parent b975396106ace01a0ddd2d01e572213ff61ff53b
Author: Gabriel G. de Brito <me@gboncoffee.dev.br>
Date:   Sun, 30 Aug 2026 00:06:53 -0300

Contagem de tempo.

Diffstat:
Mkernel/dispatcher.c | 50+++++++++++++++++++++++++++++++++++++++++++++++---
Mkernel/task.c | 11+++++++----
Mkernel/tcb.h | 20+++++++++++++-------
3 files changed, 67 insertions(+), 14 deletions(-)

diff --git a/kernel/dispatcher.c b/kernel/dispatcher.c @@ -8,10 +8,11 @@ #include "scheduler.h" #include "task.h" +#include "time.h" #include <assert.h> +#include <pplibc.h> #include <queue.h> -#include <stdio.h> struct queue_t* ready; @@ -32,18 +33,46 @@ void user_main(void*); void dispatcher() { + kernel_task.wall_start = time(); + kernel_task.wall_last_grab = kernel_task.wall_start; + kernel_task.activations = 1; + task_create("user_main", user_main, NULL); while (queue_size(ready) > 0) { struct task_t* task = scheduler(ready); - if (task != NULL) + if (task != NULL) { + kernel_task.cpu_time += time() - kernel_task.wall_last_grab; task_run(task); + } + kernel_task.activations += 1; if (task->status == TaskStatusFinished) { + printk( + "PPOS: task %d (%s) %d ms run, %d ms cpu, %d acts, exit " + "code %d\n", + task->id, + task->name, + time() - task->wall_start, + task->cpu_time, + task->activations, + task->exit_code + ); task_destroy(task); } } + kernel_task.cpu_time += time() - kernel_task.wall_last_grab; + printk( + "PPOS: task %d (%s) %d ms run, %d ms cpu, %d acts, exit " + "code %d\n", + kernel_task.id, + kernel_task.name, + time() - kernel_task.wall_start, + kernel_task.cpu_time, + kernel_task.activations, + 0 + ); } void task_run(struct task_t* task) @@ -52,25 +81,35 @@ void task_run(struct task_t* task) task->status = TaskStatusRunning; task->quantum = 10; + task->activations += 1; + task->wall_last_grab = time(); + if (task->wall_start == 0) + task->wall_start = task->wall_last_grab; task_switch(task); } void task_yield() { current->status = TaskStatusReady; + current->cpu_time += time() - current->wall_last_grab; + queue_add(ready, current); + + kernel_task.wall_last_grab = time(); task_switch(&kernel_task); } void task_suspend(struct queue_t* queue) { current->status = TaskStatusWaiting; + current->cpu_time += time() - current->wall_last_grab; if (queue != NULL) { current->waiting_queue = queue; queue_add(queue, current); } + kernel_task.wall_last_grab = time(); task_switch(&kernel_task); } @@ -87,6 +126,11 @@ void task_awake(struct task_t* task) void task_exit(int exit_code) { - current->status = TaskStatusFinished; + current->status = TaskStatusFinished; + current->exit_code = exit_code; + + current->cpu_time += time() - current->wall_last_grab; + + kernel_task.wall_last_grab = time(); task_switch(&kernel_task); } diff --git a/kernel/task.c b/kernel/task.c @@ -7,6 +7,8 @@ #include "task.h" +#include "time.h" + #include <assert.h> #include <queue.h> #include <stdbool.h> @@ -61,10 +63,11 @@ struct task_t* task_create(char* name, void (*entry)(void*), void* arg) ctx_create(&task->context, entry, arg, stack, PPOS_STACK_SIZE); uid += 1; - task->id = uid; - task->parent = current; - task->name = name; - task->status = TaskStatusReady; + task->id = uid; + task->parent = current; + task->name = name; + task->status = TaskStatusReady; + task->wall_start = time(); queue_add(ready, task); diff --git a/kernel/tcb.h b/kernel/tcb.h @@ -30,13 +30,19 @@ struct task_t { char* name; // nome da tarefa struct task_t* parent; struct queue_t* waiting_queue; - int id; // identificador da tarefa - int valgrind_id; - int nice; - int prio; - int quantum; - TaskStatus status; - bool is_system; + unsigned long wall_start; // wall time de quando ela começou + unsigned long + wall_last_grab; // wall time da última vez que ela ganhou a cpu + unsigned long cpu_time; // tempo em que ela passou com a cpu + unsigned long activations; + int id; // identificador da tarefa + int valgrind_id; + int exit_code; + int nice; + int prio; + int quantum; + TaskStatus status; + bool is_system; }; #define PPOS_CONCURRENT_TASKS (1024)