2018-05-15 02:27:17 +08:00
|
|
|
use core::{mem, str, cell::{Cell, RefCell}, fmt::Write as FmtWrite};
|
|
|
|
use alloc::{Vec, String};
|
2017-11-03 23:49:12 +08:00
|
|
|
use byteorder::{ByteOrder, NetworkEndian};
|
|
|
|
|
2018-05-15 22:14:27 +08:00
|
|
|
use io::{Read, Write, Error as IoError};
|
2018-05-15 01:54:29 +08:00
|
|
|
use board_misoc::{ident, cache, config};
|
|
|
|
use {mailbox, rpc_queue, kernel};
|
2016-10-02 12:37:24 +08:00
|
|
|
use urc::Urc;
|
2018-09-19 11:16:21 +08:00
|
|
|
use sched::{ThreadHandle, Io, Mutex, TcpListener, TcpStream, Error as SchedError};
|
2017-11-03 23:49:12 +08:00
|
|
|
use rtio_mgt;
|
|
|
|
use rtio_dma::Manager as DmaManager;
|
|
|
|
use cache::Cache;
|
|
|
|
use kern_hwreq;
|
2017-12-28 15:06:45 +08:00
|
|
|
use watchdog::WatchdogSet;
|
2018-09-14 20:26:39 +08:00
|
|
|
use board_artiq::drtio_routing;
|
2016-09-27 21:36:55 +08:00
|
|
|
|
2016-10-30 05:34:25 +08:00
|
|
|
use rpc_proto as rpc;
|
2016-10-01 12:20:27 +08:00
|
|
|
use session_proto as host;
|
|
|
|
use kernel_proto as kern;
|
|
|
|
|
2018-05-15 21:27:23 +08:00
|
|
|
#[derive(Fail, Debug)]
|
|
|
|
pub enum Error<T> {
|
|
|
|
#[fail(display = "cannot load kernel: {}", _0)]
|
|
|
|
Load(String),
|
|
|
|
#[fail(display = "kernel not found")]
|
|
|
|
KernelNotFound,
|
|
|
|
#[fail(display = "invalid kernel CPU pointer: {:#08x}", _0)]
|
|
|
|
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<T>),
|
|
|
|
#[fail(display = "{}", _0)]
|
|
|
|
Unexpected(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> From<host::Error<T>> for Error<T> {
|
|
|
|
fn from(value: host::Error<T>) -> Error<T> {
|
|
|
|
Error::Protocol(value)
|
|
|
|
}
|
2016-10-01 12:20:27 +08:00
|
|
|
}
|
|
|
|
|
2018-05-15 22:14:27 +08:00
|
|
|
impl From<SchedError> for Error<SchedError> {
|
|
|
|
fn from(value: SchedError) -> Error<SchedError> {
|
|
|
|
Error::Protocol(host::Error::Io(IoError::Other(value)))
|
2018-05-15 21:27:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-15 22:14:27 +08:00
|
|
|
impl From<IoError<SchedError>> for Error<SchedError> {
|
|
|
|
fn from(value: IoError<SchedError>) -> Error<SchedError> {
|
2018-05-15 21:27:23 +08:00
|
|
|
Error::Protocol(host::Error::Io(value))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! unexpected {
|
|
|
|
($($arg:tt)*) => (return Err(Error::Unexpected(format!($($arg)*))));
|
2016-10-02 00:26:57 +08:00
|
|
|
}
|
|
|
|
|
2016-10-02 02:24:53 +08:00
|
|
|
// Persistent state
|
|
|
|
#[derive(Debug)]
|
|
|
|
struct Congress {
|
|
|
|
now: u64,
|
2017-02-01 06:53:38 +08:00
|
|
|
cache: Cache,
|
2017-02-26 10:50:20 +08:00
|
|
|
dma_manager: DmaManager,
|
2017-02-01 06:53:38 +08:00
|
|
|
finished_cleanly: Cell<bool>
|
2016-10-02 02:24:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Congress {
|
|
|
|
fn new() -> Congress {
|
|
|
|
Congress {
|
|
|
|
now: 0,
|
2017-02-01 06:53:38 +08:00
|
|
|
cache: Cache::new(),
|
2017-02-26 10:50:20 +08:00
|
|
|
dma_manager: DmaManager::new(),
|
2017-02-01 06:53:38 +08:00
|
|
|
finished_cleanly: Cell::new(true)
|
2016-10-02 02:24:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-01 12:20:27 +08:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
2016-09-27 21:36:55 +08:00
|
|
|
enum KernelState {
|
|
|
|
Absent,
|
|
|
|
Loaded,
|
|
|
|
Running,
|
|
|
|
RpcWait
|
|
|
|
}
|
|
|
|
|
2016-10-02 02:24:53 +08:00
|
|
|
// Per-connection state
|
2016-09-27 21:36:55 +08:00
|
|
|
#[derive(Debug)]
|
2016-10-02 12:37:24 +08:00
|
|
|
struct Session<'a> {
|
|
|
|
congress: &'a mut Congress,
|
2016-09-27 21:36:55 +08:00
|
|
|
kernel_state: KernelState,
|
2017-12-28 15:06:45 +08:00
|
|
|
watchdog_set: WatchdogSet,
|
2017-02-03 19:46:45 +08:00
|
|
|
log_buffer: String
|
2016-09-27 21:36:55 +08:00
|
|
|
}
|
|
|
|
|
2016-10-02 12:37:24 +08:00
|
|
|
impl<'a> Session<'a> {
|
|
|
|
fn new(congress: &mut Congress) -> Session {
|
2016-09-27 21:36:55 +08:00
|
|
|
Session {
|
2016-10-02 12:37:24 +08:00
|
|
|
congress: congress,
|
2016-10-01 12:20:27 +08:00
|
|
|
kernel_state: KernelState::Absent,
|
2017-12-28 15:06:45 +08:00
|
|
|
watchdog_set: WatchdogSet::new(),
|
2017-02-03 19:46:45 +08:00
|
|
|
log_buffer: String::new()
|
2016-09-27 21:36:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-02 02:24:53 +08:00
|
|
|
fn running(&self) -> bool {
|
2016-09-30 04:36:04 +08:00
|
|
|
match self.kernel_state {
|
|
|
|
KernelState::Absent | KernelState::Loaded => false,
|
|
|
|
KernelState::Running | KernelState::RpcWait => true
|
|
|
|
}
|
|
|
|
}
|
2016-10-17 00:24:25 +08:00
|
|
|
|
|
|
|
fn flush_log_buffer(&mut self) {
|
|
|
|
if &self.log_buffer[self.log_buffer.len() - 1..] == "\n" {
|
|
|
|
for line in self.log_buffer.lines() {
|
|
|
|
info!(target: "kernel", "{}", line);
|
|
|
|
}
|
|
|
|
self.log_buffer.clear()
|
|
|
|
}
|
|
|
|
}
|
2016-09-30 04:36:04 +08:00
|
|
|
}
|
|
|
|
|
2016-10-02 12:37:24 +08:00
|
|
|
impl<'a> Drop for Session<'a> {
|
2016-10-02 00:26:57 +08:00
|
|
|
fn drop(&mut self) {
|
2016-11-29 22:00:43 +08:00
|
|
|
unsafe { kernel::stop() }
|
2016-10-02 00:26:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-15 21:27:23 +08:00
|
|
|
fn host_read<R>(reader: &mut R) -> Result<host::Request, Error<R::ReadError>>
|
|
|
|
where R: Read + ?Sized
|
|
|
|
{
|
|
|
|
let request = host::Request::read_from(reader)?;
|
2016-10-01 12:20:27 +08:00
|
|
|
match &request {
|
2017-03-03 14:11:35 +08:00
|
|
|
&host::Request::LoadKernel(_) => debug!("comm<-host LoadLibrary(...)"),
|
|
|
|
_ => debug!("comm<-host {:?}", request)
|
2016-09-27 21:36:55 +08:00
|
|
|
}
|
2016-10-01 12:20:27 +08:00
|
|
|
Ok(request)
|
|
|
|
}
|
|
|
|
|
2018-05-15 21:27:23 +08:00
|
|
|
fn host_write<W>(writer: &mut W, reply: host::Reply) -> Result<(), IoError<W::WriteError>>
|
|
|
|
where W: Write + ?Sized
|
|
|
|
{
|
2017-03-03 14:11:35 +08:00
|
|
|
debug!("comm->host {:?}", reply);
|
2018-05-15 21:27:23 +08:00
|
|
|
reply.write_to(writer)
|
2016-10-01 12:20:27 +08:00
|
|
|
}
|
2016-09-27 21:36:55 +08:00
|
|
|
|
2018-05-15 22:14:27 +08:00
|
|
|
pub fn kern_send(io: &Io, request: &kern::Message) -> Result<(), Error<SchedError>> {
|
2016-10-17 00:24:25 +08:00
|
|
|
match request {
|
2017-03-03 14:11:35 +08:00
|
|
|
&kern::LoadRequest(_) => debug!("comm->kern LoadRequest(...)"),
|
2017-04-19 11:11:42 +08:00
|
|
|
&kern::DmaRetrieveReply { trace, duration } => {
|
2017-04-15 15:26:18 +08:00
|
|
|
if trace.map(|data| data.len() > 100).unwrap_or(false) {
|
2017-04-19 11:11:42 +08:00
|
|
|
debug!("comm->kern DmaRetrieveReply {{ trace: ..., duration: {:?} }}", duration)
|
2017-04-15 15:26:18 +08:00
|
|
|
} else {
|
|
|
|
debug!("comm->kern {:?}", request)
|
|
|
|
}
|
|
|
|
}
|
2017-03-03 14:11:35 +08:00
|
|
|
_ => debug!("comm->kern {:?}", request)
|
2016-09-27 21:36:55 +08:00
|
|
|
}
|
2016-10-17 00:24:25 +08:00
|
|
|
unsafe { mailbox::send(request as *const _ as usize) }
|
2018-05-15 03:06:54 +08:00
|
|
|
Ok(io.until(mailbox::acknowledged)?)
|
2016-10-01 12:20:27 +08:00
|
|
|
}
|
|
|
|
|
2018-05-15 22:14:27 +08:00
|
|
|
fn kern_recv_notrace<R, F>(io: &Io, f: F) -> Result<R, Error<SchedError>>
|
|
|
|
where F: FnOnce(&kern::Message) -> Result<R, Error<SchedError>> {
|
2017-02-01 06:18:59 +08:00
|
|
|
io.until(|| mailbox::receive() != 0)?;
|
2016-10-17 00:24:25 +08:00
|
|
|
if !kernel::validate(mailbox::receive()) {
|
2018-05-15 21:27:23 +08:00
|
|
|
return Err(Error::InvalidPointer(mailbox::receive()))
|
2016-10-17 00:24:25 +08:00
|
|
|
}
|
|
|
|
|
2017-10-02 11:09:46 +08:00
|
|
|
f(unsafe { &*(mailbox::receive() as *const kern::Message) })
|
2016-10-17 00:24:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn kern_recv_dotrace(reply: &kern::Message) {
|
|
|
|
match reply {
|
2017-03-03 14:11:35 +08:00
|
|
|
&kern::Log(_) => debug!("comm<-kern Log(...)"),
|
|
|
|
&kern::LogSlice(_) => debug!("comm<-kern LogSlice(...)"),
|
2017-04-15 15:26:18 +08:00
|
|
|
&kern::DmaRecordAppend(data) => {
|
|
|
|
if data.len() > 100 {
|
2017-04-21 22:48:10 +08:00
|
|
|
debug!("comm<-kern DmaRecordAppend([_; {:#x}])", data.len())
|
2017-04-15 15:26:18 +08:00
|
|
|
} else {
|
|
|
|
debug!("comm<-kern {:?}", reply)
|
|
|
|
}
|
|
|
|
}
|
2017-03-03 14:11:35 +08:00
|
|
|
_ => debug!("comm<-kern {:?}", reply)
|
2016-10-17 00:24:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
2018-05-15 22:14:27 +08:00
|
|
|
fn kern_recv<R, F>(io: &Io, f: F) -> Result<R, Error<SchedError>>
|
|
|
|
where F: FnOnce(&kern::Message) -> Result<R, Error<SchedError>> {
|
2017-01-16 22:15:24 +08:00
|
|
|
kern_recv_notrace(io, |reply| {
|
2016-10-17 00:24:25 +08:00
|
|
|
kern_recv_dotrace(reply);
|
2016-10-01 12:20:27 +08:00
|
|
|
f(reply)
|
|
|
|
})
|
|
|
|
}
|
2016-09-27 21:36:55 +08:00
|
|
|
|
2018-05-15 22:14:27 +08:00
|
|
|
pub fn kern_acknowledge() -> Result<(), Error<SchedError>> {
|
2016-10-17 00:24:25 +08:00
|
|
|
mailbox::acknowledge();
|
2016-10-01 12:20:27 +08:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2018-05-15 21:27:23 +08:00
|
|
|
unsafe fn kern_load(io: &Io, session: &mut Session, library: &[u8])
|
2018-05-15 22:14:27 +08:00
|
|
|
-> Result<(), Error<SchedError>> {
|
2016-10-04 13:20:56 +08:00
|
|
|
if session.running() {
|
|
|
|
unexpected!("attempted to load a new kernel while a kernel was running")
|
|
|
|
}
|
|
|
|
|
|
|
|
kernel::start();
|
|
|
|
|
2017-02-01 06:18:59 +08:00
|
|
|
kern_send(io, &kern::LoadRequest(&library))?;
|
2017-01-16 22:15:24 +08:00
|
|
|
kern_recv(io, |reply| {
|
2016-10-04 13:20:56 +08:00
|
|
|
match reply {
|
2018-05-15 21:27:23 +08:00
|
|
|
kern::LoadReply(Ok(())) => {
|
2016-10-04 13:20:56 +08:00
|
|
|
session.kernel_state = KernelState::Loaded;
|
|
|
|
Ok(())
|
|
|
|
}
|
2018-05-15 21:27:23 +08:00
|
|
|
kern::LoadReply(Err(error)) => {
|
2017-02-03 19:46:45 +08:00
|
|
|
kernel::stop();
|
2018-05-15 21:27:23 +08:00
|
|
|
Err(Error::Load(format!("{}", error)))
|
2017-01-27 20:49:48 +08:00
|
|
|
}
|
2016-10-04 13:20:56 +08:00
|
|
|
other =>
|
|
|
|
unexpected!("unexpected reply from kernel CPU: {:?}", other)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-05-15 22:14:27 +08:00
|
|
|
fn kern_run(session: &mut Session) -> Result<(), Error<SchedError>> {
|
2016-10-04 13:20:56 +08:00
|
|
|
if session.kernel_state != KernelState::Loaded {
|
|
|
|
unexpected!("attempted to run a kernel while not in Loaded state")
|
|
|
|
}
|
|
|
|
|
|
|
|
session.kernel_state = KernelState::Running;
|
|
|
|
// TODO: make this a separate request
|
|
|
|
kern_acknowledge()
|
|
|
|
}
|
|
|
|
|
2017-01-16 22:15:24 +08:00
|
|
|
fn process_host_message(io: &Io,
|
2017-01-25 08:17:46 +08:00
|
|
|
stream: &mut TcpStream,
|
2018-05-15 22:14:27 +08:00
|
|
|
session: &mut Session) -> Result<(), Error<SchedError>> {
|
2017-02-01 06:18:59 +08:00
|
|
|
match host_read(stream)? {
|
2017-02-01 06:53:38 +08:00
|
|
|
host::Request::SystemInfo => {
|
|
|
|
host_write(stream, host::Reply::SystemInfo {
|
2018-05-15 01:54:29 +08:00
|
|
|
ident: ident::read(&mut [0; 64]),
|
2017-02-01 06:53:38 +08:00
|
|
|
finished_cleanly: session.congress.finished_cleanly.get()
|
|
|
|
})?;
|
2018-05-15 21:27:23 +08:00
|
|
|
session.congress.finished_cleanly.set(true)
|
2017-02-01 06:53:38 +08:00
|
|
|
}
|
2016-09-29 02:25:25 +08:00
|
|
|
|
2016-10-04 13:20:56 +08:00
|
|
|
host::Request::LoadKernel(kernel) =>
|
2017-01-16 22:15:24 +08:00
|
|
|
match unsafe { kern_load(io, session, &kernel) } {
|
2018-05-15 21:27:23 +08:00
|
|
|
Ok(()) => host_write(stream, host::Reply::LoadCompleted)?,
|
2017-01-27 20:49:48 +08:00
|
|
|
Err(error) => {
|
2018-05-15 02:27:17 +08:00
|
|
|
let mut description = String::new();
|
|
|
|
write!(&mut description, "{}", error).unwrap();
|
|
|
|
host_write(stream, host::Reply::LoadFailed(&description))?;
|
2018-05-15 21:27:23 +08:00
|
|
|
kern_acknowledge()?;
|
2016-10-17 00:24:25 +08:00
|
|
|
}
|
2016-10-04 13:20:56 +08:00
|
|
|
},
|
|
|
|
host::Request::RunKernel =>
|
|
|
|
match kern_run(session) {
|
2018-05-15 21:27:23 +08:00
|
|
|
Ok(()) => (),
|
|
|
|
Err(_) => host_write(stream, host::Reply::KernelStartupFailed)?
|
2016-10-04 13:20:56 +08:00
|
|
|
},
|
2016-09-30 04:36:04 +08:00
|
|
|
|
2016-10-07 01:25:43 +08:00
|
|
|
host::Request::RpcReply { tag } => {
|
2016-10-05 22:15:53 +08:00
|
|
|
if session.kernel_state != KernelState::RpcWait {
|
|
|
|
unexpected!("unsolicited RPC reply")
|
|
|
|
}
|
|
|
|
|
2017-02-01 06:18:59 +08:00
|
|
|
let slot = kern_recv(io, |reply| {
|
2016-10-05 22:15:53 +08:00
|
|
|
match reply {
|
2016-10-17 00:24:25 +08:00
|
|
|
&kern::RpcRecvRequest(slot) => Ok(slot),
|
|
|
|
other => unexpected!("unexpected reply from kernel CPU: {:?}", other)
|
2016-10-05 22:15:53 +08:00
|
|
|
}
|
2017-02-01 06:18:59 +08:00
|
|
|
})?;
|
2018-05-15 22:14:27 +08:00
|
|
|
rpc::recv_return(stream, &tag, slot, &|size| -> Result<_, Error<SchedError>> {
|
2017-02-01 06:18:59 +08:00
|
|
|
kern_send(io, &kern::RpcRecvReply(Ok(size)))?;
|
2018-05-15 00:52:14 +08:00
|
|
|
Ok(kern_recv(io, |reply| {
|
2016-10-07 01:25:43 +08:00
|
|
|
match reply {
|
2016-10-17 00:24:25 +08:00
|
|
|
&kern::RpcRecvRequest(slot) => Ok(slot),
|
|
|
|
other => unexpected!("unexpected reply from kernel CPU: {:?}", other)
|
2016-10-07 01:25:43 +08:00
|
|
|
}
|
2018-05-15 00:52:14 +08:00
|
|
|
})?)
|
2017-02-01 06:18:59 +08:00
|
|
|
})?;
|
|
|
|
kern_send(io, &kern::RpcRecvReply(Ok(0)))?;
|
2016-10-05 22:15:53 +08:00
|
|
|
|
2018-05-15 21:27:23 +08:00
|
|
|
session.kernel_state = KernelState::Running
|
2016-10-05 22:15:53 +08:00
|
|
|
}
|
|
|
|
|
2016-10-06 22:08:02 +08:00
|
|
|
host::Request::RpcException {
|
|
|
|
name, message, param, file, line, column, function
|
|
|
|
} => {
|
|
|
|
if session.kernel_state != KernelState::RpcWait {
|
|
|
|
unexpected!("unsolicited RPC reply")
|
|
|
|
}
|
|
|
|
|
2017-02-01 06:18:59 +08:00
|
|
|
kern_recv(io, |reply| {
|
2016-10-06 22:08:02 +08:00
|
|
|
match reply {
|
2016-10-17 00:24:25 +08:00
|
|
|
&kern::RpcRecvRequest(_) => Ok(()),
|
2016-10-06 22:08:02 +08:00
|
|
|
other =>
|
|
|
|
unexpected!("unexpected reply from kernel CPU: {:?}", other)
|
|
|
|
}
|
2017-02-01 06:18:59 +08:00
|
|
|
})?;
|
2016-10-17 00:24:25 +08:00
|
|
|
|
|
|
|
let exn = kern::Exception {
|
2017-02-03 19:46:45 +08:00
|
|
|
name: name.as_ref(),
|
|
|
|
message: message.as_ref(),
|
|
|
|
param: param,
|
|
|
|
file: file.as_ref(),
|
|
|
|
line: line,
|
|
|
|
column: column,
|
|
|
|
function: function.as_ref()
|
2016-10-17 00:24:25 +08:00
|
|
|
};
|
2017-02-01 06:18:59 +08:00
|
|
|
kern_send(io, &kern::RpcRecvReply(Err(exn)))?;
|
2016-10-06 22:08:02 +08:00
|
|
|
|
2018-05-15 21:27:23 +08:00
|
|
|
session.kernel_state = KernelState::Running
|
2016-10-06 22:08:02 +08:00
|
|
|
}
|
2016-09-27 21:36:55 +08:00
|
|
|
}
|
2018-05-15 21:27:23 +08:00
|
|
|
|
|
|
|
Ok(())
|
2016-09-27 21:36:55 +08:00
|
|
|
}
|
|
|
|
|
2018-09-19 11:16:21 +08:00
|
|
|
fn process_kern_message(io: &Io, aux_mutex: &Mutex,
|
2018-09-15 19:11:22 +08:00
|
|
|
routing_table: &drtio_routing::RoutingTable,
|
|
|
|
up_destinations: &Urc<RefCell<[bool; drtio_routing::DEST_COUNT]>>,
|
2018-09-14 20:26:39 +08:00
|
|
|
mut stream: Option<&mut TcpStream>,
|
2018-05-15 22:14:27 +08:00
|
|
|
session: &mut Session) -> Result<bool, Error<SchedError>> {
|
2017-01-16 22:15:24 +08:00
|
|
|
kern_recv_notrace(io, |request| {
|
2016-10-17 00:24:25 +08:00
|
|
|
match (request, session.kernel_state) {
|
|
|
|
(&kern::LoadReply(_), KernelState::Loaded) |
|
|
|
|
(&kern::RpcRecvRequest(_), KernelState::RpcWait) => {
|
2016-10-01 12:20:27 +08:00
|
|
|
// We're standing by; ignore the message.
|
2016-10-04 14:08:08 +08:00
|
|
|
return Ok(false)
|
2016-10-01 12:20:27 +08:00
|
|
|
}
|
|
|
|
(_, KernelState::Running) => (),
|
|
|
|
_ => {
|
|
|
|
unexpected!("unexpected request {:?} from kernel CPU in {:?} state",
|
|
|
|
request, session.kernel_state)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-17 00:24:25 +08:00
|
|
|
kern_recv_dotrace(request);
|
2017-11-03 23:49:12 +08:00
|
|
|
|
2018-09-19 11:16:21 +08:00
|
|
|
if kern_hwreq::process_kern_hwreq(io, aux_mutex, routing_table, up_destinations, request)? {
|
2017-11-03 23:56:13 +08:00
|
|
|
return Ok(false)
|
2017-06-18 12:45:07 +08:00
|
|
|
}
|
2017-11-03 23:49:12 +08:00
|
|
|
|
2016-10-01 12:20:27 +08:00
|
|
|
match request {
|
2016-10-17 00:24:25 +08:00
|
|
|
&kern::Log(args) => {
|
2018-05-15 22:14:27 +08:00
|
|
|
use core::fmt::Write;
|
2018-05-15 21:27:23 +08:00
|
|
|
session.log_buffer
|
|
|
|
.write_fmt(args)
|
|
|
|
.unwrap_or_else(|_| warn!("cannot append to session log buffer"));
|
2016-10-17 00:24:25 +08:00
|
|
|
session.flush_log_buffer();
|
|
|
|
kern_acknowledge()
|
|
|
|
}
|
2016-10-06 18:56:19 +08:00
|
|
|
|
2016-10-17 00:24:25 +08:00
|
|
|
&kern::LogSlice(arg) => {
|
|
|
|
session.log_buffer += arg;
|
|
|
|
session.flush_log_buffer();
|
|
|
|
kern_acknowledge()
|
2016-10-01 12:20:27 +08:00
|
|
|
}
|
|
|
|
|
2016-10-17 00:24:25 +08:00
|
|
|
&kern::NowInitRequest =>
|
2017-01-16 22:15:24 +08:00
|
|
|
kern_send(io, &kern::NowInitReply(session.congress.now)),
|
2016-10-01 12:20:27 +08:00
|
|
|
|
2016-10-17 00:24:25 +08:00
|
|
|
&kern::NowSave(now) => {
|
2016-10-02 12:37:24 +08:00
|
|
|
session.congress.now = now;
|
2016-10-01 12:20:27 +08:00
|
|
|
kern_acknowledge()
|
|
|
|
}
|
|
|
|
|
2017-04-15 15:27:09 +08:00
|
|
|
&kern::DmaRecordStart(name) => {
|
|
|
|
session.congress.dma_manager.record_start(name);
|
2017-02-26 10:50:20 +08:00
|
|
|
kern_acknowledge()
|
|
|
|
}
|
2017-04-15 15:26:18 +08:00
|
|
|
&kern::DmaRecordAppend(data) => {
|
|
|
|
session.congress.dma_manager.record_append(data);
|
2017-02-26 10:50:20 +08:00
|
|
|
kern_acknowledge()
|
|
|
|
}
|
2017-04-15 15:27:09 +08:00
|
|
|
&kern::DmaRecordStop { duration } => {
|
|
|
|
session.congress.dma_manager.record_stop(duration);
|
2018-05-15 01:54:29 +08:00
|
|
|
cache::flush_l2_cache();
|
2017-02-26 10:50:20 +08:00
|
|
|
kern_acknowledge()
|
|
|
|
}
|
2017-04-06 02:34:08 +08:00
|
|
|
&kern::DmaEraseRequest { name } => {
|
2017-03-01 05:28:27 +08:00
|
|
|
session.congress.dma_manager.erase(name);
|
|
|
|
kern_acknowledge()
|
|
|
|
}
|
2017-04-19 11:11:42 +08:00
|
|
|
&kern::DmaRetrieveRequest { name } => {
|
2017-04-06 02:34:08 +08:00
|
|
|
session.congress.dma_manager.with_trace(name, |trace, duration| {
|
2017-04-19 11:11:42 +08:00
|
|
|
kern_send(io, &kern::DmaRetrieveReply {
|
2017-04-06 02:34:08 +08:00
|
|
|
trace: trace,
|
|
|
|
duration: duration
|
|
|
|
})
|
2017-03-01 05:28:27 +08:00
|
|
|
})
|
|
|
|
}
|
2017-02-26 10:50:20 +08:00
|
|
|
|
2016-10-17 00:24:25 +08:00
|
|
|
&kern::WatchdogSetRequest { ms } => {
|
2018-05-15 21:27:23 +08:00
|
|
|
let id = session.watchdog_set.set_ms(ms).map_err(|()| Error::OutOfWatchdogs)?;
|
2017-01-16 22:15:24 +08:00
|
|
|
kern_send(io, &kern::WatchdogSetReply { id: id })
|
2016-10-02 00:26:57 +08:00
|
|
|
}
|
2016-10-17 00:24:25 +08:00
|
|
|
&kern::WatchdogClear { id } => {
|
2016-10-02 00:26:57 +08:00
|
|
|
session.watchdog_set.clear(id);
|
|
|
|
kern_acknowledge()
|
|
|
|
}
|
|
|
|
|
2016-10-30 05:34:25 +08:00
|
|
|
&kern::RpcSend { async, service, tag, data } => {
|
2016-10-05 22:15:53 +08:00
|
|
|
match stream {
|
|
|
|
None => unexpected!("unexpected RPC in flash kernel"),
|
|
|
|
Some(ref mut stream) => {
|
2017-02-01 06:18:59 +08:00
|
|
|
host_write(stream, host::Reply::RpcRequest { async: async })?;
|
|
|
|
rpc::send_args(stream, service, tag, data)?;
|
2016-10-30 05:34:25 +08:00
|
|
|
if !async {
|
2016-10-05 22:15:53 +08:00
|
|
|
session.kernel_state = KernelState::RpcWait
|
|
|
|
}
|
|
|
|
kern_acknowledge()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-17 00:24:25 +08:00
|
|
|
&kern::CacheGetRequest { key } => {
|
2016-10-02 12:37:24 +08:00
|
|
|
let value = session.congress.cache.get(key);
|
2017-01-16 22:15:24 +08:00
|
|
|
kern_send(io, &kern::CacheGetReply {
|
2017-10-02 11:09:46 +08:00
|
|
|
// Zing! This transmute is only safe because we dynamically track
|
|
|
|
// whether the kernel has borrowed any values from the cache.
|
2016-11-24 00:28:05 +08:00
|
|
|
value: unsafe { mem::transmute::<*const [i32], &'static [i32]>(value) }
|
2016-10-02 02:24:53 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-10-17 00:24:25 +08:00
|
|
|
&kern::CachePutRequest { key, value } => {
|
2016-10-02 12:37:24 +08:00
|
|
|
let succeeded = session.congress.cache.put(key, value).is_ok();
|
2017-01-16 22:15:24 +08:00
|
|
|
kern_send(io, &kern::CachePutReply { succeeded: succeeded })
|
2016-10-02 02:24:53 +08:00
|
|
|
}
|
|
|
|
|
2016-10-17 00:24:25 +08:00
|
|
|
&kern::RunFinished => {
|
2016-11-29 22:00:43 +08:00
|
|
|
unsafe { kernel::stop() }
|
2016-10-06 21:42:35 +08:00
|
|
|
session.kernel_state = KernelState::Absent;
|
2016-10-06 22:19:12 +08:00
|
|
|
unsafe { session.congress.cache.unborrow() }
|
2016-10-06 20:55:19 +08:00
|
|
|
|
2016-10-06 21:42:35 +08:00
|
|
|
match stream {
|
|
|
|
None => return Ok(true),
|
|
|
|
Some(ref mut stream) =>
|
2018-05-15 21:27:23 +08:00
|
|
|
host_write(stream, host::Reply::KernelFinished).map_err(|e| e.into())
|
2016-10-06 21:42:35 +08:00
|
|
|
}
|
|
|
|
}
|
2017-02-03 19:46:45 +08:00
|
|
|
&kern::RunException {
|
|
|
|
exception: kern::Exception { name, message, param, file, line, column, function },
|
|
|
|
backtrace
|
|
|
|
} => {
|
2016-11-29 22:00:43 +08:00
|
|
|
unsafe { kernel::stop() }
|
2016-10-04 14:08:08 +08:00
|
|
|
session.kernel_state = KernelState::Absent;
|
2016-10-06 22:19:12 +08:00
|
|
|
unsafe { session.congress.cache.unborrow() }
|
2016-10-06 20:55:19 +08:00
|
|
|
|
2016-10-06 21:42:35 +08:00
|
|
|
match stream {
|
|
|
|
None => {
|
|
|
|
error!("exception in flash kernel");
|
2017-02-03 19:46:45 +08:00
|
|
|
error!("{}: {} {:?}", name, message, param);
|
|
|
|
error!("at {}:{}:{} in {}", file, line, column, function);
|
2016-10-06 21:42:35 +08:00
|
|
|
return Ok(true)
|
|
|
|
},
|
2017-02-03 19:46:45 +08:00
|
|
|
Some(ref mut stream) => {
|
2016-10-06 21:42:35 +08:00
|
|
|
host_write(stream, host::Reply::KernelException {
|
2017-02-03 19:46:45 +08:00
|
|
|
name: name,
|
|
|
|
message: message,
|
|
|
|
param: param,
|
|
|
|
file: file,
|
|
|
|
line: line,
|
|
|
|
column: column,
|
|
|
|
function: function,
|
2016-10-06 21:42:35 +08:00
|
|
|
backtrace: backtrace
|
2018-05-15 21:27:23 +08:00
|
|
|
}).map_err(|e| e.into())
|
2017-02-03 19:46:45 +08:00
|
|
|
}
|
2016-10-06 21:42:35 +08:00
|
|
|
}
|
2016-10-04 14:08:08 +08:00
|
|
|
}
|
|
|
|
|
2016-10-02 00:07:45 +08:00
|
|
|
request => unexpected!("unexpected request {:?} from kernel CPU", request)
|
2016-10-04 14:08:08 +08:00
|
|
|
}.and(Ok(false))
|
2016-10-01 12:20:27 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-01-25 08:17:46 +08:00
|
|
|
fn process_kern_queued_rpc(stream: &mut TcpStream,
|
2018-05-15 22:14:27 +08:00
|
|
|
_session: &mut Session) -> Result<(), Error<SchedError>> {
|
2016-10-30 05:34:25 +08:00
|
|
|
rpc_queue::dequeue(|slice| {
|
2017-03-03 14:11:35 +08:00
|
|
|
debug!("comm<-kern (async RPC)");
|
2016-10-30 05:34:25 +08:00
|
|
|
let length = NetworkEndian::read_u32(slice) as usize;
|
2017-02-01 06:18:59 +08:00
|
|
|
host_write(stream, host::Reply::RpcRequest { async: true })?;
|
2017-03-03 14:11:35 +08:00
|
|
|
debug!("{:?}", &slice[4..][..length]);
|
2018-04-22 03:38:40 +08:00
|
|
|
stream.write_all(&slice[4..][..length])?;
|
2016-10-30 05:34:25 +08:00
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-09-19 11:16:21 +08:00
|
|
|
fn host_kernel_worker(io: &Io, aux_mutex: &Mutex,
|
2018-09-15 19:11:22 +08:00
|
|
|
routing_table: &drtio_routing::RoutingTable,
|
|
|
|
up_destinations: &Urc<RefCell<[bool; drtio_routing::DEST_COUNT]>>,
|
2017-01-25 08:17:46 +08:00
|
|
|
stream: &mut TcpStream,
|
2018-05-15 22:14:27 +08:00
|
|
|
congress: &mut Congress) -> Result<(), Error<SchedError>> {
|
2016-10-02 12:37:24 +08:00
|
|
|
let mut session = Session::new(congress);
|
2016-10-04 13:20:56 +08:00
|
|
|
|
2016-09-27 21:36:55 +08:00
|
|
|
loop {
|
2016-11-01 18:30:42 +08:00
|
|
|
while !rpc_queue::empty() {
|
2017-02-01 06:18:59 +08:00
|
|
|
process_kern_queued_rpc(stream, &mut session)?
|
2016-10-30 05:34:25 +08:00
|
|
|
}
|
|
|
|
|
2017-01-16 22:15:24 +08:00
|
|
|
if stream.can_recv() {
|
2017-02-01 06:18:59 +08:00
|
|
|
process_host_message(io, stream, &mut session)?
|
2017-01-16 22:15:24 +08:00
|
|
|
} else if !stream.may_recv() {
|
|
|
|
return Ok(())
|
2016-10-01 12:20:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if mailbox::receive() != 0 {
|
2018-09-19 11:16:21 +08:00
|
|
|
process_kern_message(io, aux_mutex,
|
2018-09-15 19:11:22 +08:00
|
|
|
routing_table, up_destinations,
|
|
|
|
Some(stream), &mut session)?;
|
2016-10-01 12:20:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if session.kernel_state == KernelState::Running {
|
2018-05-15 21:27:23 +08:00
|
|
|
if let Some(idx) = session.watchdog_set.expired() {
|
2017-02-01 06:18:59 +08:00
|
|
|
host_write(stream, host::Reply::WatchdogExpired)?;
|
2018-05-15 21:27:23 +08:00
|
|
|
return Err(Error::WatchdogExpired(idx))
|
2016-10-01 12:20:27 +08:00
|
|
|
}
|
|
|
|
|
2018-09-10 23:09:02 +08:00
|
|
|
if !rtio_mgt::crg::check() {
|
|
|
|
host_write(stream, host::Reply::ClockFailure)?;
|
|
|
|
return Err(Error::ClockFailure)
|
2016-10-01 12:20:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-01 06:18:59 +08:00
|
|
|
io.relinquish()?
|
2016-09-27 21:36:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-19 11:16:21 +08:00
|
|
|
fn flash_kernel_worker(io: &Io, aux_mutex: &Mutex,
|
2018-09-15 19:11:22 +08:00
|
|
|
routing_table: &drtio_routing::RoutingTable,
|
|
|
|
up_destinations: &Urc<RefCell<[bool; drtio_routing::DEST_COUNT]>>,
|
2016-10-04 13:20:56 +08:00
|
|
|
congress: &mut Congress,
|
2018-05-15 22:14:27 +08:00
|
|
|
config_key: &str) -> Result<(), Error<SchedError>> {
|
2016-10-02 12:37:24 +08:00
|
|
|
let mut session = Session::new(congress);
|
2016-10-04 13:20:56 +08:00
|
|
|
|
2017-02-02 10:51:13 +08:00
|
|
|
config::read(config_key, |result| {
|
|
|
|
match result {
|
2017-04-22 00:46:40 +08:00
|
|
|
Ok(kernel) if kernel.len() > 0 => unsafe {
|
|
|
|
// kernel CPU cannot access the SPI flash address space directly,
|
|
|
|
// so make a copy.
|
|
|
|
kern_load(io, &mut session, Vec::from(kernel).as_ref())
|
|
|
|
},
|
2018-05-15 21:27:23 +08:00
|
|
|
_ => Err(Error::KernelNotFound)
|
2017-02-02 10:51:13 +08:00
|
|
|
}
|
|
|
|
})?;
|
2017-02-01 06:18:59 +08:00
|
|
|
kern_run(&mut session)?;
|
2016-10-04 13:20:56 +08:00
|
|
|
|
2016-10-02 12:37:24 +08:00
|
|
|
loop {
|
2016-10-30 05:34:25 +08:00
|
|
|
if !rpc_queue::empty() {
|
2018-05-15 21:27:23 +08:00
|
|
|
unexpected!("unexpected background RPC in flash kernel")
|
2016-10-30 05:34:25 +08:00
|
|
|
}
|
|
|
|
|
2016-10-04 14:08:08 +08:00
|
|
|
if mailbox::receive() != 0 {
|
2018-09-19 11:16:21 +08:00
|
|
|
if process_kern_message(io, aux_mutex, routing_table, up_destinations, None, &mut session)? {
|
2016-10-04 14:08:08 +08:00
|
|
|
return Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-15 21:27:23 +08:00
|
|
|
if let Some(idx) = session.watchdog_set.expired() {
|
|
|
|
return Err(Error::WatchdogExpired(idx))
|
2016-10-04 14:08:08 +08:00
|
|
|
}
|
|
|
|
|
2018-09-10 23:09:02 +08:00
|
|
|
if !rtio_mgt::crg::check() {
|
|
|
|
return Err(Error::ClockFailure)
|
2016-10-04 14:08:08 +08:00
|
|
|
}
|
|
|
|
|
2017-02-01 06:18:59 +08:00
|
|
|
io.relinquish()?
|
2016-10-02 12:37:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-16 22:15:24 +08:00
|
|
|
fn respawn<F>(io: &Io, handle: &mut Option<ThreadHandle>, f: F)
|
|
|
|
where F: 'static + FnOnce(Io) + Send {
|
2016-10-02 12:37:24 +08:00
|
|
|
match handle.take() {
|
|
|
|
None => (),
|
|
|
|
Some(handle) => {
|
2016-10-04 13:20:56 +08:00
|
|
|
if !handle.terminated() {
|
|
|
|
handle.interrupt();
|
2017-01-16 22:15:24 +08:00
|
|
|
io.join(handle).expect("cannot join interrupt thread")
|
2016-10-04 13:20:56 +08:00
|
|
|
}
|
2016-10-02 12:37:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-16 22:15:24 +08:00
|
|
|
*handle = Some(io.spawn(16384, f))
|
2016-10-02 12:37:24 +08:00
|
|
|
}
|
|
|
|
|
2018-09-19 11:16:21 +08:00
|
|
|
pub fn thread(io: Io, aux_mutex: &Mutex,
|
|
|
|
routing_table: &Urc<RefCell<drtio_routing::RoutingTable>>,
|
2018-09-15 19:11:22 +08:00
|
|
|
up_destinations: &Urc<RefCell<[bool; drtio_routing::DEST_COUNT]>>) {
|
2017-01-25 08:17:46 +08:00
|
|
|
let listener = TcpListener::new(&io, 65535);
|
|
|
|
listener.listen(1381).expect("session: cannot listen");
|
2016-12-03 11:17:47 +08:00
|
|
|
info!("accepting network sessions");
|
2016-09-30 04:36:04 +08:00
|
|
|
|
2017-01-27 21:11:38 +08:00
|
|
|
let congress = Urc::new(RefCell::new(Congress::new()));
|
|
|
|
|
2016-10-02 12:37:24 +08:00
|
|
|
let mut kernel_thread = None;
|
2017-01-27 21:11:38 +08:00
|
|
|
{
|
2018-09-19 11:16:21 +08:00
|
|
|
let aux_mutex = aux_mutex.clone();
|
2018-09-14 20:26:39 +08:00
|
|
|
let routing_table = routing_table.clone();
|
2018-09-15 19:11:22 +08:00
|
|
|
let up_destinations = up_destinations.clone();
|
2017-01-27 21:11:38 +08:00
|
|
|
let congress = congress.clone();
|
|
|
|
respawn(&io, &mut kernel_thread, move |io| {
|
2018-09-14 20:26:39 +08:00
|
|
|
let routing_table = routing_table.borrow();
|
2017-12-27 12:25:46 +08:00
|
|
|
let mut congress = congress.borrow_mut();
|
2017-01-27 21:11:38 +08:00
|
|
|
info!("running startup kernel");
|
2018-09-19 11:16:21 +08:00
|
|
|
match flash_kernel_worker(&io, &aux_mutex, &routing_table, &up_destinations, &mut congress, "startup_kernel") {
|
2018-05-15 21:27:23 +08:00
|
|
|
Ok(()) =>
|
|
|
|
info!("startup kernel finished"),
|
|
|
|
Err(Error::KernelNotFound) =>
|
|
|
|
info!("no startup kernel found"),
|
2017-01-27 21:11:38 +08:00
|
|
|
Err(err) => {
|
2018-05-15 03:06:54 +08:00
|
|
|
congress.finished_cleanly.set(false);
|
|
|
|
error!("startup kernel aborted: {}", err);
|
2017-01-27 21:11:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-09-27 21:36:55 +08:00
|
|
|
loop {
|
2017-01-25 08:17:46 +08:00
|
|
|
if listener.can_accept() {
|
|
|
|
let mut stream = listener.accept().expect("session: cannot accept");
|
2017-09-25 06:57:27 +08:00
|
|
|
stream.set_timeout(Some(1000));
|
|
|
|
stream.set_keep_alive(Some(500));
|
|
|
|
|
2018-05-15 21:27:23 +08:00
|
|
|
match host::read_magic(&mut stream) {
|
2016-10-02 12:37:24 +08:00
|
|
|
Ok(()) => (),
|
2017-01-16 22:15:24 +08:00
|
|
|
Err(_) => {
|
2017-01-25 08:17:46 +08:00
|
|
|
warn!("wrong magic from {}", stream.remote_endpoint());
|
|
|
|
stream.close().expect("session: cannot close");
|
2017-01-16 22:15:24 +08:00
|
|
|
continue
|
|
|
|
}
|
2016-09-27 21:36:55 +08:00
|
|
|
}
|
2017-01-25 08:17:46 +08:00
|
|
|
info!("new connection from {}", stream.remote_endpoint());
|
2016-10-02 12:37:24 +08:00
|
|
|
|
2018-09-19 11:16:21 +08:00
|
|
|
let aux_mutex = aux_mutex.clone();
|
2018-09-14 20:26:39 +08:00
|
|
|
let routing_table = routing_table.clone();
|
2018-09-15 19:11:22 +08:00
|
|
|
let up_destinations = up_destinations.clone();
|
2016-10-02 12:37:24 +08:00
|
|
|
let congress = congress.clone();
|
2017-01-25 08:17:46 +08:00
|
|
|
let stream = stream.into_handle();
|
2017-01-16 22:15:24 +08:00
|
|
|
respawn(&io, &mut kernel_thread, move |io| {
|
2018-09-14 20:26:39 +08:00
|
|
|
let routing_table = routing_table.borrow();
|
2017-12-27 12:25:46 +08:00
|
|
|
let mut congress = congress.borrow_mut();
|
2017-01-25 08:17:46 +08:00
|
|
|
let mut stream = TcpStream::from_handle(&io, stream);
|
2018-09-19 11:16:21 +08:00
|
|
|
match host_kernel_worker(&io, &aux_mutex, &routing_table, &up_destinations, &mut stream, &mut *congress) {
|
2016-10-02 12:37:24 +08:00
|
|
|
Ok(()) => (),
|
2018-05-15 22:14:27 +08:00
|
|
|
Err(Error::Protocol(host::Error::Io(IoError::UnexpectedEnd))) =>
|
2018-05-15 21:27:23 +08:00
|
|
|
info!("connection closed"),
|
2018-05-15 22:14:27 +08:00
|
|
|
Err(Error::Protocol(host::Error::Io(
|
|
|
|
IoError::Other(SchedError::Interrupted)))) =>
|
2018-05-15 21:27:23 +08:00
|
|
|
info!("kernel interrupted"),
|
2016-10-02 12:37:24 +08:00
|
|
|
Err(err) => {
|
2018-05-15 03:06:54 +08:00
|
|
|
congress.finished_cleanly.set(false);
|
|
|
|
error!("session aborted: {}", err);
|
2016-10-02 12:37:24 +08:00
|
|
|
}
|
|
|
|
}
|
2017-01-16 22:15:24 +08:00
|
|
|
});
|
2016-09-27 21:36:55 +08:00
|
|
|
}
|
2016-10-02 12:37:24 +08:00
|
|
|
|
2016-10-04 13:20:56 +08:00
|
|
|
if kernel_thread.as_ref().map_or(true, |h| h.terminated()) {
|
2016-10-02 12:37:24 +08:00
|
|
|
info!("no connection, starting idle kernel");
|
2016-10-04 13:20:56 +08:00
|
|
|
|
2018-09-19 11:16:21 +08:00
|
|
|
let aux_mutex = aux_mutex.clone();
|
2018-09-14 20:26:39 +08:00
|
|
|
let routing_table = routing_table.clone();
|
2018-09-15 19:11:22 +08:00
|
|
|
let up_destinations = up_destinations.clone();
|
2016-10-02 12:37:24 +08:00
|
|
|
let congress = congress.clone();
|
2017-01-16 22:15:24 +08:00
|
|
|
respawn(&io, &mut kernel_thread, move |io| {
|
2018-09-14 20:26:39 +08:00
|
|
|
let routing_table = routing_table.borrow();
|
2017-12-27 12:25:46 +08:00
|
|
|
let mut congress = congress.borrow_mut();
|
2018-09-19 11:16:21 +08:00
|
|
|
match flash_kernel_worker(&io, &aux_mutex, &routing_table, &up_destinations, &mut *congress, "idle_kernel") {
|
2016-10-02 12:37:24 +08:00
|
|
|
Ok(()) =>
|
|
|
|
info!("idle kernel finished, standing by"),
|
2018-05-15 22:14:27 +08:00
|
|
|
Err(Error::Protocol(host::Error::Io(
|
|
|
|
IoError::Other(SchedError::Interrupted)))) =>
|
|
|
|
info!("idle kernel interrupted"),
|
2018-05-15 21:27:23 +08:00
|
|
|
Err(Error::KernelNotFound) => {
|
2018-05-15 03:06:54 +08:00
|
|
|
info!("no idle kernel found");
|
|
|
|
while io.relinquish().is_ok() {}
|
|
|
|
}
|
2018-05-15 21:27:23 +08:00
|
|
|
Err(err) =>
|
|
|
|
error!("idle kernel aborted: {}", err)
|
2016-10-02 12:37:24 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-01-16 22:15:24 +08:00
|
|
|
let _ = io.relinquish();
|
2016-09-27 21:36:55 +08:00
|
|
|
}
|
|
|
|
}
|