kernel: remove printlns, needless context queries

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-07-21 09:52:18 +08:00
parent 1a6b1160a3
commit 549866bcd5
3 changed files with 53 additions and 74 deletions

View file

@ -128,12 +128,12 @@ impl Process {
context: TID, context: TID,
_setup: ContextInit, _setup: ContextInit,
) -> Result<(), xous::Error> { ) -> Result<(), xous::Error> {
println!( // println!(
"KERNEL({}): Setting up context {} @ {:?}", // "KERNEL({}): Setting up context {} @ {:?}",
self.pid, // self.pid,
context, // context,
std::thread::current() // std::thread::current()
); // );
assert!(context > 0); assert!(context > 0);
PROCESS_TABLE.with(|pt| { PROCESS_TABLE.with(|pt| {
let mut process_table = pt.borrow_mut(); let mut process_table = pt.borrow_mut();
@ -142,12 +142,12 @@ impl Process {
assert!(!process.contexts[context - 1].allocated); assert!(!process.contexts[context - 1].allocated);
process.contexts[context - 1].allocated = true; process.contexts[context - 1].allocated = true;
println!( // println!(
"KERNEL({}): self.contexts[{}].allocated = {}", // "KERNEL({}): self.contexts[{}].allocated = {}",
current_pid_idx, // current_pid_idx,
context - 1, // context - 1,
process.contexts[context - 1].allocated // process.contexts[context - 1].allocated
); // );
}); });
Ok(()) Ok(())
} }

View file

@ -500,10 +500,10 @@ impl SystemServices {
pid, context, other pid, context, other
), ),
}; };
println!( // println!(
"KERNEL({}): Readying context {} -> {:?}", // "KERNEL({}): Readying context {} -> {:?}",
pid, context, process.state // pid, context, process.state
); // );
Ok(()) Ok(())
} }
@ -513,13 +513,11 @@ impl SystemServices {
/// ///
/// If the current process is not running, or if it's "Running" but has no free contexts /// If the current process is not running, or if it's "Running" but has no free contexts
pub fn switch_to(&mut self, pid: PID, context: Option<TID>) -> Result<(), xous::Error> { pub fn switch_to(&mut self, pid: PID, context: Option<TID>) -> Result<(), xous::Error> {
// println!("KERNEL(?): Getting current process...");
let process = self.get_process_mut(pid)?; let process = self.get_process_mut(pid)?;
// println!("KERNEL(?): Current process is {:?}", process); // println!(
println!( // "switch_to({}:{:?}): Old state was {:?}",
"switch_to({}:{:?}): Old state was {:?}", // pid, context, process.state
pid, context, process.state // );
);
// Determine which context number to switch to // Determine which context number to switch to
process.state = match process.state { process.state = match process.state {
@ -620,10 +618,10 @@ impl SystemServices {
ProcessState::Running(new_mask) ProcessState::Running(new_mask)
} }
}; };
println!( // println!(
"switch_to({}:{:?}): New state is {:?}", // "switch_to({}:{:?}): New state is {:?}",
pid, context, process.state // pid, context, process.state
); // );
// self.pid = pid; // self.pid = pid;
Ok(()) Ok(())
} }
@ -643,10 +641,10 @@ impl SystemServices {
can_resume: bool, can_resume: bool,
) -> Result<(), xous::Error> { ) -> Result<(), xous::Error> {
let process = self.get_process_mut(pid)?; let process = self.get_process_mut(pid)?;
println!( // println!(
"switch_from({}:{}): Old state was {:?}", // "switch_from({}:{}): Old state was {:?}",
pid, context, process.state // pid, context, process.state
); // );
process.state = match process.state { process.state = match process.state {
ProcessState::Running(x) if x & (1 << context) != 0 => panic!( ProcessState::Running(x) if x & (1 << context) != 0 => panic!(
"PID {} context {} was already queued for running when `switch_from()` was called", "PID {} context {} was already queued for running when `switch_from()` was called",
@ -675,10 +673,10 @@ impl SystemServices {
pid, other pid, other
), ),
}; };
println!( // println!(
"switch_from({}:{}): New state is {:?}", // "switch_from({}:{}): New state is {:?}",
pid, context, process.state // pid, context, process.state
); // );
Ok(()) Ok(())
} }
@ -1196,7 +1194,7 @@ impl SystemServices {
// &[arg.map(|x| x.get()).unwrap_or_default() as usize], // &[arg.map(|x| x.get()).unwrap_or_default() as usize],
// ); // );
println!("KERNEL({}): Created new context {}", pid, new_context_nr); // println!("KERNEL({}): Created new context {}", pid, new_context_nr);
// Queue the thread to run // Queue the thread to run
process.state = match process.state { process.state = match process.state {

View file

@ -111,13 +111,7 @@ fn send_message(pid: PID, thread: TID, cid: CID, message: Message) -> SysCallRes
let sender = match message { let sender = match message {
Message::Scalar(_) | Message::Move(_) => 0, Message::Scalar(_) | Message::Move(_) => 0,
Message::Borrow(_) | Message::MutableBorrow(_) => ss Message::Borrow(_) | Message::MutableBorrow(_) => ss
.remember_server_message( .remember_server_message(sidx, pid, thread, &message, client_address)
sidx,
pid,
thread,
&message,
client_address,
)
.or_else(|e| { .or_else(|e| {
ss.server_from_sidx(sidx) ss.server_from_sidx(sidx)
.expect("server couldn't be located") .expect("server couldn't be located")
@ -144,32 +138,20 @@ fn send_message(pid: PID, thread: TID, cid: CID, message: Message) -> SysCallRes
} else if blocking && !cfg!(baremetal) { } else if blocking && !cfg!(baremetal) {
// println!("Blocking client, since it sent a blocking message"); // println!("Blocking client, since it sent a blocking message");
ss.switch_to(server_pid, None)?; ss.switch_to(server_pid, None)?;
ss.set_context_result( ss.set_context_result(server_pid, ctx_number, xous::Result::Message(envelope))
server_pid, .and_then(|_| ss.switch_from(pid, thread, false))
ctx_number, .map(|_| xous::Result::BlockedProcess)
xous::Result::Message(envelope),
)
.and_then(|_| ss.switch_from(pid, thread, false))
.map(|_| xous::Result::BlockedProcess)
} else if cfg!(baremetal) { } else if cfg!(baremetal) {
// println!("Setting the return value of the Server and returning to Client"); // println!("Setting the return value of the Server and returning to Client");
ss.set_context_result( ss.set_context_result(server_pid, ctx_number, xous::Result::Message(envelope))
server_pid, .map(|_| xous::Result::Ok)
ctx_number,
xous::Result::Message(envelope),
)
.map(|_| xous::Result::Ok)
} else { } else {
// println!("Setting the return value of the Server and returning to Client"); // println!("Setting the return value of the Server and returning to Client");
// "Switch to" the server PID when not running on bare metal. This ensures // "Switch to" the server PID when not running on bare metal. This ensures
// that it's "Running". // that it's "Running".
ss.switch_to(server_pid, None)?; ss.switch_to(server_pid, None)?;
ss.set_context_result( ss.set_context_result(server_pid, ctx_number, xous::Result::Message(envelope))
server_pid, .map(|_| xous::Result::Ok)
ctx_number,
xous::Result::Message(envelope),
)
.map(|_| xous::Result::Ok)
} }
} else { } else {
// Add this message to the queue. If the queue is full, this // Add this message to the queue. If the queue is full, this
@ -199,10 +181,14 @@ fn send_message(pid: PID, thread: TID, cid: CID, message: Message) -> SysCallRes
}) })
} }
pub fn handle(pid: PID, tid: TID, call: SysCall) -> core::result::Result<xous::Result, xous::Error> { pub fn handle(
pid: PID,
tid: TID,
call: SysCall,
) -> core::result::Result<xous::Result, xous::Error> {
// let pid = arch::current_pid(); // let pid = arch::current_pid();
println!("KERNEL({}): Syscall {:?}", pid, call); // println!("KERNEL({}): Syscall {:?}", pid, call);
match call { match call {
SysCall::MapMemory(phys, virt, size, req_flags) => { SysCall::MapMemory(phys, virt, size, req_flags) => {
let mut mm = MemoryManagerHandle::get(); let mut mm = MemoryManagerHandle::get();
@ -326,13 +312,12 @@ pub fn handle(pid: PID, tid: TID, call: SysCall) -> core::result::Result<xous::R
} }
SysCall::SwitchTo(new_pid, new_context) => { SysCall::SwitchTo(new_pid, new_context) => {
SystemServices::with_mut(|ss| { SystemServices::with_mut(|ss| {
let context_nr = ss.current_context_nr(pid);
unsafe { unsafe {
assert!( assert!(
SWITCHTO_CALLER.is_none(), SWITCHTO_CALLER.is_none(),
"SWITCHTO_CALLER was not None, indicating SwitchTo was called twice" "SWITCHTO_CALLER was not None, indicating SwitchTo was called twice"
); );
SWITCHTO_CALLER = Some((pid, context_nr)); SWITCHTO_CALLER = Some((pid, tid));
} }
ss.activate_process_context(new_pid, new_context, true, false) ss.activate_process_context(new_pid, new_context, true, false)
.map(|_ctx| { .map(|_ctx| {
@ -376,7 +361,6 @@ pub fn handle(pid: PID, tid: TID, call: SysCall) -> core::result::Result<xous::R
SysCall::ReceiveMessage(sid) => { SysCall::ReceiveMessage(sid) => {
SystemServices::with_mut(|ss| { SystemServices::with_mut(|ss| {
// See if there is a pending message. If so, return immediately. // See if there is a pending message. If so, return immediately.
let context_nr = ss.current_context_nr(pid);
let sidx = ss.server_sidx(sid).ok_or(xous::Error::ServerNotFound)?; let sidx = ss.server_sidx(sid).ok_or(xous::Error::ServerNotFound)?;
let server = ss let server = ss
.server_from_sidx(sidx) .server_from_sidx(sidx)
@ -400,9 +384,9 @@ pub fn handle(pid: PID, tid: TID, call: SysCall) -> core::result::Result<xous::R
// MessageEnvelope of the incoming message. // MessageEnvelope of the incoming message.
// println!( // println!(
// "KERNEL({}): did not have any waiting messages -- parking context {}", // "KERNEL({}): did not have any waiting messages -- parking context {}",
// pid, context_nr // pid, tid
// ); // );
server.park_context(context_nr); server.park_context(tid);
// For baremetal targets, switch away from this process. // For baremetal targets, switch away from this process.
if cfg!(baremetal) { if cfg!(baremetal) {
@ -415,7 +399,7 @@ pub fn handle(pid: PID, tid: TID, call: SysCall) -> core::result::Result<xous::R
// For hosted targets, simply return `BlockedProcess` indicating we'll make // For hosted targets, simply return `BlockedProcess` indicating we'll make
// a callback to their socket at a later time. // a callback to their socket at a later time.
else { else {
ss.switch_from(pid, context_nr, false) ss.switch_from(pid, tid, false)
.map(|_| xous::Result::BlockedProcess) .map(|_| xous::Result::BlockedProcess)
} }
}) })
@ -513,12 +497,9 @@ pub fn handle(pid: PID, tid: TID, call: SysCall) -> core::result::Result<xous::R
Ok(xous::Result::Ok) Ok(xous::Result::Ok)
}) })
} }
SysCall::SendMessage(cid, message) => { SysCall::SendMessage(cid, message) => send_message(pid, tid, cid, message),
send_message(pid, tid, cid, message)
}
SysCall::TerminateProcess => SystemServices::with_mut(|ss| { SysCall::TerminateProcess => SystemServices::with_mut(|ss| {
let context_nr = ss.current_context_nr(pid); ss.switch_from(pid, tid, false)?;
ss.switch_from(pid, context_nr, false)?;
let ppid = ss.terminate_process(pid)?; let ppid = ss.terminate_process(pid)?;
if cfg!(baremetal) { if cfg!(baremetal) {
ss.switch_to(ppid, None) ss.switch_to(ppid, None)