response_time_analysis/demand/
rbf.rs

1use crate::arrival::ArrivalBound;
2use crate::time::{Duration, Service};
3use crate::wcet::JobCostModel;
4
5use super::RequestBound;
6
7/// The canonical request-bound function (RBF), which connects
8/// arrival bounds and job-cost models.
9///
10/// Given an arrival model and a job-cost model, the RBF bounds
11/// demand over an interval of length `delta` simply as the total
12/// cumulative cost of the maximum number of jobs that can arrive in
13/// an interval of length `delta`.
14#[derive(Clone, Debug)]
15pub struct RBF<B: ArrivalBound, C: JobCostModel> {
16    pub wcet: C,
17    pub arrival_bound: B,
18}
19
20impl<B: ArrivalBound, C: JobCostModel> RBF<B, C> {
21    /// Construct a new RBF from the given arrival bound and cost model.
22    pub fn new(ab: B, cm: C) -> RBF<B, C> {
23        RBF {
24            wcet: cm,
25            arrival_bound: ab,
26        }
27    }
28}
29
30impl<B: ArrivalBound, C: JobCostModel> RequestBound for RBF<B, C> {
31    fn service_needed(&self, delta: Duration) -> Service {
32        self.wcet
33            .cost_of_jobs(self.arrival_bound.number_arrivals(delta))
34    }
35
36    fn least_wcet_in_interval(&self, delta: Duration) -> Service {
37        self.wcet
38            .least_wcet(self.arrival_bound.number_arrivals(delta))
39    }
40
41    fn steps_iter<'a>(&'a self) -> Box<dyn Iterator<Item = Duration> + 'a> {
42        self.arrival_bound.steps_iter()
43    }
44
45    fn job_cost_iter<'a>(&'a self, delta: Duration) -> Box<dyn Iterator<Item = Service> + 'a> {
46        Box::new(
47            self.wcet
48                .job_cost_iter()
49                .take(self.arrival_bound.number_arrivals(delta)),
50        )
51    }
52}
53
54impl<'a, B: ArrivalBound + 'a, C: JobCostModel + 'a> AsRef<dyn RequestBound + 'a> for RBF<B, C> {
55    fn as_ref<'b>(&'b self) -> &'b (dyn RequestBound + 'a) {
56        self
57    }
58}