Salsa - Nachos Overview Salsa Topics Threads

Nachos is instructional software that allows students to study and modify a real, working operating system. It was developed at the University of Berkeley and is used by numerous schools to teach their operating system course. We will use it to do four programming assignments. This page presents a broad overview of Nachos, its directory structure, and instructions on how to compile it. This tutorial uses version 3.4 although more recent versions are available.

The following figure shows how the different components of Nachos are linked during execution. As in an actual operating system, there is a Scheduler that keeps track of all the processes in the system and switches between them periodically. It maintains a list of processes, readyList, for this purpose. All processes within Nachos execute as threads. This means that all programs that run on Nachos are implemented as threads. This fact is important for two of the labs you will do.


The time slice for which each process executes is determined by the Timer which causes an interrupt when the time slice for the currently executing process is over. The Interrupt component handles all interrupts generated by the Timer. The cause of the interrupts may be device I/O, e.g. a write to a file by a process, a request by some process to take input from the console (screen) or it may be a signal for the scheduler to switch to another process.

In Nachos, the global variable currentThread always points to the thread currently occupying the CPU. Do not worry about threadToBeDestroyed for now, that is explained in the Threads section.

All operating systems need some hardware to execute processes. The Nachos Machine provides this functionality - it simulates the MIPS architecture. The FileSystem component manages all file operations. SynchDisk provides synchronized access to the disk. To connect our machine to other machines, we have a PostOffice that manages receipt and sending of messages across the network. Stats is a component within Nachos that maintains certain statistics about the execution and performance of the system. For example, it may keep track of how many characters have been written to the screen, how many page faults have occurred, how many packets have been received across the network etc.

Directory Structure

Below is a directory listing of nachos-3.4/code:
     Makefile            bin/        network/    userprog/
     Makefile.common     filesys/    test/       vm/
     Makefile.dep        machine/    threads/

As you can see, the code directory contains several other directories - the names are very descriptive of what these actually contain. The figure below lists all the directories. Click on any tomato for a description of what that directory contains.

Compile Instructions

Detailed instruction to compile the software will be provided with each lab but here are a few quick instructions. The software comes equipped with makefiles in each directory which makes compiling very easy. After you download the software, simply type make all while in the code directory. This command compiles the files in each directory in code and places an executable file called nachos in it.

Since each directory has a separate executable, this essentially means that each lab can be done independently of others. The makefiles in each directory ensure that the changes you make to the files within that directory will be incorporated in the executable after you recompile. The commands to recompile the software if/when you change or add any files in any directories in code are:

The first command generates all dependencies, that is, all the files that need to be compiled with the rest of the software. The second command actually compiles all the files and generates an executable file called nachos in the directory where you made the changes. Note that the first command need not be run every time you change some files. You will need to run it only if you have created some new files which need to be added to the software (note that this involves changing some of the makefiles).

Remember that in any program, execution always begins from the main() routine. For Nachos, this routine is contained in main.cc in the threads directory. For each lab, execution always begins in main.cc but flow of control depends on which lab you are attempting. This functionality is provided through the #ifdef directives in main.cc. The arguments to this directive are defined in the makefiles.

Upon startup, Nachos executes as a single UNIX process. This user process is converted to a thread called main . Thus, by default, Nachos executes as a single thread. When the Nachos entry point routine main returns, that thread exits as well. If other threads have been created and continue to exist, the UNIX process continues executing Nachos. Only after all threads have terminated does the UNIX Nachos process exit.

Back to Top

Last modified on Thursday, 29-May-97 17:30:20 EDT