Provide mem_unit and procs in sysinfo

This commit is contained in:
Chen Chengjun 2025-10-31 06:23:19 +00:00 committed by Tate, Hongliang Tian
parent 63efd4891b
commit c77edbace8
3 changed files with 12 additions and 5 deletions

View File

@ -28,6 +28,11 @@ pub fn process_table_mut() -> MutexGuard<'static, ProcessTable> {
PROCESS_TABLE.lock()
}
/// Returns the number of current processes.
pub fn process_num() -> usize {
PROCESS_TABLE.lock().inner.len()
}
/// Process Table.
pub struct ProcessTable {
inner: BTreeMap<Pid, Arc<Process>>,

View File

@ -3,11 +3,11 @@
use aster_time::read_monotonic_time;
use super::SyscallReturn;
use crate::prelude::*;
use crate::{prelude::*, process::process_table};
#[derive(Debug, Default, Clone, Copy, Pod)]
#[repr(C)]
pub struct sysinfo {
struct SysInfo {
uptime: i64, /* Seconds since boot */
loads: [u64; 3], /* 1, 5, and 15 minute load averages */
totalram: u64, /* Total usable main memory size */
@ -23,10 +23,14 @@ pub struct sysinfo {
}
pub fn sys_sysinfo(sysinfo_addr: Vaddr, ctx: &Context) -> Result<SyscallReturn> {
let info = sysinfo {
let info = SysInfo {
uptime: read_monotonic_time().as_secs() as i64,
totalram: crate::vm::mem_total() as u64,
freeram: osdk_frame_allocator::load_total_free_size() as u64,
procs: process_table::process_num() as u16,
// `mem_unit` will always be 1 byte since Asterinas only supports
// 64-bit CPU architectures.
mem_unit: 1,
..Default::default() // TODO: add other system information
};
ctx.user_space().write_val(sysinfo_addr, &info)?;

View File

@ -1,2 +0,0 @@
SysinfoTest.MemunitSet
SysinfoTest.NumProcsSaneValue