MIT 6.1810: page tables
MIT 6.1810 中第三个 lab 的 solution
page tables
Speed up system calls (easy)
When each process is created, map one read-only page at USYSCALL (a virtual address defined in memlayout.h). At the start of this page, store a struct usyscall (also defined in memlayout.h), and initialize it to store the PID of the current process. For this lab, ugetpid() has been provided on the userspace side and will automatically use the USYSCALL mapping. You will receive full credit for this part of the lab if the ugetpid test case passes when running pgtbltest.
在kernel/proc.h中的proc结构体定义中新增一个变量:
|
|
在kernel/proc.c中的allocproc函数分配trapframe页的下面加上:
|
|
|
|
记得还得在freeproc中加上对应的free处理:
|
|
在proc_pagetable函数中添加分配USYSCALL页的处理逻辑。
|
|
在proc_freepagetable也加上对应的处理逻辑:
|
|
这些照着前面抄就完了()
Print a page table (easy)
Define a function called vmprint(). It should take a pagetable_t argument, and print that pagetable in the format described below. Insert if(p->pid==1) vmprint(p->pagetable) in exec.c just before the return argc, to print the first process’s page table. You receive full credit for this part of the lab if you pass the pte printout test of make grade.
|
|
Detect which pages have been accessed (hard)
Your job is to implement pgaccess(), a system call that reports which pages have been accessed. The system call takes three arguments. First, it takes the starting virtual address of the first user page to check. Second, it takes the number of pages to check. Finally, it takes a user address to a buffer to store the results into a bitmask (a datastructure that uses one bit per page and where the first page corresponds to the least significant bit). You will receive full credit for this part of the lab if the pgaccess test case passes when running pgtbltest.
和 lab2 不一样,这次的虽然需要实现一个系统调用,但是写 syscall 的那些准备工作(比如在user/user.h、user/usys.pl等文件写好syscall的信息)已经被写好了。
通过查看riscv-privileged文档的图4.18得知,PTE_A应该被设置为(1L « 6)。
|
|
之后在kernel/sysproc.c中修改sys_pgaccess函数的内容:
|
|