Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rp: Fix time driver hang #3763

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

robot-rover
Copy link

Fixes: #3758

This commit fixes a race condition in the embassy-rp time driver IRQ that causes the time driver to lock up when an alarm is scheduled that expires before the IRQ finishes.

I convinced myself that this fix worked by first changing the IRQ to be

fn check_alarm(&self) { 
     let n = 0; 
     critical_section::with(|cs| { 
         let alarm = &self.alarms.borrow(cs); 
         let timestamp = alarm.timestamp.get(); 
         if timestamp <= self.now() { 
             self.trigger_alarm(cs) 
         } else { 
             // Not elapsed, arm it again. 
             // This can happen if it was set more than 2^32 us in the future. 
             TIMER.alarm(n).write_value(timestamp as u32); 
         } 
     }); 

     // NEW LINES HERE
     for _ in 0..1000 {
         cortex_m::asm::nop()
     }
     // END NEW LINES
  
     // clear the irq 
     TIMER.intr().write(|w| w.set_alarm(n, true)); 
 }

This change made the corner case much easier to hit, and I was able to reproduce the issue in ~30 seconds rather than every 15 minutes or so. By moving the IRQ clear to the start of the ISR, I was able to stop the hang from happening altogether.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

embassy-rp time-driver-impl hangs
1 participant