Projects‎ > ‎


Exploring and Modifying xv6

Due Tuesday, November 7th at 11:59pm. Turn into your Project03 git repo.

For this project you are going to explore the xv6 source code, get familiar with building and running xv6, running xv6 with gdb, adding user programs to xv6, adding new system calls, and modifying the xv6 kernel.

Setting up your project03 Github repo

You will want to seed your project03 Github repo with a fresh copy the xv6 source code. After you clone your repo:

$ git clone<username>.git

You can copy the xv6 source into your local repo. You want all the top level files (non dot "." file) plus these dot files:


Make sure you do not copy the ".git" directory to your repo.

For example, if you have a fresh copy xv6-public in ~/git/xv6-public and your repo is in ~/git/projec03-<usernmae> you can do the following:

$ cd ~/git/xv6-public
$ cp * ~/git/project03-<username>
$ cp .dir-locals.el .gdbinit.tmpl .gitignore ~/git/project03-<username>
$ cd ~/git/project03-<username>
$ git add *
$ git add .dir-locals.el .gdbinit.tmpl .gitignore
$ git commit -m "Initial commit of fresh xv6 source code."
$ git push

Now you will have populated you local and Github repo.

Setting up a Build and Test Environment on the RPi

You need to following the instructions given here:

You should be able to compile xv6, run xv6 in qemu, and debug xv6 using qemu and gdb.

Debugging with GDB

For this part of the project, you need to demonstrate that you can effective use gdb or cgdb to debug the xv6 kernel.

During interactive grading you will need to show to set a breakpoint in piperead(), then execute the following command in the xv6 shell:

$ echo hello world | wc

In gdb (or cgdb) you should be able to show that the string "hello world" is in the pipe buffer.

Porting usfgrep and usfsh to xv6

For this problem you need to port your implementation of usfgrep and usfsh to xv6.

You will need to do a few things to get this to work:
  • Get usfgrep and usfsh working if they are broken for any reason
  • Port usfgrep and usfsh so that it uses xv6 system calls and library calls (look at the existed xv6 user programs as a guide)
  • Figure out how to add a new user program to the xv6 filesystem (you will have to modify the Makefile to get this to work)
Once added, you need to demonstrate that usfsort works in xv6:

$ cat > hello.txt
$ usfgrep hello hello.txt
hello.txt[2] hello

Adding a New System Call to xv6

For this problem you need to add a new system call to the xv6 kernel and write a new xv6 user program to demonstrate that it works.

The system call you are going to add is called 

int pipe_count(int fd)

This system call will return the number of bytes currently in a pipe pointed to by fd. The fd value can be either the read end or the write end of the pipe.

In addition, if fd is not a valid pipe, you need to return -1.

Write a new user program, pipetest, that tests your pipe_count() system call.

Your test should invoke pipe_count() in the following situations:
  • The pipe is empty
  • The pipe is full
  • The pipe is in between empty and full
  • The fd is not a valid pipe

Scheduler Tracing

For this part of the project you need to add the ability to trace the scheduling decisions made by the xv6 schedule.

You will add two new system calls:



The trace_start() system call will turn on tracing and the trace_end() system call will stop tracing and write the trace log to the file represented by fd. This could be stdout (1) or it could be a file previously opened.

The contents of the trace log output should be:

(ticks) proc_name

Where each entry represents the tick count and the proc_name of a chose process. In this way we can see a log of the scheduling decisions.


Driver and two processes a and b.
Driver and three processes a, b, and c.


Round Robin Scheduling with LInked LIsts

You need to incorporate the linked list code into the xv6 kernel and use this linked list code to replace the table based scheduler.

Show that your schedule supports round robin by writing a test programs that forks two processes and shows that the trace log is fair.