This commit is contained in:
2026-08-11 17:48:20 +02:00
committed by Marvin Friedrich
parent cf33867e68
commit 0e2d4ed8c6
55 changed files with 279 additions and 346 deletions
+13 -13
View File
@@ -1,6 +1,5 @@
#include <zinnia/status.h>
#include <kernel/alloc.h>
#include <kernel/assert.h>
#include <kernel/irq.h>
#include <kernel/list.h>
#include <kernel/percpu.h>
@@ -8,6 +7,7 @@
#include <kernel/sched.h>
#include <kernel/spin.h>
#include <kernel/tailq.h>
#include <assert.h>
#include <bits/irq.h>
#include <stdatomic.h>
#include <stdint.h>
@@ -35,30 +35,30 @@ void sched_to_user_context(uintptr_t ctx) {
void sched_init(struct sched_percpu* sched) {
struct task* idle_task;
ASSERT(
assert(
task_create("idle", &kernel_vas, nullptr, idle_func, 0, &idle_task) == ZN_OK,
"Unable to create idle task!\n"
);
sched->idle_task = idle_task;
sched->current = idle_task;
TAILQ_INIT(&sched->run_queue);
tailq_init(&sched->run_queue);
kprintf("Scheduler initialized\n");
}
void sched_add_task(struct sched_percpu* sched, struct task* task) {
ASSERT(task != nullptr, "Tried to add NULL to the run queue\n");
TAILQ_INSERT_TAIL(&sched->run_queue, task, next);
assert(task != nullptr, "Tried to add NULL to the run queue\n");
tailq_insert_tail(&sched->run_queue, task, next);
}
static struct task* next_task(struct sched_percpu* sched) {
struct task* t = TAILQ_FIRST(&sched->run_queue);
struct task* t = tailq_first(&sched->run_queue);
if (t == nullptr)
return sched->idle_task;
TAILQ_REMOVE(&sched->run_queue, t, next);
tailq_remove(&sched->run_queue, t, next);
return t;
}
@@ -143,7 +143,7 @@ void task_entry(task_fn_t entry, uintptr_t arg0) {
}
void wait_queue_init(struct wait_queue* wq) {
TAILQ_INIT(&wq->waiters);
tailq_init(&wq->waiters);
wq->lock = (struct spinlock){0};
}
@@ -152,7 +152,7 @@ void sched_block(struct sched_percpu* sched, struct wait_queue* wq) {
spin_lock(&wq->lock);
sched->current->state = TASK_STATE_BLOCKED;
TAILQ_INSERT_TAIL(&wq->waiters, sched->current, next);
tailq_insert_tail(&wq->waiters, sched->current, next);
spin_unlock(&wq->lock);
do_reschedule(sched);
@@ -161,9 +161,9 @@ void sched_block(struct sched_percpu* sched, struct wait_queue* wq) {
void sched_wake(struct sched_percpu* sched, struct wait_queue* wq) {
spin_lock(&wq->lock);
struct task* t = TAILQ_FIRST(&wq->waiters);
struct task* t = tailq_first(&wq->waiters);
if (t != nullptr) {
TAILQ_REMOVE(&wq->waiters, t, next);
tailq_remove(&wq->waiters, t, next);
t->state = TASK_STATE_READY;
sched_add_task(sched, t);
}
@@ -175,8 +175,8 @@ void sched_wake_all(struct sched_percpu* sched, struct wait_queue* wq) {
spin_lock(&wq->lock);
struct task* t;
while ((t = TAILQ_FIRST(&wq->waiters)) != nullptr) {
TAILQ_REMOVE(&wq->waiters, t, next);
while ((t = tailq_first(&wq->waiters)) != nullptr) {
tailq_remove(&wq->waiters, t, next);
t->state = TASK_STATE_READY;
sched_add_task(sched, t);
}