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.
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.
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
Last modified on Thursday, 29-May-97 17:08:39 EDT