练习0
填写已有实验
本实验依赖实验1~实验5.请把已做的实验2~实验5的代码填入本实验中代码中有lab1、lab2、lab3、lab4、lab5的注释相应部分,并确保编译通过。注意:为了能够正确执行lab6的测试应用程序,可能需对已完成的实验1~实验5的代码进一步改进
发现缺失的是kdebug.c、trap.c、default_pmm.c、pmm.c、swap_fifo.c、vmm.c、proc.c
七个文件的相关代码,补全后发现部分文件还需要更改部分代码
lab6的整体思想
根据整体思想,结合注释的提示,主要是一下两个函数需要额外加以修改。
alloc_proc函数
这里alloc_proc
还需要修改一下,完整的代码如下:
// alloc_proc - alloc a proc_struct and init all fields of proc_struct
static struct proc_struct *
alloc_proc(void) {
struct proc_struct *proc = kmalloc(sizeof(struct proc_struct));
if (proc != NULL) {
//LAB4:EXERCISE1 YOUR CODE
/*
* below fields in proc_struct need to be initialized
* enum proc_state state; // Process state
* int pid; // Process ID
* int runs; // the running times of Proces
* uintptr_t kstack; // Process kernel stack
* volatile bool need_resched; // bool value: need to be rescheduled to release CPU?
* struct proc_struct *parent; // the parent process
* struct mm_struct *mm; // Process's memory management field
* struct context context; // Switch here to run process
* struct trapframe *tf; // Trap frame for current interrupt
* uintptr_t cr3; // CR3 register: the base addr of Page Directroy Table(PDT)
* 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)
*/
proc->state = PROC_UNINIT;//设置进程为未初始化状态
proc->pid = -1; //未初始化的进程id=-1
proc->runs = 0; //初始化时间片
proc->kstack = 0; //初始化内存栈的地址
proc->need_resched = 0; //是否需要调度设为不需要
proc->parent = NULL; //置空父节点
proc->mm = NULL; //置空虚拟内存
memset(&(proc->context), 0, sizeof(struct context));//初始化上下文
proc->tf = NULL; //中断帧指针设置为空
proc->cr3 = boot_cr3; //页目录设为内核页目录表的基址
proc->flags = 0;