Skip to content

Commit 69421e4

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 0ce5a6c commit 69421e4

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
@@ -82,6 +82,10 @@ typedef struct tcb {
8282

8383
/* Real-time Scheduling Support */
8484
void *rt_prio; /* Opaque pointer for custom real-time scheduler hook */
85+
86+
/* State transition support */
87+
/* Ready queue membership node (only one per task) */
88+
list_node_t rq_node;
8589
} tcb_t;
8690

8791
/* Kernel Control Block (KCB)
@@ -104,6 +108,15 @@ typedef struct {
104108
/* Timer Management */
105109
list_t *timer_list; /* List of active software timers */
106110
volatile uint32_t ticks; /* Global system tick, incremented by timer */
111+
112+
/* Scheduling attribution */
113+
uint8_t ready_bitmap; /* 8-bit priority bitmap */
114+
list_t
115+
*ready_queues[TASK_PRIORITY_LEVELS]; /* Separate queue per priority */
116+
uint16_t queue_counts[TASK_PRIORITY_LEVELS]; /* O(1) size tracking */
117+
118+
/* Weighted Round-Robin State per Priority Level */
119+
list_node_t *rr_cursors[TASK_PRIORITY_LEVELS]; /* Round-robin position */
107120
} kcb_t;
108121

109122
/* 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
@@ -25,6 +25,9 @@ static kcb_t kernel_state = {
2525
.task_count = 0,
2626
.ticks = 0,
2727
.preemptive = true, /* Default to preemptive mode */
28+
.ready_bitmap = 0,
29+
.ready_queues = {NULL},
30+
.rr_cursors = {NULL},
2831
};
2932
kcb_t *kcb = &kernel_state;
3033

0 commit comments

Comments
 (0)