diff --git a/os/src/task/id.rs b/os/src/task/id.rs index cfb50367..4eec31ed 100644 --- a/os/src/task/id.rs +++ b/os/src/task/id.rs @@ -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( diff --git a/os/src/task/process.rs b/os/src/task/process.rs index c881c59a..08ca3104 100644 --- a/os/src/task/process.rs +++ b/os/src/task/process.rs @@ -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 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>> = 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 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 diff --git a/os/src/task/task.rs b/os/src/task/task.rs index 07127bd4..b01f68bf 100644 --- a/os/src/task/task.rs +++ b/os/src/task/task.rs @@ -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");