Skip to content

Commit df1c5c1

Browse files
committed
Add sched_t to kcb for O(1) scheduler support
Introduce sched_t structure to encapsulate O(1) scheduler state. sched_t maintains ready_queues separated by priority, enabling task selection in O(1) complexity. kcb now contains a sched_t instance, allowing per-hart scheduler control and future SMP extensions.
1 parent b3a4062 commit df1c5c1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

include/sys/task.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,28 @@ typedef struct tcb {
8484
void *rt_prio; /* Opaque pointer for custom real-time scheduler hook */
8585
} tcb_t;
8686

87+
/* Scheduler attribution */
88+
typedef struct sched {
89+
volatile uint32_t ready_bitmap; /* 8-bit priority bitmap */
90+
list_t
91+
*ready_queues[TASK_PRIORITY_LEVELS]; /* Separate queue per priority */
92+
uint16_t queue_counts[TASK_PRIORITY_LEVELS]; /* O(1) size tracking */
93+
94+
/* Weighted Round-Robin State per Priority Level */
95+
list_node_t *rr_cursors[TASK_PRIORITY_LEVELS]; /* Round-robin position */
96+
uint32_t
97+
quantum_cycles[TASK_PRIORITY_LEVELS]; /* Scheduling cycles per level */
98+
99+
/* Performance Optimization */
100+
uint8_t last_selected_prio; /* Cache hint for next selection */
101+
uint32_t local_switches; /* Context switch count */
102+
103+
/* Hart-Specific Data */
104+
tcb_t *current_task; /* Currently running task */
105+
uint8_t hart_id; /* RISC-V hart identifier */
106+
107+
} sched_t;
108+
87109
/* Kernel Control Block (KCB)
88110
*
89111
* Singleton structure holding global kernel state, including task lists,
@@ -104,6 +126,9 @@ typedef struct {
104126
/* Timer Management */
105127
list_t *timer_list; /* List of active software timers */
106128
volatile uint32_t ticks; /* Global system tick, incremented by timer */
129+
130+
/* per-hart scheduler management */
131+
sched_t scheduler;
107132
} kcb_t;
108133

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

0 commit comments

Comments
 (0)