From ed16fc1b2f4388b2797e196d9d92d7a00c3322f6 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 21 May 2022 01:34:35 +0800 Subject: [PATCH 1/3] advance timer state by +1 ms on suspend to avoid double-interrupts on resume Issue #159 may be caused by queueing a connection to respond to when the timer expires, but if the timer expires twice then it tries to respond to a null connection id. And if it goes to suspend in the same millisecond as it services the condvar, then it'll reissue the interrupt when it comes back from suspend. --- services/susres/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/susres/src/main.rs b/services/susres/src/main.rs index 7b9e32a8a..10a0074e7 100644 --- a/services/susres/src/main.rs +++ b/services/susres/src/main.rs @@ -243,7 +243,7 @@ mod implementation { self.stored_time = Some( (self.csr.r(utra::susres::TIME0) as u64 | (self.csr.r(utra::susres::TIME1) as u64) << 32) - + 0 // a placeholder in case we need to advance time on save + + 1 // a placeholder in case we need to advance time on save ); #[cfg(feature = "debugprint")] println!("Stored time: {}", self.stored_time.unwrap()); From d6d5c897463d2ea641c10232fdad8276a147e872 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 23 May 2022 13:47:57 +0800 Subject: [PATCH 2/3] add facility to help debug stalled suspend/resume --- services/susres/src/lib.rs | 7 ++++++- services/susres/src/main.rs | 14 +++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/services/susres/src/lib.rs b/services/susres/src/lib.rs index 2c9423bee..f525a8935 100644 --- a/services/susres/src/lib.rs +++ b/services/susres/src/lib.rs @@ -154,12 +154,17 @@ impl Drop for Susres { fn suspend_cb_server(sid0: usize, sid1: usize, sid2: usize, sid3: usize) { let sid = xous::SID::from_u32(sid0 as u32, sid1 as u32, sid2 as u32, sid3 as u32); + let mut print_once = false; loop { let msg = xous::receive_message(sid).unwrap(); match FromPrimitive::from_usize(msg.body.id()) { Some(SuspendEventCallback::Event) => msg_scalar_unpack!(msg, cid, id, token, _, { // directly pass the scalar message onto the CID with the ID memorized in the original hook - log::debug!("PID {} has s/r token {}", xous::current_pid().unwrap().get(), token); // <-- use this to debug s/r + if !print_once { + // dump this only once so we have a PID->token map in the debug logs, but don't dump it every time as it slows down the suspend + log::info!("PID {} has s/r token {}", xous::current_pid().unwrap().get(), token); // <-- use this to debug s/r + print_once = true; + } send_message(cid as u32, Message::new_scalar(id, token, 0, 0, 0) ).unwrap(); diff --git a/services/susres/src/main.rs b/services/susres/src/main.rs index 10a0074e7..e8922f06c 100644 --- a/services/susres/src/main.rs +++ b/services/susres/src/main.rs @@ -738,7 +738,19 @@ fn xmain() -> ! { } timeout_pending = false; log::warn!("Suspend timed out, forcing an unclean suspend"); - // susres_hw.debug_delay(500); // let the messages print + for sub in suspend_subscribers.iter() { + if sub.order == current_op_order { + if !sub.ready_to_suspend { + // note to debugger: you will get a token number, which is in itself not useful. + // There should be, at least once in the debug log, printed on the very first suspend cycle, + // a list of PID->tokens. Tokens are assigned in the order that the registration happens + // to the susres server. Empirically, this list is generally stable for every build, + // and is guaranteed to be stable across a single cold boot. + log::warn!(" -> NOT READY: {}", sub.token); + } + } + } + susres_hw.debug_delay(500); // let the messages print // force a suspend susres_hw.do_suspend(true); From 8221f92d954a57931023556582ecc8e76f408db2 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 23 May 2022 17:27:05 +0800 Subject: [PATCH 3/3] potential fix for #162 see issue for discussion --- services/ticktimer-server/src/main.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/services/ticktimer-server/src/main.rs b/services/ticktimer-server/src/main.rs index 358ce703b..e41d68ade 100644 --- a/services/ticktimer-server/src/main.rs +++ b/services/ticktimer-server/src/main.rs @@ -625,16 +625,15 @@ fn xmain() -> ! { let sender = args.arg1; let request_kind = args.arg2; let condvar = args.arg3; - let sender_pid = msg.sender.pid().map(|p| p.get()).unwrap_or_default() as u32; + let sender_pid = xous::MessageSender::from_usize(sender).pid(); // If we're being asked to recalculate due to a timeout expiring, drop the sent // message from the `entries` list. - if sender_pid == xous::process::id() - && (request_kind == RequestKind::Timeout as usize) + if (request_kind == RequestKind::Timeout as usize) && (sender > 0) { let entries = notify_hash - .entry(msg.sender.pid()) + .entry(sender_pid) .or_default() .entry(condvar) .or_default(); @@ -648,6 +647,7 @@ fn xmain() -> ! { if let Some(idx) = idx { entries.remove(idx); } + // log::trace!("new entries for PID {:?}/condvar {:08x}: {:?}", sender_pid, condvar, notify_hash.get(&sender_pid).unwrap().get(&condvar)); } } recalculate_sleep(&mut ticktimer, &mut sleep_heap, None); @@ -771,6 +771,7 @@ fn xmain() -> ! { .or_default() .push_back(msg.sender); + // log::trace!("New waiting senders: {:?}", notify_hash.get(&pid).unwrap().get(&condvar)); continue; } else { info!(