Commit 489485c
committed
Use preemptive EDF scheduler with ecall-based switch
This commit introduces a preemptive Earliest Deadline First (EDF) scheduler
that uses RISC-V ecall instructions for voluntary context switches while
preserving the existing cooperative scheduling mode.
The preemptive scheduler required several architectural changes. Tasks now
maintain separate stack pointer (sp) fields for ISR-based context switching,
distinct from the jmp_buf context used in cooperative mode. The dispatcher
accepts a from_timer parameter to distinguish timer-driven preemption from
voluntary yields, ensuring tick counters only increment on actual timer
interrupts.
Context switching in preemptive mode builds ISR stack frames with mepc
pointing to task entry points, allowing mret to resume execution. The ecall
handler invokes the dispatcher directly, enabling tasks to yield without
relying on setjmp/longjmp which are incompatible with interrupt contexts.
The cooperative mode preserves its setjmp/longjmp semantics. The dispatcher
always calls hal_context_restore() even when the same task continues,
because the longjmp completes the save/restore cycle initiated by
hal_context_save(). The hal_interrupt_tick() function enables interrupts
on a task's first run by detecting when the entry point still resides in
the context's return address slot.
Real-time scheduling support includes EDF with deadline-based priority
calculation, configurable through mo_task_rt_priority(). The RT scheduler
hook in KCB allows custom scheduling policies. Delay handling was enhanced
with batch updates to minimize critical section duration.
The logger subsystem gained a direct_mode flag for ISR-safe output, and
printf was made flush-aware to support synchronous output when needed.
Exception handling uses trap_puts() to avoid printf deadlock in trap
context.
Close #261 parent d75c1da commit 489485c
11 files changed
+1014
-185
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
0 commit comments