To develop a better sense of how an operating system works, you will also do a few projects inside a real OS kernel. The kernel we’ll be using is a port of the original Unix (version 6), and is runnable on modern x86 processors. It was developed at MIT and is a small and relatively understandable OS and thus an excellent focus for simple projects.
This first project is just a warmup, and thus relatively light on work. The goal of the project is simple: to add a system call to xv6. Your system call, getopenedcount(), simply returns how many times that the open() system call has been called by user processes since the time that the kernel was booted.
More information about xv6, including a very useful book written by the MIT folks who built xv6, is available here. Do note, however, that we use a slightly older version of xv6 (for various pedagogical reasons), and thus the book may not match our code base exactly.
You may extract the xv6 source using of the CSL machines. To do so follow the steps below:
> cp -r /p/course/cs537-shivaram/xv6-sp19 .
> make qemu
Your new system call should look have the following return codes and parameters:
Your system call returns the value of a counter (perhaps called openedcount or something like that) which is incremented every time any process calls the open() system call. That’s it!
Watch this discussion video – it contains a detailed walk-through of all the things you need to know to unpack xv6, build it, and modify it to make this project successful.
One good way to start hacking inside a large code base is to find something similar to what you want to do and to carefully copy/modify that. Here, you should find some other system call, like getpid() (or any other simple call). Copy it in all the ways you think are needed, and then modify it to do what you need.
Most of the time will be spent on understanding the code. There shouldn’t be a whole lot of code added.
Using gdb (the debugger) may be helpful in understanding code, doing code traces, and is helpful for later projects too. Get familiar with this fine tool!
By applying the same technique used to create getopenedcount(), create a second systemcall getclosedcount() which supplies the number of times which the close() system call has been called by user processes.
Comparing the values of both getopenedcount() and getclosedcount() allows the system a way to estimate if user processes have closed the files which have been opened. However, these counts alone are not enough for a system or individual user processes to know if all of the opened files have been closed. What additional information might be useful to determine this?
This project is due on February, 8th, 2019 at 11:59PM.
To submit your solution, copy all of the xv6 files and directories with your changes into
~cs537-1/handin/<cs-login>/p1b/. One way to do this is to navigate to your solution’s working directory and execute the following command:
cp -r . ~cs537-1/handin/<cs-login>/p1b/
ls -l in the
~cs537-1/handin/<cs-login>/p1b/ directory the contents should be similar to what is shown below:
$ ls -l total 28 -rw-r----- 1 <user-name> <user-name> 223 Feb 27 2012 FILES drwxr-x--- 2 <user-name> <user-name> 2048 Jan 24 16:04 include/ drwxr-x--- 2 <user-name> <user-name> 6144 Jan 28 12:01 kernel/ -rw------- 1 <user-name> <user-name> 4823 Jan 23 14:51 Makefile -rw------- 1 <user-name> <user-name> 4809 Feb 27 2012 Makefile~ -rw-r----- 1 <user-name> <user-name> 1793 Feb 27 2012 README drwxr-x--- 2 <user-name> <user-name> 2048 Jan 28 12:01 tools/ drwxr-x--- 2 <user-name> <user-name> 4096 Jan 28 12:01 user/ -rw-r----- 1 <user-name> <user-name> 22 Feb 27 2012 version