forktree worked with depth=3 on k210 platform.

This commit is contained in:
Yifan Wu 2020-12-11 16:14:14 +08:00
parent 244c0ee84d
commit 84b10893d4
6 changed files with 62 additions and 17 deletions

View file

@ -212,7 +212,7 @@ impl MemorySet {
pub fn translate(&self, vpn: VirtPageNum) -> Option<PageTableEntry> {
self.page_table.translate(vpn)
}
pub fn clear(&mut self) {
pub fn recycle_data_pages(&mut self) {
//*self = Self::new_bare();
self.areas.clear();
}

View file

@ -1,5 +1,5 @@
use crate::mm::translated_byte_buffer;
use crate::task::{current_user_token};
use crate::task::{current_user_token, suspend_current_and_run_next};
use crate::sbi::console_getchar;
const FD_STDIN: usize = 0;
@ -28,7 +28,7 @@ pub fn sys_read(fd: usize, buf: *const u8, len: usize) -> isize {
loop {
c = console_getchar();
if c == 0 {
//suspend_current_and_run_next();
suspend_current_and_run_next();
continue;
} else {
break;

View file

@ -10,6 +10,7 @@ use switch::__switch;
use task::{TaskControlBlock, TaskStatus};
use alloc::sync::Arc;
use manager::fetch_task;
use lazy_static::*;
pub use context::TaskContext;
pub use processor::{
@ -51,22 +52,20 @@ pub fn exit_current_and_run_next(exit_code: i32) {
inner.task_status = TaskStatus::Zombie;
// Record exit code
inner.exit_code = exit_code;
// move any child to its parent
// TODO: do not move to its parent but under initproc
// do not move to its parent but under initproc
// ++++++ hold parent PCB lock here
// ++++++ hold initproc PCB lock here
{
let parent = inner.parent.as_ref().unwrap().upgrade().unwrap();
let mut parent_inner = parent.acquire_inner_lock();
let mut initproc_inner = INITPROC.acquire_inner_lock();
for child in inner.children.iter() {
parent_inner.children.push(child.clone());
initproc_inner.children.push(child.clone());
}
}
// ++++++ release parent PCB lock here
inner.children.clear();
// deallocate user space
inner.memory_set.clear();
inner.memory_set.recycle_data_pages();
drop(inner);
// **** release current PCB lock
// drop task manually to maintain rc correctly
@ -76,7 +75,12 @@ pub fn exit_current_and_run_next(exit_code: i32) {
schedule(&_unused as *const _);
}
pub fn add_initproc() {
let data = get_app_data_by_name("initproc").unwrap();
add_task(Arc::new(TaskControlBlock::new(data)));
lazy_static! {
pub static ref INITPROC: Arc<TaskControlBlock> = Arc::new(
TaskControlBlock::new(get_app_data_by_name("initproc").unwrap())
);
}
pub fn add_initproc() {
add_task(INITPROC.clone());
}