Repository navigation
feat(dag): add per-node WCET estimation - #785
romancardenas wants to merge 1 commit into
Conversation
97cebbb to
2cd41e2
Compare
There was a problem hiding this comment.
I suggest adding wcet: Option<Duration> as an argument to the three register_*_reactor() functions, instead of a separate set_node_wcet() call. None means no estimate, and the analysis treats it as zero, as in this PR. The reasons are:
- Both current callers know the execution time at registration.
rd_gen_to_dagsalready hasexecution_timefor each node, andSome(convert_duration(execution_time))gives the WCET. This PR does not update it, so its WCETs stay zero and the new check always passes. With the argument, every caller must passSome(...)orNoneexplicitly. periodandrelative_deadlineare already registration arguments.- The register functions no longer need to return a public
NodeIndex. This removes two misuses. An index from one DAG passed to another DAG can silently change the WCET of a different node, and aset_node_wcet()call afterfinish_create_dags()stores a value that is never validated. Nonekeeps "no estimate" apart from an estimate of zero.
With this change, set_node_wcet(), the unused get_node_wcet(), and the per-node .map_err(...) calls in test_dag can go. If a later use case needs to update a WCET after registration, a setter can come back then.
2cd41e2 to
6f45743
Compare
|
@atsushi421 I addressed your comments. |
| pub_topics, | ||
| $sched_type, | ||
| convert_duration($node_data.get_period().expect("Source node's period should always be Some.")), | ||
| None, |
There was a problem hiding this comment.
execution_time is in scope here and in the other two macros (lines 157 and 220), but all three pass None. Every WCET of this application is therefore zero, and compute_timing() can never reject a generated DAG. Can you pass Some(convert_duration(execution_time)) in the three macros? A generated DAG whose longest path exceeds its end-to-end deadline will then fail finish_create_dags, so please confirm that this is the behavior you want.
|
|
||
| /// Timing estimates for a node, expressed as offsets from the DAG job's release. | ||
| #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] | ||
| pub struct NodeTiming { |
There was a problem hiding this comment.
Only the test helper timing_of reads NodeInfo.timing, and no public function returns a NodeTiming. Users therefore cannot get the per-node ES, LF, and critical-path values that the description mentions. Also, only tests use the public NodeTiming, estimated_latest_start(), and is_critical. Because validation already guarantees one source and one sink, the forward pass alone decides feasibility. I suggest keeping only that check here and adding the stored timing in the PR that reads it. If you prefer to keep it, add a documented Dag accessor.
| test_dag::run().await; // test for DAG | ||
| test_dag::run() | ||
| .await | ||
| .map_err(|errors| Cow::Owned(alloc::format!("DAG test failed: {errors:?}")))?; // test for DAG |
There was a problem hiding this comment.
With ?, a failure in test_dag now skips test_dvfs, test_raspi_dvfs, test_voluntary_preemption, and test_edf. The errors also appear only once, in Debug form such as [InfeasibleWcet(1, 0)], instead of through the Display impl that test_dag::run() used before. Can you keep the previous log-and-continue handling in test_dag::run(), as rd_gen_to_dags/src/lib.rs does, and leave this file unchanged?
| }; | ||
| let slack = timing | ||
| .slack() | ||
| .ok_or_else(|| DagError::InfeasibleWcet(dag_id, idx.index()))?; |
There was a problem hiding this comment.
No test reaches this check. It catches a DAG whose WCETs each fit but whose path sum exceeds the deadline, for example a 50, 40, 30 ms chain with a 100 ms deadline. The two existing infeasible tests fail earlier, in checked_add and checked_sub. Also, every timing test calls compute_timing() directly. The suite still passes if validate_all_rules loses its compute_timing branch or if a register_*_reactor function drops wcet. Can you add a chain test and a diamond test for this case? Can you also add one test that registers nodes through the public functions and expects InfeasibleWcet from validate_all_rules?
| DagError::NodeNotFound(dag_id, node_id) => write!(f, "DAG#{dag_id} Node#{node_id} not found"), | ||
| DagError::MissingSinkDeadline(dag_id) => write!(f, "DAG#{dag_id} has no sink relative deadline"), | ||
| DagError::InfeasibleWcet(dag_id, node_id) => { | ||
| write!(f, "DAG#{dag_id} Node#{node_id}: estimated WCETs exceed the sink relative deadline") |
There was a problem hiding this comment.
When the path sum exceeds the deadline, the slack check reports the source, because it is first in topological order. Node#N then looks like the cause. The message also omits the critical-path length and the deadline, so the user cannot tell by how much the DAG misses. Can you carry the longest-path length and the sink deadline in the variant and print both, instead of a node index?
| #[cfg(feature = "perf")] | ||
| mod performance; | ||
|
|
||
| pub use crate::dag::graph::NodeIndex; |
There was a problem hiding this comment.
The register functions now return (), so no public function in this PR takes or returns a NodeIndex. Can you move it back into the private graph::{...} import?
| /// Returns the nodes in topological order: every node comes after all its predecessors. | ||
| /// | ||
| /// Returns an error for a cycle or an inconsistent predecessor count. | ||
| fn topological_order(&self, dag_id: u32) -> Result<Vec<NodeIndex>, DagError> { |
There was a problem hiding this comment.
validate_dag() already rejects cycles with is_cyclic_directed() before compute_timing() runs. The ContainsCycle and NodeNotFound branches here are therefore reachable only from timing_rejects_a_partial_topological_order. The reversed DfsEvent::Finish order from depth_first_search in dag/visit/dfsvisit.rs gives a topological order in a few lines. Can you use it and remove this function and that test?
| let order = graph.topological_order(dag_id)?; | ||
|
|
||
| // Forward pass to compute per-node earliest start times. | ||
| let mut earliest_start: BTreeMap<NodeIndex, Duration> = BTreeMap::new(); |
There was a problem hiding this comment.
The graph never removes nodes, so indices are dense in 0..node_count(). earliest_start, latest_finish, slacks, and timings can each be a Vec indexed by idx.index(). That removes the per-node allocations under the interrupt-disabling dag.graph lock and five unreachable NodeNotFound branches. slacks can also become a running minimum. The has_successor flag can go too, because finish = finish.min(succ_start) starting from sink_deadline gives the same result.
| //! rejects estimates whose longest dependency path exceeds the sink's relative deadline. | ||
| //! | ||
| //! WCET estimates are used for feasibility validation only. They do not change interval-tick job | ||
| //! release times or the existing GEDF deadline assignment: GEDF continues to use the job release |
There was a problem hiding this comment.
This is the only "GEDF" in the tree. The scheduler is SchedulerType::EDF, and DAGs also run under other schedulers, for example PrioritizedFIFO in rd_gen_to_dags. Can you write "the DAG deadline assignment used by the EDF scheduler" and number this heading ## 4. like its siblings?
Description
@atsushi421 this is the third PR from #738
It adds per-node timing information. Users can now optionally provide WCET estimates per node. With them, when validating the DAG, Awkernel will compute estimated earliest start, estimated latest finish, and whether the node belongs to the critical path. If the DAG seems unfeasible, the validation will return an error.
Earliest Start Time
For source nodes, ES = 0
For other nodes, ES = max over predecessors p (ES(p) + WCET(p)
Latest Finish Time
For sink nodes, LF = Deadline
For other nodes, LF = min over successors p (LF(p) - WCET(p))
We can now check if, a priori, the DAG scheduling is feasible
ES + WCET <= LF
How was this PR tested?
scripts/ci.shpasses on my machine.