Skip to content

Commit ae78151

Browse files
committed
Add data structures for O(1) scheduler
This commit extends the core scheduler data structures to support the new O(1) scheduler design. Adds in tcb_t: - rq_node: embedded list node for ready-queue membership used during task state transitions. This avoids redundant malloc/free for per-enqueue/dequeue nodes by tying the node's lifetime to the task control block. Adds in kcb_t: - ready_bitmap: 8-bit bitmap tracking which priority levels have runnable tasks. - ready_queues[]: per-priority ready queues for O(1) task selection. - rr_cursors[]: round-robin cursor per priority level to support fair selection within the same priority. These additions are structural only and prepare the scheduler for O(1) ready-queue operations; they do not change behavior yet.
1 parent b4c2d10 commit ae78151

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

include/sys/task.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ typedef struct tcb {
8686

8787
/* Stack Protection */
8888
uint32_t canary; /* Random stack canary for overflow detection */
89+
90+
/* State transition support */
91+
/* Ready queue membership node (only one per task) */
92+
list_node_t rq_node;
8993
} tcb_t;
9094

9195
/* Kernel Control Block (KCB)
@@ -108,6 +112,12 @@ typedef struct {
108112
/* Timer Management */
109113
list_t *timer_list; /* List of active software timers */
110114
volatile uint32_t ticks; /* Global system tick, incremented by timer */
115+
116+
/* Scheduling attributions */
117+
uint8_t ready_bitmap; /* 8-bit priority bitmap */
118+
list_t
119+
*ready_queues[TASK_PRIORITY_LEVELS]; /* Separate queue per priority */
120+
list_node_t *rr_cursors[TASK_PRIORITY_LEVELS]; /* Round-robin position */
111121
} kcb_t;
112122

113123
/* Global pointer to the singleton Kernel Control Block */

kernel/task.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ static kcb_t kernel_state = {
2626
.task_count = 0,
2727
.ticks = 0,
2828
.preemptive = true, /* Default to preemptive mode */
29+
.ready_bitmap = 0,
30+
.ready_queues = {NULL},
31+
.rr_cursors = {NULL},
2932
};
3033
kcb_t *kcb = &kernel_state;
3134

0 commit comments

Comments
 (0)