Repository navigation
fix(task): mark a task taken by preemption as running - #817
Merged
Merged
Conversation
…xt() (tier4#814) After tier4#809, `get_next_task()` is always called with `execution_ensured == true`, so the parameter and the `false` branches of the schedulers are dead code. Remove the parameter from `Scheduler::get_next()`, `scheduler::get_next_task()`, and `task::get_next_task()`. The dequeued task is now unconditionally marked as running. The behavior does not change. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A task that `do_preemption()` starts was not marked as running, unlike a task taken by `Scheduler::get_next()`. It ran with the state `Runnable` on a new thread, or `Preempted` when it resumed on its own thread. - `task::get_next_task()`: set `State::Running` for a task taken from `preempt::get_next_task()`. - `do_preemption()`: set `State::Running` for a preempted task that resumes on its own thread. - `run_main()`: reword the comment on the redundant `RUNNING` store. - mdbook: sync the `Scheduler` trait with the source. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
mdbook v0.5 resolves the relative path of `-d` from the current directory, so `make docs` wrote the book outside the repository. Pass an absolute path instead, and regenerate `docs/` with mdbook v0.5.4. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
ytakano
marked this pull request as ready for review
November 25, 2026 09:49
atsushi421
reviewed
Nov 25, 2026
romancardenas
requested changes
Nov 26, 2026
romancardenas
left a comment
Contributor
There was a problem hiding this comment.
LGTM! @atsushi421 found a few issues that should be considered. Probably, the one about moving the task state change in preemptions to the update_last_executed() critical section at preempt.rs:197-201.
Address review comments on tier4#817. - Mark `next` as `Running` (and clear `need_preemption` if it was `Preempted`) in the same critical section as `update_last_executed()`, before its ID is stored in `RUNNING`. Other CPUs no longer see a running task in `Runnable` or `Preempted`, and the separate markings in `get_next_task()` and the preempt-context branch are removed. - On `create_thread` failure, revert `next` to `Runnable` and restore `RUNNING[cpu_id]` to the current task. Previously the stale ID made the `assert_eq!` in `run_main` panic after the current task's poll. - Replace the redundant `RUNNING` store in `run_main` with `debug_assert_eq!` so a missing `set_current_task()` is detected instead of hidden. - Reuse the local `cpu_id` in `ClusteredScheduler::get_next()`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
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.
Description
This PR fixes the three points found in the code review of the change for #814, and fixes the output directory of
make docs.This PR is stacked on the PR for #814 (branch
refactor/remove-execution-ensured). Please merge that PR first.1. Mark a task taken by preemption as running
A task that
do_preemption()starts was not marked as running, unlike a task taken byScheduler::get_next().Runnable.Preempted.Task::wake()handlesRunning,RunnableandPreemptedin the same way, so no wrong behavior was found. The fix makes the state consistent withScheduler::get_next().awkernel_async_lib/src/task.rs,get_next_task(): setState::Runningfor a task taken frompreempt::get_next_task(). A task inTerminatedorPanickedis not changed.awkernel_async_lib/src/task/preempt.rs,do_preemption(): setState::Runningfor a preempted task that resumes on its own thread.2. Reword a comment in
run_main()The comment on
RUNNING[cpu_id].store(task.id, ...)said that the store is needed for schedulers other than PrioritizedFIFO. Every path ofget_next_task()now stores the task ID, so the comment says that the store is redundant and remains as a safeguard. The store itself is not removed.3. Sync the
Schedulertrait in the mdbookmdbook/src/internal/scheduler.mddid not haveget_next_if()andqueued_cpu_mask(). The trait in the page now matchesawkernel_async_lib/src/scheduler.rs.4. Build the mdbook into
awkernel/docsmdbook v0.5 resolves the relative path of
-dfrom the current directory, somake docswrote the book outside the repository. TheMakefilenow passes$(CURDIR)/docs.docs/is regenerated with mdbook v0.5.4.Related links
execution_ensuredparameter ofScheduler::get_next()and `get_next_task() #814How was this PR tested?
scripts/ci.shpasses on my machine.scripts/ci.shwas not run. The following were run instead.make clippy: no warnings or errors on all targets.cargo +nightly-2026-11-09 test_awkernel_async_libpasses.QEMU x86_64 (16 CPUs, release build), no panic:
test_multi_prioritized_scheduler: all 30 tasks started and finished.test_prioritized_rr: in about 57 seconds, each of the 24 high-priority tasks ran 503 to 517 times. This is the same as before the fix.The state of running tasks was measured on QEMU x86_64 (16 CPUs, release build) with
test_prioritized_rrfor 60 seconds. Temporary code counted the state at two points. The code is not included in this PR.3150007d)run_main(), just before the pollRunningRunnableRunningPreemptedBefore the fix, most tasks ran with the state
RunnableorPreempted. After the fix, all tasks ran with the stateRunning. "Before" is the commit for Remove theexecution_ensuredparameter ofScheduler::get_next()and `get_next_task() #814, which has the same code asmainon this path.mainitself was not measured.make docswrites the book toawkernel/docs, anddocs/internal/scheduler.htmlhasget_next_ifandqueued_cpu_mask.Notes for reviewers
fix(task): mark a task taken by preemption as runninghas the code and mdbook source changes.fix(docs): build mdbook into awkernel/docs and regenerate ithas theMakefilechange and the generated files (69 files).docs/is large because mdbook v0.5.4 adds a hash to the file names of CSS, JavaScript and fonts. The only change in the content isdocs/internal/scheduler.html.specification/awkernel_async_lib/src/task/preemptive_spin/preemptive.pmlis not updated. The model does not set the state toRunningon the preemption path, so it now differs from the code in point 1. The model will be updated and verified in a separate PR.