Salsa - Interrupts Topics Nachos System Calls and Exception Handling


[ Source code in code/machine | Quiz ]

To see where interrupts fit into an operating system, consider what happens when a computer first starts running. It first executes a bootstrap program which initializes all aspects of the system, e.g., the CPU registers, device controllers, memory management unit etc. It then locates the operating system kernel and loads it into memory to start executing it. The operating system then starts executing the first process, and then waits for some event to occur. The occurrence of an event is signaled by an interrupt from either the hardware or software. The hardware may trigger an interrupt by sending a signal to the CPU, usually by way of the system bus. A software interrupt or a trap may be triggered by executing a special operation called a system call. This document discusses how the OS handles interrupts and then explains how that is simulated in Nachos.

Interrupt Management

There are many different types of events that may trigger an interrupt - the completion of an I/O operation, an error in a user program such as division by zero, an invalid memory access, or a request for some operating system service such as a system call. Associated with each I/O device class, e.g., floppy disks, hard disks, timers, console, is a location at the bottom of memory called the interrupt vector. This contains the addresses of the interrupt service routines for various devices. When an interrupt occurs, the interrupt hardware pushes the program counter, program status word, and possibly one or more registers onto the current stack. The computer then jumps to the address specified in the appropriate entry in the interrupt vector and starts execution from there.

In order to determine which entry in the interrupt vector to use, a unique device number provided with the interrupt request is used to index into the vector. The interrupt service routine starts out by saving all the registers in the process table entry for the current process. The instructions in the service routine are then executed. Upon completion, registers and other data structures for the current process are re-loaded and the process starts running again. Usually, interrupts are disabled while an interrupt is being serviced, delaying any other incoming interrupts. Thus, it is important that interrupt service routines be short.

Interrupt Management in Nachos

All routines related to interrupt management are in interrupt.h and interrupt.cc in the machine directory. The class PendingInterrupt defines an interrupt that is scheduled to occur in the future. The main routines are:

The Timer class defined in timer.h(cc) in the machine directory simulates a real-time clock in Nachos by generating interrupts at regular intervals. The constructor function of this class creates a real-time clock that interrupts the CPU every TimerTicks units. This constant is defined in stats.h to be 100. The variable randomize specifies that the time between interrupts should be taken from a interval between 1 and 2 * TimerTicks. Note that running Nachos with the -rs option creates a timer object that interrupts at random intervals and preempts the currently running thread.

As part of the multiprogramming lab, you will need to set the interval between these interrupts to a specified time slice.

Nachos simulates interrupts by maintaining an event queue together with a simulated clock. As the clock ticks, the event queue is examined to find events scheduled to take place at that time. The clock is maintained entirely in software and advances under the following conditions:

Whenever the clock advances, the event queue is examined and any pending interrupts are serviced by invoking the interrupt service routine. All interrupt service routines are run with interrupts disabled, and the service routine may not re-enable them.

Source code in code/machine
Quiz

Back to Top

Last modified on Thursday, 29-May-97 17:08:39 EDT