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

fixes

parent 7d19d448
Branches master
No related tags found
No related merge requests found
......@@ -64,29 +64,31 @@ fn main() {
},
};
let debug = false;
let advance = false;
let debug = true;
let advance = true;
// builds a vector of tasks t1, t2, t3
// in falling prio order IMPORTENT The order are used
let mut tasks: Tasks = vec![t1, t2, t3];
tasks.sort_by(|a, b| (a.prio).partial_cmp(&b.prio).unwrap());
tasks.reverse();
// tasks.sort_by(|a, b| (a.prio).partial_cmp(&b.prio).unwrap());
// 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 (l, l_tot) = load(&tasks, &c);
let b = block(&tasks, &ip, &tr);
let i = interferens(&tasks, &c, advance);
let b = block(&tp, &rp, &tr);
let i = interferens(&tp, &c, &a, &dl, advance);
let r = response(&c, &b, &i);
if debug{
println!("Debug data");
println!("tasks {:?}", &tasks);
println!("ip: {:?}", ip);
println!("tp: {:?}", tp);
println!("rp: {:?}", rp);
println!("tr: {:?}", tr);
println!("DeadLine: {:?}", dl);
println!("A: {:?}", a);
println!("C(t): {:?}", c);
println!("L(t): {:?}",l);
println!("L(T): {:?}",l_tot);
......@@ -101,7 +103,7 @@ fn main() {
}
// 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");
if l <= 1.0 {
println!("Load test SUCSES");
......@@ -119,7 +121,7 @@ fn test(dl: data, l: f32, r: &data) {
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!("Total load {}%", load);
println!("ID | L | R | C | B | I | PRIO ");
......
......@@ -33,20 +33,22 @@ pub type IdPrio = HashMap<String, u8>;
// id_task, {id_res, longest}
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>;
// Derives the above maps from a set of tasks
pub fn pre_analysis(tasks: &Tasks) -> (IdPrio, TaskResources) {
let mut ip = HashMap::new();
pub fn pre_analysis(tasks: &Tasks) -> (IdPrio, IdPrio, TaskResources, Data, Data) {
let mut tp = HashMap::new();
let mut rp = HashMap::new();
let mut tr: TaskResources = HashMap::new();
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 {
update_tr(t.id.clone(), i, &mut tr);
}
}
(ip, tr)
(tp, rp, tr, inter_arival(&tasks), dead_line(&tasks))
}
// helper functions
......@@ -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();
for t in tasks {
c.insert(t.id.clone(), t.trace.end - t.trace.start);
......@@ -99,7 +101,7 @@ pub fn c_times(tasks: &Tasks) -> data {
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 tot = 0.0;
for t in tasks {
......@@ -111,35 +113,33 @@ pub fn load(tasks: &Tasks, c: &data) -> (L, f32){
(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();
for t in tasks {
for (task_id, task_prio) in tp {
let mut block_time = 0;
let resourses = tr.get(&t.id);
let resourses = tr.get(task_id);
match resourses {
Some(res) => {
for vectorn in res {
for (id, _) in vectorn {
// iter this, all res
for (tr_id, tr_has) in tr {
if ip.get(tr_id).unwrap() < &t.prio {
for (tr_id, tr_resorses) in tr {
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) {
block_time += time;
}
}
}
}
}
}
b.insert(t.id.clone(), block_time);
b.insert(task_id.clone(), block_time);
},
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 {
b
}
pub fn interferens(tasks: &Tasks, c: &data, advance: bool) -> data {
pub fn interferens(tp: &IdPrio, c: &Data, a: &Data, dl: &Data, advance: bool) -> Data {
let mut i = HashMap::new();
let a = inter_arival(&tasks);
i.insert(tasks[0].id.clone(), 0);
if !advance {
for index in 1..tasks.len() {
for (id_curent, prio_curent) in tp {
let mut sum = 0;
for index2 in 0..index {
let id = &tasks[index2].id;
sum += block_eq(*a.get(&tasks[index].id).unwrap(),
*a.get(id).unwrap(),
*c.get(id).unwrap());
let mut block = *dl.get(&id_curent.clone()).unwrap();
if advance {
block = *c.get(&id_curent.clone()).unwrap();
}
i.insert(tasks[index].id.clone(), sum);
}
} else {
for index in 1..tasks.len() {
let mut sum = 0;
let mut block = *c.get(&tasks[index].id).unwrap();
let mut temp = 0;
while sum < block {
sum = block;
temp = block;
let mut part = 0;
for index2 in 0..index {
let id = &tasks[index2].id;
part += block_eq(block, *a.get(id).unwrap(), *c.get(id).unwrap());
for (id_ref, prio_ref) in tp {
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
}
fn block_eq(block: u32, a: u32, c: u32) -> u32 {
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();
for t in tasks {
a.insert(t.id.clone(), t.inter_arrival.clone());
......@@ -196,7 +192,7 @@ fn inter_arival(tasks: &Tasks) -> data {
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();
for (id, tim) in c {
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 {
r
}
pub fn dead_line(tasks: &Tasks) -> data {
fn dead_line(tasks: &Tasks) -> Data {
let mut dl = HashMap::new();
for t in tasks {
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