🌐
Linux Kernel Labs
linux-kernel-labs.github.io › refs › heads › master › lectures › interrupts.html
Interrupts — The Linux Kernel documentation
We will name the identifier as ... instructions as interrupt/exception handler. ... Below we can find Linux IRQ vector layout. The first 32 entries are reserved for exceptions, vector 128 is used for syscall interface and the rest are used mostly for hardware interrupts handlers. On x86 an IDT entry has 8 bytes and it is named gate. There can be 3 types of ...
🌐
Opensource.com
opensource.com › article › 20 › 10 › linux-kernel-interrupts
How the Linux kernel handles interrupts | Opensource.com
October 5, 2020 - Moreover, the keyboard is not the only component that can cause interrupts. In general, there are three types of events that can cause the CPU to interrupt: Hardware interrupts, software interrupts, and exceptions.
🌐
Montana
cs.montana.edu › courses › spring2005 › 518 › Hypertextbook › jim › media › interrupts_on_linux.pdf pdf
Linux Interrupts: The Basic Concepts Mika J. Järvenpää University of Helsinki
Linux uses this vector 128 to implement a system call ie. when an int 0x80 opcode ([6]) is executed by a process · running in user mode the CPU switches into kernel mode · and starts executing kernel function system call(). ... Interrupt Controller.
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_enterprise_linux_for_real_time › 7 › html › reference_guide › chap-hardware_interrupts
Chapter 3. Hardware Interrupts | Reference Guide | Red Hat Enterprise Linux for Real Time | 7 | Red Hat Documentation
It may also receive special kinds of interrupts, such as NMI (Non-Maskable Interrupts) and SMI (System Management Interrupts). Hardware interrupts are referenced by an interrupt number. These numbers are mapped back to the piece of hardware that created the interrupt.
🌐
Linux Inside
0xax.gitbooks.io › linux-insides › content › Interrupts › linux-interrupts-7.html
Dive into external hardware interrupts · Linux Inside - 0xax
I will try to describe all types of interrupts in this book. Generally, a handler of an I/O interrupt must be flexible enough to service several devices at the same time. For example in the PCI bus architecture several devices may share the same IRQ line. In the simplest way the Linux kernel ...
🌐
O'Reilly
oreilly.com › library › view › understanding-the-linux › 0596005652 › ch04s06.html
4.6. Interrupt Handling - Understanding the Linux Kernel, 3rd Edition [Book]
November 17, 2005 - The Advanced Programmable Interrupt Controller (APIC)4.2.2. Exceptions4.2.3. Interrupt Descriptor Table4.2.4. Hardware Handling of Interrupts and Exceptions · 4.4.1. Interrupt, Trap, and System Gates4.4.2. Preliminary Initialization of the IDT
Authors   Daniel P. BovetMarco Cesati
Published   2005
Pages   942
🌐
Site24x7
site24x7.com › learn › linux › kernel-hardware-interrupts.html
What are hardware interrupts, and how do Linux kernels handle them: Site24x7
This is where interrupts come in: ... A Linux kernel needs to handle three kinds of interrupts: software interrupts, hardware interrupts, and exceptions....
🌐
EmbeTronicX
embetronicx.com › tutorials › linux › device-drivers › interrupts-in-linux-kernel
Interrupts in Linux Kernel - Linux Device Driver Tutorial Part 12
May 19, 2023 - ... Interrupts – asynchronous interrupts generated by hardware. Exceptions – synchronous interrupts generated by the processor. System calls (one type of exception) on the x86 architecture are implemented by the issuance of a software interrupt, ...
Find elsewhere
🌐
Columbia University
cs.columbia.edu › ~krj › os › lectures › L07-LinuxEvents.pdf pdf
Interrupts in Linux COMS W4118 Prof. Kaustubh R. Joshi
February 13, 2013 - In common address space · Syscall · Syscall · Interrupt · Overview · • Interrupts and ExcepWons · • ExcepWon Types and Handling · • Interrupt Request Lines (IRQs) • Programmable Interrupt Controllers (PIC) • Interrupt Descriptor Table (IDT) • Interrupt Handling · • SoaIRQs, Tasklets · • Work Queues · Interrupts · • Forcibly change normal flow of control ·
🌐
Linux Inside
0xax.gitbooks.io › linux-insides › content › Interrupts › linux-interrupts-1.html
Introduction · Linux Inside - 0xax
You can find the table with the description of these vector numbers in the second part of the Linux kernel initialization process - Early interrupt and exception handling. Vector numbers from 32 to 255 are designated as user-defined interrupts and are not reserved by the processor. These interrupts are generally assigned to external I/O devices to enable those devices to send interrupts to the processor. Now let's talk about the types of interrupts.
🌐
The Linux Documentation Project
tldp.org › LDP › tlk › dd › interrupts.html
Chapter 7 Interrupts and Interrupt Handling
So, an interrupt on bit 1 of the ISR at 0xA0 would be treated as system interrupt 9. Bit 2 of PIC1 is not available as this is used to chain interrupts from PIC2, any interrupt on PIC2 results in bit 2 of PIC1 being set. The kernel's interrupt handling data structures are set up by the device ...
🌐
The Geek Stuff
thegeekstuff.com › 2014 › 01 › linux-interrupts
Introduction to Linux Interrupts and CPU SMP Affinity
January 27, 2014 - All of the above discussed scenarios are example of Hardware interrupts. Hardware interrupts are further classified into two major categories: Non-maskable interrupts [NMI]: As the name suggests these types of interrupts cannot be ignored or suppressed by the CPU.
🌐
Baeldung
baeldung.com › home › processes › interrupt handling in linux
Interrupt Handling in Linux | Baeldung on Linux
March 19, 2025 - The CPU produces synchronous interrupts or exceptions when it encounters an error that the kernel needs to handle. These are mostly programming errors such as overflows or page faults.
🌐
LinuxVox
linuxvox.com › blog › trigger-kernel-interrupt-handler-how
Kernel Interrupt Handlers in Linux: How & Who Triggers Them? + Defining/Modifying Hardware Handlers Explained — linuxvox.com
Interrupts allow the CPU to focus on other tasks until an event requires action, making systems responsive and efficient. Linux categorizes interrupts into two broad types: hardware interrupts and software interrupts.
🌐
O'Reilly
oreilly.com › library › view › linux-device-drivers › 0596005903 › ch10.html
10. Interrupt Handling - Linux Device Drivers, 3rd Edition [Book]
February 7, 2005 - The /proc Interface10.2.2. Autodetecting the IRQ Number10.2.2.1. Kernel-assisted probing10.2.2.2. Do-it-yourself probing10.2.3. Fast and Slow Handlers10.2.3.1. The internals of interrupt handling on the x8610.3. Implementing a Handler10.3.1. Handler Arguments and Return Value10.3.2. Enabling and Disabling Interrupts10.3.2.1. Disabling a single interrupt10.3.2.2. Disabling all interrupts10.4. Top and Bottom Halves10.4.1. Tasklets10.4.2. Workqueues10.5. Interrupt Sharing10.5.1. Installing a Shared Handler10.5.2. Running the Handler10.5.3. The /proc Interface and Shared Interrupts10.6. Interrupt-Driven I/O10.6.1. A Write-Buffering Example10.7. Quick Reference · 11.1. Use of Standard C Types11.2.
Authors   Jonathan CorbetAlessandro Rubini
Published   2005
Pages   636
🌐
Reddit
reddit.com › r/linux › linux - interrupt handling: overview (part 1)
r/linux on Reddit: Linux - Interrupt Handling: Overview (Part 1)
December 18, 2022 -

After talking in general about the concept of interrupts (https://medium.com/@boutnaru/computer-architecture-interrupts-9d0dc849c1e5) now we are going to deep dive into how they are handled under Linux.

In order to handle an interrupt we first need to register it using a call to “request_irq” which adds the handler (https://elixir.bootlin.com/linux/v6.1/source/include/linux/interrupt.h#L165). In order to remove a handler we call “free_irq”. Fun fact, “request_irq” is referenced in 1280 files in the source code of the Linux kernel (version 6.1).

Overall, we can think about two major use cases when we are handling interrupts. First, interrupts that are designed to execute quickly. Second, interrupts which have to do several operations to complete (meaning they won’t execute quickly).

Due to that, interrupt handling has two phases (by the way it is true not only for Linux). We have “Top Half” and “Bottom Half”. The main reason for the split is the fact that we can’t perform large operations in interrupt-context (when interrupts are disable). So, what “Bottom Half” allows us is to defer work for later. For more information I suggest reading https://0xax.gitbooks.io/linux-insides/content/Interrupts/linux-interrupts-9.html.

We can sum up the phases of a “Top Half” as follows: ensure that the interrupt was triggered by the correct hardware (in case of line sharing), clearing interrupt pending bit on the hardware (if needed), does everything that needs to be immediate (like reading/writing to/from the device) and schedule the “Bottom Half” (if needed). As an example we can see the interrupt handler for a floppy (https://elixir.bootlin.com/linux/v6.1/source/drivers/block/floppy.c#L1712) that calls the deferred work in the following line https://elixir.bootlin.com/linux/v6.1/source/drivers/block/floppy.c#L1765.

Thus, “Top Half” runs in an interrupt context, which is used for quick responses to external events and it is responsible for creating the deferred work for later (the “Bottom Half”) - as we can see in the timeline diagram shown below.

Lastly, We have three types for the category of “Bottom Half”: workques, tasklets and softirq (https://www.oreilly.com/library/view/understanding-the-linux/0596002130/ch04s07.html). We will dive into each one of them in future writeups. By the way, there are also timers and normal regular kernel threads that can be used for deferred work but they are less natural for interrupt handling so I won’t go over them in this series.

Next we are going to start diving into workques, tasklets and softirq. See you in the next writeup :-).

https://hugh712.gitbooks.io/embeddedsystem/content/Images/RealTime/RT006.png
🌐
Medium
medium.com › @boutnaru › linux-interrupt-handling-overview-part-1-bd0a841047d2
Linux — Interrupt Handling: Overview (Part 1) | by Shlomi Boutnaru, Ph.D. | Medium
December 17, 2022 - As an example we can see the interrupt handler for a floppy (https://elixir.bootlin.com/linux/v6.1/source/drivers/block/floppy.c#L1712) that calls the deferred work in the following line https://elixir.bootlin.com/linux/v6.1/source/drivers/block/floppy.c#L1765. Thus, “Top Half” runs in an interrupt context, which is used for quick responses to external events and it is responsible for creating the deferred work for later (the “Bottom Half”) — as we can see in the timeline diagram shown below. Lastly, We have three types for the category of “Bottom Half”: workques, tasklets and softirq (https://www.oreilly.com/library/view/understanding-the-linux/0596002130/ch04s07.html).
🌐
The Linux Documentation Project
tldp.org › LDP › lkmpg › 2.6 › html › x1256.html
12.1. Interrupt Handlers
The second, called interrupts, ... lost. Under Linux, hardware interrupts are called IRQ's (InterruptRe quests)[1]. There are two types of IRQ's, short and long....
Top answer
1 of 3
45

Here's a high-level view of the low-level processing. I'm describing a simple typical architecture, real architectures can be more complex or differ in ways that don't matter at this level of detail.

When an interrupt occurs, the processor looks if interrupts are masked. If they are, nothing happens until they are unmasked. When interrupts become unmasked, if there are any pending interrupts, the processor picks one.

Then the processor executes the interrupt by branching to a particular address in memory. The code at that address is called the interrupt handler. When the processor branches there, it masks interrupts (so the interrupt handler has exclusive control) and saves the contents of some registers in some place (typically other registers).

The interrupt handler does what it must do, typically by communicating with the peripheral that triggered the interrupt to send or receive data. If the interrupt was raised by the timer, the handler might trigger the OS scheduler, to switch to a different thread. When the handler finishes executing, it executes a special return-from-interrupt instruction that restores the saved registers and unmasks interrupts.

The interrupt handler must run quickly, because it's preventing any other interrupt from running. In the Linux kernel, interrupt processing is divided in two parts:

  • The “top half” is the interrupt handler. It does the minimum necessary, typically communicate with the hardware and set a flag somewhere in kernel memory.
  • The “bottom half” does any other necessary processing, for example copying data into process memory, updating kernel data structures, etc. It can take its time and even block waiting for some other part of the system since it runs with interrupts enabled.

As usual on this topic, for more information, read Linux Device Drivers; chapter 10 is about interrupts.

2 of 3
26

Gilles already described the general case of an interrupt, the following applies specifically to Linux 2.6 on an Intel architecture (part of this is also based on Intel's specifications).

An interrupt is an event that changes the sequence of instructions executed by the processor.
There are two different kinds of interrupts:

  • Synchronous interrupt (Exception) produced by the CPU while processing instructions
  • Asynchronous interrupt (Interrupt) issued by other hardware devices

Exceptions are caused by programming errors (f.e. Divide error, Page Fault, Overflow) that must be handled by the kernel. He sends a signal to the program and tries to recover from the error.

The following two exceptions are classified:

  • Processor-detected exception generated by the CPU while detecting a anomalous condition; divided into three groups: Faults can generally be corrected, Traps report an execution, Aborts are serious errors.
  • Programmed exception requested by the programmer, handled like a trap.

Interrupts can be issued by I/O devices (keyboard, network adapter, ..), interval timers and (on multiprocessor systems) other CPUs. When an interrupt occures, the CPU must stop his current instruction and execute the newly arrived interrupt. He needs to save the old interrupted process state to (probably) resume it after the interrupt is handled.

Handling interrupts is a sensitive task:

  • Interrupts can occur at any time, the kernel tries to get it out of the way as soon as possible
  • An interrupt can be interrupted by another interrupt
  • There are regions in the kernel which must not be interrupted at all

Two different interrupt levels are defined:

  • Maskable interrupts issued by I/O devices; can be in two states, masked or unmasked. Only unmasked interrupts are getting processed.
  • Nonmaskable interrupts; critical malfunctions (f.e. hardware failure); always processed by the CPU.

Every hardware device has it's own Interrupt Request (IRQ) line. The IRQs are numbered starting from 0. All IRQ lines are connected to a Programmable Interrupt Controller (PIC). The PIC listens on IRQs and assigns them to the CPU. It is also possible to disable a specific IRQ line.
Modern multiprocessing Linux systems generally include the newer Advanced PIC (APIC), which distributes IRQ requests equally between the CPUs.

The mid-step between an interrupt or exception and the handling of it is the Interrupt Descriptor Table (IDT). This table associates each interrupt or exception vector (a number) with a specified handler (f.e. Divide error gets handled by the function divide_error()).

Through the IDT, the kernel knows exactly how to handle the occurred interrupt or exception.


So, what does the kernel when an interrupt occurres?

  • The CPU checks after each instruction if there's a IRQ from the (A)PIC
  • If so, consults the IDT to map the received vector to a function
  • Checks if the interrupt was issued by a authorized source
  • Saves the registers of the interrupted process
  • Call the according function to handle the interrupt
  • Load the recently saved registers of the interrupted process and try to resume it
🌐
O'Reilly
oreilly.com › library › view › understanding-the-linux › 0596002130 › ch04.html
4. Interrupts and Exceptions - Understanding the Linux Kernel, Second Edition [Book]
December 17, 2002 - Synchronous interrupts are produced by the CPU control unit while executing instructions and are called synchronous because the control unit issues them only after terminating the execution of an instruction.
Authors   Daniel P. BovetMarco Cesati
Published   2002
Pages   784