Implement totalram and freeram computation for sysinfo

This commit is contained in:
Roman Korostinskiy
2024-12-13 00:19:47 +03:00
committed by Tate, Hongliang Tian
parent 8b24e74642
commit 13229cc037
2 changed files with 15 additions and 14 deletions

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: MPL-2.0
use aster_time::read_monotonic_time;
use ostd::mm::stat::{mem_total, mem_available};
use super::SyscallReturn;
use crate::prelude::*;
@ -8,23 +9,25 @@ use crate::prelude::*;
#[derive(Debug, Default, Clone, Copy, Pod)]
#[repr(C)]
pub struct sysinfo {
uptime: i64,
loads: [u64; 3],
totalram: u64,
freeram: u64,
sharedram: u64,
bufferram: u64,
totalswap: u64,
freeswap: u64,
procs: u16,
totalhigh: u64,
freehigh: u64,
mem_unit: u32,
uptime: i64, /* Seconds since boot */
loads: [u64; 3], /* 1, 5, and 15 minute load averages */
totalram: u64, /* Total usable main memory size */
freeram: u64, /* Available memory size */
sharedram: u64, /* Amount of shared memory */
bufferram: u64, /* Memory used by buffers */
totalswap: u64, /* Total swap space size */
freeswap: u64, /* swap space still available */
procs: u16, /* Number of current processes */
totalhigh: u64, /* Total high memory size */
freehigh: u64, /* Available high memory size */
mem_unit: u32, /* Memory unit size in bytes */
}
pub fn sys_sysinfo(sysinfo_addr: Vaddr, ctx: &Context) -> Result<SyscallReturn> {
let info = sysinfo {
uptime: read_monotonic_time().as_secs() as i64,
totalram: mem_total() as u64,
freeram: mem_available() as u64,
..Default::default() // TODO: add other system information
};
ctx.user_space().write_val(sysinfo_addr, &info)?;

View File

@ -1,4 +1,2 @@
SysinfoTest.TotalRamSaneValue
SysinfoTest.MemunitSet
SysinfoTest.FreeRamSaneValue
SysinfoTest.NumProcsSaneValue