diff --git a/crate/process/src/process_manager.rs b/crate/process/src/process_manager.rs index 988d56d..9df6a69 100644 --- a/crate/process/src/process_manager.rs +++ b/crate/process/src/process_manager.rs @@ -138,7 +138,7 @@ impl ProcessManager { fn set_status(&self, pid: Pid, status: Status) { let mut proc_lock = self.procs[pid].lock(); let mut proc = proc_lock.as_mut().expect("process not exist"); - //info!("process {} {:?} -> {:?}", pid, proc.status, status); + trace!("process {} {:?} -> {:?}", pid, proc.status, status); { // limit the lifetime of scheduler let mut scheduler = self.scheduler.lock(); match (&proc.status, &status) { diff --git a/crate/process/src/processor.rs b/crate/process/src/processor.rs index c1432ca..9b56c48 100644 --- a/crate/process/src/processor.rs +++ b/crate/process/src/processor.rs @@ -68,6 +68,7 @@ impl Processor { /// Called by process running on this Processor. /// Yield and reschedule. pub fn yield_now(&self) { + trace!("yield start"); let inner = self.inner(); unsafe { inner.proc.as_mut().unwrap().1.switch_to(&mut *inner.loop_context); @@ -75,7 +76,7 @@ impl Processor { } pub fn pid(&self) -> Pid { - self.inner().proc.as_ref().unwrap().0 + self.inner().proc.as_ref().expect("pid should not be none").0 } pub fn context(&self) -> &Context { diff --git a/crate/process/src/thread.rs b/crate/process/src/thread.rs index 3742a21..a0e9048 100644 --- a/crate/process/src/thread.rs +++ b/crate/process/src/thread.rs @@ -149,6 +149,7 @@ impl JoinHandle { /// Waits for the associated thread to finish. pub fn join(self) -> Result { loop { + trace!("{} join", self.thread.pid); match processor().manager().get_status(self.thread.pid) { Some(Status::Exited(exit_code)) => { processor().manager().wait_done(current().id(), self.thread.pid); diff --git a/docs/OSTrain2018docs-g4/expr4/lcy-labguide.md b/docs/OSTrain2018docs-g4/expr4/lcy-labguide.md deleted file mode 100644 index e69de29..0000000 diff --git a/docs/OSTrain2018docs-g4/expr4/report.md b/docs/OSTrain2018docs-g4/expr4/report.md new file mode 100644 index 0000000..dd5a7c0 --- /dev/null +++ b/docs/OSTrain2018docs-g4/expr4/report.md @@ -0,0 +1,21 @@ +# Rust OS lab 教学lab实验的制作 功能完善文档 +## 0 添加注释 +我们小组对于kernel以及crate中绝大部分重要函数都进行了注释,表明了参数@param,简要功能@brief以及返回值@retval. + +此外对于部分代码中比较难以理解的部分和重点部分我们也进行了行内注释. + +## 1 内存管理 +@刘辰屹 + +## 2 进程管理与同步互斥 +@陈秋昊 + +## 3 文件系统 +@朱书聪 + +## 4 测试结果 +### 4.1 用户程序测试结果 +@刘辰屹 将最开始的RustOS版本与现在版本的用户程序运行结果进行对比 + +### 4.2 同步互斥测试结果 +@陈秋昊 diff --git a/kernel/src/fs.rs b/kernel/src/fs.rs index c90499d..025cdad 100644 --- a/kernel/src/fs.rs +++ b/kernel/src/fs.rs @@ -43,6 +43,9 @@ pub fn shell() { let layout = Layout::from_size_align(BUF_SIZE, 0x1000).unwrap(); let buf = unsafe{ slice::from_raw_parts_mut(alloc(layout), BUF_SIZE) }; // start interaction + use sync; + //sync::test::philosopher_using_mutex(); + //sync::test::philosopher_using_monitor(); loop { print!(">> "); diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index bcbde31..d959882 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -64,6 +64,9 @@ pub mod arch; pub fn kmain() -> ! { info!("Come into kmain"); +// sync::test::philosopher_using_mutex(); +// sync::test::philosopher_using_monitor(); +// sync::mpsc::test::test_all(); process::processor().run(); // thread::test::local_key(); diff --git a/kernel/src/memory.rs b/kernel/src/memory.rs index dc9cd40..d1aca52 100644 --- a/kernel/src/memory.rs +++ b/kernel/src/memory.rs @@ -123,6 +123,9 @@ pub fn page_fault_handler(addr: usize) -> bool { let id = memory_set_record().iter() .position(|x| unsafe{(*(x.clone() as *mut MemorySet)).get_page_table_mut().token() == ActivePageTable::token()}); let mut mmsets = memory_set_record(); + /*LAB3 EXERCISE 1: YOUR STUDENT NUMBER + * handle the frame deallocated + */ match id { Some(targetid) => { info!("get id from memroy set recorder."); @@ -154,9 +157,9 @@ pub fn page_fault_handler(addr: usize) -> bool { } }, }; + ////////////////////////////////////////////////////////////////////////////// - // Handle copy on write (not being used now) unsafe { ACTIVE_TABLE.force_unlock(); } if active_table().page_fault_handler(addr, || alloc_frame().unwrap()){ diff --git a/kernel/src/sync/test.rs b/kernel/src/sync/test.rs index 8ddb295..43a4615 100644 --- a/kernel/src/sync/test.rs +++ b/kernel/src/sync/test.rs @@ -92,6 +92,7 @@ fn philosopher(table: Arc) { let handles: Vec<_> = philosophers.into_iter().map(|p| { let table = table.clone(); + trace!("philosopher start"); thread::spawn(move || { for i in 0..5 { @@ -101,9 +102,10 @@ fn philosopher(table: Arc
) { } }) }).collect(); + trace!("philosopher starting finish"); for h in handles { - h.join().unwrap(); + h.join().expect("join expects some value"); } println!("philosophers dining end"); }