-
Notifications
You must be signed in to change notification settings - Fork 28
O(1) scheduler: Task state transition relative APIs modifications #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
vicLin8712
wants to merge
4
commits into
sysprog21:main
Choose a base branch
from
vicLin8712:o1-sched-state-transition-APIs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
O(1) scheduler: Task state transition relative APIs modifications #37
vicLin8712
wants to merge
4
commits into
sysprog21:main
from
vicLin8712:o1-sched-state-transition-APIs
+129
−25
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Nov 19, 2025
Draft
Contributor
|
Do not include numbers in pull-request titles. |
jserv
requested changes
Nov 19, 2025
Contributor
jserv
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refine the git commits to ensure each one contains only minimal, functional changes.
ebee1c2 to
ffd8c66
Compare
Contributor
|
The commits below are really annoying:
Read https://cbea.ms/git-commit/ carefully. |
ffd8c66 to
b00f4b3
Compare
This commit extends the core scheduler data structures to support the new O(1) scheduler design. Adds in tcb_t: - rq_node: embedded list node for ready-queue membership used during task state transitions. This avoids redundant malloc/free for per-enqueue/dequeue nodes by tying the node's lifetime to the task control block. Adds in kcb_t: - ready_bitmap: 8-bit bitmap tracking which priority levels have runnable tasks. - ready_queues[]: per-priority ready queues for O(1) task selection. - queue_counts[]: per-priority runnable task counters used for bookkeeping and consistency checks. - rr_cursors[]: round-robin cursor per priority level to support fair selection within the same priority. These additions are structural only and prepare the scheduler for O(1) ready-queue operations; they do not change behavior yet.
When a task is enqueued into or dequeued from the ready queue, the bitmap that indicates the ready queue state should be updated. These three marcos can be used in mo_task_dequeue() and mo_task_enqueue() APIs to improve readability and maintain consistency.
This commit introduces two helper functions for intrusive list usage, where each task embeds its own list node instead of relying on per-operation malloc/free. The new APIs allow the scheduler to manipulate ready-queue nodes directly: - list_pushback_node(): append an existing node to the end of the list (before the tail sentinel) without allocating memory. - list_remove_node(): remove a node from the list without freeing it, allowing the caller to control the node's lifetime. These helpers will be used by the upcoming O(1) scheduler enqueue/dequeue paths, which require embedded list nodes stored in tcb_t.
This commit refactors sched_enqueue_task() and sched_dequeue_task() to use the per-priority ready queues and the embedded rq_node stored in tcb_t, instead of relying only on task state inspection. Tasks are now explicitly added to and removed from the appropriate ready queue, and queue_counts, rr_cursors, and the ready_bitmap are updated accordingly.
b00f4b3 to
9ca3f90
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
O(1) scheduler: Task state transition relative APIs modifications
This PR integrates the modified sched_enqueue_task() and sched_dequeue_task() helpers introduced in #36 into the existing task state transition APIs.
This is part 2 of a 3-part stacked PR series, and depends on #36 (Part 1: infrastructure).
Summary
To support a ready-queue-based O(1) scheduler, task state transitions must explicitly maintain the ready queues by invoking the enqueue/dequeue helpers whenever a task moves into or out of the schedulable state set.
This PR updates all relevant task state transition paths to ensure that the ready queue remains consistent with the task’s state.
Detail
The task state transition of the original scheduler is shown below:

Only tasks in
TASK_READYorTASK_RUNNINGmay be selected as the next runnable task.All other task states are considered non-schedulable and may appear in arbitrary situations.
From this scheduling rule, task states naturally fall into two groups:
Schedulable: { TASK_RUNNING, TASK_READY }
Non-schedulable: { all other states }
Therefore, the enqueue/dequeue helper functions must be invoked whenever a task transitions between these two groups.
This ensures that the ready queue accurately reflects the set of tasks eligible for scheduling.
Code changes
This PR is part 2 of the stacked O(1) scheduler series.
Only the commits listed below are unique to this PR:
Verification
Linmo still operates under the original linear-search scheduler at this stage.
No scheduling behavior is changed; the ready queue is updated, but not yet used by the dispatch path introduced in later PRs.
All tests/applications in
/appsbuild and run successfully.Reference
#23 — Prior draft discussion
#36 — Part 1: O(1) scheduler infrastructure (base of this PR)
Summary by cubic
Updates task state transitions to keep O(1) ready queues in sync via enqueue/dequeue helpers with embedded rq_node. This is part 2 of the O(1) scheduler; no behavior change and all apps still build and run.
Refactors
Bug Fixes
Written for commit 9ca3f90. Summary will update automatically on new commits.