diff --git a/examples/timing_resources.rs b/examples/timing_resources.rs index 6c00759987950a2af9c17be7a2c0ee99fade497d..67dde0c5e146d3db9c2fd29a91e431f5ee889fe0 100644 --- a/examples/timing_resources.rs +++ b/examples/timing_resources.rs @@ -82,7 +82,12 @@ const APP: () = { // strd r2, r3, [r1] = // msr basepri, r0 = Writes the value of r0 into coprocessor register basepri. // bx lr = -// +// +// The function starts by loading the priority celling into registry r0. +// Then it loads in the shared variable into register r2. +// Then it add one to the shared variable(r1). +// Then it sets the shared variable. +// Lastly it sets the priority celling back to what it was before. // // // > cargo run --example timing_resources --release --features nightly @@ -103,7 +108,7 @@ const APP: () = { // (gdb) x 0xe0001004 // // [Your answer here] -// 0xe0001004: 0x00000010 +// 0xe0001004: 0x00000010 = 16 cycles // // (gdb) disassemble // @@ -129,12 +134,12 @@ const APP: () = { // What was the software latency observed to enter the task? // // [Your answer here] -// 16 - 2 = 14 +// 16 - 2 = 14 cycles // // Does RTIC infer any overhead? // // [Your answer here] -// Yes, it add 2 cycles. Because Cortex-M4 interupt takes 12 cycles. +// Yes, it add 2 cycles of overhead. Cortex-M4 interupt takes 12 cycles. // // The debugger reports that the breakpoint was hit in the `run<closure>`. // The reason is that the RTIC implements the actual interrupt handler, @@ -153,7 +158,7 @@ const APP: () = { // (gdb) x 0xe0001004 // // [Your answer here] -// 0xe0001004: 0x00000025 +// 0xe0001004: 0x00000025 = 32 + 5 = 37 cycles // // You should have a total execution time in the range of 30-40 cycles. // @@ -161,7 +166,9 @@ const APP: () = { // `exti0` was safe without locking the resource. // // [Your answer here] -// TODO +// I think the reason is that EXTI0 has a higher priorety then EXTI1 which means that EXTI0 will +// never be interupted by EXTI1. And EXTI0 can never interupt EXTI1 when it is using the shared +// variable becaise EXTI1 uses a lock. // // In `exti1` we also access `shared` but this time through a lock. // @@ -191,12 +198,12 @@ const APP: () = { // (gdb) x 0xe0001004 // // [Your answer here] -// 0xe0001004: 0x00000034 +// 0xe0001004: 0x00000034 = 32 + 16 + 4 = 52 cycles // // Calculate the total time (in cycles), for this section of code. // // [Your answer here] -// 52 - 37 = 15 +// 52 - 37 = 15 cycles // // You should get a value around 15 cycles. // @@ -237,7 +244,7 @@ const APP: () = { // (gdb) x 0xe0001004 // // [Your answer here] -// 0xe0001004: 0x00000028 +// 0xe0001004: 0x00000028 = 32 + 8 = 40 cycles // // (gdb) c // @@ -248,7 +255,7 @@ const APP: () = { // (gdb) x 0xe0001004 // // [Your answer here] -// 0xe0001004: 0x00000032 +// 0xe0001004: 0x00000032 = 32 + 16 + 2 = 50 cycles // // From a real-time perspective the critical section infers // blocking (of higher priority tasks). @@ -256,7 +263,7 @@ const APP: () = { // How many clock cycles is the blocking? // // [Your answer here] -// 50 - 40 = 10 +// 50 - 40 = 10 cycles // // Finally continue out of the closure. // @@ -267,7 +274,7 @@ const APP: () = { // (gdb) x 0xe0001004 // // [Your answer here] -// 0xe0001004: 0x00000034 +// 0xe0001004: 0x00000034 = 32 + 16 + 4 = 52 cycles // // This is the total execution time of: // @@ -291,7 +298,19 @@ const APP: () = { // Motivate your answer (not just a number). // // [Your answer here] -// TODO +// Estimated cost per task: +// Pending the task EXTI1 cost 650 cycles (job latency). +// Starting the thread EXTI1 cost 1522 cycles (job overhead). +// Pending the task EXTI0 cost 650 cycles (job latency). +// Starting the thread EXTI0 cost 1522 cycles (job overhead). +// Locking the shared variable cost 260 cycles (). +// Unlocking the shared variable cost 170 cycles (). +// Returning to EXTI1 cost 1522 cycles (job overhead). +// Locking the shared variable cost 260 cycles (). +// Unlocking the shared variable cost 170 cycles (). +// +// +// The total cost: 650 + 1522 + 650 + 1522 + 260 + 170 + 1522 + 260 + 170 = 6726 // // Notice, the Rust implementation is significantly faster than the C code version // of Real-Time For the Masses back in 2013.