Skip to content
Snippets Groups Projects
Commit 8ada6661 authored by Samuel Karlsson's avatar Samuel Karlsson
Browse files

fixes

parent 7d19d448
Branches 4b
No related tags found
No related merge requests found
...@@ -64,29 +64,31 @@ fn main() { ...@@ -64,29 +64,31 @@ fn main() {
}, },
}; };
let debug = false; let debug = true;
let advance = false; let advance = true;
// builds a vector of tasks t1, t2, t3 // builds a vector of tasks t1, t2, t3
// in falling prio order IMPORTENT The order are used // in falling prio order IMPORTENT The order are used
let mut tasks: Tasks = vec![t1, t2, t3]; let mut tasks: Tasks = vec![t1, t2, t3];
tasks.sort_by(|a, b| (a.prio).partial_cmp(&b.prio).unwrap()); // tasks.sort_by(|a, b| (a.prio).partial_cmp(&b.prio).unwrap());
tasks.reverse(); // tasks.reverse();
let (tp, rp, tr, a, dl) = pre_analysis(&tasks);
let (ip, tr) = pre_analysis(&tasks);
let dl = dead_line(&tasks);
let c = c_times(&tasks); let c = c_times(&tasks);
let (l, l_tot) = load(&tasks, &c); let (l, l_tot) = load(&tasks, &c);
let b = block(&tasks, &ip, &tr); let b = block(&tp, &rp, &tr);
let i = interferens(&tasks, &c, advance); let i = interferens(&tp, &c, &a, &dl, advance);
let r = response(&c, &b, &i); let r = response(&c, &b, &i);
if debug{ if debug{
println!("Debug data"); println!("Debug data");
println!("tasks {:?}", &tasks); println!("tasks {:?}", &tasks);
println!("ip: {:?}", ip); println!("tp: {:?}", tp);
println!("rp: {:?}", rp);
println!("tr: {:?}", tr); println!("tr: {:?}", tr);
println!("DeadLine: {:?}", dl); println!("DeadLine: {:?}", dl);
println!("A: {:?}", a);
println!("C(t): {:?}", c); println!("C(t): {:?}", c);
println!("L(t): {:?}",l); println!("L(t): {:?}",l);
println!("L(T): {:?}",l_tot); println!("L(T): {:?}",l_tot);
...@@ -101,7 +103,7 @@ fn main() { ...@@ -101,7 +103,7 @@ fn main() {
} }
// WARNIGN assums 0 overhead // WARNIGN assums 0 overhead
fn test(dl: data, l: f32, r: &data) { fn test(dl: Data, l: f32, r: &Data) {
println!("TEST of real time critarias"); println!("TEST of real time critarias");
if l <= 1.0 { if l <= 1.0 {
println!("Load test SUCSES"); println!("Load test SUCSES");
...@@ -119,7 +121,7 @@ fn test(dl: data, l: f32, r: &data) { ...@@ -119,7 +121,7 @@ fn test(dl: data, l: f32, r: &data) {
println!(""); println!("");
} }
fn analys_data(tasks: &Tasks, l: L, r: &data, c: data, b: data, i: data, load: f32){ fn analys_data(tasks: &Tasks, l: L, r: &Data, c: Data, b: Data, i: Data, load: f32){
println!("The data for analyse"); println!("The data for analyse");
println!("Total load {}%", load); println!("Total load {}%", load);
println!("ID | L | R | C | B | I | PRIO "); println!("ID | L | R | C | B | I | PRIO ");
......
...@@ -33,20 +33,22 @@ pub type IdPrio = HashMap<String, u8>; ...@@ -33,20 +33,22 @@ pub type IdPrio = HashMap<String, u8>;
// id_task, {id_res, longest} // id_task, {id_res, longest}
pub type TaskResources = HashMap<String, Vec<HashMap<String, u32>>>; pub type TaskResources = HashMap<String, Vec<HashMap<String, u32>>>;
pub type data = HashMap<String, u32>; pub type Data = HashMap<String, u32>;
pub type L = HashMap<String, f32>; pub type L = HashMap<String, f32>;
// Derives the above maps from a set of tasks // Derives the above maps from a set of tasks
pub fn pre_analysis(tasks: &Tasks) -> (IdPrio, TaskResources) { pub fn pre_analysis(tasks: &Tasks) -> (IdPrio, IdPrio, TaskResources, Data, Data) {
let mut ip = HashMap::new(); let mut tp = HashMap::new();
let mut rp = HashMap::new();
let mut tr: TaskResources = HashMap::new(); let mut tr: TaskResources = HashMap::new();
for t in tasks { for t in tasks {
update_prio(t.prio, &t.trace, &mut ip); update_prio(t.prio, &t.trace, &mut rp);
tp.insert(t.id.clone(), t.prio);
for i in &t.trace.inner { for i in &t.trace.inner {
update_tr(t.id.clone(), i, &mut tr); update_tr(t.id.clone(), i, &mut tr);
} }
} }
(ip, tr) (tp, rp, tr, inter_arival(&tasks), dead_line(&tasks))
} }
// helper functions // helper functions
...@@ -91,7 +93,7 @@ fn update_tr(s: String, trace: &Trace, trmap: &mut TaskResources) { ...@@ -91,7 +93,7 @@ fn update_tr(s: String, trace: &Trace, trmap: &mut TaskResources) {
} }
} }
pub fn c_times(tasks: &Tasks) -> data { pub fn c_times(tasks: &Tasks) -> Data {
let mut c = HashMap::new(); let mut c = HashMap::new();
for t in tasks { for t in tasks {
c.insert(t.id.clone(), t.trace.end - t.trace.start); c.insert(t.id.clone(), t.trace.end - t.trace.start);
...@@ -99,7 +101,7 @@ pub fn c_times(tasks: &Tasks) -> data { ...@@ -99,7 +101,7 @@ pub fn c_times(tasks: &Tasks) -> data {
c c
} }
pub fn load(tasks: &Tasks, c: &data) -> (L, f32){ pub fn load(tasks: &Tasks, c: &Data) -> (L, f32){
let mut l = HashMap::new(); let mut l = HashMap::new();
let mut tot = 0.0; let mut tot = 0.0;
for t in tasks { for t in tasks {
...@@ -111,35 +113,33 @@ pub fn load(tasks: &Tasks, c: &data) -> (L, f32){ ...@@ -111,35 +113,33 @@ pub fn load(tasks: &Tasks, c: &data) -> (L, f32){
(l, tot) (l, tot)
} }
pub fn block(tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) -> data { pub fn block(tp: &IdPrio, rp: &IdPrio, tr: &TaskResources) -> Data {
let mut b = HashMap::new(); let mut b = HashMap::new();
for t in tasks { for (task_id, task_prio) in tp {
let mut block_time = 0; let mut block_time = 0;
let resourses = tr.get(&t.id); let resourses = tr.get(task_id);
match resourses { match resourses {
Some(res) => { Some(res) => {
for vectorn in res { for vectorn in res {
for (id, _) in vectorn { for (id, _) in vectorn {
// iter this, all res // iter this, all res
for (tr_id, tr_has) in tr { for (tr_id, tr_resorses) in tr {
if ip.get(tr_id).unwrap() < &t.prio { if rp.get(tr_id).unwrap() < task_prio {
for bl in tr_has { for bl in tr_resorses {
if let Some(time) = bl.get(id) { if let Some(time) = bl.get(id) {
block_time += time; block_time += time;
} }
} }
} }
} }
} }
} }
b.insert(t.id.clone(), block_time); b.insert(task_id.clone(), block_time);
}, },
None => { None => {
b.insert(t.id.clone(), 0); b.insert(task_id.clone(), 0);
}, },
} }
...@@ -147,48 +147,44 @@ pub fn block(tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) -> data { ...@@ -147,48 +147,44 @@ pub fn block(tasks: &Tasks, ip: &IdPrio, tr: &TaskResources) -> data {
b b
} }
pub fn interferens(tp: &IdPrio, c: &Data, a: &Data, dl: &Data, advance: bool) -> Data {
pub fn interferens(tasks: &Tasks, c: &data, advance: bool) -> data {
let mut i = HashMap::new(); let mut i = HashMap::new();
let a = inter_arival(&tasks); for (id_curent, prio_curent) in tp {
i.insert(tasks[0].id.clone(), 0);
if !advance {
for index in 1..tasks.len() {
let mut sum = 0; let mut sum = 0;
for index2 in 0..index { let mut block = *dl.get(&id_curent.clone()).unwrap();
let id = &tasks[index2].id; if advance {
sum += block_eq(*a.get(&tasks[index].id).unwrap(), block = *c.get(&id_curent.clone()).unwrap();
*a.get(id).unwrap(),
*c.get(id).unwrap());
} }
i.insert(tasks[index].id.clone(), sum); let mut temp = 0;
}
} else {
for index in 1..tasks.len() {
let mut sum = 0;
let mut block = *c.get(&tasks[index].id).unwrap();
while sum < block { while sum < block {
sum = block; temp = block;
let mut part = 0; let mut part = 0;
for index2 in 0..index { for (id_ref, prio_ref) in tp {
let id = &tasks[index2].id;
part += block_eq(block, *a.get(id).unwrap(), *c.get(id).unwrap()); if *id_curent == *id_ref {
continue;
} else {
if *prio_curent == *prio_ref {
part += *c.get(id_ref).unwrap();
} else if prio_curent < prio_ref {
part += block_eq(block, *a.get(id_ref).unwrap(), *c.get(id_ref).unwrap());
} }
block = part;
} }
i.insert(tasks[index].id.clone(), sum);
} }
block = part;
sum = part;
if !advance {break;}
}
i.insert(id_curent.clone(), sum);
} }
i i
} }
fn block_eq(block: u32, a: u32, c: u32) -> u32 { fn block_eq(block: u32, a: u32, c: u32) -> u32 {
return ceil(block as f64 / a as f64, 0) as u32 * c; return ceil(block as f64 / a as f64, 0) as u32 * c;
} }
fn inter_arival(tasks: &Tasks) -> data { fn inter_arival(tasks: &Tasks) -> Data {
let mut a = HashMap::new(); let mut a = HashMap::new();
for t in tasks { for t in tasks {
a.insert(t.id.clone(), t.inter_arrival.clone()); a.insert(t.id.clone(), t.inter_arrival.clone());
...@@ -196,7 +192,7 @@ fn inter_arival(tasks: &Tasks) -> data { ...@@ -196,7 +192,7 @@ fn inter_arival(tasks: &Tasks) -> data {
a a
} }
pub fn response(c: &data, b: &data, i: &data) -> data { pub fn response(c: &Data, b: &Data, i: &Data) -> Data {
let mut r = HashMap::new(); let mut r = HashMap::new();
for (id, tim) in c { for (id, tim) in c {
r.insert(id.clone(), tim + b.get(id).unwrap() + i.get(id).unwrap()); r.insert(id.clone(), tim + b.get(id).unwrap() + i.get(id).unwrap());
...@@ -204,7 +200,7 @@ pub fn response(c: &data, b: &data, i: &data) -> data { ...@@ -204,7 +200,7 @@ pub fn response(c: &data, b: &data, i: &data) -> data {
r r
} }
pub fn dead_line(tasks: &Tasks) -> data { fn dead_line(tasks: &Tasks) -> Data {
let mut dl = HashMap::new(); let mut dl = HashMap::new();
for t in tasks { for t in tasks {
dl.insert(t.id.clone(), t.deadline); dl.insert(t.id.clone(), t.deadline);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment