From 97a20365923d5c642b8c33b1586dcd86991db9d9 Mon Sep 17 00:00:00 2001 From: Blinningjr <nicke.l@telia.com> Date: Fri, 1 Jan 2021 17:31:04 +0100 Subject: [PATCH] Finished total load factor function --- srp_analysis/src/main.rs | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/srp_analysis/src/main.rs b/srp_analysis/src/main.rs index 4e528df..9246224 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); +} + + -- GitLab