From d825393e81c0829868ee0524ed874c9a9a98e450 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 1 Oct 2016 16:26:57 +0000 Subject: [PATCH] Rust: implement watchdogs. --- artiq/runtime.rs/src/clock.rs | 1 - artiq/runtime.rs/src/session.rs | 25 +++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/artiq/runtime.rs/src/clock.rs b/artiq/runtime.rs/src/clock.rs index b9a0584b3..3c203a196 100644 --- a/artiq/runtime.rs/src/clock.rs +++ b/artiq/runtime.rs/src/clock.rs @@ -58,7 +58,6 @@ impl WatchdogSet { } } - warn!("cannot add watchdog; all {} watchdogs used", MAX_WATCHDOGS); Err(()) } diff --git a/artiq/runtime.rs/src/session.rs b/artiq/runtime.rs/src/session.rs index 65c250279..c9ef4383f 100644 --- a/artiq/runtime.rs/src/session.rs +++ b/artiq/runtime.rs/src/session.rs @@ -17,6 +17,10 @@ macro_rules! unexpected { }; } +fn io_error(msg: &str) -> io::Error { + io::Error::new(io::ErrorKind::Other, msg) +} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum KernelState { Absent, @@ -49,6 +53,12 @@ impl Session { } } +impl Drop for Session { + fn drop(&mut self) { + kernel::stop() + } +} + fn check_magic(stream: &mut TcpStream) -> io::Result<()> { const MAGIC: &'static [u8] = b"ARTIQ coredev\n"; @@ -226,6 +236,17 @@ fn kern_handle(waiter: Waiter, kern_acknowledge() } + kern::WatchdogSetRequest { ms } => { + let id = try!(session.watchdog_set.set_ms(ms) + .map_err(|()| io_error("out of watchdogs"))); + kern_send(waiter, kern::WatchdogSetReply { id: id }) + } + + kern::WatchdogClear { id } => { + session.watchdog_set.clear(id); + kern_acknowledge() + } + request => unexpected!("unexpected request {:?} from kernel CPU", request) } }) @@ -249,12 +270,12 @@ fn handle(waiter: Waiter, if session.kernel_state == KernelState::Running { if session.watchdog_set.expired() { try!(host_write(stream, host::Reply::WatchdogExpired)); - return Err(io::Error::new(io::ErrorKind::Other, "watchdog expired")) + return Err(io_error("watchdog expired")) } if !rtio_crg::check() { try!(host_write(stream, host::Reply::ClockFailure)); - return Err(io::Error::new(io::ErrorKind::Other, "RTIO clock failure")) + return Err(io_error("RTIO clock failure")) } }