From e3a80a1223e12203327b26e6a50da52c0c0bf371 Mon Sep 17 00:00:00 2001 From: WangRunji Date: Fri, 13 Jul 2018 01:45:16 +0800 Subject: [PATCH] Better some logging --- src/arch/riscv32/paging.rs | 6 +++--- src/memory.rs | 5 ++++- src/process/processor.rs | 2 +- src/thread.rs | 5 +++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/arch/riscv32/paging.rs b/src/arch/riscv32/paging.rs index a07fa18..c1b23a5 100644 --- a/src/arch/riscv32/paging.rs +++ b/src/arch/riscv32/paging.rs @@ -175,7 +175,7 @@ impl InactivePageTable for InactivePageTable0 { unsafe fn activate(&self) { let old_frame = satp::read().frame(); let new_frame = self.p2_frame.clone(); - debug!("switch table {:?} -> {:?}", old_frame, new_frame); + debug!("switch table {:x?} -> {:x?}", old_frame, new_frame); if old_frame != new_frame { satp::set(satp::Mode::Sv32, 0, new_frame); sfence_vma_all(); @@ -185,13 +185,13 @@ impl InactivePageTable for InactivePageTable0 { unsafe fn with(&self, f: impl FnOnce()) { let old_frame = satp::read().frame(); let new_frame = self.p2_frame.clone(); - debug!("switch table {:?} -> {:?}", old_frame, new_frame); + debug!("switch table {:x?} -> {:x?}", old_frame, new_frame); if old_frame != new_frame { satp::set(satp::Mode::Sv32, 0, new_frame); sfence_vma_all(); } f(); - debug!("switch table {:?} -> {:?}", new_frame, old_frame); + debug!("switch table {:x?} -> {:x?}", new_frame, old_frame); if old_frame != new_frame { satp::set(satp::Mode::Sv32, 0, old_frame); sfence_vma_all(); diff --git a/src/memory.rs b/src/memory.rs index 54735d5..a2dc902 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -14,10 +14,13 @@ lazy_static! { } pub fn alloc_frame() -> Option { - FRAME_ALLOCATOR.lock().alloc().map(|id| id * PAGE_SIZE + MEMORY_OFFSET) + let ret = FRAME_ALLOCATOR.lock().alloc().map(|id| id * PAGE_SIZE + MEMORY_OFFSET); + trace!("Allocate frame: {:x?}", ret); + ret } pub fn dealloc_frame(target: usize) { + trace!("Deallocate frame: {:x}", target); FRAME_ALLOCATOR.lock().dealloc((target - MEMORY_OFFSET) / PAGE_SIZE); } diff --git a/src/process/processor.rs b/src/process/processor.rs index 98081a7..140a370 100644 --- a/src/process/processor.rs +++ b/src/process/processor.rs @@ -131,7 +131,7 @@ impl Processor { to.status = Status::Running; self.scheduler.remove(pid); - info!("switch from {} to {}\n rsp: ??? -> {:?}", pid0, pid, to.context); + info!("switch from {} to {} {:x?}", pid0, pid, to.context); unsafe { // FIXME: safely pass MutexGuard use core::mem::forget; diff --git a/src/thread.rs b/src/thread.rs index 3a19637..b3749d4 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -20,10 +20,11 @@ pub fn current() -> Thread { /// Puts the current thread to sleep for the specified amount of time. pub fn sleep(dur: Duration) { - info!("sleep: {:?}", dur); + let time = dur_to_ticks(dur); + info!("sleep: {:?} ticks", time); let mut processor = PROCESSOR.try().unwrap().lock(); let pid = processor.current_pid(); - processor.sleep(pid, dur_to_ticks(dur)); + processor.sleep(pid, time); processor.schedule(); fn dur_to_ticks(dur: Duration) -> usize {