some todo changes
Este commit está contenido en:
@@ -267,6 +267,12 @@ pub fn write_str(s: &str) {
|
|||||||
console.write_str(s);
|
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);
|
struct ConsoleWriter<'a>(&'a mut Console);
|
||||||
|
|
||||||
impl Write for ConsoleWriter<'_> {
|
impl Write for ConsoleWriter<'_> {
|
||||||
|
|||||||
@@ -90,10 +90,32 @@ impl SlabAllocator {
|
|||||||
Err(Error::InvalidArgument)
|
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());
|
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
|
/// Allocate kernel memory
|
||||||
pub fn kmalloc(size: usize) -> Result<*mut u8> {
|
pub fn kmalloc(size: usize) -> Result<*mut u8> {
|
||||||
// Increment performance counter
|
// Increment performance counter
|
||||||
|
|||||||
@@ -128,10 +128,24 @@ impl VmallocAllocator {
|
|||||||
self.next_addr = addr + size;
|
self.next_addr = addr + size;
|
||||||
Ok(addr)
|
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());
|
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
|
/// Allocate virtual memory
|
||||||
pub fn vmalloc(size: usize) -> Result<VirtAddr> {
|
pub fn vmalloc(size: usize) -> Result<VirtAddr> {
|
||||||
let mut allocator = VMALLOC_ALLOCATOR.lock();
|
let mut allocator = VMALLOC_ALLOCATOR.lock();
|
||||||
|
|||||||
@@ -231,8 +231,27 @@ impl KernelShell {
|
|||||||
info!(" Total pages: {}", total);
|
info!(" Total pages: {}", total);
|
||||||
info!(" Allocated pages: {}", allocated);
|
info!(" Allocated pages: {}", allocated);
|
||||||
info!(" Free pages: {}", free);
|
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
|
/// Process command
|
||||||
@@ -258,8 +277,7 @@ impl KernelShell {
|
|||||||
|
|
||||||
/// Clear command
|
/// Clear command
|
||||||
fn cmd_clear(&self) {
|
fn cmd_clear(&self) {
|
||||||
// TODO: Clear console screen
|
crate::console::clear();
|
||||||
info!("Clear screen not implemented yet");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Network command
|
/// Network command
|
||||||
|
|||||||
Referencia en una nueva incidencia
Block a user