8801a27ccb6efb6dd736076e9e8b3a06a4cc17e4
[pintos-anon] / sigcse2009 / assignments.tex
1 \section{Assignments}
2 \label{sec:assignments}
3
4 %
5 % Not sure if we need that.
6 %
7 \subsection{Project 0}
8 If Pintos is used in a semester-long course, project 0 serves as a ``warm-up'' project.
9 In this project, students will gain familiarity with the Pintos source tree and some
10 supporting classes, in particular its implementation of doubly-linked lists.
11 In OS, doubly-linked lists are frequently used because they allow $O(1)$ insertion and
12 removal operations.  Moreover, they are often used in a style in which the list cell
13 containing the next and prev pointers is embedded in some larger structure, such as
14 a thread control block, rather than having separately allocated list cells.
15 In project 0, students use Pintos's list implementation to implement a simple, first-fit 
16 memory allocator.  
17
18 \subsection{Project 1 -- Threads}
19 % intro
20 Project 1 centers around threads.  The baseline Pintos code boots into a kernel that
21 supports multiple in-kernel threads.  It provides code for initialization, thread creation and
22 destruction, context switches, thread blocking and unblocking as well as a simple but
23 preemptive round-robin scheduler.
24 Students study the existing, barebones threading system (about 600 lines of C code) to 
25 understand how threads are created and destroyed, and to understand the transitioning of 
26 threads between the READY, RUNNING, and BLOCKED states.  They also study how a thread's
27 internal memory is managed, which is used to store its runtime stack and thread control block.
28 Student can examine the context switch code, but the projects do not involve any modifications
29 to it.
30
31 After reading the baseline code, the projects ask students to implement several features
32 that exercise thread state transitions.  The first part of this project includes a simple
33 alarm clock, which requires maintaining a timer queue of sleeping threads and changing 
34 the timer interrupt handler to unblock those threads whose wakeup time has arrived.
35 Students learn how to protect data structures that are shared between a thread and an
36 interrupt handler.  The second part of the project constitutes a strict priority-based
37 uniprocessor scheduler.  In this model, one of the threads with the highest priority
38 always runs.  When a thread's priority changes, or when threads block or unblock,  
39 a scheduling decision must be triggered to ensure this invariant.  Students learn about
40 the different ways in which such situations occur.  
41 Project 1 also introduces synchronization primitives such as semaphores, locks,
42 and condition variables.  The project explores the interaction between such primitives,
43 thread states, and the scheduler.
44
45 Based on the priority scheduler, students implement two additional tasks: priority 
46 inheritance and a multi-level feedback queue scheduler.  Priority inheritance is a way
47 to avoid priority inversion, a phenonemon that most famously led to an almost-failure
48 of the Mars Pathfinder Mission~\cite{MarsPathFinder}.  We use this example to motivate
49 the problem.  Implementing priority inheritance correctly requires a deep understanding of the 
50 interaction of threads and locks.
51 Separately, students build a multi-level feedback queue scheduler on top of the strict
52 priority scheduler.  This scheduler adjusts threads' priority based on a sampling  of how
53 much CPU time a thread has received recently.
54
55 \paragraph{Testing and Grading.}
56 Project 1 is accompanied by about $XX$ tests, which are run using the Bochs simulator by
57 a grading script.  Most tests are designed to test a single aspect, but some tests 
58 test more involved scenarios.  Most of the tests are designed to produce a deterministic 
59 output; the grading script will point out differences between the expected and the actual output. 
60 Usually, a test failure leads students to study the documented source code of the test
61 and understand how the expected output derives from it.
62
63 The MLFQS scheduler tests are graded in a different way. Since those tests rely on estimating CPU
64 usage, they depend on how much CPU time a specific implementation uses, which in turn depends on how
65 efficient it is.  We compute the expected CPU consumption values by simulation and provide an
66 envelope within which we accept the output.  The envelope is large enough to allow for minor
67 inefficiencies, but major inefficiencies will usually lead to test failures.  Such failures
68 convey the importance of using efficient algorithms and data structures within a kernel,
69 because wasting CPU cycles in the kernel reduces the amount available to applications.
70
71 % intro
72 \paragraph{Learning Objectives.}
73 Project 1 has three learning objectives.  First, students will understand how
74 the illusion that ``computers can do multiple things at once'' is created by a sequence
75 of thread state transitions and context switches.  Second, they will understand how
76 a simple underlying mechanism - such as priority-based scheduling - can lead to more
77 sophisticated scheduling policies.  Third, having seen the mechanisms a preemptive scheduler
78 uses to create apparent concurrency, students gain a better intuition of the non-determinism
79 inherent in concurrent systems. 
80
81 %
82 %
83 %
84 \subsection{Project 2 -- User Programs}
85 The second project illustrates how OS implements protection and isolation between user processes,
86 how user processes gain access to kernel services, and how user processes lay out the virtual
87 address space in which their program and data is contained.
88 The project adds support to Pintos to load and execute user programs that make use
89 of kernel services.  We kept the provided code purposefully minimal, consisting of
90 only a library that reads the program and data segments of ELF binaries.   These binaries
91 are loaded into a new address space; the baseline code includes functionality to allocate
92 physical memory and set up a page directory to establish the process's virtual address
93 mappings.
94
95 Students implement support for a small set of system calls that allow processes to perform
96 I/O, start new processes, wait for their termination, and exit.  Both the Pintos user 
97 process model and system call API are modeled after traditional Unix, with the exception 
98 that Pintos processes do not separate process creation (i.e., fork()) from program loading
99 (i.e., exec) - instead, Pintos's exec() system call combines these two pieces of functionality 
100 into one.  The implementation of these calls requires the students to keep track of
101 per-process resources such as file descriptors, deepening their understanding of how
102 an operating system provides the abstraction of a process.
103
104 Like most current OS, Pintos exploits dual-mode operation in which user processes run
105 in a nonprivileged mode that prevents access to kernel resources and to resources allocated
106 to other processes.  Processes attempting to bypass these restrictions are terminated.
107 Students implement the system call handling code, a key aspect of which includes the
108 careful examination of arguments passed by user processes.
109
110 Project 2 also illustrates parallel programming techniques, notably fork/join
111 parallelism, which students implement when providing support for the exec()/wait()/exit() 
112 system calls.  The rendezvous-style synchronization necessary to support this model
113 can be implemented using semaphores, providing a practical example of this style
114 synchronization presented in accompanying lectures.
115
116 % How threads extend into processes.
117
118 \paragraph{Testing and Grading.}
119 The tests for project 2 exclusively consist of user programs written in C.
120 They are divided into functionality and robustness tests.  Functionality tests check that
121 the operating system provides the expected set of services when it is used as
122 expected.  A set of robustness tests checks that the OS rejects all attempts at passing
123 invalid input to system calls.  To pass those tests, the student's kernel must be 
124 ``bullet-proof.'' We include a stress test in which we artificially induce low memory
125 conditions by creating a large number of processes and pseudo-randomly introducing
126 failures in some of them.  We expect the kernel to fully recover from such situations.
127
128 \paragraph{Learning Objectives.}
129 In project 2, students learn how the thread abstraction introduced in project 1 is 
130 extended into the process abstraction, which combines a thread, a virtual address space, 
131 and its associated resources.
132 Project 2 enables students to understand how operating systems employ dual-mode
133 operation to implement isolation between processes and to protect system resources
134 even in the presence of failing or misbehaving processes.  
135 Students understand how processes transition into the kernel to access its services,
136 and how kernels implement such services in a robust way.
137 The principles learned in this exercise carry over to all scenarios
138 in which applications must be robust in the face of input coming from untrusted 
139 sources and uncertain resource availability, as is the case in many server systems.
140
141 \subsection{Project 3}
142 Project 3 asks students to implement several virtual memory techniques, including
143 on-demand paging of programs, stack growth, page replacement, and memory-mapped files.
144 This functionality is implemented in a page fault service handler and during the
145 program loading process.
146 We provide supporting code to create and maintain page directories, which hide
147 the x86-specifics of how to program the memory management unit (MMU) and how
148 to ensure consistency with the CPU's translation look-aside buffer (TLB).  
149 As a result, students can treat the MMU as an abstract device in which to 
150 install, update, or remove virtual to physical address mappings.
151 Consequently, they are free to choose any design for the data structures needed to
152 keep track of the state of each page or region in a process's virtual address 
153 space.
154
155 In early offerings, this significant creative freedom came at the cost that 
156 some students were lost as how to accomplish set goals.  We added an intermediate
157 design review stage to this projects using a structured questionnaire in which students 
158 outline their planned design.  We also provide a suggested order of implementation.
159
160 Like project 2, project 3 requires reasoning using parallel programming strategies.  
161 Since the Pintos kernel is fully preemptive, students must consider which data structures
162 require locking, and the must design a locking strategy that both avoids deadlock
163 and reduces unnecessary serialization.
164
165 \paragraph{Testing and Grading.}
166 Project 3 relies on project 2, therefore, we include all tests provided with project 2
167 as regression tests to ensure that system call functionality does not break in the
168 presence of virtual memory.  Furthermore, we provide functionality tests for the
169 added functionality that lends itself to such testing, namely, memory-mapped files
170 and stack growth.  Some of the project tasks, such as on-demand paging, are 
171 performance-enhancing techniques that do not directly add functionality that is
172 apparent to user programs, which are graded by inspection.  We test the students
173 page replacement code by varying the amount of physical memory available to
174 the kernel when run under emulation, relative to the amount of memory that is 
175 accessed by our test programs.  Timeouts are used to detect grossly inefficient 
176 page replacement schemes.
177
178 \paragraph{Learning Objectives.}
179 In project 3, students learn how an OS creates the environment in which a user
180 program executes, specifically as it relates to code and variables used in a program.
181 It provides a deep understanding of how OS use fault resumption to
182 to virtualize a process's interaction with physical memory.
183 In addition, students gain hands-on experience with page replacement algorithms
184 and have the opportunity to observe their performance impact.
185
186 %
187 %
188 %
189 \subsection{Project 4}
190 \paragraph{Testing and Grading.}
191 \paragraph{Learning Objectives.}
192