Commit 279364e
committed
Add sched_t to kcb for O(1) scheduler support
Previously, the scheduler performed a linear search through the global
task list (kcb->tasks) to find the next TASK_READY task. This approach
limited scalability as the search iterations increased with the number
of tasks, resulting in higher scheduling latency.
To support an O(1) scheduler and improve extensibility, a sched_t
structure is introduced and integrated into kcb. The new structure
contains:
- ready_queues: Holds all runnable tasks, including TASK_RUNNING and
TASK_READY. The scheduler selects tasks directly from these queues.
- ready_bitmap: Records the state of each ready queue. Using the bitmap,
the scheduler can locate the highest-priority runnable task in O(1)
time complexity.
- rr_cursors: Round-robin cursors that track the next task node in each
ready queue. Each priority level maintains its own RR cursor. The top
priority cursor is assigned to kcb->task_current, which is advanced
circularly after each scheduling cycle.
- hart_id: Identifies the scheduler instance per hart (0 for single-hart
configurations).
- task_idle: The system idle task, executed when no runnable tasks exist.
In the current design, kcb binds only one sched_t instance (hart0) for
single-hart systems, but this structure can be extended for multi-hart
scheduling in the future.1 parent fdd7587 commit 279364e
2 files changed
+27
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
87 | 102 | | |
88 | 103 | | |
89 | 104 | | |
| |||
104 | 119 | | |
105 | 120 | | |
106 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
107 | 125 | | |
108 | 126 | | |
109 | 127 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
18 | 26 | | |
19 | 27 | | |
20 | 28 | | |
| |||
25 | 33 | | |
26 | 34 | | |
27 | 35 | | |
| 36 | + | |
28 | 37 | | |
29 | 38 | | |
30 | 39 | | |
| |||
0 commit comments