some todo changes

Este commit está contenido en:
google-labs-jules[bot]
2025-08-20 02:13:04 +00:00
cometido por ale
padre f9be9904fc
commit 9d37968084
Se han modificado 4 ficheros con 63 adiciones y 3 borrados

Ver fichero

@@ -267,6 +267,12 @@ pub fn write_str(s: &str) {
console.write_str(s);
}
/// Clear the console screen
pub fn clear() {
let mut console = CONSOLE.lock();
console.clear_screen();
}
struct ConsoleWriter<'a>(&'a mut Console);
impl Write for ConsoleWriter<'_> {

Ver fichero

@@ -90,10 +90,32 @@ impl SlabAllocator {
Err(Error::InvalidArgument)
}
}
pub fn stats(&self) -> (usize, usize, usize) {
let mut allocated_count = 0;
let mut allocated_bytes = 0;
for (_, size_class) in &self.allocated_blocks {
allocated_count += 1;
allocated_bytes += size_class;
}
let mut free_count = 0;
for (_, free_list) in &self.size_classes {
free_count += free_list.len();
}
(allocated_count, allocated_bytes, free_count)
}
}
static SLAB_ALLOCATOR: Spinlock<SlabAllocator> = Spinlock::new(SlabAllocator::new());
/// Get kmalloc statistics
pub fn get_stats() -> (usize, usize, usize) {
let allocator = SLAB_ALLOCATOR.lock();
allocator.stats()
}
/// Allocate kernel memory
pub fn kmalloc(size: usize) -> Result<*mut u8> {
// Increment performance counter

Ver fichero

@@ -128,10 +128,24 @@ impl VmallocAllocator {
self.next_addr = addr + size;
Ok(addr)
}
pub fn stats(&self) -> (usize, usize) {
let mut allocated_bytes = 0;
for (_, area) in &self.areas {
allocated_bytes += area.size;
}
(self.areas.len(), allocated_bytes)
}
}
static VMALLOC_ALLOCATOR: Spinlock<VmallocAllocator> = Spinlock::new(VmallocAllocator::new());
/// Get vmalloc statistics
pub fn get_stats() -> (usize, usize) {
let allocator = VMALLOC_ALLOCATOR.lock();
allocator.stats()
}
/// Allocate virtual memory
pub fn vmalloc(size: usize) -> Result<VirtAddr> {
let mut allocator = VMALLOC_ALLOCATOR.lock();

Ver fichero

@@ -231,8 +231,27 @@ impl KernelShell {
info!(" Total pages: {}", total);
info!(" Allocated pages: {}", allocated);
info!(" Free pages: {}", free);
info!(
" Memory usage: {} / {} KB",
(allocated * 4096) / 1024,
(total * 4096) / 1024
);
// TODO: Add more memory statistics (kmalloc, vmalloc, etc.)
let (kmalloc_alloc_count, kmalloc_alloc_bytes, kmalloc_free_count) =
crate::memory::kmalloc::get_stats();
info!("\nKmalloc (slab) statistics:");
info!(
" Allocated: {} blocks ({} bytes)",
kmalloc_alloc_count, kmalloc_alloc_bytes
);
info!(" Free: {} blocks", kmalloc_free_count);
let (vmalloc_areas, vmalloc_bytes) = crate::memory::vmalloc::get_stats();
info!("\nVmalloc statistics:");
info!(
" Allocated: {} areas ({} bytes)",
vmalloc_areas, vmalloc_bytes
);
}
/// Process command
@@ -258,8 +277,7 @@ impl KernelShell {
/// Clear command
fn cmd_clear(&self) {
// TODO: Clear console screen
info!("Clear screen not implemented yet");
crate::console::clear();
}
/// Network command