Skip to content

Add idle task#116

Merged
LuernOutOfOrder merged 16 commits intodevelopfrom
107-add-idle-task
Feb 10, 2026
Merged

Add idle task#116
LuernOutOfOrder merged 16 commits intodevelopfrom
107-add-idle-task

Conversation

@LuernOutOfOrder
Copy link
Owner

This pull request introduces significant improvements to the kernel's task management and scheduling system, with a focus on supporting an idle task, refining the scheduler, and enhancing context switching for RISC-V. The changes add new kernel features, update task context structures, improve rescheduling logic, and introduce new configuration options.

Key changes include:

Idle Task Support & Task Management

  • Added support for an idle task, including documentation, creation function (task_idle_task), and run-queue fallback when no other tasks are ready. The idle task is statically defined, lowest priority, and ensures the kernel always has something to run. [1] [2] [3] [4] [5]
  • Added get_by_priority and task_list_get_idle_task functions to retrieve tasks by priority, enabling the scheduler to select the idle task when needed. [1] [2]

Scheduler & Run Queue Refactor

  • Replaced the old BUFFER with a new RUN_QUEUE for ready tasks, and improved blocked task queue management. Added configuration for queue sizes and CPU core count. [1] [2] [3] [4]
  • Implemented centralized reschedule flag management via a new CpusState structure in misc.rs, with functions to set, clear, and read the reschedule bit per core. Scheduler now checks and clears this flag as needed. [1] [2] [3]

Task Context & RISC-V Architecture Updates

  • Extended TaskContext to include mstatus, with correct save/restore in context switch assembly, and default initialization to enable interrupts (mie). Updated context offsets and added a test to verify correct initialization. [1] [2] [3] [4] [5] [6] [7]

Documentation & Versioning

  • Updated task documentation to describe the idle task and new TaskBlockControl enum for blocking reasons. [1] [2]
  • Bumped kernel version to 0.4.4 in both Cargo.toml and info.rs. [1] [2]

Miscellaneous

  • Added helper to read the current CPU core (current_cpu_core), and improved trap handling to trigger rescheduling when required. [1] [2]
  • Added and documented new kernel features in Cargo.toml, including idle_task.

These changes collectively improve the reliability, modularity, and extensibility of the kernel's multitasking and scheduling capabilities, laying groundwork for future multicore support and more sophisticated task management.

…o test

Change the BUFFER static to RUN_QUEUE static using a config static for
max size, add a basic idle task, static, no change possible for the dev
calling it, and update the main function to create task and test. Need
sleep primitive to continue on this branch
The CpusState structure will be used to store all useful flags per CPU
core. Like scheduler flags, state flags, and more if needed.
…c API for CPUS_STATE

The reschedule work only once, then it won't work after that, weird but
there's still improvement
…bug log, fix the clear need resched bit to use correct bitwise
Trying to fix the bug on the idle task, after some time running task and
idle task it crash. Don't know why
…port on primitives task test

The test for context switch doesn't work, updating task context with
mstatus broke the test. The context switch still work; just tested it in
main. But the test mode need refactor to use correctly trap handling
…e_task feature on the idle task creation

Added a idle_task feature for the idle task creation. Avoid to always
have it enable.
Also update the Cargo.toml with comment on feature and add the idle_task
feature
Update the definition of task  with the structure, and add a small
definition for the idle task
@LuernOutOfOrder LuernOutOfOrder added this to the v0.4.5 milestone Feb 10, 2026
@LuernOutOfOrder LuernOutOfOrder self-assigned this Feb 10, 2026
@LuernOutOfOrder LuernOutOfOrder added documentation Improvements or additions to documentation enhancement New feature or request labels Feb 10, 2026
@LuernOutOfOrder LuernOutOfOrder merged commit 3a37968 into develop Feb 10, 2026
3 checks passed
@LuernOutOfOrder LuernOutOfOrder deleted the 107-add-idle-task branch February 10, 2026 09:51
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