Process Concepts:Interrupts
Interrupts
As discussed in Chapter 2, Hardware and Software Concepts, interrupts enable software to respond to signals from hardware. The operating system may specify a set of instructions, called an interrupt handler, to be executed in response to each type of interrupt. This allows the operating system to gain control of the processor to manage system resources.
A processor may generate an interrupt as a result of executing a process’s instructions (in which case it is often called a trap and is said to be synchronous with the operation of the process). For example, synchronous interrupts occur when a process attempts to perform an illegal action, such as dividing by zero or referencing a protected memory location.
Interrupts may also be caused by some event that is unrelated to a process’s current instruction (in which case they are said to be asynchronous with process execution; see the Operating Systems Thinking feature, Asynchronism vs. Synchronism). Hardware devices issue asynchronous interrupts to communicate a status change to the processor. For example, the keyboard generates an interrupt when a user presses a key; the mouse generates an interrupt when it moves or when one of its buttons is pressed.
Interrupts provide a low-overhead means of gaining the attention of a processor. An alternative to interrupts is for a processor to repeatedly request the status of each device. This approach, called polling, increases overhead as the complexity of the computer system increases. Interrupts eliminate the need for a processor to repeatedly poll devices.
A simple example of the difference between polling and interrupts can be seen in microwave ovens.A chef may either set a timer to expire after an appropriate number of minutes (the timer sounding after this interval interrupts the chef), or the chef may regularly peek through the oven’s glass door and watch as the roast cooks (this kind of regular monitoring is an example of polling).
Interrupt-oriented systems can become overloaded—if interrupts arrive too quickly, the system may not be able to keep up with them. A human air traffic con- troller, for example, could easily be overwhelmed by a situation in which too many planes converged in a narrow area.
In networked systems, the network interface contains a small amount of memory in which it stores each packet of data that it receives from other computers.
Operating Systems Thinking
Asynchronism vs. Synchronism
When we say events occur asynchronously with the operation of a process, we mean that they hap- pen independently of what is going on in the process. I/O operations can proceed concurrently and asynchronously with an executing process. Once the process initiates an asynchronous I/O operation, the process can continue executing while the I/O operation proceeds. When the I/O completes, the process is notified. That notification can come at any time. The process can deal with it at that moment or can proceed with other tasks and deal with the I/O-completion interrupt at an appropriate time. So interrupts are often characterized as an asynchronous mechanism. Polling is a synchronous mechanism. The processor repeatedly tests a device until the I/O is complete. Synchronous mechanisms can spend a lot of time waiting or retesting a device until an event occurs. Asynchronous mechanisms can proceed with other work and waste no time testing for events that have not happened, which generally improves performance.
Each time the network interface receives a packet, it generates an interrupt to inform a processor that data is ready for processing. If a processor cannot process data from the network interface before the interface’s memory fills, packets might be lost. Systems typically implement queues to hold interrupts to be processed when a processor becomes available. These queues, of course, consume memory that is limited in size. Under heavy load, the system might not be able to enqueue all arriving interrupts, meaning that some could be lost.
Self Review
1. What does it mean for an interrupt to be synchronous?
2. What is an alternative to interrupts and why is it rarely used?
Ans: 1) A synchronous interrupt occurs due to software execution. 2) A system can per- form polling, in which the processor periodically checks the status of devices. This technique is rarely used, because it creates significant overhead when the processor polls devices whose status has not changed. Interrupts eliminate this overhead by notifying a processor only when a device’s status changes.
Interrupt Processing
We now consider how computer systems typically process hardware interrupts. (Note that there are other interrupt schemes.)
1. The interrupt line, an electrical connection between the mainboard and a processor, becomes active—devices such as timers, peripheral cards and controllers send signals that activate the interrupt line to inform a processor that an event has occurred (e.g., a period of time has passed or an I/O request has completed). Most processors contain an interrupt controller that orders interrupts according to their priority so that important interrupts are serviced first. Other interrupts are queued until all higher-priority interrupts have been serviced.
2. After the interrupt line becomes active, the processor completes execution of the current instruction, then pauses the execution of the current process. To pause process execution, the processor must save enough information so that the process can be resumed at the correct place and with the correct register information. In early IBM systems, this data was contained in a data structure called the program status word (PSW). In the Intel IA-32 architecture, such process state is referred to as the task state segment (TSS). The TSS is typically stored in a process’s PCB.22
3. The processor then passes control to the appropriate interrupt handler.
Each type of interrupt is assigned a unique value that the processor uses as an index into the interrupt vector, which is an array of pointers to interrupt handlers. The interrupt vector is located in memory that processes cannot access, so that errant processes cannot modify its contents.
4. The interrupt handler performs appropriate actions based on the type of interrupt.
5. After the interrupt handler completes, the state of the interrupted process (or some other “next process” if the kernel initiates a context switch) is restored.
6. The interrupted process (or some other “next process”) executes. It is the responsibility of the operating system to determine whether the interrupted process or some other “next process” executes. This important decision, which can significantly impact the level of service each application receives, is discussed in Chapter 8, Processor Scheduling. For example, if the interrupt signaled an I/O completion event that caused a high-priority process to transition from blocked to ready, the operating system might preempt the interrupted process and dispatch the high-priority process.
Let us consider how the operating system and hardware interact in response to clock interrupts (Fig. 3.7). At each timer interval, the interrupting clock generates an interrupt that allows the operating system to execute to perform system management operations such as process scheduling. In this case, the processor is executing process P1 (1) when the clock issues an interrupt (2). Upon receiving the interrupt, the pro- cessor accesses the interrupt vector entry that corresponds to the timer interrupt (3).
The processor then saves the process’s execution context to memory (4) so that the P1’s execution context is not lost when the interrupt handler executes.23 The processor then executes the interrupt handler, which determines how to respond to the inter- rupt (5). The interrupt handler may then restore the state of the previously executing process (P1) or call the operating system processor scheduler to determine the “next” process to run. In this case, the handler calls the process scheduler, which decides that process P2, the highest-priority waiting process, should obtain the processor (6). The context for process P2 is then loaded from its PCB in main memory, and process P1’s execution context is saved to its PCB in main memory.
Self Review
1. Why are the locations of interrupt handlers generally not stored in a linked list?
2. Why is the process’s execution context saved to memory while the interrupt handler exe- cutes?
Ans: 1) To avoid becoming overwhelmed by interrupts, the system must be able to process each interrupt quickly. Traversing a linked list could significantly increase a system’s response time if the number of interrupt types were large. Therefore, most systems use an interrupt vector (i.e., an array) to quickly access the location of an interrupt handler. 2) If the process’s execution context is not saved in memory, the interrupt handler could overwrite the process’s registers.
Interrupt Classes
The set of interrupts a computer supports is dependent on the system’s architecture. Several types of interrupts are common to many architectures; in this section we discuss the interrupt structure supported by the Intel IA-32 specification,24 which is implemented in Intel® Pentium® processors. (Intel produced over 80 percent of the personal computer processors shipped in 2002.25)
The IA-32 specification distinguishes between two types of signals a processor may receive: interrupts and exceptions. Interrupts notify the processor that an event has occurred (e.g., a timer interval has passed) or that an external device’s status has changed (e.g., an I/O completion). The IA-32 architecture also provides software-generated interrupts—processes can use these to perform system calls. Exceptions indicate that an error has occurred, either in hardware or as a result of a software instruction. The IA-32 architecture also uses exceptions to pause a process when it reaches a breakpoint in code.26
Devices that generate interrupts, typically in the form of I/O signals and timer interrupts, are external to a processor. These interrupts are asynchronous with the running process, because they occur independently of instructions being executed by the processor. Software-generated interrupts, such as system calls, are synchronous with the running process, because they are generated in response to an instruction. Figure 3.8 lists several types of interrupts recognized by the IA-32 architecture.
The IA-32 specification classifies exceptions as faults, traps or aborts (Fig. 3.9). Faults and traps are exceptions to which an exception handler can respond to allow processes to continue execution. A fault indicates an error that an exception handler can correct. For example, a page fault occurs when a process attempts to access data that is not in memory (we discuss page faults in Chapter 10, Virtual Memory Organization, and in Chapter 11, Virtual Memory Management). The operating system can correct this error by placing the requested data in main memory. After the problem is corrected, the processor restarts the process that caused
of the accumulator. In this case, the operating system can simply notify the process that an overflow occurred. After executing the trap’s exception handler, the processor restarts the process at the next instruction following the one that caused the exception.
Aborts indicate errors from which the process (or perhaps even the system) cannot recover, such as hardware failure. In this case, the processor cannot reliably save the process’s execution context. Typically, as a result, the operating system terminates prematurely the process that caused the abort.
Most architectures and operating systems prioritize interrupts, because some require more immediate action than others. For example, responding to a hardware failure is more important than responding to an I/O-completion event. Interrupt priorities can be implemented in both hardware and software simultaneously. For example,a processor might block or queue interrupts of a lower priority than that of the interrupt the processor is currently handling. At times, the kernel can become so overloaded with interrupts that it can no longer respond to them. Rapid response to interrupts and quick return of control to interrupted processes is essen- tial to maximizing resource utilization and achieving a high degree of interactivity. Most processors therefore allow the kernel to disable (or mask) an interrupt type. The processor may then ignore interrupts of that type or store them in a queue of pending interrupts that are delivered when that type of interrupt is reenabled. In the IA-32 architecture, the processor provides a register that indicates whether interrupts are disabled.27
Self Review
1. In the IA-32 architecture, what two types of signals can a processor receive?
2. In the IA-32 architecture, what is the difference between a fault and a trap?
Ans: 1) A processor can receive interrupts or exceptions. Interrupts indicate that an event has occurred; exceptions indicate that an error has occurred. 2) A fault restarts a process from the instruction that caused the exception. Faults are generally errors that can be corrected. A trap restarts a process at the next instruction following the one that caused the exception. Traps are usually generated by system calls and by the arrival of program control at breakpoints.
Comments
Post a Comment