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

Fixed preemption with exact calculation

parent e9ae2680
No related branches found
No related tags found
No related merge requests found
......@@ -76,13 +76,16 @@ fn main() {
println!("tr: {:?}", tr);
print_analysis(&tasks, &ip, &tr);
let test = (10.0 as f32/30.0 as f32).ceil();
println!("Test {}", test);
}
// Prints out vector with [task id, response time, wcet time, blocking time, preemption time]
fn print_analysis(tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) {
for t in tasks {
let b = blocking(t, &tasks, &ip, &tr);
// let p = preemptions(t, &tasks);
let p = recurrence_preemption(t, &tasks, &ip, &tr, true).unwrap();
let p = preemptions(t, &tasks, &ip, &tr, true).unwrap();
let r = response_time(t, &tasks, &ip, &tr, true);
let c = wcet(t);
let tasks_analysis = vec![t.id.to_string(), r.to_string(), c.to_string(), b.to_string(), p.to_string()];
......@@ -93,8 +96,7 @@ fn print_analysis(tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) {
fn response_time(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources, exact_solution: bool) -> u32 {
let b = blocking(task, &tasks, &ip, &tr);
let c = wcet(task);
// let p = preemptions(task, &tasks);
let p = recurrence_preemption(task, &tasks, &ip, &tr, exact_solution).unwrap();
let p = preemptions(task, &tasks, &ip, &tr, exact_solution).unwrap();
return b + c + p;
}
......@@ -113,43 +115,48 @@ fn load_factor(tasks: &Tasks) -> f32{
return l_tot;
}
fn recurrence_preemption(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources, exact_solution: bool) -> Result<u32, String> {
if !exact_solution {
return Ok(preemptions(task, &tasks, 0, exact_solution));
}
let sum = wcet(task) + blocking(task, &tasks, &ip, &tr);
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;
fn preemptions_approx(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) -> u32 {
let mut p_time = 0;
let mut busy_period = task.deadline;
for t in tasks {
if (t.prio >= task.prio) && (t.id != task.id) {
p_time = p_time + wcet(t)*(((busy_period as f32) / (t.inter_arrival as f32)).ceil() as u32);
}
}
return p_time;
}
fn preemptions(task: &Task, tasks: &Tasks, busy_period: u32, exact_solution: bool) -> u32 {
let mut p_time = 0;
fn preemptions_exact(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources, busy_period: u32) -> Result<u32, String> {
let base_case = wcet(task) + blocking(task, &tasks, &ip, &tr);
let mut new_busy_period = base_case;
let mut busy_period = busy_period;
if !exact_solution {
busy_period = task.deadline;
if busy_period == 0 {
busy_period = base_case;
}
for t in tasks {
if t.id == task.id {
continue;
if t.prio >= task.prio && (t.id != task.id) {
new_busy_period = new_busy_period + wcet(t)*(((busy_period as f32) / (t.inter_arrival as f32)).ceil() as u32);
}
}
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!("nb {}, b {}", new_busy_period, busy_period);
if new_busy_period.wrapping_sub(base_case) == 0 {
return Ok(0);
} else if new_busy_period > task.deadline {
return Err("Deadline miss!".to_string());
} else if new_busy_period == busy_period {
return Ok(new_busy_period - base_case);
} else {
return preemptions_exact(task, &tasks, ip, tr, new_busy_period);
}
}
println!("{}", p_time);
return p_time;
fn preemptions(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources, exact: bool) -> Result<u32, String> {
if exact {
return preemptions_exact(task, &tasks, ip, tr, 0);
} else {
return Ok(preemptions_approx(task, &tasks, ip, tr));
}
}
fn blocking(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) -> u32 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment