response_time_analysis/supply/
periodic.rs1use super::SupplyBound;
2use crate::time::{Duration, Service};
3
4#[derive(Debug, Clone, Copy)]
10pub struct Periodic {
11 pub period: Duration,
12 pub budget: Service,
13}
14
15impl Periodic {
16 pub fn new(budget: Service, period: Duration) -> Self {
18 assert!(Duration::from(budget) <= period);
19 Periodic { period, budget }
20 }
21}
22
23impl SupplyBound for Periodic {
24 fn provided_service(&self, delta: Duration) -> Service {
25 let budget = Duration::from(self.budget);
29
30 let slack = self.period - budget;
31 if slack > delta {
32 return Service::none();
33 }
34 let full_periods = (delta - slack) / self.period;
36 let x = slack + slack + self.period * full_periods;
37 let fractional_period = if x < delta {
38 Service::from(delta - x)
39 } else {
40 Service::none()
41 };
42
43 self.budget * full_periods + fractional_period
44 }
45
46 fn service_time(&self, demand: Service) -> Duration {
47 if demand.is_none() {
48 return Duration::zero();
49 }
50
51 let demand = Duration::from(demand);
52 let budget = Duration::from(self.budget);
53 let slack = self.period - budget;
54
55 let full_periods = demand / budget;
57 let full_budget = budget * full_periods;
58 let fractional_budget = if full_budget < demand {
59 slack + demand - full_budget
60 } else {
61 Duration::zero()
62 };
63
64 slack + self.period * full_periods + fractional_budget
65 }
66}