Skip to content
Snippets Groups Projects
Commit c0eee49c authored by Ruben Asplund's avatar Ruben Asplund
Browse files

Added function reccurence_preemptions()

parent ceacb8de
No related branches found
No related tags found
No related merge requests found
...@@ -76,28 +76,26 @@ fn main() { ...@@ -76,28 +76,26 @@ fn main() {
println!("tr: {:?}", tr); println!("tr: {:?}", tr);
print_analysis(&tasks, &ip, &tr); print_analysis(&tasks, &ip, &tr);
} }
// Prints out vector with [task id, response time, wcet time, blocking time, preemption time]
fn print_analysis(tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) { fn print_analysis(tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) {
for t in tasks { for t in tasks {
let b = blocking(t, &tasks, &ip, &tr); let b = blocking(t, &tasks, &ip, &tr);
let p = preemptions(t, &tasks); // let p = preemptions(t, &tasks);
let r = response_time(t, &tasks, &ip, &tr); let p = recurrence_preemption(t, &tasks, &ip, &tr, true).unwrap();
let r = response_time(t, &tasks, &ip, &tr, true);
let c = wcet(t); let c = wcet(t);
let tasks_analysis = vec![t.id.to_string(), r.to_string(), c.to_string(), b.to_string(), p.to_string()]; let tasks_analysis = vec![t.id.to_string(), r.to_string(), c.to_string(), b.to_string(), p.to_string()];
println!("{:?}", tasks_analysis) println!("{:?}", tasks_analysis)
} }
} }
fn response_time(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources, exact_solution: bool) -> u32 {
fn response_time(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) -> u32 { let b = blocking(task, &tasks, &ip, &tr);
let blocking = blocking(task, &tasks, &ip, &tr); let c = wcet(task);
let wcet = wcet(task); // let p = preemptions(task, &tasks);
let preemption = preemptions(task, &tasks); let p = recurrence_preemption(task, &tasks, &ip, &tr, exact_solution).unwrap();
return blocking + wcet + preemption; return b + c + p;
} }
fn wcet(task: &Task) -> u32 { fn wcet(task: &Task) -> u32 {
...@@ -115,29 +113,42 @@ fn load_factor(tasks: &Tasks) -> f32{ ...@@ -115,29 +113,42 @@ fn load_factor(tasks: &Tasks) -> f32{
return l_tot; return l_tot;
} }
fn preemptions(task: &Task, tasks: &Tasks) -> u32 { fn recurrence_preemption(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources, exact_solution: bool) -> Result<u32, String> {
// Find higher or same task prio if !exact_solution {
let mut higher_prio_tasks = HashSet::new(); return Ok(preemptions(task, &tasks, 0, exact_solution));
for t in tasks {
if t.id == task.id {
continue;
} }
if t.prio >= task.prio { let sum = wcet(task) + blocking(task, &tasks, &ip, &tr);
higher_prio_tasks.insert(t.id.to_string()); let mut current_busy_period: u32 = sum + preemptions(task, &tasks, sum, exact_solution);
loop {
let busy_period: u32 = current_busy_period + preemptions(task, &tasks, current_busy_period, exact_solution);
if current_busy_period == busy_period {
return Ok(busy_period);
}
if current_busy_period > task.deadline {
return Err("Deadline miss!".to_string());
} }
current_busy_period = busy_period;
} }
// Calculate preemptions time (I(t)) }
fn preemptions(task: &Task, tasks: &Tasks, busy_period: u32, exact_solution: bool) -> u32 {
let mut p_time = 0; let mut p_time = 0;
for t_id in higher_prio_tasks { let mut busy_period = busy_period;
if !exact_solution {
busy_period = task.deadline;
}
for t in tasks { for t in tasks {
if t_id == t.id { if t.id == task.id {
let inter_arrival = t.inter_arrival; continue;
let busy_period = t.deadline;
p_time = p_time + wcet(t)*(busy_period / inter_arrival);
} }
if t.prio >= task.prio {
let inter_arrival = t.inter_arrival;
// println!("bp{} ia{}", busy_period, inter_arrival);
p_time = p_time + wcet(t)*(((busy_period as f32) / (inter_arrival as f32)).ceil() as u32);
} }
} }
// println!("{}", p_time); println!("{}", p_time);
return p_time; return p_time;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment