-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathREADME.lab2
106 lines (68 loc) · 4.68 KB
/
README.lab2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
Joon Lim
109558002
Lab 2
Design process
1. I first started by merging the new code with my homework 1.
2. I then went through exercise 1, by adding a reference count parameter to struct run in kalloc.c and initialized it to 1 inside kalloc().
3. I added helper function to increment and decrement the previously added reference count. The functions are:
incref() - increment the reference count of a page descriptor.
decref() - decrement the reference count of a page descriptor.
4. After that, I added an assertion inside kfree() to check that the reference count is 1 inside the call. This caused some bugs for me, so I added the function _kfree(), which is identical to kfree() except that there is no assertion. The initialization functions kinit1() and kinit2() call the newly created _kfree() rather than kfree().
_kfree() - kfree() minus the assertion.
5. I added some extra helper functions near the bottom of kalloc.c:
getref() - get the reference count of a page descriptor.
printref() - print the reference count of a page descriptor.
6. Next, I added a macro T_PGFAULT to replace the already existing T_PGFLT because the instructions explicitly say "T_PGFAULT."
6. Then, I continued onto exercise 2, where I registered a page fault handler function pgfault() to handle page faults. At this point, the function simply printed a statement indicating that a page fault occured and exited. trap() calls pgfault() when tf->trapno == T_PGFAULT.
pgfault() - page fault handler.
7. I added a unit test pgfaulttest to trigger a page fault to check to see if my function was being properly called.
pgfaulttest.c - test that deliberately accesses an invalid address to trigger a page fault.
8. I defined a flag PTE_COW as 0x800 in mmu.h.
9. I began exercise 4, where I started by creating the function cowuvm(), which allocates a new page directory by setting the pages of the parent process to copy-on-write and read-only, and then adding references to the pages to the new page directory.
cowuvm() - convert each writable page table entry in the parent and child to read-only and PTE_COW.
10. I had fork() call cowuvm() instead of copyuvm() in proc.c.
11. I implemented the page fault handler pgfault().
12. I had a wicked bug where my program was page faulting every time a process terminated. My fix for the bug is in vm.c line 268, where I added a conditional so that the program wouldn't free pages with a reference count greater than 1.
13. I added 3 additional unit tests for fork.
forkunittest1.c
forkunittest2.c
forkunittest3.c
14. My code passes forktest, forkunittest1, forkunittest2, and forkunittest3. At my code's current state, it still fails 'usertests'.
--------------------------------------------------------------------------------
xv6 is a re-implementation of Dennis Ritchie's and Ken Thompson's Unix
Version 6 (v6). xv6 loosely follows the structure and style of v6,
but is implemented for a modern x86-based multiprocessor using ANSI C.
ACKNOWLEDGMENTS
xv6 is inspired by John Lions's Commentary on UNIX 6th Edition (Peer
to Peer Communications; ISBN: 1-57398-013-7; 1st edition (June 14,
2000)). See also http://pdos.csail.mit.edu/6.828/2014/xv6.html, which
provides pointers to on-line resources for v6.
xv6 borrows code from the following sources:
JOS (asm.h, elf.h, mmu.h, bootasm.S, ide.c, console.c, and others)
Plan 9 (entryother.S, mp.h, mp.c, lapic.c)
FreeBSD (ioapic.c)
NetBSD (console.c)
The following people have made contributions:
Russ Cox (context switching, locking)
Cliff Frey (MP)
Xiao Yu (MP)
Nickolai Zeldovich
Austin Clements
In addition, we are grateful for the bug reports and patches contributed by
Silas Boyd-Wickizer, Peter Froehlich, Shivam Handa, Anders Kaseorg, Eddie
Kohler, Yandong Mao, Hitoshi Mitake, Carmi Merimovich, Joel Nider, Greg Price,
Eldar Sehayek, Yongming Shen, Stephen Tu, and Zouchangwei.
The code in the files that constitute xv6 is
Copyright 2006-2014 Frans Kaashoek, Robert Morris, and Russ Cox.
ERROR REPORTS
If you spot errors or have suggestions for improvement, please send
email to Frans Kaashoek and Robert Morris (kaashoek,[email protected]).
BUILDING AND RUNNING XV6
To build xv6 on an x86 ELF machine (like Linux or FreeBSD), run "make".
On non-x86 or non-ELF machines (like OS X, even on x86), you will
need to install a cross-compiler gcc suite capable of producing x86 ELF
binaries. See http://pdos.csail.mit.edu/6.828/2014/tools.html.
Then run "make TOOLPREFIX=i386-jos-elf-".
To run xv6, install the QEMU PC simulators. To run in QEMU, run "make qemu".
To create a typeset version of the code, run "make xv6.pdf". This
requires the "mpage" utility. See http://www.mesa.nl/pub/mpage/.