3.3 Interrupt management

The nachos.machine.Interrupt class 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 now.

The clock is maintained entirely in software and ticks only under the following conditions:

Whenever the clock advances, the event queue is examined and any pending interrupt events are serviced by invoking the device event handler associated with the event. Note that this handler is not an interrupt handler (a.k.a. interrupt service routine). Interrupt handlers are part of software, while device event handlers are part of the hardware simulation. A device event handler will invoke the software interrupt handler for the device, as we will see later. For this reason, the Interrupt class disables interrupts before calling a device event handler.

The Interrupt class accomplishes the above through three methods. These methods are only accessible to hardware simulation devices. schedule() takes a time and a device event handler as arguments, and schedules the specified handler to be called at the specified time. tick() advances the time by 1 tick or 10 ticks, depending on whether Nachos is in user mode or kernel mode. It is called by setStatus() whenever interrupts go from being disabled to being enabled, and also by Processor.run() after each user instruction is executed. checkIfDue() invokes event handlers for queued events until no more events are due to occur. It is invoked by tick().

The Interrupt class also simulates the hardware interface to enable and disable interrupts via the enable() and disable() methods. These methods are useful in the thread project.

The remainder of the hardware devices present in Nachos depend on the Interrupt device. No hardware devices in Nachos create threads, thus, the only time the code in the device classes execute is due to a function call by the running KThread or due to an interrupt handler executed by the Interrupt object.