In a instruction cycle, the interrupt is the last part.
Interrupts occur at random times during the execution of a program, in response to signals from hardware.
|Type||Mean of Communication between|
|Interrupts||the CPU and the OS kernel|
|Signals||the OS kernel and OS processes|
An interrupt is an indication to a thread that it should stop what it is doing and do something else. It's up to the programmer to decide exactly how a thread responds to an interrupt, but it is very common for the thread to terminate.
Interrupts may be initiated by;
- the CPU (exceptions - e.g.: divide by zero, page fault),
- devices (hardware interrupts - e.g: input available),
- or by a CPU instruction (traps - e.g: syscalls, breakpoints).
They are eventually managed by the CPU, which “interrupts” the current task, and invokes an OS-kernel provided ISR/interrupt handler.
Interrupt process from Keyboard to Process
After USB host (computer’s USB “port”) receives the data from keyboard, it generates a hardware interrupt so that software driver in operating system can read the received data via host controller interface (usually over PCI or PCIe). After that, the data is processed by Human Interface Device (HID) subsystem in the OS which eventually results in placing a “key pressed” event (like WM_KEYDOWN) in operating system’s message queue. Then the event is dispatched by event loop to active application window.
Documentation / Reference
- Vol3 chapter 6 - https://software.intel.com/en-us/articles/intel-sdm