Repository navigation
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>
| let mut info = next.info.lock(&mut node); | ||
|
|
||
| if !matches!(info.state, State::Terminated | State::Panicked) { | ||
| info.state = State::Running; |
There was a problem hiding this comment.
RUNNING[cpu_id] points at next from preempt.rs:203. But next becomes Running only here or at preempt.rs:227, so other CPUs can briefly see a running task in Runnable or Preempted. Consider setting Running (with the Terminated | Panicked guard from this block) in the update_last_executed() critical section at preempt.rs:197-201 instead. That removes this block, the branch at preempt.rs:227 and one next.info lock, but the create_thread failure path then must restore Runnable.
| // `next` resumes on its own thread without passing through | ||
| // `Scheduler::get_next()`, so mark it as running here. | ||
| if next_thread.is_some() { | ||
| task_info.state = super::State::Running; |
There was a problem hiding this comment.
Unlike Scheduler::get_next(), this branch does not set need_preemption = false, although a task here is always Preempted. Nothing reads the flag today, so behavior does not change. Add task_info.need_preemption = false; here, or remove the write-only field in a follow-up.
|
|
||
| // This is unnecessary if the task is scheduled by PrioritizedFIFO. This remains for other schedulers. | ||
| // `get_next_task()` has already stored the task ID. | ||
| // This store is redundant and remains as a safeguard. |
There was a problem hiding this comment.
Because every path of get_next_task() already stores the ID, this store matters only when a future get_next() forgets set_current_task(). In that case it hides the bug from assert_eq!(running_id, task.id) below, so it does not act as a safeguard. Remove it, or replace it with debug_assert_eq!(RUNNING[cpu_id].load(Ordering::Relaxed), task.id);.
There was a problem hiding this comment.
I would say debug_assert_eq! is better, so it does not cause unconditional panics on release mode.
romancardenas
left a comment
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.
| set_current_task(awkernel_lib::cpu::cpu_id(), task.id); | ||
| } | ||
| task_info.state = State::Running; | ||
| set_current_task(awkernel_lib::cpu::cpu_id(), task.id); |
There was a problem hiding this comment.
Would it make sense to reuse cpu_id?
| set_current_task(awkernel_lib::cpu::cpu_id(), task.id); | |
| set_current_task(cpu_id, task.id); |
| set_current_task(awkernel_lib::cpu::cpu_id(), task.id); | ||
| } | ||
| task_info.state = State::Running; | ||
| set_current_task(awkernel_lib::cpu::cpu_id(), task.id); |
There was a problem hiding this comment.
Would it make sense to reuse cpu_id?
| set_current_task(awkernel_lib::cpu::cpu_id(), task.id); | |
| set_current_task(cpu_id, task.id); |
| set_current_task(awkernel_lib::cpu::cpu_id(), task.task.id); | ||
| } | ||
| task_info.state = State::Running; | ||
| set_current_task(awkernel_lib::cpu::cpu_id(), task.task.id); |
There was a problem hiding this comment.
Would it make sense to reuse cpu_id?
| set_current_task(awkernel_lib::cpu::cpu_id(), task.task.id); | |
| set_current_task(cpu_id, task.id); |
| // `invoke_preemption_tick` rotate the task out before | ||
| // it runs. | ||
| task_info.update_last_executed(); | ||
| set_current_task(awkernel_lib::cpu::cpu_id(), rr_task.task.id); |
There was a problem hiding this comment.
Would it make sense to reuse cpu_id?
| set_current_task(awkernel_lib::cpu::cpu_id(), rr_task.task.id); | |
| set_current_task(cpu_id, task.id); |
|
|
||
| // This is unnecessary if the task is scheduled by PrioritizedFIFO. This remains for other schedulers. | ||
| // `get_next_task()` has already stored the task ID. | ||
| // This store is redundant and remains as a safeguard. |
There was a problem hiding this comment.
I would say debug_assert_eq! is better, so it does not cause unconditional panics on release mode.
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.