update lab1-8 codes and docs. now version is 0.2
This commit is contained in:
@@ -106,6 +106,22 @@ alloc_proc(void) {
|
||||
* uint32_t flags; // Process flag
|
||||
* char name[PROC_NAME_LEN + 1]; // Process name
|
||||
*/
|
||||
//LAB5 YOUR CODE : (update LAB4 steps)
|
||||
/*
|
||||
* below fields(add in LAB5) in proc_struct need to be initialized
|
||||
* uint32_t wait_state; // waiting state
|
||||
* struct proc_struct *cptr, *yptr, *optr; // relations between processes
|
||||
*/
|
||||
//LAB6 YOUR CODE : (update LAB5 steps)
|
||||
/*
|
||||
* below fields(add in LAB6) in proc_struct need to be initialized
|
||||
* struct run_queue *rq; // running queue contains Process
|
||||
* list_entry_t run_link; // the entry linked in run queue
|
||||
* int time_slice; // time slice for occupying the CPU
|
||||
* skew_heap_entry_t lab6_run_pool; // FOR LAB6 ONLY: the entry in the run pool
|
||||
* uint32_t lab6_stride; // FOR LAB6 ONLY: the current stride of the process
|
||||
* uint32_t lab6_priority; // FOR LAB6 ONLY: the priority of process, set by lab6_set_priority(uint32_t)
|
||||
*/
|
||||
//LAB8:EXERCISE2 YOUR CODE HINT:need add some code to init fs in proc_struct, ...
|
||||
}
|
||||
return proc;
|
||||
@@ -355,9 +371,10 @@ copy_thread(struct proc_struct *proc, uintptr_t esp, struct trapframe *tf) {
|
||||
proc->context.esp = (uintptr_t)(proc->tf);
|
||||
}
|
||||
|
||||
//copy_fs&put_fs function used by do_fork in LAB8
|
||||
//copy_files&put_files function used by do_fork in LAB8
|
||||
//copy the files_struct from current to proc
|
||||
static int
|
||||
copy_fs(uint32_t clone_flags, struct proc_struct *proc) {
|
||||
copy_files(uint32_t clone_flags, struct proc_struct *proc) {
|
||||
struct files_struct *filesp, *old_filesp = current->filesp;
|
||||
assert(old_filesp != NULL);
|
||||
|
||||
@@ -371,7 +388,7 @@ copy_fs(uint32_t clone_flags, struct proc_struct *proc) {
|
||||
goto bad_files_struct;
|
||||
}
|
||||
|
||||
if ((ret = dup_fs(filesp, old_filesp)) != 0) {
|
||||
if ((ret = dup_files(filesp, old_filesp)) != 0) {
|
||||
goto bad_dup_cleanup_fs;
|
||||
}
|
||||
|
||||
@@ -386,8 +403,9 @@ bad_files_struct:
|
||||
return ret;
|
||||
}
|
||||
|
||||
//decrease the ref_count of files, and if ref_count==0, then destroy files_struct
|
||||
static void
|
||||
put_fs(struct proc_struct *proc) {
|
||||
put_files(struct proc_struct *proc) {
|
||||
struct files_struct *filesp = proc->filesp;
|
||||
if (filesp != NULL) {
|
||||
if (files_count_dec(filesp) == 0) {
|
||||
@@ -435,6 +453,15 @@ do_fork(uint32_t clone_flags, uintptr_t stack, struct trapframe *tf) {
|
||||
// 5. insert proc_struct into hash_list && proc_list
|
||||
// 6. call wakup_proc to make the new child process RUNNABLE
|
||||
// 7. set ret vaule using child proc's pid
|
||||
|
||||
//LAB5 YOUR CODE : (update LAB4 steps)
|
||||
/* Some Functions
|
||||
* set_links: set the relation links of process. ALSO SEE: remove_links: lean the relation links of process
|
||||
* -------------------
|
||||
* update step 1: set child proc's parent to current process, make sure current process's wait_state is 0
|
||||
* update step 5: insert proc_struct into hash_list && proc_list, set the relation links of process
|
||||
*/
|
||||
|
||||
fork_out:
|
||||
return ret;
|
||||
|
||||
@@ -470,7 +497,7 @@ do_exit(int error_code) {
|
||||
}
|
||||
current->mm = NULL;
|
||||
}
|
||||
put_fs(current); //for LAB8
|
||||
put_files(current); //for LAB8
|
||||
current->state = PROC_ZOMBIE;
|
||||
current->exit_code = error_code;
|
||||
|
||||
@@ -787,7 +814,7 @@ init_main(void *arg) {
|
||||
}
|
||||
|
||||
size_t nr_free_pages_store = nr_free_pages();
|
||||
size_t slab_allocated_store = kallocated();
|
||||
size_t kernel_allocated_store = kallocated();
|
||||
|
||||
int pid = kernel_thread(user_main, NULL, 0);
|
||||
if (pid <= 0) {
|
||||
@@ -808,7 +835,7 @@ init_main(void *arg) {
|
||||
assert(list_next(&proc_list) == &(initproc->list_link));
|
||||
assert(list_prev(&proc_list) == &(initproc->list_link));
|
||||
assert(nr_free_pages_store == nr_free_pages());
|
||||
assert(slab_allocated_store == kallocated());
|
||||
assert(kernel_allocated_store == kallocated());
|
||||
cprintf("init check memory pass.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user