mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
add a call to get the free memory status from the kernel
this will be helpful for debugging our page tracker
This commit is contained in:
parent
fe7ee9554c
commit
fd4a8cf7e2
3 changed files with 60 additions and 0 deletions
|
|
@ -178,6 +178,8 @@ impl MemoryManager {
|
||||||
owned_bytes
|
owned_bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn ram_size(&self) -> usize { self.ram_size }
|
||||||
|
|
||||||
#[cfg(all(baremetal, feature = "print-debug"))]
|
#[cfg(all(baremetal, feature = "print-debug"))]
|
||||||
pub fn print_ownership(&self) {
|
pub fn print_ownership(&self) {
|
||||||
println!("Ownership ({} bytes in all):", unsafe { MEMORY_ALLOCATIONS.len() });
|
println!("Ownership ({} bytes in all):", unsafe { MEMORY_ALLOCATIONS.len() });
|
||||||
|
|
|
||||||
|
|
@ -10,16 +10,23 @@ use crate::arch::mem::PAGE_SIZE;
|
||||||
use crate::mem::MemoryManager;
|
use crate::mem::MemoryManager;
|
||||||
use crate::services::SystemServices;
|
use crate::services::SystemServices;
|
||||||
|
|
||||||
|
/// This ABI is copy-paste synchronized with what's in the userspace handler. It's left out of
|
||||||
|
/// xous-rs so that we can change it without having to push crates to crates.io.
|
||||||
|
/// Since there is only one place the ABI could be used, we're going to stick with
|
||||||
|
/// this primitive method of synchronization because it reduces the activation barrier
|
||||||
|
/// to fix bugs.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
pub enum SwapAbi {
|
pub enum SwapAbi {
|
||||||
Invalid = 0,
|
Invalid = 0,
|
||||||
Evict = 1,
|
Evict = 1,
|
||||||
|
GetFreeMem = 2,
|
||||||
}
|
}
|
||||||
impl SwapAbi {
|
impl SwapAbi {
|
||||||
pub fn from(val: usize) -> SwapAbi {
|
pub fn from(val: usize) -> SwapAbi {
|
||||||
use SwapAbi::*;
|
use SwapAbi::*;
|
||||||
match val {
|
match val {
|
||||||
1 => Evict,
|
1 => Evict,
|
||||||
|
2 => GetFreeMem,
|
||||||
_ => Invalid,
|
_ => Invalid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -88,6 +95,20 @@ impl Swap {
|
||||||
SWAP.with(|ss| f(&mut ss.borrow_mut()))
|
SWAP.with(|ss| f(&mut ss.borrow_mut()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(baremetal)]
|
||||||
|
pub fn with<F, R>(f: F) -> R
|
||||||
|
where
|
||||||
|
F: FnOnce(&Swap) -> R,
|
||||||
|
{
|
||||||
|
#[cfg(baremetal)]
|
||||||
|
unsafe {
|
||||||
|
f(&*core::ptr::addr_of!(SWAP))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(baremetal))]
|
||||||
|
SWAP.with(|ss| f(&ss.borrow_mut()))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn register_handler(
|
pub fn register_handler(
|
||||||
&mut self,
|
&mut self,
|
||||||
s0: u32,
|
s0: u32,
|
||||||
|
|
@ -342,6 +363,42 @@ impl Swap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_free_mem(&self) -> SysCallResult {
|
||||||
|
println!("RAM usage:");
|
||||||
|
let mut total_bytes = 0;
|
||||||
|
let mut ram_size = 0;
|
||||||
|
crate::services::SystemServices::with(|system_services| {
|
||||||
|
crate::mem::MemoryManager::with(|mm| {
|
||||||
|
for process in &system_services.processes {
|
||||||
|
if !process.free() {
|
||||||
|
let bytes_used = mm.ram_used_by(process.pid);
|
||||||
|
total_bytes += bytes_used;
|
||||||
|
println!(
|
||||||
|
" PID {:>3}: {:>4} k {}",
|
||||||
|
process.pid,
|
||||||
|
bytes_used / 1024,
|
||||||
|
system_services.process_name(process.pid).unwrap_or("")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ram_size = mm.ram_size();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
println!("{} k total", total_bytes / 1024);
|
||||||
|
|
||||||
|
/*
|
||||||
|
crate::services::SystemServices::with(|system_services| {
|
||||||
|
let current_pid = system_services.current_pid();
|
||||||
|
let process = system_services.get_process(PID::new(9).unwrap()).unwrap();
|
||||||
|
println!("PID {} {}:", process.pid, system_services.process_name(process.pid).unwrap_or(""));
|
||||||
|
process.activate().unwrap();
|
||||||
|
crate::arch::mem::MemoryMapping::current().print_map();
|
||||||
|
system_services.get_process(current_pid).unwrap().activate().unwrap();
|
||||||
|
}); */
|
||||||
|
|
||||||
|
Ok(xous_kernel::Result::Scalar5(total_bytes, ram_size, 0, 0, 0))
|
||||||
|
}
|
||||||
|
|
||||||
/// The address space on entry to `retrieve_page` is `target_pid`; it must ensure
|
/// The address space on entry to `retrieve_page` is `target_pid`; it must ensure
|
||||||
/// that the address space is still `target_pid` on return.
|
/// that the address space is still `target_pid` on return.
|
||||||
///
|
///
|
||||||
|
|
|
||||||
|
|
@ -1029,6 +1029,7 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR
|
||||||
}
|
}
|
||||||
match SwapAbi::from(op) {
|
match SwapAbi::from(op) {
|
||||||
SwapAbi::Evict => Swap::with_mut(|swap| swap.evict_page(a1, a2)),
|
SwapAbi::Evict => Swap::with_mut(|swap| swap.evict_page(a1, a2)),
|
||||||
|
SwapAbi::GetFreeMem => Swap::with(|swap| swap.get_free_mem()),
|
||||||
SwapAbi::Invalid => {
|
SwapAbi::Invalid => {
|
||||||
println!(
|
println!(
|
||||||
"Invalid SwapOp: {:x} {:x} {:x} {:x} {:x} {:x} {:x}",
|
"Invalid SwapOp: {:x} {:x} {:x} {:x} {:x} {:x} {:x}",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue