CS395T Fall 2010 Lab 7: Final Project

Handed out Monday, November 1, 2010
Project proposals due Wednesday, November 10, 2010, 11:59 PM
Code due Wednesday, December 8, 2010, 11:59 PM
Project demos: December 8-9 and 14-16, 2:00 - 4:00 PM

Introduction

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. In this piece of the lab, you will work in pairs. You have two broad choices for the final project. (1) The default option is for you to add a significant piece of functionality to JOS, as described below. (2) Another option is to build something that is independent of JOS. The three requirements for this second option are as follows. The project must (a) have a significant implementation component, specified by deliverables (b) concern operating systems and (c) be challenging and potentially research-worthy. For all projects, you must write a proposal that is accepted by the course staff.

Lab Requirements

Here is a list of examples and projects from past years and other versions of this course. This is meant to be inspiration only, not a menu. The actual project is up to you. Please pick something manageable. It is far better to complete your project to spec than it is to take on something too big and not have anything to show for it except excellent intentions (also true in the real world).

The project you choose 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).

Getting Started

Use Git to commit your Lab 6 source, 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 ~/CS395T/lab
tig% git commit -am 'my solution to lab6'
Created commit 734fab7: my solution to lab6
 4 files changed, 42 insertions(+), 9 deletions(-)
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.
 fs/fs.c |   42 +++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)
tig% 

Demos

You will need to give a 20 minute demonstration of your finished project to the course staff. Please go to this link, choose a time, and enter both partners' names to sign up for a slot that fits with your schedule. Both members in your group must be present at the demo, so plan accordingly.

Late policy and procedure for submitting the assignment.

Late policy: You must hand in the individual portion as if you had the minimum of the two team members' late hours, and you can hand in the project portion as if you had the maximum of the two team members' late hours. Two notes here: (1) We recognize that this is not perfectly fair (in the sense of treating everyone exactly the same), but we couldn't think of a perfectly equitable approach that is also simple to implement. As with computer systems, we are trying to get this roughly right at minimal implementation cost. (2) If, as a member of a newly paired team, you feel that this policy puts you at a disadvantage (say because you had many late hours stored up that you wanted to use for the individual portion of lab 7), please let us know.

Turn in procedure: You will submit this lab in two parts. Once you have completed exercises 1, 2, and 3, do make turnin to submit your solutions to this part of the lab. To submit your final project code, do make project-turnin. Note that you need not do these in order. It's more important to get your project working than to pass the grading scripts for exercises 1, 2, and 3. On the other hand, you may find it useful in your final project to have a working shell, so there may be good technical reasons to do the lab in order.

Part 1: 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 that running "(date; ls) >file" will not work properly, because even though date updates its own file offset, ls will not see the change.) 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. (Note that you should use PTE_USER, not PTE_FLAGS, to mask out the relevant bits from the page table entry. PTE_FLAGS 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-nox 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-nox 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 data page succeeded".

Part 2: 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 appears as input from the keyboard to JOS, while input typed to the console appears 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 user/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-nox or make run-icode. 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:

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

You can also play around with the (primitive) shell, though you will see that there are some obvious limitations, like that the shell cannot create new files with its redirect operator.

Note that the user library routines cprintf and printf print 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, "...", ...). See user/ls.c for examples.

Run make run-testshell-nox 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.

At this point, you should probably commit your code to your local git repo and use make turnin to submit it.

Challenge! Do an awesome final project!

This ends the lab. As usual, you can grade your submission with make grade and hand it in with 1. make turnin for the initial exercises and 2. make project-turnin after completing the project.

Congratulations on having completed all of the CS 395T labs! We are looking forward to seeing your projects!