From e2876ba7587083ba0de27d33bd58547cdc3cc52b Mon Sep 17 00:00:00 2001 From: Blinningjr <nicke.l@telia.com> Date: Sat, 2 Jan 2021 16:55:25 +0100 Subject: [PATCH] Implemented exact preemptions --- srp_analysis/src/main.rs | 67 +++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/srp_analysis/src/main.rs b/srp_analysis/src/main.rs index 8ba2019..fa13577 100644 --- a/srp_analysis/src/main.rs +++ b/srp_analysis/src/main.rs @@ -74,7 +74,7 @@ fn main() { println!("ip: {:?}", ip); println!("tr: {:?}", tr); - let analysis = analyse(&tasks, &ip, &tr); + let analysis = analyse(&tasks, &ip, &tr, true); println!("Analysis {:#?}", analysis); } @@ -124,9 +124,9 @@ fn wcet(trace: &Trace) -> u32 { * - B(t) is the blocking time for task t, and * - I(t) is the interference (preemptions) to task t */ -fn response_time(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) -> u32 { - let r: u32 = block_time(task, tasks, ip, tr) + wcet(&task.trace) + interference_time(task, tasks); - println!("response_time {:?}", r); +fn response_time(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources, approx: bool) -> u32 { + let r: u32 = block_time(task, tasks, ip, tr) + wcet(&task.trace) + interference_time(task, tasks, ip, tr, approx).unwrap(); + //println!("response_time {:?}", r); return r; } @@ -194,7 +194,7 @@ fn block_time(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) -> u3 } } - println!("block time {:?}", block_time); + //println!("block time {:?}", block_time); return block_time; } @@ -208,28 +208,37 @@ fn block_time(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) -> u3 * Note: I(t) = sum(C(h) * ceiling(Bp(t)/A(h))), forall tasks h, P(h) > P(t), where * Bp(t) is the busy-period */ -fn interference_time(task: &Task, tasks: &Tasks) -> u32 { - let mut interference: u32 = 0; - for t in tasks { - if t.prio > task.prio { - interference += wcet(&t.trace) * (((busy_period(t) as f32) / (t.inter_arrival as f32)).ceil() as u32); - } - } - - println!("interference_time {:?}", interference); - return interference; -} - +fn interference_time(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources, approx: bool) -> Result<u32, String> { + fn calc_interference(task: &Task, tasks: &Tasks, busy_period: u32) -> u32 { + let mut interference: u32 = 0; + for t in tasks { + if t.prio > task.prio { + interference += wcet(&t.trace) * (((busy_period as f32) / (t.inter_arrival as f32)).ceil() as u32); + } + } + return interference; + } -/* - * Caclulates the busy period of task t(Bp(t)). - * Bp(t) - * - * Note: We can over approximate the busy period Bp(i) = D(i) (assuming the worst allowed busy-period). - * D(i) is the deadline of task i. - */ -fn busy_period(task: &Task) -> u32 { - return task.deadline; + if approx { + let interference: u32 = calc_interference(task, tasks, task.deadline); + //println!("interference_time {:?}", interference); + return Ok(interference); + } else { + let constant = block_time(task, tasks, ip, tr) + wcet(&task.trace); + let mut busy_period: u32 = constant + calc_interference(task, tasks, constant); + loop { + if busy_period > task.deadline { + return Err("Busy period is longer then deadline".to_string()); + } else { + let new_busy_period: u32 = constant + calc_interference(task, tasks, busy_period); + if busy_period == new_busy_period { + return Ok(new_busy_period - constant); + } else { + busy_period = new_busy_period; + } + } + } + } } @@ -239,13 +248,13 @@ fn busy_period(task: &Task) -> u32 { * Note: Finally, make a function that iterates over the task set and returns a vector with containing: Vec<Task, R(t), C(t), B(t), I(t)>. Just a simple println! of that vector gives the essential information on the analysis. */ -fn analyse(tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) -> Vec<(Task, u32, u32, u32, u32)> { +fn analyse(tasks: &Tasks, ip: &IdPrio, tr: &TaskResources, approx: bool) -> Vec<(Task, u32, u32, u32, u32)> { let mut analysis: Vec<(Task, u32, u32, u32, u32)> = vec!(); for t in tasks { - let r_t = response_time(t, tasks, ip, tr); + let r_t = response_time(t, tasks, ip, tr, approx); let c_t = wcet(&t.trace); let b_t = block_time(t, tasks, ip, tr); - let i_t = interference_time(t, tasks); + let i_t = interference_time(t, tasks, ip, tr, approx).unwrap(); analysis.push((t.clone(), r_t, c_t, b_t, i_t)); } return analysis; -- GitLab