response_time_analysis/wcet/
scalar.rs

1use std::iter;
2
3use super::JobCostModel;
4use crate::time::Service;
5
6/// The classic and most simple characterization of the worst-case
7/// processor demand of a single job: the scalar WCET bound.
8#[derive(Debug, Clone, Copy)]
9pub struct Scalar {
10    /// The worst-case execution bound.
11    pub wcet: Service,
12}
13
14impl Scalar {
15    /// Construct a new `Sclar` cost model by wrapping a given WCET bound.
16    pub fn new(wcet: Service) -> Self {
17        Scalar { wcet }
18    }
19}
20
21impl From<Service> for Scalar {
22    fn from(val: Service) -> Self {
23        Self::new(val)
24    }
25}
26
27impl JobCostModel for Scalar {
28    fn cost_of_jobs(&self, n: usize) -> Service {
29        self.wcet * n as u64
30    }
31
32    fn least_wcet(&self, n: usize) -> Service {
33        if n > 0 {
34            self.wcet
35        } else {
36            Service::none()
37        }
38    }
39
40    fn job_cost_iter<'a>(&'a self) -> Box<dyn Iterator<Item = Service> + 'a> {
41        Box::new(iter::repeat(self.wcet))
42    }
43}