Skip to content
Snippets Groups Projects
Commit 8ecf733e authored by Blinningjr's avatar Blinningjr
Browse files

Finished block time function

parent 2d2f7572
No related branches found
No related tags found
No related merge requests found
......@@ -104,7 +104,7 @@ fn total_load_factor(tasks: &Tasks) -> f32 {
* worst case. And the task t will not be able to finish in time in the worst case.
*/
fn cpu_load(task: &Task) -> f32 {
return (wcet(task) as f32) / (task.inter_arrival as f32)
return (wcet(&task.trace) as f32) / (task.inter_arrival as f32)
}
......@@ -112,8 +112,8 @@ fn cpu_load(task: &Task) -> f32 {
* Worst case execution time(WCET) of a task t(C(t)).
* C(t)
*/
fn wcet(task: &Task) -> u32 {
return task.trace.end.wrapping_sub(task.trace.start);
fn wcet(trace: &Trace) -> u32 {
return trace.end.wrapping_sub(trace.start);
}
......@@ -140,6 +140,24 @@ fn response_time(task: &Task) -> u32 {
* Note: B(t) = max(C(l_r)), where P(l) < P(t), π(l_r) >= P(t)
*/
fn block_time(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) -> u32 {
/*
* Helper function for finding the trace of a resource using only the id an a trace.
*/
fn find_res_tr<'a>(res_id: &String, trace: &'a Trace) -> Option<&'a Trace> {
if trace.id == *res_id {
return Some(trace);
} else {
for tr in &trace.inner {
match find_res_tr(res_id, tr) {
Some(val) => return Some(val),
None => (),
}
}
}
return None;
}
// Find all lower priority tasks
let mut lower_prio: Vec<&Task> = vec!();
for t in tasks {
......@@ -148,35 +166,43 @@ fn block_time(task: &Task, tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) -> u3
}
}
println!("prio {:?}", task.prio);
println!("lower_prio {:?}", lower_prio);
//println!("prio {:?}", task.prio);
//println!("lower_prio {:?}", lower_prio);
// Find all resources that will block the task(resources with a higher of equal priority) from
// the resources that the lower priority tasks use.
let mut block_res: Vec<String> = vec!();
let mut block_res: Vec<&Trace> = vec!();
for lpt in lower_prio {
match tr.get(&lpt.id) {
match tr.get(&lpt.id) {
Some(resources) =>{
for r in resources {
if *ip.get(r).unwrap() >= task.prio {
block_res.push(r.clone());
block_res.push(find_res_tr(r, &lpt.trace).unwrap());
}
}
},
None => (),
};
};
}
println!("block_res {:?}", block_res);
let mut wcets: Vec<u32> = vec!();
//println!("block_res {:?}", block_res);
// Calculate the max wcet of the list of blocking resource traces.
let mut block_time: u32 = 0;
for tr in block_res {
let wcet = wcet(tr);
if wcet > block_time {
block_time = wcet;
}
}
println!("block time {:?}", block_time);
// TODO: Implement
return 0;
return block_time;
}
/*
* Calculates the interference (preemptions) to task t(I(t)).
* I(t)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment