add more runtime info

ch9-log
Yu Chen 3 years ago
parent 26404b4a0d
commit 863e61edbc

@ -10,7 +10,10 @@ use crate::fs::easy_fs::BlockDevice;
use lazy_static::*;
lazy_static! {
pub static ref BLOCK_DEVICE: Arc<dyn BlockDevice> = Arc::new(BlockDeviceImpl::new());
pub static ref BLOCK_DEVICE: Arc<dyn BlockDevice> = {
kprintln!("[KERN] drivers::block::lazy_static!BLOCK_DEVICE begin");
Arc::new(BlockDeviceImpl::new())
};
}
#[allow(unused)]

@ -20,7 +20,10 @@ pub struct VirtIOBlock {
}
lazy_static! {
static ref QUEUE_FRAMES: UPIntrFreeCell<Vec<FrameTracker>> = unsafe { UPIntrFreeCell::new(Vec::new()) };
static ref QUEUE_FRAMES: UPIntrFreeCell<Vec<FrameTracker>> = {
kprintln!("[KERN] drivers::block::virtio_blk::lazy_static!QUEUE_FRAMES begin");
unsafe { UPIntrFreeCell::new(Vec::new()) }
};
}
impl BlockDevice for VirtIOBlock {

@ -13,5 +13,8 @@ pub trait CharDevice {
}
lazy_static! {
pub static ref UART: Arc<CharDeviceImpl> = Arc::new(CharDeviceImpl::new());
pub static ref UART: Arc<CharDeviceImpl> = {
kprintln!("[KERN] drivers::chardev::lazy_static!UART begin");
Arc::new(CharDeviceImpl::new())
};
}

@ -121,8 +121,10 @@ impl BlockCacheManager {
}
lazy_static! {
pub static ref BLOCK_CACHE_MANAGER: Mutex<BlockCacheManager> =
Mutex::new(BlockCacheManager::new());
pub static ref BLOCK_CACHE_MANAGER: Mutex<BlockCacheManager> = {
kprintln!("[KERN EASYFS] block_cache::lazy_static!BLOCK_CACHE_MANAGER begin");
Mutex::new(BlockCacheManager::new())
};
}
pub fn get_block_cache(

@ -32,7 +32,7 @@ impl Inode {
}
fn read_disk_inode<V>(&self, f: impl FnOnce(&DiskInode) -> V) -> V {
//kprintln!("[KERN EASYFS] vfs::Inode::read_disk_inode() begin");
kprintln!("[KERN EASYFS] vfs::Inode::read_disk_inode() begin");
get_block_cache(self.block_id, Arc::clone(&self.block_device))
.lock()
.read(self.block_offset, f)
@ -166,7 +166,7 @@ impl Inode {
}
pub fn read_at(&self, offset: usize, buf: &mut [u8]) -> usize {
//kprintln!("[KERN EASYFS] vfs::Inode::read_at() begin");
kprintln!("[KERN EASYFS] vfs::Inode::read_at() begin");
let _fs = self.fs.lock();
self.read_disk_inode(|disk_inode| disk_inode.read_at(offset, buf, &self.block_device))
}

@ -21,6 +21,7 @@ pub struct OSInodeInner {
impl OSInode {
pub fn new(readable: bool, writable: bool, inode: Arc<Inode>) -> Self {
kprintln!("[KERN] fs::inode::OSInode::new() begin");
Self {
readable,
writable,
@ -28,6 +29,7 @@ impl OSInode {
}
}
pub fn read_all(&self) -> Vec<u8> {
kprintln!("[KERN] fs::inode::OSInode::read_all() begin");
let mut inner = self.inner.exclusive_access();
let mut buffer = [0u8; 512];
let mut v: Vec<u8> = Vec::new();
@ -45,6 +47,7 @@ impl OSInode {
lazy_static! {
pub static ref ROOT_INODE: Arc<Inode> = {
kprintln!("[KERN] fs::inode::lazy_static!ROOT_INODE begin");
let efs = EasyFileSystem::open(BLOCK_DEVICE.clone());
Arc::new(EasyFileSystem::root_inode(&efs))
};
@ -114,7 +117,7 @@ impl File for OSInode {
self.writable
}
fn read(&self, mut buf: UserBuffer) -> usize {
kprintln!("[KERN] fs::inode::read() begin");
kprintln!("[KERN] fs::inode::OSInode<FIle>::read() begin");
let mut inner = self.inner.exclusive_access();
let mut total_read_size = 0usize;
for slice in buf.buffers.iter_mut() {
@ -125,11 +128,11 @@ impl File for OSInode {
inner.offset += read_size;
total_read_size += read_size;
}
kprintln!("[KERN] fs::inode::read() end");
kprintln!("[KERN] fs::inode::OSInode<FIle>::read() end");
total_read_size
}
fn write(&self, buf: UserBuffer) -> usize {
kprintln!("[KERN] fs::inode::write() begin");
kprintln!("[KERN] fs::inode::OSInode<FIle>::write() begin");
let mut inner = self.inner.exclusive_access();
let mut total_write_size = 0usize;
for slice in buf.buffers.iter() {
@ -138,7 +141,7 @@ impl File for OSInode {
inner.offset += write_size;
total_write_size += write_size;
}
kprintln!("[KERN] fs::inode::write() end");
kprintln!("[KERN] fs::inode::OSInode<FIle>::write() end");
total_write_size
}
}

@ -50,7 +50,10 @@ use lazy_static::*;
use sync::UPIntrFreeCell;
lazy_static! {
pub static ref DEV_NON_BLOCKING_ACCESS: UPIntrFreeCell<bool> = unsafe { UPIntrFreeCell::new(false) };
pub static ref DEV_NON_BLOCKING_ACCESS: UPIntrFreeCell<bool> = {
kprintln!("[KERN] main::lazy_static!DEV_NON_BLOCKING_ACCESS begin");
unsafe { UPIntrFreeCell::new(false) }
};
}
#[no_mangle]

@ -83,8 +83,10 @@ impl FrameAllocator for StackFrameAllocator {
type FrameAllocatorImpl = StackFrameAllocator;
lazy_static! {
pub static ref FRAME_ALLOCATOR: UPIntrFreeCell<FrameAllocatorImpl> =
unsafe { UPIntrFreeCell::new(FrameAllocatorImpl::new()) };
pub static ref FRAME_ALLOCATOR: UPIntrFreeCell<FrameAllocatorImpl> ={
kprintln!("[KERN] mm::frame_allocator::lazy_static!FRAME_ALLOCATOR begin");
unsafe { UPIntrFreeCell::new(FrameAllocatorImpl::new()) }
};
}
pub fn init_frame_allocator() {

@ -25,8 +25,10 @@ extern "C" {
}
lazy_static! {
pub static ref KERNEL_SPACE: Arc<UPIntrFreeCell<MemorySet>> =
Arc::new(unsafe { UPIntrFreeCell::new(MemorySet::new_kernel()) });
pub static ref KERNEL_SPACE: Arc<UPIntrFreeCell<MemorySet>> ={
kprintln!("[KERN] mm::memory_set::lazy_static!KERNEL_SPACE begin");
Arc::new(unsafe { UPIntrFreeCell::new(MemorySet::new_kernel()) })
};
}
pub fn kernel_token() -> usize {

@ -57,6 +57,7 @@ pub struct IntrMaskingInfo {
lazy_static! {
static ref INTR_MASKING_INFO: UPSafeCellRaw<IntrMaskingInfo> = unsafe {
kprintln!("[KERN] sync::up::lazy_static!INTR_MASKING_INFO begin");
UPSafeCellRaw::new(IntrMaskingInfo::new())
};
}

@ -40,10 +40,17 @@ impl RecycleAllocator {
}
lazy_static! {
static ref PID_ALLOCATOR: UPIntrFreeCell<RecycleAllocator> =
unsafe { UPIntrFreeCell::new(RecycleAllocator::new()) };
static ref KSTACK_ALLOCATOR: UPIntrFreeCell<RecycleAllocator> =
unsafe { UPIntrFreeCell::new(RecycleAllocator::new()) };
static ref PID_ALLOCATOR: UPIntrFreeCell<RecycleAllocator> = {
kprintln!("[KERN] task::id::lazy_static!PID_ALLOCATOR begin");
unsafe { UPIntrFreeCell::new(RecycleAllocator::new()) }
};
}
lazy_static! {
static ref KSTACK_ALLOCATOR: UPIntrFreeCell<RecycleAllocator> ={
kprintln!("[KERN] task::id::lazy_static!KSTACK_ALLOCATOR begin");
unsafe { UPIntrFreeCell::new(RecycleAllocator::new()) }
};
}
pub struct PidHandle(pub usize);
@ -60,14 +67,17 @@ impl Drop for PidHandle {
/// Return (bottom, top) of a kernel stack in kernel space.
pub fn kernel_stack_position(kstack_id: usize) -> (usize, usize) {
kprintln!("[KERN] task::id::kernel_stack_position() begin");
let top = TRAMPOLINE - kstack_id * (KERNEL_STACK_SIZE + PAGE_SIZE);
let bottom = top - KERNEL_STACK_SIZE;
kprintln!("[KERN] task::id::kernel_stack_position() end");
(bottom, top)
}
pub struct KernelStack(pub usize);
pub fn kstack_alloc() -> KernelStack {
kprintln!("[KERN] task::id::kstack_alloc() begin");
let kstack_id = KSTACK_ALLOCATOR.exclusive_access().alloc();
let (kstack_bottom, kstack_top) = kernel_stack_position(kstack_id);
KERNEL_SPACE.exclusive_access().insert_framed_area(
@ -75,6 +85,7 @@ pub fn kstack_alloc() -> KernelStack {
kstack_top.into(),
MapPermission::R | MapPermission::W,
);
kprintln!("[KERN] task::id::kstack_alloc() end");
KernelStack(kstack_id)
}
@ -127,6 +138,7 @@ impl TaskUserRes {
ustack_base: usize,
alloc_user_res: bool,
) -> Self {
kprintln!("[KERN] task::id::TaskUserRes::new() begin");
let tid = process.inner_exclusive_access().alloc_tid();
let task_user_res = Self {
tid,
@ -136,13 +148,16 @@ impl TaskUserRes {
if alloc_user_res {
task_user_res.alloc_user_res();
}
kprintln!("[KERN] task::id::TaskUserRes::new() end");
task_user_res
}
pub fn alloc_user_res(&self) {
kprintln!("[KERN] task::id::TaskUserRes::alloc_user_res() begin");
let process = self.process.upgrade().unwrap();
let mut process_inner = process.inner_exclusive_access();
// alloc user stack
kprintln!("[KERN] task::id::TaskUserRes::alloc_user_res(): alloc user stack");
let ustack_bottom = ustack_bottom_from_tid(self.ustack_base, self.tid);
let ustack_top = ustack_bottom + USER_STACK_SIZE;
process_inner.memory_set.insert_framed_area(
@ -151,6 +166,7 @@ impl TaskUserRes {
MapPermission::R | MapPermission::W | MapPermission::U,
);
// alloc trap_cx
kprintln!("[KERN] task::id::TaskUserRes::alloc_user_res(): alloc trap_cx");
let trap_cx_bottom = trap_cx_bottom_from_tid(self.tid);
let trap_cx_top = trap_cx_bottom + PAGE_SIZE;
process_inner.memory_set.insert_framed_area(
@ -158,22 +174,29 @@ impl TaskUserRes {
trap_cx_top.into(),
MapPermission::R | MapPermission::W,
);
kprintln!("[KERN] task::id::TaskUserRes::alloc_user_res() end");
}
fn dealloc_user_res(&self) {
kprintln!("[KERN] task::id::TaskUserRes::dealloc_user_res() begin");
// dealloc tid
kprintln!("[KERN] task::id::TaskUserRes::dealloc_user_res(): dealloc tid");
let process = self.process.upgrade().unwrap();
let mut process_inner = process.inner_exclusive_access();
// dealloc ustack manually
kprintln!("[KERN] task::id::TaskUserRes::dealloc_user_res(): dealloc ustack manually");
let ustack_bottom_va: VirtAddr = ustack_bottom_from_tid(self.ustack_base, self.tid).into();
process_inner
.memory_set
.remove_area_with_start_vpn(ustack_bottom_va.into());
// dealloc trap_cx manually
kprintln!("[KERN] task::id::TaskUserRes::dealloc_user_res(): dealloc trap_cx manually");
let trap_cx_bottom_va: VirtAddr = trap_cx_bottom_from_tid(self.tid).into();
process_inner
.memory_set
.remove_area_with_start_vpn(trap_cx_bottom_va.into());
kprintln!("[KERN] task::id::TaskUserRes::dealloc_user_res() end");
}
#[allow(unused)]

@ -24,10 +24,17 @@ impl TaskManager {
}
lazy_static! {
pub static ref TASK_MANAGER: UPIntrFreeCell<TaskManager> =
unsafe { UPIntrFreeCell::new(TaskManager::new()) };
pub static ref PID2PCB: UPIntrFreeCell<BTreeMap<usize, Arc<ProcessControlBlock>>> =
unsafe { UPIntrFreeCell::new(BTreeMap::new()) };
pub static ref TASK_MANAGER: UPIntrFreeCell<TaskManager> ={
kprintln!("[KERN] task::manager::lazy_static!TASK_MANAGER begin");
unsafe { UPIntrFreeCell::new(TaskManager::new()) }
};
}
lazy_static! {
pub static ref PID2PCB: UPIntrFreeCell<BTreeMap<usize, Arc<ProcessControlBlock>>> ={
kprintln!("[KERN] task::manager::lazy_static!PID2PCB begin");
unsafe { UPIntrFreeCell::new(BTreeMap::new()) }
};
}
pub fn add_task(task: Arc<TaskControlBlock>) {

@ -74,9 +74,12 @@ impl ProcessControlBlock {
pub fn new(elf_data: &[u8]) -> Arc<Self> {
// memory_set with elf program headers/trampoline/trap context/user stack
kprintln!("[KERN] task::process::new() begin");
kprintln!("[KERN] task::process::new(): build MemorySet, set user_stack_base, set entry_point");
let (memory_set, ustack_base, entry_point) = MemorySet::from_elf(elf_data);
// allocate a pid
kprintln!("[KERN] task::process::new(): allocate a pid");
let pid_handle = pid_alloc();
kprintln!("[KERN] task::process::new(): new ProcessControlBlockInner");
let process = Arc::new(Self {
pid: pid_handle,
inner: unsafe {
@ -104,12 +107,15 @@ impl ProcessControlBlock {
},
});
// create a main thread, we should allocate ustack and trap_cx here
kprintln!("[KERN] task::process::new(): create a main thread begin");
kprintln!("[KERN] task::process::new(): create a main thread: new TCB(alloc kstack, utack & trap_cx...) ");
let task = Arc::new(TaskControlBlock::new(
Arc::clone(&process),
ustack_base,
true,
));
// prepare trap_cx of main thread
kprintln!("[KERN] task::process::new(): create a main thread: set trap_cx(entry_point, ustack_top, k_satp, k_sp, trap_handler) ");
let task_inner = task.inner_exclusive_access();
let trap_cx = task_inner.get_trap_cx();
let ustack_top = task_inner.res.as_ref().unwrap().ustack_top();
@ -122,12 +128,15 @@ impl ProcessControlBlock {
kstack_top,
trap_handler as usize,
);
kprintln!("[KERN] task::process::new(): create a main thread end");
// add main thread to the process
kprintln!("[KERN] task::process::new(): add main thread to the process");
let mut process_inner = process.inner_exclusive_access();
process_inner.tasks.push(Some(Arc::clone(&task)));
drop(process_inner);
insert_into_pid2process(process.getpid(), Arc::clone(&process));
// add main thread to scheduler
kprintln!("[KERN] task::process::new(): add_task(task): add main thread to tscheduler");
add_task(task);
kprintln!("[KERN] task::process::new() end");
process

@ -30,7 +30,10 @@ impl Processor {
}
lazy_static! {
pub static ref PROCESSOR: UPIntrFreeCell<Processor> = unsafe { UPIntrFreeCell::new(Processor::new()) };
pub static ref PROCESSOR: UPIntrFreeCell<Processor> = {
kprintln!("[KERN] task::processor::lazy_static!PROCESSOR begin");
unsafe { UPIntrFreeCell::new(Processor::new()) }
};
}
pub fn run_tasks() {

@ -52,8 +52,10 @@ impl Ord for TimerCondVar {
}
lazy_static! {
static ref TIMERS: UPIntrFreeCell<BinaryHeap<TimerCondVar>> =
unsafe { UPIntrFreeCell::new(BinaryHeap::<TimerCondVar>::new()) };
static ref TIMERS: UPIntrFreeCell<BinaryHeap<TimerCondVar>> ={
kprintln!("[KERN] timer::lazy_static!TIMERS begin");
unsafe { UPIntrFreeCell::new(BinaryHeap::<TimerCondVar>::new()) }
};
}
pub fn add_timer(expire_ms: usize, task: Arc<TaskControlBlock>) {

Loading…
Cancel
Save