Skip to content

Commit 89c3816

Browse files
committed
perf(port_arm_m): issue DSB in yield_cpu
Despite the addition of an additional instruction, this may hypotheti- cally confer a performance benefit: In `wait_until_woken_up`, if the pend operation didn't complete before the subsequent `enter_cpu_lock` operation, `wait_until_woken_up` would run extra iterations before PendSV is actually taken, thereby incurring performance penalty. The DSB operation prevents this from happening. The measured changes in the execution times of the benchmark suite lie across the ranges of -3–+5 cycles (STM32F401, Cortex-M4F) and -158–0 cycles (RP2040, Cortex-M0+).
1 parent a1262cb commit 89c3816

File tree

1 file changed

+4
-0
lines changed
  • src/r3_port_arm_m/src/threading

1 file changed

+4
-0
lines changed

src/r3_port_arm_m/src/threading/imp.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ impl State {
171171
pub unsafe fn yield_cpu<Traits: PortInstance>(&'static self) {
172172
// Safety: See `use_port!`
173173
cortex_m::peripheral::SCB::set_pendsv();
174+
175+
// Technically this DSB isn't required for correctness, but ensures
176+
// PendSV is taken before the next operation.
177+
cortex_m::asm::dsb();
174178
}
175179

176180
pub unsafe fn exit_and_dispatch<Traits: PortInstance>(

0 commit comments

Comments
 (0)