5
$\begingroup$

Just need a little help understanding hardware interrupts.

As I understand (feel free to correct) a hardware interrupts occurs when hardware wants attention of the computer. In basic terms the hardware sends a message down the interrupt line which is then controlled by the PIC. The CPU receives the interrupt and carries out the instruction once it has completed the current one it is on.

Every time I've seen examples of interrupts they have been 'printer running out of paper', 'network adapter receiving data packet' etc. My question is, how is the process of the hardware interrupt any different from pressing a key on a keyboard or moving a mouse? Each of these actions requires attention from the CPU but as I understand they are never used as examples of interrupts. Are they interrupts? Does everything I do with an input device cause an interrupt?

Any clarification would be much appreciated.

$\endgroup$
6
$\begingroup$

In general, no, on modern platforms, not everything is a hardware interrupt -- though you could imagine a platform where it is.

On some platforms, hardware interrupts are used for all input events (including, yes, pressing a key on a keyboard or moving a mouse).

However, interrupts come with some performance implications. Therefore, in modern platforms, we often use a combination of interrupts and other I/O mechanisms. We might use interrupts for some input devices, but other input devices might use memory-mapped I/O. For instance, your Ethernet card might use memory-mapped I/O, to write incoming packets into a region of memory dedicated for this use. Memory-mapped I/O can be combined with interrupts or with polling.

You can find more on interrupts, polling, memory-mapped I/O, DMA, and related topics in a good operating systems textbook.

$\endgroup$
3
1
$\begingroup$

Not everything is a hardware interrupt. Hardware interrupts are mostly used to gather input from IO devices. Today, it is rather complex and quite different from how it used to work with the old 8259 PIC. Today, there's a combination of IO APIC which serves the whole CPU and local APIC which serves a specific core of the CPU.

The IO APIC is becoming more and more obsolete with the MSI/MSI-X capability of PCI devices. PCI devices are MMIO meaning that you write to certain (uncached) part of RAM and it sends the data to the PCI devices instead. I don't know exactly how it is implemented in hardware itself. I would guess that there is a separate part in the CPU which is configured by the PCI devices themselves. For example, when you plug a PCI device, it would send signals to the CPU. Again, I don't know how that works exactly. What I know is that the configuration space of a PCI device can change position. For example, a BAR can point to different addresses depending on the device and its version.

Most chips today are PCI-express and they have the mandatory MSI-X capability. They thus bypass the IO APIC and send some kind of inter-processor interrupt to the CPU. It thus makes the IO APIC more and more obsolete because everything is PCI today.

For x86, you could think of the AHCI which drives SATA hard-drives, the xHCI which drives USB devices, network cards which are PCI or graphics cards which are also PCI.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.