CS372H Spring 2012 Lab 7: Final Project

Released Tuesday, April 10, 2012
Project proposals due by email Friday, April 20, 2012, 3:00 PM
Part A due Friday, April 27, 2012, 9:00 PM
Part B due Monday, May 14, 2012, 9:00 PM
Project demos: afternoons of May 14 and 15, 2012


In this lab you will flesh out your kernel and library operating system enough to run a shell on the console. You will then do the core of the lab: the final project.

Lab Requirements

Here is a list of examples and projects from past years:

Your project must have a significant operating systems component. For example, you shouldn't simply port a user-level application that requires little or no kernel modification. You should email a proposal to the course staff email alias (not the course staff separately) at the deadline given above. The proposal must include: (1) The names of your group members; (2) What you want to do; and (3) What you are expecting to present (a list of deliverables). Please keep it short (no more than several paragraphs).

To complete the assignment, you will turn in your code as usual. In addition, you will have to demonstrate your final project for the course staff in person. The demos will be in the afternoons of May 14 and 15; there will be an electronic signup.

Late policy. Late policy: Part A of the lab will be treated as every other lab has been: you are welcome to use late hours, if you have them, and if you turn in part A late, your grade on that part of the lab decreases each day (as usual). However, you cannot use late hours for part B. If your part B is late, you will lose points according to the late policy but not beyond the end of the semester, i.e., if the semester ends with no project from you, we count the project as not handed in. This in turn will unfortunately trigger the non-linearity in the lab grading in which a not-turned-in lab causes an F on the entire lab portion of the grade (see the policies page). Turn in procedure: You will submit this lab in two parts. Once you have completed part A, do make turnin-partA to submit your solutions to this part of the lab. To submit your final project code, do make turnin-partB.

Getting Started

Use Git to commit your Lab 6 source (if you haven't already), fetch the latest version of the course repository, and then create a local branch called lab7 based on our lab7 branch, origin/lab7:

tig% cd ~/CS372H/lab
tig% git commit -am 'my solution to lab6'
nothing to commit (working directory clean)
tig% git pull
Already up-to-date.
tig% git checkout -b lab7 origin/lab7
Branch lab7 set up to track remote branch refs/remotes/origin/lab7.
Switched to a new branch "lab7"
tig% git merge lab6
Merge made by recursive.
 kern/env.c |   42 +++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)

Part A

Sharing library code across fork and spawn

We would like to share file descriptor state across fork and spawn, but file descriptor state is kept in user-space memory. Right now, on fork, the memory will be marked copy-on-write, so the state will be duplicated rather than shared. (This means environments won't be able to seek in files they didn't open themselves and that pipes won't work across a fork.) On spawn, the memory will be left behind, not copied at all. (Effectively, the spawned environment starts with no open file descriptors.)

We will change fork to know that certain regions of memory are used by the "library operating system" and should always be shared. Rather than hard-code a list of regions somewhere, we will set an otherwise-unused bit in the page table entries (just like we did with the PTE_COW bit in fork).

We have defined a new PTE_SHARE bit in inc/lib.h. This bit is one of the three PTE bits that are marked "available for software use" in the Intel and AMD manuals. We will establish the convention that if a page table entry has this bit set, the PTE should be copied directly from parent to child in both fork and spawn. Note that this is different from marking it copy-on-write: as described in the first paragraph, we want to make sure to share updates to the page.

Exercise 1. Change duppage in lib/fork.c to follow the new convention. If the page table entry has the PTE_SHARE bit set, just copy the mapping directly. (You should use PTE_SYSCALL, not 0xfff, to mask out the relevant bits from the page table entry. 0xfff picks up the accessed and dirty bits as well.)

Likewise, implement copy_shared_pages in lib/spawn.c. It should loop through all page table entries in the current process (just like fork did), copying any page mappings that have the PTE_SHARE bit set into the child process.

Use make run-testpteshare to check that your code is behaving properly. You should see lines that say "fork handles PTE_SHARE right" and "spawn handles PTE_SHARE right".

Exercise 2. Change the file server so that all the file descriptor pages get mapped with PTE_SHARE.

Use make run-testfdsharing to check that file descriptors are shared properly. You should see lines that say "read in child succeeded", "read in parent succeeded", and "write to file succeeded".

The keyboard interface

For the shell to work, we need a way to type at it. QEMU has been displaying output we write to the CGA display and the serial port, but so far we've only taken input while in the kernel monitor. In QEMU, input typed in the graphical window appear as input from the keyboard to JOS, while input typed to the console appear as characters on the serial port. kern/console.c already contains the keyboard and serial drivers that have been used by the kernel monitor since lab 1, but now you need to attach these to the rest of the system.

Exercise 3. In your kern/trap.c, call kbd_intr to handle trap IRQ_OFFSET+IRQ_KBD and serial_intr to handle trap IRQ_OFFSET+IRQ_SERIAL.

We implemented the console input/output file type for you, in lib/console.c.

Test your code by running make run-testkbd and type a few lines. The system should echo your lines back to you as you finish them. Try typing in both the console and the graphical window, if you have both available.

The Shell

Run make run-icode or make run-icode-nox. This will run your kernel and start user/icode. icode execs init, which will set up the console as file descriptors 0 and 1 (standard input and standard output). It will then spawn sh, the shell. You should be able to run the following commands:

	echo hello world | cat
	cat lorem >out
	cat out
	cat lorem |num
	cat lorem |num |num |num |num |num
	cat script
	sh <script

Note that the user library routine cprintf prints straight to the console, without using the file descriptor code. This is great for debugging but not great for piping into other programs. To print output to a particular file descriptor (for example, 1, standard output), use fprintf(1, "...", ...). printf("...", ...) is a short-cut for printing to FD 1. See user/lsfd.c for examples.

Run make run-testshell to test your shell. testshell simply feeds the above commands (also found in fs/testshell.sh) into the shell and then checks that the output matches fs/testshell.key.

Your code should pass all tests at this point. As usual, you can grade your submission with make grade and hand it in with make turnin-partA. This completes Part A.

Part B: The project

For this part of the lab you no longer are required to follow the pair programming requirements as laid out before. More specifically, you are not required to be sitting at the same terminal to code, and instead can work asynchronously. This does not change the collaboration policy.

Challenge! Do an awesome final project!

Before your demo and after you are done, make turnin-partB. Please include a brief write-up about what you did and how. Also, we need to be able to run your code, so please also include in your submission a step-by-step HOWTO or README stating what commands we should run to execute your code.

Congratulations on completing all of the CS372H labs!

Last updated: Tue May 15 16:02:40 -0500 2012 [validate xhtml]