Skip to content

feat(scheduler): Add Least Latest Finish Time (LLFT) scheduler - #815

Open
romancardenas wants to merge 3 commits into
tier4:mainfrom
romancardenas:scheduler/llft
Open

romancardenas wants to merge 3 commits into
tier4:mainfrom
romancardenas:scheduler/llft

Conversation

@romancardenas

Copy link
Copy Markdown
Contributor

Description

  • Add per-node TimingInfo estimates during DAG validation, including earliest/latest start and finish, slack, and critical-path membership.
  • Add the clustered Least Latest Finish Time (LLFT) scheduler, which orders DAG tasks by earliest estimated latest-finish time while keeping their real deadlines unchanged. EDF retains higher scheduler priority.
  • Add test_llft, an end-to-end example that pins the DAG to one worker and verifies the earlier-latest-finish branch runs first, even though the other branch is published first.

How was this PR tested?

  • scripts/ci.sh passes on my machine.
  • cargo fmt --all -- --check — passed.
  • cargo test_awkernel_async_lib llft -- --nocapture — passed (2 tests).
  • cargo x86 --features test_llft — passed.
  • cargo clippy_x86 --features test_llft -- -D warnings — passed.
  • make x86_64 OPT='--features debug --features test_llft' — passed.
  • make qemu-x86_64-nographic — QEMU booted with 16 CPUs and printed test_llft: early then late on CPU 1; DAG completed [OK]. QEMU was stopped after the result.

Notes for reviewers

  • LLFT uses WCET-derived estimates for ordering, not as real deadlines; EDF behavior and precedence are preserved.
  • The example’s expected latest-finish offsets are 780 ms for the source, 790 ms for the early branch, and 990 ms for the late branch.
  • LLFT uses the shared clustered scheduler and retains its existing priority-width limitations.
  • I have been looking for a "standard" naming for this scheduler but could not find any. Thus, I decided to call it LLFT. If you can send me literature with better nomenclature, please do so and I will take a look.

@romancardenas

Copy link
Copy Markdown
Contributor Author

The PR is divided into three commits:

  • First, I add the NodeTiming capability to DAG nodes. While I am not using all the fields (e.g., earliest start or the slack), I added them so we can include new scheduling algorithms easily from them (e.g., least laxity first or earliest finish time).
  • Next, I added the LLFT scheduler.
  • Finally, I included a test application that makes sure that LLFT preserves the expected job ordering.

/// Missing job/timing means the scheduler falls back to the real deadline.
fn released_job_latest_finish(dag_info: &DagInfo) -> Option<u64> {
let dag = get_dag(dag_info.dag_id)?;
let job = dag.get_or_release_job(to_node_index(dag_info.node_id), false)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calculate_dag_latest_finish_priority looks up the job twice, so each LLFT wake takes the DAGS, jobs and graph locks about twice as often as EDF, all under the task.info lock. The second get_or_release_job also rewrites deadline_job. If the source releases the job between the two calls, the task keeps the fallback deadline and has_stale_deadline no longer corrects it. A single lookup that returns the JobInfo and the node's timing from the same graph critical section fixes both, and EDF and LLFT can share it.


/// Returns the estimates computed during DAG validation for a node ID from [`DagInfo`].
/// Analysis is invalidated when the graph or its sink deadline changes.
pub fn timing_info(&self, node_id: u32) -> Result<TimingInfo, DagError> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outside this module, only test_llft calls timing_info, and it relies on node IDs that follow registration order, which no API returns or documents. Future schedulers live in this crate, so pub(crate) is enough, and the unit tests in this file already cover the estimates.

match self.node_weight_mut(node_idx) {
Some(info) => {
info.relative_deadline = Some(deadline);
self.clear_timing();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compute_timing runs only in finish_create_dags, so a register_* call after that clears the timing of every node, and LLFT then orders by the real deadline with no log or error. A log::warn! when existing timing is cleared, or a rejection of registration on a spawned DAG, makes this visible.

### Least Latest Finish Time (LLFT) Scheduler

`SchedulerType::LLFT(relative_deadline, cpu_set)` schedules the **earliest** estimated
latest finish first. It shares EDF's clustered queue, affinity normalization, wake-time

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

llft::SCHEDULER is a separate ClusteredScheduler with its own queue, so LLFT shares the implementation with EDF but not the queue. This section also lacks the link to llft.rs that the other sections have, and it does not say that preemption (PriorityInfo) uses the latest-finish key and not the real deadline.

}

#[test]
fn affinity_queue_orders_latest_finish_then_wake_time() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test only pushes literal tuples into AffinityBTreeQueue and pops them, so it passes even if LeastLatestFinish is wrong or removed. I suggest removing it, because latest_finish_priority_tracks_each_released_job_and_keeps_real_deadline covers the key and test_llft covers the order.

Comment thread userland/src/lib.rs
test_edf::run().await; // test for EDF scheduler

#[cfg(feature = "test_llft")]
test_llft::run().await?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other test applications return () and log their own result. With ?, a test_llft failure stops userland::run(), so any application added after it does not run, and the failure shows only as the generic task-failure warning. Can run() log the error with log::error! and return () like its siblings?

/// A forward pass computes `EF(v) = max(EF(p)) + C(v)` over predecessors, including the
/// sink's own WCET.
///
/// A

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc comment stops at /// A. It probably meant to describe the backward pass, for example "A backward pass computes LF(v) = min(LF(s) - C(s)) over successors, starting from the sink deadline."

assert_eq!(info(sink).estimated_wcet(), Duration::ZERO);
let source = dag.get_source_nodes()[0];
assert_eq!(info(source).estimated_wcet(), Duration::ZERO);
assert_eq!(info(source).estimated_wcet(), Duration::ZERO);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line repeats the assertion above it. Was earliest_start() the intended assertion?

@@ -0,0 +1,66 @@
//! Least latest finish time first, distinct from the real job deadline.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a full-width space (U+3000) between "finish" and "time". The name also differs from "Least Latest Finish Time (LLFT)" used elsewhere.

@atsushi421

Copy link
Copy Markdown
Contributor

@romancardenas

If you can send me literature with better nomenclature, please do so and I will take a look.

LLFT looks fine!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants