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

Added a recursive function to blocking

parent 570955e0
No related branches found
No related tags found
No related merge requests found
...@@ -77,8 +77,6 @@ fn main() { ...@@ -77,8 +77,6 @@ fn main() {
print_analysis(&tasks, &ip, &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] // 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) {
...@@ -139,7 +137,7 @@ fn preemptions_exact(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources ...@@ -139,7 +137,7 @@ fn preemptions_exact(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources
new_busy_period = new_busy_period + wcet(t)*(((busy_period as f32) / (t.inter_arrival as f32)).ceil() as u32); new_busy_period = new_busy_period + wcet(t)*(((busy_period as f32) / (t.inter_arrival as f32)).ceil() as u32);
} }
} }
println!("nb {}, b {}", new_busy_period, busy_period); // println!("nb {}, b {}", new_busy_period, busy_period);
if new_busy_period.wrapping_sub(base_case) == 0 { if new_busy_period.wrapping_sub(base_case) == 0 {
return Ok(0); return Ok(0);
} else if new_busy_period > task.deadline { } else if new_busy_period > task.deadline {
...@@ -162,30 +160,83 @@ fn preemptions(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources, exac ...@@ -162,30 +160,83 @@ fn preemptions(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources, exac
fn blocking(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) -> u32 { fn blocking(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) -> u32 {
// Checks if the Task is claming a resource // Checks if the Task is claming a resource
if !tr.contains_key(&task.id) { if !tr.contains_key(&task.id) {
// println!("0");
return 0; return 0;
} }
// Find lower prio tasks // Find lower prio tasks that holds a resource
let mut lower_prio_tasks = HashSet::new(); let mut lower_prio_tasks = HashSet::new();
for t in tasks { for t in tasks {
if t.prio < task.prio { if t.prio < task.prio && tr.contains_key(&t.id) {
lower_prio_tasks.insert(t.id.to_string()); lower_prio_tasks.insert(t.id.to_string());
} }
} }
// Do these task hold a resource, if not delete from list if lower_prio_tasks.len() == 0 {
return 0;
}
let resources = &tr[&task.id];
println!("{}", &task.id);
println!("{:?}", tr);
println!("{:?}", resources);
// Checking every resource it holds
let mut max_block = 0;
let mut current_block = 0;
// Iterate through current task resources
for r1 in resources {
// Iterate through lower prio tasks
for t_id in &lower_prio_tasks {
let mut lower_prio_task_resources = &tr[t_id];
// Iterate through lower prio task resources
for r2 in lower_prio_task_resources {
// When current task use the same resource as a task
if r1 == r2 {
// Takes forward the blocking task
for t in tasks { for t in tasks {
if !lower_prio_tasks.contains(&t.id) { if &t.id == t_id {
continue; max_block = longest_blocking(&t.trace, r1);
}
}
}
} }
if !tr.contains_key(&t.id) { }
lower_prio_tasks.remove(&t.id); }
return max_block;
}
fn longest_blocking(trace: &Trace, r: &str) -> u32 {
let mut max_block = 0;
if trace.id == r {
max_block = trace.end.wrapping_sub(trace.start);
}
if trace.inner.len() != 0 {
for inner in &trace.inner {
let block = longest_blocking(&inner, r);
if max_block < block {
max_block = block;
}
}
}
return max_block;
}
/*
fn blocking(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) -> u32 {
// Checks if the Task is claming a resource
if !tr.contains_key(&task.id) {
return 0;
}
// Find lower prio tasks that holds a resource
let mut lower_prio_tasks = HashSet::new();
for t in tasks {
if t.prio < task.prio && tr.contains_key(&t.id) {
lower_prio_tasks.insert(t.id.to_string());
} }
} }
if lower_prio_tasks.len() == 0 { if lower_prio_tasks.len() == 0 {
return 0; return 0;
} }
/* Finding longest blocking */
let resources = &tr[&task.id]; let resources = &tr[&task.id];
println!("{:?}", tr);
println!("{:?}", resources);
// Checking every resource it holds // Checking every resource it holds
let mut max_block = 0; let mut max_block = 0;
let mut current_block = 0; let mut current_block = 0;
...@@ -234,3 +285,4 @@ fn blocking(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) -> u32 ...@@ -234,3 +285,4 @@ fn blocking(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) -> u32
} }
return max_block; return max_block;
} }
*/
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment