Skip to content

Add sleep and delay for task handling#115

Merged
LuernOutOfOrder merged 24 commits intodevelopfrom
108-add-sleepdelay
Feb 9, 2026
Merged

Add sleep and delay for task handling#115
LuernOutOfOrder merged 24 commits intodevelopfrom
108-add-sleepdelay

Conversation

@LuernOutOfOrder
Copy link
Owner

This pull request introduces kernel task blocking and sleeping primitives, improves documentation, and refines several core kernel mechanisms. The most significant changes are the addition of the sleep primitive and blocked task management, as well as new and updated documentation for kernel structures, primitives, and timing helpers.

Kernel task blocking and sleeping primitives:

  • Added a new sleep primitive (with supporting assembly and Rust code) to allow tasks to block themselves for a specified number of ticks, updating their state and moving them between ready and blocked queues as appropriate. This includes the new TaskBlockControl enum and changes to the Task struct to track block reasons. (src/task/primitives.rs, src/arch/riscv32/asm/sleep.S, src/arch/riscv32/asm/mod.rs, src/task/mod.rs, src/main.rs, [1] [2] [3] [4] [5] [6]

  • Implemented the task_awake_blocked function, which checks the blocked queue and moves tasks back to the ready queue when their sleep duration has elapsed. This is now called from the timer interrupt handler. (src/task/primitives.rs, src/arch/riscv32/traps/handler.rs, [1] [2] [3]

Documentation improvements:

  • Added comprehensive documentation for kernel data structures, primitives, and timing helpers, including invariants and usage notes. (Documentation/kernel/data_structure.md, Documentation/kernel/primitives.md, Documentation/kernel/timing_helpers.md, [1] [2] [3]

Kernel and scheduling changes:

  • Modified the scheduler to only requeue tasks as ready if they are not blocked, and added a separate blocked queue. (src/scheduler/mod.rs, src/main.rs, [1] [2]

Testing and test infrastructure:

  • Added and updated test coverage for task primitives, including yield and sleep, and integrated the new tests into the test suite. (src/tests/suites.rs, src/tests/arch/riscv32/task/task_context.rs, [1] [2] [3]

Miscellaneous improvements:

  • Increased the ROM size in the linker script to accommodate new code. (linkers/linker_test_mode.ld, linkers/linker_test_mode.ldL6-R6)
  • Updated version numbers in Cargo.toml and src/info.rs. [1] [2]
  • Minor code cleanups and improvements, such as removing unnecessary trait bounds and improving trap handler argument passing. (src/primitives/ring_buff.rs, src/arch/riscv32/asm/trap_entry.S, [1] [2]

These changes lay the groundwork for more advanced task scheduling and blocking mechanisms in the kernel and improve maintainability through better documentation and testing.

Add a sleep primitive composed by an asm entry point and a rust
function, save the current task context and compute awake tick
Sleep is more a task public API fn than a primitive type
Add a small description, and very trivial documentation on all current
primitives types. If I haven't forgot any.
The ROM is not really used for now in test mode so it's ok I guess
Testing the invariants from sleep primitive, from the blocked queue and
the timer interrupt
Add run queue check for invariants
…e and timing_helpers to documentation

Split the primitives documentation to have more separate logic
documentation, data structure and timing helpers are not primitives so
there's should not be in the primitives documentation.
…eep test behavior

Add the info header to primitives task file to keep track of what is
tested at this point, update the task sleep test behavior to skipped to
not always running it
@LuernOutOfOrder LuernOutOfOrder added this to the v0.4.5 milestone Feb 9, 2026
@LuernOutOfOrder LuernOutOfOrder self-assigned this Feb 9, 2026
@LuernOutOfOrder LuernOutOfOrder added documentation Improvements or additions to documentation enhancement New feature or request labels Feb 9, 2026
@LuernOutOfOrder LuernOutOfOrder merged commit 9b79e7c into develop Feb 9, 2026
3 checks passed
@LuernOutOfOrder LuernOutOfOrder deleted the 108-add-sleepdelay branch February 9, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant