From 90017da48445c43637b5c9b753f4cd77e4971e98 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 15 Oct 2020 18:38:00 +0800 Subject: [PATCH] firmware: remove obsolete watchdog code (#1458) --- artiq/firmware/ksupport/api.rs | 3 -- artiq/firmware/ksupport/lib.rs | 15 ------ artiq/firmware/libproto_artiq/kernel_proto.rs | 4 -- .../firmware/libproto_artiq/session_proto.rs | 4 -- artiq/firmware/runtime/main.rs | 1 - artiq/firmware/runtime/session.rs | 25 ---------- artiq/firmware/runtime/watchdog.rs | 49 ------------------- 7 files changed, 101 deletions(-) delete mode 100644 artiq/firmware/runtime/watchdog.rs diff --git a/artiq/firmware/ksupport/api.rs b/artiq/firmware/ksupport/api.rs index c07f9776b..89a6f638c 100644 --- a/artiq/firmware/ksupport/api.rs +++ b/artiq/firmware/ksupport/api.rs @@ -121,9 +121,6 @@ static mut API: &'static [(&'static str, *const ())] = &[ api!(now = csr::rtio::NOW_HI_ADDR as *const _), - api!(watchdog_set = ::watchdog_set), - api!(watchdog_clear = ::watchdog_clear), - api!(rpc_send = ::rpc_send), api!(rpc_send_async = ::rpc_send_async), api!(rpc_recv = ::rpc_recv), diff --git a/artiq/firmware/ksupport/lib.rs b/artiq/firmware/ksupport/lib.rs index c6e747fdb..5e42fd100 100644 --- a/artiq/firmware/ksupport/lib.rs +++ b/artiq/firmware/ksupport/lib.rs @@ -200,21 +200,6 @@ fn terminate(exception: &eh_artiq::Exception, backtrace: &mut [usize]) -> ! { loop {} } -#[unwind(allowed)] -extern fn watchdog_set(ms: i64) -> i32 { - if ms < 0 { - raise!("ValueError", "cannot set a watchdog with a negative timeout") - } - - send(&WatchdogSetRequest { ms: ms as u64 }); - recv!(&WatchdogSetReply { id } => id) as i32 -} - -#[unwind(aborts)] -extern fn watchdog_clear(id: i32) { - send(&WatchdogClear { id: id as usize }) -} - #[unwind(aborts)] extern fn cache_get(key: CSlice) -> CSlice<'static, i32> { send(&CacheGetRequest { diff --git a/artiq/firmware/libproto_artiq/kernel_proto.rs b/artiq/firmware/libproto_artiq/kernel_proto.rs index a64f0f0b7..3ca55426d 100644 --- a/artiq/firmware/libproto_artiq/kernel_proto.rs +++ b/artiq/firmware/libproto_artiq/kernel_proto.rs @@ -52,10 +52,6 @@ pub enum Message<'a> { }, RunAborted, - WatchdogSetRequest { ms: u64 }, - WatchdogSetReply { id: usize }, - WatchdogClear { id: usize }, - RpcSend { async: bool, service: u32, diff --git a/artiq/firmware/libproto_artiq/session_proto.rs b/artiq/firmware/libproto_artiq/session_proto.rs index cc0012da5..db353e874 100644 --- a/artiq/firmware/libproto_artiq/session_proto.rs +++ b/artiq/firmware/libproto_artiq/session_proto.rs @@ -105,7 +105,6 @@ pub enum Reply<'a> { RpcRequest { async: bool }, - WatchdogExpired, ClockFailure, } @@ -191,9 +190,6 @@ impl<'a> Reply<'a> { writer.write_u8(async as u8)?; }, - Reply::WatchdogExpired => { - writer.write_u8(14)?; - }, Reply::ClockFailure => { writer.write_u8(15)?; }, diff --git a/artiq/firmware/runtime/main.rs b/artiq/firmware/runtime/main.rs index 73660b611..c64d0fc64 100644 --- a/artiq/firmware/runtime/main.rs +++ b/artiq/firmware/runtime/main.rs @@ -53,7 +53,6 @@ mod mgmt; mod profiler; mod kernel; mod kern_hwreq; -mod watchdog; mod session; #[cfg(any(has_rtio_moninj, has_drtio))] mod moninj; diff --git a/artiq/firmware/runtime/session.rs b/artiq/firmware/runtime/session.rs index 4a14f3fb6..a05e18c2f 100644 --- a/artiq/firmware/runtime/session.rs +++ b/artiq/firmware/runtime/session.rs @@ -11,7 +11,6 @@ use rtio_clocking; use rtio_dma::Manager as DmaManager; use cache::Cache; use kern_hwreq; -use watchdog::WatchdogSet; use board_artiq::drtio_routing; use rpc_proto as rpc; @@ -28,10 +27,6 @@ pub enum Error { InvalidPointer(usize), #[fail(display = "RTIO clock failure")] ClockFailure, - #[fail(display = "watchdog {} expired", _0)] - WatchdogExpired(usize), - #[fail(display = "out of watchdogs")] - OutOfWatchdogs, #[fail(display = "protocol error: {}", _0)] Protocol(#[cause] host::Error), #[fail(display = "{}", _0)] @@ -91,7 +86,6 @@ enum KernelState { struct Session<'a> { congress: &'a mut Congress, kernel_state: KernelState, - watchdog_set: WatchdogSet, log_buffer: String } @@ -100,7 +94,6 @@ impl<'a> Session<'a> { Session { congress: congress, kernel_state: KernelState::Absent, - watchdog_set: WatchdogSet::new(), log_buffer: String::new() } } @@ -396,15 +389,6 @@ fn process_kern_message(io: &Io, aux_mutex: &Mutex, }) } - &kern::WatchdogSetRequest { ms } => { - let id = session.watchdog_set.set_ms(ms).map_err(|()| Error::OutOfWatchdogs)?; - kern_send(io, &kern::WatchdogSetReply { id: id }) - } - &kern::WatchdogClear { id } => { - session.watchdog_set.clear(id); - kern_acknowledge() - } - &kern::RpcSend { async, service, tag, data } => { match stream { None => unexpected!("unexpected RPC in flash kernel"), @@ -522,11 +506,6 @@ fn host_kernel_worker(io: &Io, aux_mutex: &Mutex, } if session.kernel_state == KernelState::Running { - if let Some(idx) = session.watchdog_set.expired() { - host_write(stream, host::Reply::WatchdogExpired)?; - return Err(Error::WatchdogExpired(idx)) - } - if !rtio_clocking::crg::check() { host_write(stream, host::Reply::ClockFailure)?; return Err(Error::ClockFailure) @@ -567,10 +546,6 @@ fn flash_kernel_worker(io: &Io, aux_mutex: &Mutex, } } - if let Some(idx) = session.watchdog_set.expired() { - return Err(Error::WatchdogExpired(idx)) - } - if !rtio_clocking::crg::check() { return Err(Error::ClockFailure) } diff --git a/artiq/firmware/runtime/watchdog.rs b/artiq/firmware/runtime/watchdog.rs deleted file mode 100644 index 202a1d1a0..000000000 --- a/artiq/firmware/runtime/watchdog.rs +++ /dev/null @@ -1,49 +0,0 @@ -use board_misoc::clock; - -#[derive(Debug, Clone, Copy)] -struct Watchdog { - active: bool, - threshold: u64 -} - -pub const MAX_WATCHDOGS: usize = 16; - -#[derive(Debug)] -pub struct WatchdogSet { - watchdogs: [Watchdog; MAX_WATCHDOGS] -} - -impl WatchdogSet { - pub fn new() -> WatchdogSet { - WatchdogSet { - watchdogs: [Watchdog { active: false, threshold: 0 }; MAX_WATCHDOGS] - } - } - - pub fn set_ms(&mut self, interval: u64) -> Result { - for (index, watchdog) in self.watchdogs.iter_mut().enumerate() { - if !watchdog.active { - watchdog.active = true; - watchdog.threshold = clock::get_ms() + interval; - return Ok(index) - } - } - - Err(()) - } - - pub fn clear(&mut self, index: usize) { - if index < MAX_WATCHDOGS { - self.watchdogs[index].active = false - } - } - - pub fn expired(&self) -> Option { - self.watchdogs - .iter() - .enumerate() - .filter(|(_, wd)| wd.active && clock::get_ms() > wd.threshold) - .min_by_key(|(_, wd)| wd.threshold) - .map_or(None, |(i, _)| Some(i)) - } -}