mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
track current tid in swap manager
This commit is contained in:
parent
2c183c2e18
commit
1af43fba7b
1 changed files with 21 additions and 11 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use xous_kernel::{AllocAdvice, PID, SID};
|
use xous_kernel::{AllocAdvice, PID, SID, TID};
|
||||||
|
|
||||||
/* for non-blocking calls
|
/* for non-blocking calls
|
||||||
use xous_Kernel::{try_send_message, MemoryFlags, Message, MessageEnvelope, SysCallResult, TID};
|
use xous_Kernel::{try_send_message, MemoryFlags, Message, MessageEnvelope, SysCallResult, TID};
|
||||||
|
|
@ -16,7 +16,7 @@ pub enum BlockingSwapOp {
|
||||||
/// physical address of block
|
/// physical address of block
|
||||||
ReadFromSwap(PID, usize, usize, usize),
|
ReadFromSwap(PID, usize, usize, usize),
|
||||||
/// PID of the process to return to after the allocate advisory
|
/// PID of the process to return to after the allocate advisory
|
||||||
AllocateAdvisory(PID),
|
AllocateAdvisory(PID, TID),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(baremetal)]
|
#[cfg(baremetal)]
|
||||||
|
|
@ -179,7 +179,7 @@ impl Swap {
|
||||||
self.swapper_args[3] = vaddr_in_pid;
|
self.swapper_args[3] = vaddr_in_pid;
|
||||||
self.swapper_args[4] = vaddr_in_swap;
|
self.swapper_args[4] = vaddr_in_swap;
|
||||||
}
|
}
|
||||||
BlockingSwapOp::AllocateAdvisory(_pid) => {
|
BlockingSwapOp::AllocateAdvisory(_pid, _tid) => {
|
||||||
self.swapper_args[0] = self.swapper_state;
|
self.swapper_args[0] = self.swapper_state;
|
||||||
self.swapper_args[1] = 2; // AllocateAdvisory
|
self.swapper_args[1] = 2; // AllocateAdvisory
|
||||||
for (index, advisory) in self.alloc_advisories.iter_mut().enumerate() {
|
for (index, advisory) in self.alloc_advisories.iter_mut().enumerate() {
|
||||||
|
|
@ -239,6 +239,7 @@ impl Swap {
|
||||||
SystemServices::with(|system_services| {
|
SystemServices::with(|system_services| {
|
||||||
// swap to the swapper space
|
// swap to the swapper space
|
||||||
let target_map = system_services.get_process(pid).unwrap().mapping;
|
let target_map = system_services.get_process(pid).unwrap().mapping;
|
||||||
|
crate::arch::process::set_current_pid(pid);
|
||||||
target_map.activate()
|
target_map.activate()
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|
@ -263,13 +264,12 @@ impl Swap {
|
||||||
Ok(xous_kernel::Result::ResumeProcess)
|
Ok(xous_kernel::Result::ResumeProcess)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Some(BlockingSwapOp::AllocateAdvisory(pid)) => {
|
Some(BlockingSwapOp::AllocateAdvisory(pid, tid)) => {
|
||||||
// return to the target PID
|
// Switch to the previous process' address space.
|
||||||
SystemServices::with(|system_services| {
|
SystemServices::with_mut(|ss| {
|
||||||
// swap back to the original allocator's space
|
ss.finish_callback_and_resume(pid, tid).expect("unable to resume previous PID")
|
||||||
system_services.get_process(pid).unwrap().mapping.activate()?;
|
});
|
||||||
Ok(xous_kernel::Result::ResumeProcess)
|
Ok(xous_kernel::Result::ResumeProcess)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
None => panic!("No previous swap op was set"),
|
None => panic!("No previous swap op was set"),
|
||||||
}
|
}
|
||||||
|
|
@ -315,6 +315,7 @@ impl Swap {
|
||||||
&mut self,
|
&mut self,
|
||||||
// also the PID to return from after reporting to the swapper
|
// also the PID to return from after reporting to the swapper
|
||||||
target_pid: PID,
|
target_pid: PID,
|
||||||
|
target_tid: TID,
|
||||||
target_vaddr_in_pid: usize,
|
target_vaddr_in_pid: usize,
|
||||||
paddr: usize,
|
paddr: usize,
|
||||||
is_allocate: bool,
|
is_allocate: bool,
|
||||||
|
|
@ -338,6 +339,15 @@ impl Swap {
|
||||||
}
|
}
|
||||||
if self.pc != 0 {
|
if self.pc != 0 {
|
||||||
if last_index >= self.alloc_advisories.len() - 1 {
|
if last_index >= self.alloc_advisories.len() - 1 {
|
||||||
|
{
|
||||||
|
// debugging
|
||||||
|
SystemServices::with(|ss| {
|
||||||
|
let current = ss.get_process(current_pid()).unwrap();
|
||||||
|
let state = current.state();
|
||||||
|
println!("state before swapper switch: {} {:?}", current.pid.get(), state);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let swapper_pid = PID::new(xous_kernel::SWAPPER_PID).unwrap();
|
let swapper_pid = PID::new(xous_kernel::SWAPPER_PID).unwrap();
|
||||||
SystemServices::with(|ss| ss.get_process(swapper_pid).unwrap().mapping.activate().unwrap());
|
SystemServices::with(|ss| ss.get_process(swapper_pid).unwrap().mapping.activate().unwrap());
|
||||||
|
|
||||||
|
|
@ -345,7 +355,7 @@ impl Swap {
|
||||||
#[cfg(feature = "debug-swap")]
|
#[cfg(feature = "debug-swap")]
|
||||||
println!("advise_alloc - swapper activate, PC: {:08x}", self.pc);
|
println!("advise_alloc - swapper activate, PC: {:08x}", self.pc);
|
||||||
unsafe {
|
unsafe {
|
||||||
self.blocking_activate_swapper(BlockingSwapOp::AllocateAdvisory(target_pid));
|
self.blocking_activate_swapper(BlockingSwapOp::AllocateAdvisory(target_pid, target_tid));
|
||||||
// ^^ also note this has the side effect of clearing the advisory storage table
|
// ^^ also note this has the side effect of clearing the advisory storage table
|
||||||
}
|
}
|
||||||
// call proceeds to swapper space -> we've diverged and will return via the
|
// call proceeds to swapper space -> we've diverged and will return via the
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue