response_time_analysis/arrival/
propagated.rs

1use std::iter;
2
3use super::ArrivalBound;
4use crate::time::Duration;
5
6/// A simple model of arrivals induced by a precedence relationship.
7///
8/// Suppose two components *A* and *B* are connected such that each
9/// activation of *A* subsequently triggers (up to) one activation of
10/// *B* (e.g., *A* is a producer and *B* a consumer). Then, if
11/// `input_event_model` is the arrival model of *A* and activations
12/// of *A* have a maximum response time bounded by
13/// `response_time_jitter`, then this arrival model upper-bounds the
14/// activations of *B*.
15pub struct Propagated<T: ArrivalBound> {
16    pub response_time_jitter: Duration,
17    pub input_event_model: T,
18}
19
20impl<T: ArrivalBound + Clone> Propagated<T> {
21    pub fn with_jitter(event_model: &T, response_time_jitter: Duration) -> Self {
22        Propagated {
23            input_event_model: event_model.clone(),
24            response_time_jitter,
25        }
26    }
27}
28
29impl<T: ArrivalBound + Clone + 'static> ArrivalBound for Propagated<T> {
30    fn number_arrivals(&self, delta: Duration) -> usize {
31        if delta.is_non_zero() {
32            self.input_event_model
33                .number_arrivals(delta + self.response_time_jitter)
34        } else {
35            0
36        }
37    }
38
39    fn steps_iter<'a>(&'a self) -> Box<dyn Iterator<Item = Duration> + 'a> {
40        Box::new(
41            iter::once(Duration::from(1)).chain(
42                // shift the steps of the input event model earlier by the jitter amount
43                self.input_event_model
44                    .steps_iter()
45                    .filter(move |x| *x > self.response_time_jitter + Duration::from(1))
46                    .map(move |x| x - self.response_time_jitter),
47            ),
48        )
49    }
50
51    fn clone_with_jitter(&self, added_jitter: Duration) -> Box<dyn ArrivalBound> {
52        Box::new(Propagated {
53            response_time_jitter: self.response_time_jitter + added_jitter,
54            input_event_model: self.input_event_model.clone(),
55        })
56    }
57}