Skip to content

Commit 43f9499

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. - queue_counts[]: per-priority runnable task counters used for bookkeeping and consistency checks. - 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 3d94a32 commit 43f9499

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

include/sys/task.h

Lines changed: 13 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,15 @@ 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 attribution */
117+
uint8_t ready_bitmap; /* 8-bit priority bitmap */
118+
list_t
119+
*ready_queues[TASK_PRIORITY_LEVELS]; /* Separate queue per priority */
120+
uint16_t queue_counts[TASK_PRIORITY_LEVELS]; /* O(1) size tracking */
121+
122+
/* Weighted Round-Robin State per Priority Level */
123+
list_node_t *rr_cursors[TASK_PRIORITY_LEVELS]; /* Round-robin position */
111124
} kcb_t;
112125

113126
/* 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)