diff --git a/examples/timing_exam.rs b/examples/timing_exam.rs index e582440f7860927e20fbfe5804695f0da4c1e258..892ef69f1aabe7e22c9e0beb311eb675901990cb 100644 --- a/examples/timing_exam.rs +++ b/examples/timing_exam.rs @@ -48,19 +48,21 @@ const APP: () = { // emulates timing behavior of t1 cortex_m::asm::delay(10_000); + asm::bkpt(); // 2) your code here to update T1_MAX_RP and // break if deadline missed let resp: u32= cx.scheduled.elapsed().as_cycles(); + asm::bkpt(); if resp > 100_000 { //panic!(); asm::bkpt(); - } else { - unsafe { - if resp > T1_MAX_RP { - T1_MAX_RP = resp; - } + } + unsafe { + if resp > T1_MAX_RP { + T1_MAX_RP = resp; } } + asm::bkpt(); } // Deadline 200, Inter-arrival 200 @@ -81,7 +83,9 @@ const APP: () = { asm::delay(2_000); // R2 : claim cx.resources.R2.lock(|r2| { + *r2 = 1338; asm::delay(4_000); + *r2 = 1668; }); // R2 : release asm::delay(4_000); @@ -93,19 +97,20 @@ const APP: () = { asm::delay(2_000); // == End trace == + asm::bkpt(); // 2) your code here to update T2_MAX_RP and // break if deadline missed let resp: u32= cx.scheduled.elapsed().as_cycles(); if resp > 200_000 { //panic!(); asm::bkpt(); - } else { - unsafe { - if resp > T2_MAX_RP { - T2_MAX_RP = resp; - } + } + unsafe { + if resp > T2_MAX_RP { + T2_MAX_RP = resp; } } + asm::bkpt(); } // Deadline 50, Inter-arrival 50 @@ -122,24 +127,26 @@ const APP: () = { // == Begin trace == asm::delay(10_000); // R2 : claim + *cx.resources.R2 = 1337; asm::delay(10_000); // R2 : release asm::delay(10_000); // == End trace == + asm::bkpt(); // 2) your code here to update T3_MAX_RP and // break if deadline missed let resp: u32= cx.scheduled.elapsed().as_cycles(); if resp > 50_000 { //panic!(); asm::bkpt(); - } else { - unsafe { - if resp > T3_MAX_RP { - T3_MAX_RP = resp; - } + } + unsafe { + if resp > T3_MAX_RP { + T3_MAX_RP = resp; } } + asm::bkpt(); } // RTIC requires that unused interrupts are declared in an extern block when @@ -276,62 +283,99 @@ Because multiple tasks can access these variables, rust can't ensure that the re // 3A) Why is there an offset 50240 (instead of 50000)? // // [Your answer here] +/* +Because of the context-switching into the task. +*/ // // 3B) Why is the calculated response time larger than the // delays you inserted to simulate workload? // // [Your answer here] +/* +Because of the context switching and the amount of instructions it takes to re-schedule T3. +*/ // // 3C) Why is the second arrival of `t3` further delayed? // // [Your answer here] // Hint, think about what happens at time 100_000, what tasks // are set to `arrive` at that point compared to time 50_000. +/* +Because their has to be a preemption check between t3 and t1 because they are scheduled for the same instance. +*/ // // 3D) What is the scheduled time for task `t1` (130595 is the // measured time according to CYCYCNT). // // [Your answer here] +/* +Scheduled time is 100_000. +*/ // // Why is the measured value much higher than the scheduled time? // // [Your answer here] +/* +Because t1 has been preempted by t3 and is not allowed to run until t3 is done executing. +*/ // // Now you can continue until you get a first update of `T1_MAX_RP`. // // What is the first update of `T1_MAX_RP`? // // [Your answer here] +/* +T1_MAX_RP: 40704 +*/ // // Explain the obtained value in terms of: // Execution time, blocking and preemptions // (that occurred for this task instance). // // [Your answer here] +/* +WCET for t1 is roughly ~= 10_000 (Give or take, beacause of the context switching) +B(t1) = 0, because t1 doesn't share any resources (in fact it doesn't have any) with other tasks it can never be blocked. +I(t1) = R(t3), t1 has to wait for t3 (and only t3) to execute. The preemption time is the responsetime of t3. +*/ // // Now continue until you get a first timing measurement for `T2_MAX_RP`. // // What is the first update of `T2_MAX_RP`? // // [Your answer here] +/* +T2_MAX_RP: 91_224 +*/ // // Now continue until you get a second timing measurement for `T1_MAX_RP`. // // What is the second update of `T3_MAX_RP`? // // [Your answer here] +/* +I'm assuming we're suppose to check the second update of T1_MAX_RP. +T1_MAX_RP: 131_992 +*/ // // Now you should have ended up in a deadline miss right!!!! // // Why did this happen? // // [Your answer here] +/* +Because t1 has the lowest priority of all the tasks and they all happend at once t1 got preempted to the point it could no longer hold its deadline. +*/ // // Compare that to the result obtained from your analysis tool. // // Do they differ, if so why? // // [Your answer here] +/* +In the analysis this scheduling works out fine (even if its a tight squeeze) but that's because all the times are exact. +In this real life example we have some longer responsetimes which means it doesn't hold. +*/ // // Commit your repository once you completed this part. //