Skip to content

Commit 99255fd

Browse files
committed
Fix code that assumes timer notification => timer fired
There are two main reasons why a timer notification bit might be set without the timer firing: 1. Subtle state machine bug in previous iteration (not super common but it has happened). 2. Another task, accidentally or deliberately, posting to the bit. This changes the cases I could easily find to check that their timers have actually expired before acting.
1 parent dd76a4c commit 99255fd

15 files changed

Lines changed: 54 additions & 12 deletions

File tree

drv/cosmo-hf/src/hf.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,9 @@ impl NotificationHandler for ServerImpl {
786786
}
787787

788788
fn handle_notification(&mut self, bits: u32) {
789-
if (bits & notifications::TIMER_MASK) != 0 {
789+
if (bits & notifications::TIMER_MASK) != 0
790+
&& userlib::sys_get_timer().deadline.is_none()
791+
{
790792
self.step_hash();
791793
}
792794
}

drv/cosmo-seq-server/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,9 @@ impl NotificationHandler for ServerImpl {
893893
self.handle_sequencer_interrupt();
894894
}
895895

896-
if (bits & notifications::TIMER_MASK) == 0 {
896+
if (bits & notifications::TIMER_MASK) == 0
897+
|| sys_get_timer().deadline.is_some()
898+
{
897899
return;
898900
}
899901
let state = self.log_state_registers();

drv/gimlet-hf-server/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,9 @@ impl NotificationHandler for ServerImpl {
948948
}
949949

950950
fn handle_notification(&mut self, bits: u32) {
951-
if (bits & notifications::TIMER_MASK) != 0 {
951+
if (bits & notifications::TIMER_MASK) != 0
952+
&& userlib::sys_get_timer().deadline.is_none()
953+
{
952954
self.step_hash();
953955
}
954956
}

drv/gimlet-seq-server/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,9 @@ impl<S: SpiServer> NotificationHandler for ServerImpl<S> {
545545
self.vcore.handle_notification(self.ereport_buf);
546546
}
547547

548-
if (bits & notifications::TIMER_MASK) == 0 {
548+
if (bits & notifications::TIMER_MASK) == 0
549+
|| sys_get_timer().deadline.is_some()
550+
{
549551
return;
550552
}
551553

drv/ignition-server/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,10 @@ impl idol_runtime::NotificationHandler for ServerImpl {
421421
}
422422

423423
fn handle_notification(&mut self, _bits: u32) {
424+
if sys_get_timer().deadline.is_some() {
425+
return;
426+
}
427+
424428
let start = sys_get_timer().now;
425429

426430
// Only poll the presence summary if the port count seems reasonable. A

drv/meanwell/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ impl NotificationHandler for ServerImpl {
112112
}
113113

114114
fn handle_notification(&mut self, _bits: u32) {
115+
if userlib::sys_get_timer().deadline.is_some() {
116+
return;
117+
}
118+
115119
let user_leds =
116120
drv_user_leds_api::UserLeds::from(USER_LEDS.get_task_id());
117121

drv/minibar-ignition-server/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ impl idol_runtime::NotificationHandler for ServerImpl {
399399
}
400400

401401
fn handle_notification(&mut self, _bits: u32) {
402+
if sys_get_timer().deadline.is_some() {
403+
return;
404+
}
405+
402406
let start = sys_get_timer().now;
403407

404408
// Only poll the presence summary if the port count seems reasonable. A

drv/minibar-seq-server/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ impl NotificationHandler for ServerImpl {
134134
}
135135

136136
fn handle_notification(&mut self, bits: u32) {
137-
if (bits & notifications::TIMER_MASK) == 0 {
137+
if (bits & notifications::TIMER_MASK) == 0
138+
|| sys_get_timer().deadline.is_some()
139+
{
138140
return;
139141
}
140142
let start = sys_get_timer().now;

drv/psc-seq-server/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,10 @@ fn main() -> ! {
469469

470470
// Wait for a pin change or timer.
471471
let n = sys_recv_notification(sleep_notifications);
472-
if n & notifications::TIMER_MASK != 0 {
472+
// If the timer bit is set _and the timer has actually fired_...
473+
if n & notifications::TIMER_MASK != 0
474+
&& sys_get_timer().deadline.is_none()
475+
{
473476
// Reset our timer forward.
474477
sys_set_timer(
475478
Some(now.saturating_add(POLL_MS)),

drv/sidecar-seq-server/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,10 @@ impl NotificationHandler for ServerImpl {
775775
}
776776

777777
fn handle_notification(&mut self, _bits: u32) {
778+
if sys_get_timer().deadline.is_some() {
779+
return;
780+
}
781+
778782
let start = sys_get_timer().now;
779783

780784
// Determine if the front IO board has been initialized and no further

0 commit comments

Comments
 (0)