summaryrefslogtreecommitdiff
path: root/kernel/sched_class_o1.cc
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-07-10 11:31:46 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-07-10 11:31:46 +0800
commite90b72ec3082588b296956730bd2930cf8d5d671 (patch)
tree36ff6916af9b4176ea5a9662219d11e721f0b691 /kernel/sched_class_o1.cc
parent1767d390fbf3d0c65389de46caf0b6d43ef3b6ad (diff)
downloadlume-e90b72ec3082588b296956730bd2930cf8d5d671.tar.gz
lume-e90b72ec3082588b296956730bd2930cf8d5d671.tar.xz
refactor: promote new architecture to repository root
Archive the deprecated implementation under lume-legacy, make the new kernel the default root-level build, and update repository entry points without changing kernel behavior.
Diffstat (limited to 'kernel/sched_class_o1.cc')
-rw-r--r--kernel/sched_class_o1.cc81
1 files changed, 81 insertions, 0 deletions
diff --git a/kernel/sched_class_o1.cc b/kernel/sched_class_o1.cc
new file mode 100644
index 0000000..28c693c
--- /dev/null
+++ b/kernel/sched_class_o1.cc
@@ -0,0 +1,81 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright (C) 2026 Richard Qin */
+
+/*
+ * O(1) Priority Bitmap Scheduling Class
+ */
+
+#include <lume/sched.h>
+#include <lume/sched_class.h>
+#include <lume/task.h>
+#include <lume/bitops.h>
+#include <kernel/sched_internal.h>
+
+static void o1_init_rq(RunQueue* rq)
+{
+ rq->o1().init();
+}
+
+static void o1_enqueue_task(RunQueue* rq, TaskControlBlock* task)
+{
+ rq->o1().enqueue(task);
+ rq->inc_running();
+}
+
+static void o1_dequeue_task(RunQueue* rq, TaskControlBlock* task)
+{
+ rq->o1().dequeue(task);
+ rq->dec_running();
+}
+
+static TaskControlBlock* o1_pick_next_task(RunQueue* rq)
+{
+ return rq->o1().pick_next();
+}
+
+static void o1_put_prev_task(RunQueue* /*rq*/, TaskControlBlock* /*task*/) {}
+
+int32 priority_to_timeslice(uint8 priority)
+{
+ int32 ts = 20 - static_cast<int32>(priority) * 19 / 31;
+ if (ts < 1) ts = 1;
+ return ts;
+}
+
+static void o1_task_tick(RunQueue* rq, TaskControlBlock* curr)
+{
+ if (curr == rq->idle()) {
+ /* Idle task: if anything is runnable, yield immediately */
+ if (rq->nr_running() > 0) {
+ rq->set_need_resched(true);
+ }
+ return;
+ }
+
+ curr->time_slice--;
+ if (curr->time_slice <= 0) {
+ curr->time_slice = priority_to_timeslice(curr->priority);
+ rq->set_need_resched(true);
+ }
+}
+
+static void o1_yield_task(RunQueue* rq, TaskControlBlock* curr)
+{
+ if (curr == rq->idle())
+ return;
+
+ curr->time_slice = 0;
+ rq->set_need_resched(true);
+}
+
+const SchedClass g_sched_class_o1 = {
+ .name = "o1",
+ .next = &g_sched_class_idle,
+ .init_rq = o1_init_rq,
+ .enqueue_task = o1_enqueue_task,
+ .dequeue_task = o1_dequeue_task,
+ .pick_next_task = o1_pick_next_task,
+ .put_prev_task = o1_put_prev_task,
+ .task_tick = o1_task_tick,
+ .yield_task = o1_yield_task,
+};