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

View File

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