diff --git a/srp_analysis/src/main.rs b/srp_analysis/src/main.rs index 4e528df95e3ba4b7e3378c6e435079df9f2feda8..9246224a27fe825280ab2ab7e23004903f023b37 100644 --- a/srp_analysis/src/main.rs +++ b/srp_analysis/src/main.rs @@ -68,9 +68,44 @@ fn main() { let tasks: Tasks = vec![t1, t2, t3]; println!("tasks {:?}", &tasks); - // println!("tot_util {}", tot_util(&tasks)); + println!("tot_util {}", total_load_factor(&tasks)); let (ip, tr) = pre_analysis(&tasks); println!("ip: {:?}", ip); println!("tr: {:?}", tr); } + + +/* + * Calculates the total load factor(Ltot). + * + * Note: We can compute the total CPU request (or load factor), as Ltot = sum(L(T)), T being the set of tasks. + */ +fn total_load_factor(tasks: &Tasks) -> f32 { + let mut ltot: f32 = 0.0; + for t in tasks { + ltot += cpu_load(t); + } + return ltot; +} + + +/* + * Calculates the cpu load of a task(L(t) where t is a task). + * + * Note: Each task t has a WCET C(t) and given (assumed) inter-arrival time A(t). The CPU request (or load) inferred by a task is L(t) = C(t)/A(t). Ask yourself, what is the consequence of C(t) > A(t)? + */ +fn cpu_load(task: &Task) -> f32 { + return (wcet(task) as f32) / (task.inter_arrival as f32) +} + + +/* + * Worst case execution time(WCET) of a task t(C(t)). + */ +fn wcet(task: &Task) -> u32 { + // TODO: Check if this is correct. + return task.trace.end.wrapping_sub(task.trace.start); +} + +