mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
kernel: fix process suspension
This enables processes to be "suspended" by going into a Debug state. Messages will back up and processes will continue to be scheduled around the suspended process, while the system will continue to operate. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
13204d1714
commit
9ced90190e
2 changed files with 157 additions and 88 deletions
|
|
@ -20,6 +20,12 @@ const MAX_SERVER_COUNT: usize = 128;
|
||||||
|
|
||||||
pub use crate::arch::process::{INITIAL_TID, MAX_PROCESS_COUNT};
|
pub use crate::arch::process::{INITIAL_TID, MAX_PROCESS_COUNT};
|
||||||
|
|
||||||
|
// fn log_process_update(f: &str, l: u32, process: &Process, old_state: ProcessState) {
|
||||||
|
// if process.pid.get() == 3 {
|
||||||
|
// println!("[{}:{}] Updated PID {:?} state: {:?} -> {:?}", f, l, process.pid, old_state, process.state);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
/// A big unifying struct containing all of the system state.
|
/// A big unifying struct containing all of the system state.
|
||||||
/// This is inherited from the stage 1 bootloader.
|
/// This is inherited from the stage 1 bootloader.
|
||||||
pub struct SystemServices {
|
pub struct SystemServices {
|
||||||
|
|
@ -325,6 +331,7 @@ impl SystemServices {
|
||||||
process.ppid = PID::new_unchecked(1);
|
process.ppid = PID::new_unchecked(1);
|
||||||
process.pid = PID::new(pid as _).unwrap();
|
process.pid = PID::new(pid as _).unwrap();
|
||||||
};
|
};
|
||||||
|
// let old_state = process.state;
|
||||||
if pid == 1 {
|
if pid == 1 {
|
||||||
process.state = ProcessState::Running(0);
|
process.state = ProcessState::Running(0);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -337,6 +344,7 @@ impl SystemServices {
|
||||||
0,
|
0,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
// log_process_update(file!(), line!(), process, old_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up our handle with a bogus sp and pc. These will get updated
|
// Set up our handle with a bogus sp and pc. These will get updated
|
||||||
|
|
@ -433,28 +441,39 @@ impl SystemServices {
|
||||||
.get_process_mut(current_pid)
|
.get_process_mut(current_pid)
|
||||||
.expect("couldn't get current PID");
|
.expect("couldn't get current PID");
|
||||||
// println!("Finishing callback in PID {}", current_pid);
|
// println!("Finishing callback in PID {}", current_pid);
|
||||||
|
// let old_state = current.state;
|
||||||
current.state = match current.state {
|
current.state = match current.state {
|
||||||
ProcessState::Running(0) => ProcessState::Sleeping,
|
ProcessState::Running(0) => ProcessState::Sleeping,
|
||||||
ProcessState::Running(x) => ProcessState::Ready(x),
|
ProcessState::Running(x) => ProcessState::Ready(x),
|
||||||
y => panic!("current process was {:?}, not 'Running(_)'", y),
|
y => panic!("current process was {:?}, not 'Running(_)'", y),
|
||||||
};
|
};
|
||||||
|
// log_process_update(file!(), line!(), current, old_state);
|
||||||
// current.current_thread = current.previous_context;
|
// current.current_thread = current.previous_context;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the new process, and ensure that it is in a state where it's fit
|
// Get the new process, and ensure that it is in a state where it's fit
|
||||||
// to run. Again, if the new process isn't fit to run, then the system
|
// to run. Again, if the new process isn't fit to run, then the system
|
||||||
// is in a very bad state.
|
// is in a very bad state.
|
||||||
{
|
{
|
||||||
let mut process = self.get_process_mut(pid)?;
|
let mut process = self.get_process_mut(pid)?;
|
||||||
|
let ppid = process.ppid;
|
||||||
|
// let old_state = process.state;
|
||||||
// Ensure the new context is available to be run
|
// Ensure the new context is available to be run
|
||||||
let available_contexts = match process.state {
|
let available_threads = match process.state {
|
||||||
ProcessState::Ready(x) if x & 1 << tid != 0 => x & !(1 << tid),
|
ProcessState::Ready(x) if x & 1 << tid != 0 => x & !(1 << tid),
|
||||||
|
// If we're currently debugging the process, return to its parent.
|
||||||
|
// This can happen when the process handles a debug interrupt.
|
||||||
|
ProcessState::Debug(_) => {
|
||||||
|
crate::syscall::reset_switchto_caller();
|
||||||
|
return self.switch_to_thread(ppid, None)
|
||||||
|
},
|
||||||
other => panic!(
|
other => panic!(
|
||||||
"process {} was in an invalid state {:?} -- thread {} not available to run",
|
"process {} was in an invalid state {:?} -- thread {} not available to run",
|
||||||
pid, other, tid
|
pid, other, tid
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
process.state = ProcessState::Running(available_contexts);
|
process.state = ProcessState::Running(available_threads);
|
||||||
|
// log_process_update(file!(), line!(), process, old_state);
|
||||||
// process.current_thread = tid as u8;
|
// process.current_thread = tid as u8;
|
||||||
process.mapping.activate()?;
|
process.mapping.activate()?;
|
||||||
process.activate()?;
|
process.activate()?;
|
||||||
|
|
@ -500,12 +519,14 @@ impl SystemServices {
|
||||||
let mut current = self
|
let mut current = self
|
||||||
.get_process_mut(current_pid)
|
.get_process_mut(current_pid)
|
||||||
.expect("couldn't get current PID");
|
.expect("couldn't get current PID");
|
||||||
|
// let old_state = current.state;
|
||||||
current.state = match current.state {
|
current.state = match current.state {
|
||||||
ProcessState::Running(x) => {
|
ProcessState::Running(x) => {
|
||||||
ProcessState::Ready(x | (1 << arch::process::current_tid()))
|
ProcessState::Ready(x | (1 << arch::process::current_tid()))
|
||||||
}
|
}
|
||||||
y => panic!("current process was {:?}, not 'Running(_)'", y),
|
y => panic!("current process was {:?}, not 'Running(_)'", y),
|
||||||
};
|
};
|
||||||
|
// log_process_update(file!(), line!(), current, old_state);
|
||||||
// println!("Making PID {} state {:?}", current_pid, current.state);
|
// println!("Making PID {} state {:?}", current_pid, current.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -522,7 +543,9 @@ impl SystemServices {
|
||||||
panic!("process hasn't been set up yet")
|
panic!("process hasn't been set up yet")
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// let old_state = process.state;
|
||||||
process.state = ProcessState::Running(available_threads);
|
process.state = ProcessState::Running(available_threads);
|
||||||
|
// log_process_update(file!(), line!(), process, old_state);
|
||||||
process.previous_thread = process.current_thread;
|
process.previous_thread = process.current_thread;
|
||||||
process.current_thread = arch::process::IRQ_TID;
|
process.current_thread = arch::process::IRQ_TID;
|
||||||
process.mapping.activate()?;
|
process.mapping.activate()?;
|
||||||
|
|
@ -580,6 +603,7 @@ impl SystemServices {
|
||||||
/// it as Ready.
|
/// it as Ready.
|
||||||
pub fn ready_thread(&mut self, pid: PID, tid: TID) -> Result<(), xous_kernel::Error> {
|
pub fn ready_thread(&mut self, pid: PID, tid: TID) -> Result<(), xous_kernel::Error> {
|
||||||
let process = self.get_process_mut(pid)?;
|
let process = self.get_process_mut(pid)?;
|
||||||
|
// let old_state = process.state;
|
||||||
process.state = match process.state {
|
process.state = match process.state {
|
||||||
ProcessState::Free => {
|
ProcessState::Free => {
|
||||||
panic!("PID {} was not running, so cannot wake thread {}", pid, tid)
|
panic!("PID {} was not running, so cannot wake thread {}", pid, tid)
|
||||||
|
|
@ -595,6 +619,7 @@ impl SystemServices {
|
||||||
pid, tid, other
|
pid, tid, other
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
// log_process_update(file!(), line!(), process, old_state);
|
||||||
klog!("Readying ({}:{}) -> {:?}", pid, tid, process.state);
|
klog!("Readying ({}:{}) -> {:?}", pid, tid, process.state);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -615,6 +640,7 @@ impl SystemServices {
|
||||||
// pid, tid, process.state
|
// pid, tid, process.state
|
||||||
// );
|
// );
|
||||||
|
|
||||||
|
// let old_state = process.state;
|
||||||
// Determine which thread to switch to
|
// Determine which thread to switch to
|
||||||
process.state = match process.state {
|
process.state = match process.state {
|
||||||
ProcessState::Free => return Err(xous_kernel::Error::ProcessNotFound),
|
ProcessState::Free => return Err(xous_kernel::Error::ProcessNotFound),
|
||||||
|
|
@ -721,6 +747,7 @@ impl SystemServices {
|
||||||
ProcessState::Running(new_mask)
|
ProcessState::Running(new_mask)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// log_process_update(file!(), line!(), process, old_state);
|
||||||
|
|
||||||
// println!(
|
// println!(
|
||||||
// "switch_to_thread({}:{:?}): New state is {:?} Thread is ",
|
// "switch_to_thread({}:{:?}): New state is {:?} Thread is ",
|
||||||
|
|
@ -747,6 +774,7 @@ impl SystemServices {
|
||||||
// );
|
// );
|
||||||
// ArchProcess::with_current(|current| current.print_thread());
|
// ArchProcess::with_current(|current| current.print_thread());
|
||||||
|
|
||||||
|
// let old_state = process.state;
|
||||||
process.state = match process.state {
|
process.state = match process.state {
|
||||||
ProcessState::Running(x) if x & (1 << tid) != 0 => panic!(
|
ProcessState::Running(x) if x & (1 << tid) != 0 => panic!(
|
||||||
"PID {} thread {} was already queued for running when `switch_from_thread()` was called",
|
"PID {} thread {} was already queued for running when `switch_from_thread()` was called",
|
||||||
|
|
@ -774,6 +802,7 @@ impl SystemServices {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
// log_process_update(file!(), line!(), process, old_state);
|
||||||
// klog!(
|
// klog!(
|
||||||
// "switch_from_thread({}:{}): New state is {:?}",
|
// "switch_from_thread({}:{}): New state is {:?}",
|
||||||
// pid, tid, process.state
|
// pid, tid, process.state
|
||||||
|
|
@ -900,6 +929,7 @@ impl SystemServices {
|
||||||
|
|
||||||
// Set up the new process, if necessary. Remove the new thread from
|
// Set up the new process, if necessary. Remove the new thread from
|
||||||
// the list of ready threads.
|
// the list of ready threads.
|
||||||
|
// let old_state = new.state;
|
||||||
new.state = match new.state {
|
new.state = match new.state {
|
||||||
ProcessState::Setup(thread_init) => {
|
ProcessState::Setup(thread_init) => {
|
||||||
// println!("Setting up new process...");
|
// println!("Setting up new process...");
|
||||||
|
|
@ -920,6 +950,7 @@ impl SystemServices {
|
||||||
ProcessState::Sleeping => ProcessState::Running(0),
|
ProcessState::Sleeping => ProcessState::Running(0),
|
||||||
ProcessState::Debug(_) => panic!("Process was being debugged"),
|
ProcessState::Debug(_) => panic!("Process was being debugged"),
|
||||||
};
|
};
|
||||||
|
// log_process_update(file!(), line!(), new, old_state);
|
||||||
new.activate()?;
|
new.activate()?;
|
||||||
|
|
||||||
// Mark the previous process as ready to run, since we just switched
|
// Mark the previous process as ready to run, since we just switched
|
||||||
|
|
@ -957,6 +988,7 @@ impl SystemServices {
|
||||||
previous_pid, other
|
previous_pid, other
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
// log_process_update(file!(), line!(), previous, _oldstate);
|
||||||
klog!(
|
klog!(
|
||||||
"PID {:?} state change from {:?} -> {:?}",
|
"PID {:?} state change from {:?} -> {:?}",
|
||||||
previous_pid,
|
previous_pid,
|
||||||
|
|
@ -986,6 +1018,7 @@ impl SystemServices {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transition to the new state.
|
// Transition to the new state.
|
||||||
|
// let old_state = new.state;
|
||||||
new.state = if let ProcessState::Running(x) = new.state {
|
new.state = if let ProcessState::Running(x) = new.state {
|
||||||
let previous_tid = new.current_thread;
|
let previous_tid = new.current_thread;
|
||||||
// If no new thread is specified, take the previous
|
// If no new thread is specified, take the previous
|
||||||
|
|
@ -1017,6 +1050,7 @@ impl SystemServices {
|
||||||
previous_pid, new.state
|
previous_pid, new.state
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
// log_process_update(file!(), line!(), new, old_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut process = crate::arch::process::Process::current();
|
let mut process = crate::arch::process::Process::current();
|
||||||
|
|
@ -1416,6 +1450,7 @@ impl SystemServices {
|
||||||
|
|
||||||
// println!("KERNEL({}): Created new thread {}", pid, new_tid);
|
// println!("KERNEL({}): Created new thread {}", pid, new_tid);
|
||||||
|
|
||||||
|
// let old_state = process.state;
|
||||||
// Queue the thread to run
|
// Queue the thread to run
|
||||||
process.state = match process.state {
|
process.state = match process.state {
|
||||||
ProcessState::Running(x) => ProcessState::Running(x | (1 << new_tid)),
|
ProcessState::Running(x) => ProcessState::Running(x | (1 << new_tid)),
|
||||||
|
|
@ -1431,6 +1466,7 @@ impl SystemServices {
|
||||||
other
|
other
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
// log_process_update(file!(), line!(), process, old_state);
|
||||||
|
|
||||||
Ok(new_tid)
|
Ok(new_tid)
|
||||||
}
|
}
|
||||||
|
|
@ -1470,12 +1506,14 @@ impl SystemServices {
|
||||||
let mut new_pid = pid;
|
let mut new_pid = pid;
|
||||||
{
|
{
|
||||||
let process = self.get_process_mut(pid)?;
|
let process = self.get_process_mut(pid)?;
|
||||||
|
// let old_state = process.state;
|
||||||
process.state = if waiting_threads == 0 {
|
process.state = if waiting_threads == 0 {
|
||||||
new_pid = process.ppid;
|
new_pid = process.ppid;
|
||||||
ProcessState::Sleeping
|
ProcessState::Sleeping
|
||||||
} else {
|
} else {
|
||||||
ProcessState::Ready(waiting_threads)
|
ProcessState::Ready(waiting_threads)
|
||||||
};
|
};
|
||||||
|
// log_process_update(file!(), line!(), process, old_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch to the next available TID. This moves the process back to a `Running` state.
|
// Switch to the next available TID. This moves the process back to a `Running` state.
|
||||||
|
|
@ -2011,12 +2049,19 @@ impl SystemServices {
|
||||||
ProcessState::Ready(tids | 1 << current_tid)
|
ProcessState::Ready(tids | 1 << current_tid)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
self.get_process_mut(pid).unwrap().state = new_process_state;
|
{
|
||||||
|
let process = self.get_process_mut(pid).unwrap();
|
||||||
|
// let old_state = process.state;
|
||||||
|
process.state = new_process_state;
|
||||||
|
// log_process_update(file!(), line!(), process, old_state);
|
||||||
|
}
|
||||||
|
// self.get_process_mut(pid).unwrap().state = new_process_state;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn continue_process(&mut self, pid: PID) -> Result<(), xous_kernel::Error> {
|
pub fn continue_process(&mut self, pid: PID) -> Result<(), xous_kernel::Error> {
|
||||||
let process = self.get_process_mut(pid)?;
|
let process = self.get_process_mut(pid)?;
|
||||||
|
// let old_state = process.state;
|
||||||
process.state = match process.state {
|
process.state = match process.state {
|
||||||
ProcessState::Allocated => ProcessState::Allocated,
|
ProcessState::Allocated => ProcessState::Allocated,
|
||||||
ProcessState::Free => ProcessState::Free,
|
ProcessState::Free => ProcessState::Free,
|
||||||
|
|
@ -2027,6 +2072,7 @@ impl SystemServices {
|
||||||
ProcessState::Debug(tids) => ProcessState::Ready(tids),
|
ProcessState::Debug(tids) => ProcessState::Ready(tids),
|
||||||
ProcessState::Running(tids) => ProcessState::Running(tids),
|
ProcessState::Running(tids) => ProcessState::Running(tids),
|
||||||
};
|
};
|
||||||
|
// log_process_update(file!(), line!(), process, old_state);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -146,89 +146,106 @@ fn send_message(pid: PID, thread: TID, cid: CID, message: Message) -> SysCallRes
|
||||||
|
|
||||||
// If the server has an available thread to receive the message,
|
// If the server has an available thread to receive the message,
|
||||||
// transfer it right away.
|
// transfer it right away.
|
||||||
if ss.runnable(server_pid, None).unwrap() {
|
let server = ss
|
||||||
let server = ss
|
.server_from_sidx_mut(sidx)
|
||||||
.server_from_sidx_mut(sidx)
|
.expect("server couldn't be located");
|
||||||
.expect("server couldn't be located");
|
if let Some(server_tid) = server.take_available_thread() {
|
||||||
if let Some(server_tid) = server.take_available_thread() {
|
// klog!(
|
||||||
// klog!(
|
// "there are threads available in PID {} to handle this message -- marking as Ready",
|
||||||
// "there are threads available in PID {} to handle this message -- marking as Ready",
|
// server_pid
|
||||||
// server_pid
|
// );
|
||||||
// );
|
let sender_idx = if message.is_blocking() {
|
||||||
let sender_idx = if message.is_blocking() {
|
ss.remember_server_message(sidx, pid, thread, &message, client_address)
|
||||||
ss.remember_server_message(sidx, pid, thread, &message, client_address)
|
.map_err(|e| {
|
||||||
.map_err(|e| {
|
klog!("error remembering server message: {:?}", e);
|
||||||
klog!("error remembering server message: {:?}", e);
|
ss.server_from_sidx_mut(sidx)
|
||||||
ss.server_from_sidx_mut(sidx)
|
.expect("server couldn't be located")
|
||||||
.expect("server couldn't be located")
|
.return_available_thread(server_tid);
|
||||||
.return_available_thread(server_tid);
|
e
|
||||||
e
|
})?
|
||||||
})?
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
let sender = SenderID::new(sidx, sender_idx, Some(pid));
|
||||||
|
klog!(
|
||||||
|
"server connection data: sidx: {}, idx: {}, server pid: {}",
|
||||||
|
sidx,
|
||||||
|
sender_idx,
|
||||||
|
server_pid
|
||||||
|
);
|
||||||
|
let envelope = MessageEnvelope {
|
||||||
|
sender: sender.into(),
|
||||||
|
body: message,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Mark the server's context as "Ready". If this fails, return the context
|
||||||
|
// to the blocking list.
|
||||||
|
ss.ready_thread(server_pid, server_tid).map_err(|e| {
|
||||||
|
ss.server_from_sidx_mut(sidx)
|
||||||
|
.expect("server couldn't be located")
|
||||||
|
.return_available_thread(server_tid);
|
||||||
|
e
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let runnable = ss
|
||||||
|
.runnable(server_pid, Some(server_tid))
|
||||||
|
.expect("server doesn't exist");
|
||||||
|
// --- NOTE: Returning this value //
|
||||||
|
return if blocking && cfg!(baremetal) {
|
||||||
|
if !runnable {
|
||||||
|
// If it's not runnable (e.g. it's being debugged), switch to the parent.
|
||||||
|
let (ppid, ptid) = unsafe { SWITCHTO_CALLER.take().unwrap() };
|
||||||
|
klog!("Activating Server parent process (server is blocked) and switching away from Client");
|
||||||
|
ss.set_thread_result(
|
||||||
|
server_pid,
|
||||||
|
server_tid,
|
||||||
|
xous_kernel::Result::Message(envelope),
|
||||||
|
)
|
||||||
|
.expect("couldn't set result for server thread");
|
||||||
|
ss.activate_process_thread(thread, ppid, ptid, false)
|
||||||
|
.map(|_| Ok(xous_kernel::Result::ResumeProcess))
|
||||||
|
.unwrap_or(Err(xous_kernel::Error::ProcessNotFound))
|
||||||
} else {
|
} else {
|
||||||
0
|
// Switch to the server, since it's in a state to be run.
|
||||||
};
|
|
||||||
let sender = SenderID::new(sidx, sender_idx, Some(pid));
|
|
||||||
klog!(
|
|
||||||
"server connection data: sidx: {}, idx: {}, server pid: {}",
|
|
||||||
sidx,
|
|
||||||
sender_idx,
|
|
||||||
server_pid
|
|
||||||
);
|
|
||||||
let envelope = MessageEnvelope {
|
|
||||||
sender: sender.into(),
|
|
||||||
body: message,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Mark the server's context as "Ready". If this fails, return the context
|
|
||||||
// to the blocking list.
|
|
||||||
ss.ready_thread(server_pid, server_tid).map_err(|e| {
|
|
||||||
ss.server_from_sidx_mut(sidx)
|
|
||||||
.expect("server couldn't be located")
|
|
||||||
.return_available_thread(server_tid);
|
|
||||||
e
|
|
||||||
})?;
|
|
||||||
|
|
||||||
// --- NOTE: Returning this value //
|
|
||||||
return if blocking && cfg!(baremetal) {
|
|
||||||
klog!("Activating Server context and switching away from Client");
|
klog!("Activating Server context and switching away from Client");
|
||||||
ss.activate_process_thread(thread, server_pid, server_tid, false)
|
ss.activate_process_thread(thread, server_pid, server_tid, false)
|
||||||
.map(|_| Ok(xous_kernel::Result::Message(envelope)))
|
.map(|_| Ok(xous_kernel::Result::Message(envelope)))
|
||||||
.unwrap_or(Err(xous_kernel::Error::ProcessNotFound))
|
.unwrap_or(Err(xous_kernel::Error::ProcessNotFound))
|
||||||
} else if blocking && !cfg!(baremetal) {
|
}
|
||||||
klog!("Blocking client, since it sent a blocking message");
|
} else if blocking && !cfg!(baremetal) {
|
||||||
ss.switch_from_thread(pid, thread)?;
|
klog!("Blocking client, since it sent a blocking message");
|
||||||
ss.switch_to_thread(server_pid, Some(server_tid))?;
|
ss.switch_from_thread(pid, thread)?;
|
||||||
ss.set_thread_result(
|
ss.switch_to_thread(server_pid, Some(server_tid))?;
|
||||||
server_pid,
|
ss.set_thread_result(
|
||||||
server_tid,
|
server_pid,
|
||||||
xous_kernel::Result::Message(envelope),
|
server_tid,
|
||||||
)
|
xous_kernel::Result::Message(envelope),
|
||||||
.map(|_| xous_kernel::Result::BlockedProcess)
|
)
|
||||||
} else if cfg!(baremetal) {
|
.map(|_| xous_kernel::Result::BlockedProcess)
|
||||||
klog!("Setting the return value of the Server ({}:{}) to {:?} and returning to Client",
|
} else if cfg!(baremetal) {
|
||||||
server_pid, server_tid, envelope);
|
klog!("Setting the return value of the Server ({}:{}) to {:?} and returning to Client",
|
||||||
ss.set_thread_result(
|
server_pid, server_tid, envelope);
|
||||||
server_pid,
|
ss.set_thread_result(
|
||||||
server_tid,
|
server_pid,
|
||||||
xous_kernel::Result::Message(envelope),
|
server_tid,
|
||||||
)
|
xous_kernel::Result::Message(envelope),
|
||||||
.map(|_| xous_kernel::Result::Ok)
|
)
|
||||||
} else {
|
.map(|_| xous_kernel::Result::Ok)
|
||||||
klog!(
|
} else {
|
||||||
"setting the return value of the Server to {:?} and returning to Client",
|
klog!(
|
||||||
envelope
|
"setting the return value of the Server to {:?} and returning to Client",
|
||||||
);
|
envelope
|
||||||
// "Switch to" the server PID when not running on bare metal. This ensures
|
);
|
||||||
// that it's "Running".
|
// "Switch to" the server PID when not running on bare metal. This ensures
|
||||||
ss.switch_to_thread(server_pid, Some(server_tid))?;
|
// that it's "Running".
|
||||||
ss.set_thread_result(
|
ss.switch_to_thread(server_pid, Some(server_tid))?;
|
||||||
server_pid,
|
ss.set_thread_result(
|
||||||
server_tid,
|
server_pid,
|
||||||
xous_kernel::Result::Message(envelope),
|
server_tid,
|
||||||
)
|
xous_kernel::Result::Message(envelope),
|
||||||
.map(|_| xous_kernel::Result::Ok)
|
)
|
||||||
};
|
.map(|_| xous_kernel::Result::Ok)
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
klog!(
|
klog!(
|
||||||
"no threads available in PID {} to handle this message, so queueing",
|
"no threads available in PID {} to handle this message, so queueing",
|
||||||
|
|
@ -344,12 +361,14 @@ fn return_memory(
|
||||||
len.get(),
|
len.get(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
let client_is_runnable = ss.runnable(client_pid, Some(client_tid))?;
|
||||||
|
|
||||||
// Unblock the client context to allow it to continue.
|
// Unblock the client context to allow it to continue.
|
||||||
if !cfg!(baremetal) || in_irq {
|
if !cfg!(baremetal) || in_irq || !client_is_runnable {
|
||||||
// Send a message to the client, in order to wake it up
|
// Send a message to the client, in order to wake it up
|
||||||
// print!(" [waking up PID {}:{}]", client_pid, client_tid);
|
// print!(" [waking up PID {}:{}]", client_pid, client_tid);
|
||||||
ss.ready_thread(client_pid, client_tid)?;
|
ss.ready_thread(client_pid, client_tid)?;
|
||||||
ss.switch_to_thread(client_pid, Some(client_tid))?;
|
// ss.switch_to_thread(client_pid, Some(client_tid))?;
|
||||||
ss.set_thread_result(
|
ss.set_thread_result(
|
||||||
client_pid,
|
client_pid,
|
||||||
client_tid,
|
client_tid,
|
||||||
|
|
@ -415,7 +434,9 @@ fn return_scalar(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if !cfg!(baremetal) || in_irq {
|
let client_is_runnable = ss.runnable(client_pid, Some(client_tid))?;
|
||||||
|
|
||||||
|
if !cfg!(baremetal) || in_irq || !client_is_runnable {
|
||||||
// In a hosted environment, `switch_to_thread()` doesn't continue
|
// In a hosted environment, `switch_to_thread()` doesn't continue
|
||||||
// execution from the new thread. Instead it continues in the old
|
// execution from the new thread. Instead it continues in the old
|
||||||
// thread. Therefore, we need to instruct the client to resume, and
|
// thread. Therefore, we need to instruct the client to resume, and
|
||||||
|
|
@ -423,7 +444,7 @@ fn return_scalar(
|
||||||
// In a baremetal environment, the opposite is true -- we instruct
|
// In a baremetal environment, the opposite is true -- we instruct
|
||||||
// the server to resume and return to the client.
|
// the server to resume and return to the client.
|
||||||
ss.set_thread_result(client_pid, client_tid, xous_kernel::Result::Scalar1(arg))?;
|
ss.set_thread_result(client_pid, client_tid, xous_kernel::Result::Scalar1(arg))?;
|
||||||
if in_irq {
|
if cfg!(baremetal) {
|
||||||
ss.ready_thread(client_pid, client_tid)?;
|
ss.ready_thread(client_pid, client_tid)?;
|
||||||
}
|
}
|
||||||
Ok(xous_kernel::Result::Ok)
|
Ok(xous_kernel::Result::Ok)
|
||||||
|
|
@ -484,7 +505,9 @@ fn return_scalar2(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if !cfg!(baremetal) || in_irq {
|
let client_is_runnable = ss.runnable(client_pid, Some(client_tid))?;
|
||||||
|
|
||||||
|
if !cfg!(baremetal) || in_irq || !client_is_runnable {
|
||||||
// In a hosted environment, `switch_to_thread()` doesn't continue
|
// In a hosted environment, `switch_to_thread()` doesn't continue
|
||||||
// execution from the new thread. Instead it continues in the old
|
// execution from the new thread. Instead it continues in the old
|
||||||
// thread. Therefore, we need to instruct the client to resume, and
|
// thread. Therefore, we need to instruct the client to resume, and
|
||||||
|
|
@ -496,7 +519,7 @@ fn return_scalar2(
|
||||||
client_tid,
|
client_tid,
|
||||||
xous_kernel::Result::Scalar2(arg1, arg2),
|
xous_kernel::Result::Scalar2(arg1, arg2),
|
||||||
)?;
|
)?;
|
||||||
if in_irq {
|
if cfg!(baremetal) {
|
||||||
ss.ready_thread(client_pid, client_tid)?;
|
ss.ready_thread(client_pid, client_tid)?;
|
||||||
}
|
}
|
||||||
Ok(xous_kernel::Result::Ok)
|
Ok(xous_kernel::Result::Ok)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue