Interrupt Overview
Interrupt concept
- Interrupt source: refers to the event that causes an interrupt or the source of an interrupt request.
- Interrupt request: The request sent by the interrupt source to the CPU to suspend the currently executed task and handle the urgent task.
- Breakpoint: When an interrupt occurs, the pause point of the interrupted program, that is, the place where the program is paused.
Interrupt priority and interrupt masking
Interrupt priority
- Interrupt priority is to enable the system to respond to and handle all interrupt events in a timely manner. The system will classify interrupt sources into different levels according to the importance and urgency of the event.
- In general, the order of interrupt priority from high to low is:
- Hardware fault interrupt
- Voluntary interrupt
- Program interrupt
- External interrupt
- Input and output interrupt
Interrupt masking
- Interrupt masking: In order to prevent low-priority interrupt event processing from interrupting high-priority interrupts, computer systems use interrupt masking technology. According to whether it can be masked, interrupts are divided into two categories:
- Non-maskable interrupt: Once requested, the CPU must respond unconditionally.
- Maskable interrupt: The CPU can choose to respond or ignore.
Interrupt processing method
-
Sequential processing method:
- In this method, when the processor is processing an interrupt, all new interrupt requests are masked until the current interrupt is processed and then check whether there is a new interrupt. If there is a new interrupt, continue to process it in sequence.
-
Nested processing method:
- When the system sets the interrupt priority, multiple interrupt requests of different priorities may arrive at the same time. The system will respond to the highest priority interrupt request first.
- High-priority interrupt requests can preempt low-priority interrupt processing, similar to preemptive scheduling in process scheduling.
Interrupt processing process
- Wake up the blocked driver process:
- When an interrupt occurs, the system may need to wake up some blocked processes to process resources or complete specific tasks.
- Protect the CPU environment of the interrupted process:
- Save the state of the current process (such as register values) to ensure that the process can be restored after the interrupt processing is completed.
- Transfer to the corresponding device handler:
- Jump to the corresponding device handler according to the interrupt source.
- Interrupt processing:
- Execute the interrupt handler to handle related interrupt events.
- Restore the scene of the interrupted process:
- After the interrupt processing is completed, restore the state of the original process and continue to execute the interrupted task.