mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-24 10:26:25 +04:00
add more runtime info
This commit is contained in:
parent
863e61edbc
commit
e7084e4a96
@ -157,7 +157,7 @@ impl TaskUserRes {
|
||||
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");
|
||||
kprintln!("[KERN] task::id::TaskUserRes::alloc_user_res(): alloc user stack for TCB");
|
||||
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(
|
||||
@ -166,7 +166,7 @@ impl TaskUserRes {
|
||||
MapPermission::R | MapPermission::W | MapPermission::U,
|
||||
);
|
||||
// alloc trap_cx
|
||||
kprintln!("[KERN] task::id::TaskUserRes::alloc_user_res(): alloc trap_cx");
|
||||
kprintln!("[KERN] task::id::TaskUserRes::alloc_user_res(): alloc trap_cx for TCB");
|
||||
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(
|
||||
|
@ -134,9 +134,10 @@ impl ProcessControlBlock {
|
||||
let mut process_inner = process.inner_exclusive_access();
|
||||
process_inner.tasks.push(Some(Arc::clone(&task)));
|
||||
drop(process_inner);
|
||||
kprintln!("[KERN] task::process::new(): insert <pid, PCB> in PID2PCB BTreeMap");
|
||||
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");
|
||||
kprintln!("[KERN] task::process::new(): add_task(task): add main thread to scheduler");
|
||||
add_task(task);
|
||||
kprintln!("[KERN] task::process::new() end");
|
||||
process
|
||||
@ -203,10 +204,13 @@ impl ProcessControlBlock {
|
||||
let mut parent = self.inner_exclusive_access();
|
||||
assert_eq!(parent.thread_count(), 1);
|
||||
// clone parent's memory_set completely including trampoline/ustacks/trap_cxs
|
||||
kprintln!("[KERN] task::process::fork(): clone parent's memory_set for child");
|
||||
let memory_set = MemorySet::from_existed_user(&parent.memory_set);
|
||||
// alloc a pid
|
||||
kprintln!("[KERN] task::process::fork(): alloc a new pid for child");
|
||||
let pid = pid_alloc();
|
||||
// copy fd table
|
||||
kprintln!("[KERN] task::process::fork(): copy fd table for child");
|
||||
let mut new_fd_table: Vec<Option<Arc<dyn File + Send + Sync>>> = Vec::new();
|
||||
for fd in parent.fd_table.iter() {
|
||||
if let Some(file) = fd {
|
||||
@ -216,6 +220,7 @@ impl ProcessControlBlock {
|
||||
}
|
||||
}
|
||||
// create child process pcb
|
||||
kprintln!("[KERN] task::process::fork(): new child PCB with new pid, memory_set, fd_table, ...");
|
||||
let child = Arc::new(Self {
|
||||
pid,
|
||||
inner: unsafe {
|
||||
@ -236,8 +241,10 @@ impl ProcessControlBlock {
|
||||
},
|
||||
});
|
||||
// add child
|
||||
kprintln!("[KERN] task::process::fork(): add child link in parent' children Vec");
|
||||
parent.children.push(Arc::clone(&child));
|
||||
// create main thread of child process
|
||||
kprintln!("[KERN] task::process::fork(): TaskControlBlock::new(): create main thread of child process");
|
||||
let task = Arc::new(TaskControlBlock::new(
|
||||
Arc::clone(&child),
|
||||
parent
|
||||
@ -252,16 +259,20 @@ impl ProcessControlBlock {
|
||||
false,
|
||||
));
|
||||
// attach task to child process
|
||||
kprintln!("[KERN] task::process::fork(): attach child TCB to child PCB");
|
||||
let mut child_inner = child.inner_exclusive_access();
|
||||
child_inner.tasks.push(Some(Arc::clone(&task)));
|
||||
drop(child_inner);
|
||||
// modify kstack_top in trap_cx of this thread
|
||||
kprintln!("[KERN] task::process::fork(): modify child's kstack_top in trap_cx of child");
|
||||
let task_inner = task.inner_exclusive_access();
|
||||
let trap_cx = task_inner.get_trap_cx();
|
||||
trap_cx.kernel_sp = task.kstack.get_top();
|
||||
drop(task_inner);
|
||||
kprintln!("[KERN] task::process::fork(): insert <child pid, child PCB> in PID2PCB BTreeMap");
|
||||
insert_into_pid2process(child.getpid(), Arc::clone(&child));
|
||||
// add this thread to scheduler
|
||||
kprintln!("[KERN] task::process::fork(): add_task(child task): add child thread to scheduler");
|
||||
add_task(task);
|
||||
kprintln!("[KERN] task::process::fork() end");
|
||||
child
|
||||
|
@ -52,6 +52,7 @@ impl TaskControlBlock {
|
||||
kprintln!("[KERN] TaskControlBlock::new() begin");
|
||||
let res = TaskUserRes::new(Arc::clone(&process), ustack_base, alloc_user_res);
|
||||
let trap_cx_ppn = res.trap_cx_ppn();
|
||||
kprintln!("[KERN] TaskControlBlock::new(): alloc kernel stack for TCB");
|
||||
let kstack = kstack_alloc();
|
||||
let kstack_top = kstack.get_top();
|
||||
kprintln!("[KERN] TaskControlBlock::new() end");
|
||||
|
Loading…
Reference in New Issue
Block a user