Add support for querying numa info from userspace

This commit is contained in:
R Aadarsh
2026-07-10 15:39:54 +05:30
parent fbfe439451
commit bb06db93ce
2 changed files with 40 additions and 0 deletions
+38
View File
@@ -9,6 +9,7 @@ use alloc::{sync::Arc, vec::Vec};
use hashbrown::HashMap;
use rmm::{Arch, BumpAllocator, MemoryArea, PhysicalAddress};
use spin::once::Once;
use syscall::{Error, Result, ENODATA, EOPNOTSUPP};
pub const MAX_DOMAINS: usize = 128;
@@ -184,3 +185,40 @@ pub fn nearest_preceding_memory_region(addr: usize, overlap: bool) -> Option<&'s
})
.max_by_key(|e| e.start)
}
pub fn get_numa_info(token: &mut CleanLockToken) -> Result<Vec<u8>> {
let cpu_info = NUMA_CPUS
.get()
.ok_or(Error::new(EOPNOTSUPP))?
.iter()
.map(|e| e.to_ne_bytes())
.flatten()
.collect::<Vec<u8>>();
let mem_info = NUMA_MEMORY
.get()
.ok_or(Error::new(EOPNOTSUPP))?
.iter()
.map(|e| {
[
e.start.to_ne_bytes(),
e.length.to_ne_bytes(),
(e.node_id as usize).to_ne_bytes(),
]
})
.flatten()
.flatten()
.collect::<Vec<u8>>();
let mut numa_info = Vec::new();
numa_info.extend(cpu_info);
numa_info.extend(mem_info);
Ok(numa_info)
}
pub fn get_numa_distance_info(token: &mut CleanLockToken) -> Result<Vec<u8>> {
Ok(DISTANCES
.get()
.ok_or(Error::new(ENODATA))?
.iter()
.map(|e| *e)
.collect())
}
+2
View File
@@ -76,6 +76,8 @@ const FILES: &[(&str, Kind)] = &[
("iostat", Rd(iostat::resource)),
("irq", Rd(irq::resource)),
("log", Rd(log::resource)),
("numa", Rd(crate::numa::get_numa_info)),
("numa_dist", Rd(crate::numa::get_numa_distance_info)),
("syscall", Rd(syscall::resource)),
("uname", Rd(uname::resource)),
("env", Rd(|_| Ok(Vec::from(crate::startup::init_env())))),