response_time_analysis/wcet/
multiframe.rs

1use super::JobCostModel;
2use crate::time::Service;
3
4/// The classic multi-frame model of job costs. The worst-case
5/// execution time of jobs is specified as a vector of bounds.
6/// Consecutive jobs cycle through the given vector of bounds.
7#[derive(Debug, Clone)]
8pub struct Multiframe {
9    costs: Vec<Service>,
10}
11
12impl Multiframe {
13    /// Construct a new multi-frame cost model by wrapping a given
14    /// vector of WCET values.
15    pub fn new(costs: Vec<Service>) -> Self {
16        Multiframe { costs }
17    }
18}
19
20impl JobCostModel for Multiframe {
21    fn job_cost_iter<'a>(&'a self) -> Box<dyn Iterator<Item = Service> + 'a> {
22        Box::new(self.costs.iter().copied().cycle())
23    }
24
25    fn least_wcet(&self, n: usize) -> Service {
26        self.costs
27            .iter()
28            .take(n)
29            .copied()
30            .min()
31            .unwrap_or_else(Service::none)
32    }
33}