Understanding
Linux Interrupt Subsystem
Priya Dixit
Foundry Design Services (FDS) SW 1
Agenda
❑ Overview of Interrupt
❑ Types of interrupt
❑ Interrupt Controllers
❑ Generic Interrupt Handling
❑ Details of Structures used
❑ Generic Interrupt Handling Process
❑ High level Driver APIs
❑ Example: Insights of interrupts with Device Drivers
❑ Interrupt view from User Space
❑ Debugging Interrupts
Foundry Design Services (FDS) SW 2
Overview of Interrupts
❑ The Need:
o For communication between hardware devices and CPU
o Polling cause latency and overhead
❑ The Plan:
o Interrupt is a method used by the devices to get the CPU attention
o A signal is sent over a dedicated line from hardware devices to the processor
Foundry Design Services (FDS) SW 3
Interrupts Types
❑ Hardware and Software interrupts
o Hardware interrupts- Generated by connected devices
o Software interrupts- Synchronized events, generated by any internal system of the
computer (instruction in the program)
❑ Maskable and Non Maskable interrupts
o Maskable interrupts- The interrupts which can be ignored
o Non Maskable interrupts- The interrupts which cannot be ignored
❏ And many more ...
○ Shared Interrupts
○ Spurious Interrupts,
○ GIC Specific Interrupts ( PPI, SPI, SGI)
Foundry Design Services (FDS) SW 4
Trigger Level
❑ Level triggered (high or low)
o State
o As long as it needs attention, the line is asserted
❑ Edge triggered (rising or falling)
o Event
o Needs immediate action, irrespective of the activity of the source
Foundry Design Services (FDS) SW 5
Interrupt Controller
❑ On chip device to manage interrupts from various different peripheral devices
❑ Upon receiving an interrupt, sends a signal to the processor
The purpose is:
❑ To multiplex interrupts
❑ For Interrupt Masking
❑ Setting priorities
❑ Setting affinity
❑ Shared Interrupt lines
Foundry Design Services (FDS) SW 6
Generic Interrupt Subsystem
Structures and Generic APIs used in Interrupt Subsystem
Foundry Design Services (FDS) SW 7
The Relationship between IRQ Structures
Foundry Design Services (FDS) SW 8
1. Structure for irq_domain
Foundry Design Services (FDS) SW 9
APIs for Domain Operations
Foundry Design Services (FDS) SW 10
Example: irq_domain Operations
Foundry Design Services (FDS) SW 11
Recap: irq_domain
struct irq_domain: Hardware interrupt number Translator
❑ irq_domain is tied to the node of interrupt controller in Device Tree
❑ This structure shows relation between the global interrupt number to the local one
❑ The irq_alloc_desc*() and irq_free_desc*() APIs provide allocation and deallocation of irq
numbers
❑ When an interrupt is received, irq_find_mapping() function should be used to find the Linux IRQ
number from the hwirq number
Foundry Design Services (FDS) SW 12
2. Structure for irq_desc
Foundry Design Services (FDS) SW 13
Recap: irq_desc
struct irq_desc : Interrupt descriptor
❑ Contains all the core stuff information
❑ Include interrupt handler function
❑ Provides 1:1 mapping to the Linux interrupt number
❑ struct irq_data is embedded here
Foundry Design Services (FDS) SW 14
3. Structure for irq_data
Foundry Design Services (FDS) SW 15
Recap: irq_data
Struct irq_data: per irq chip data passed down to chip functions
❑ This is embedded in irq_desc structure
❑ Contains both hardware irq number and Linux irq number
❑ Contains the pointer to the irq_chip structure
❑ Provides link between irq_chip and irq_desc
Foundry Design Services (FDS) SW 16
4. Structure for irq_chip
Foundry Design Services (FDS) SW 17
Recap: irq_chip
struct irq_chip : Hardware Interrupt chip descriptor
❑ This structure is used to interact with the hardware at very low level
❑ A set of methods describing how to drive the interrupt controller
❑ Directly called by core IRQ code
Foundry Design Services (FDS) SW 18
Interrupt State and related APIs
❑ irqchip_state is embedded into irq_chip structure
Foundry Design Services (FDS) SW 19
Interrupt Handling Flow
Foundry Design Services (FDS) SW 20
Generic Interrupt Handler APIs
❑Generic_handle_irq_desc ❑handle_irq_event
Foundry Design Services (FDS) SW 21
Recap: Interrupt Handling
❑ When interrupt occurs, “handle_irq” function which is stored in the IRQ descriptor (irq_desc) is
called directly or we can call the “generic_handle_irq_desc” function
❑ “handle_irq_event “ sets the IRQ state as “in progress”, acquire the IRQ description lock and
then call “handle_irq_event_percpu”
❑ Inside “handle_irq_event_percpu” function, we call “__handle_irq_event_percpu” and add
some randomness to the pool of interrupts handled by the CPU
❑ “__handle_irq_event_percpu” takes all the actions (based on irq_desc) required for the
interrupt and then clear the interrupt
❑ To handle the spurious or bad interrupts, we call “handle_bad_irq” function
Foundry Design Services (FDS) SW 22
High Level Driver APIs
❑ request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags, const char *name,
void *dev_id)
❑ free_irq(unsigned int irq, void *dev_id)
❑ enable_irq(unsigned int irq)
❑ disable_irq(unsigned int irq)
❑ disable_irq_nosync(unsigned int irq)
❑ in_irq()
❑ in_interrupt()
Disabling all interrupts
❑ void local_irq_save(unsigned long flags);
❑ void local_irq_disable(void);
A call to local_irq_save disables interrupt delivery on the current processor after saving the current
interrupt state into flags.
local_irq_disable shuts off local interrupt delivery without saving the state.
Foundry Design Services (FDS) SW 23
Interrupt Flags
Foundry Design Services (FDS) SW 24
Example of driver using generic interrupt APIs
❑request_irq ❑free_irq
Foundry Design Services (FDS) SW 25
procfs Interface view
❑Enable CONFIG_PROCFS
Foundry Design Services (FDS) SW 26
Interrupt View from User space
Foundry Design Services (FDS) SW 27
Configuration for Debugging Interrupts
❑ Enable DEBUG_FS and mount the debugfs (mount -t debugfs none /sys/kernel/debug)
❑ Enable GENERIC_IRQ_DEBUGFS(“General Setup->irq subsystem->expose irq internals in
debugfs..." in menuconfig). This expose internal interrupt state information
❑ We can see various properties like hardware irq number, count per cpu, actions, name, type,
etc. using /sys/kernel/irq/ interface. (CONFIG_SYSFS need to be enabled)
Foundry Design Services (FDS) SW 28
sysfs Interface View
Foundry Design Services (FDS) SW 29
Any Questions ?
Foundry Design Services (FDS) SW 30
THANK YOU
Foundry Design Services (FDS) SW 31