20.4 Accommodating Architecture-Specific Interrupt Requirements
The low-level initialization of the interrupt subsystem is completed across two distinct steps. The first step is dispatched via the routine early_irq_init(), which is engineered primarily to accommodate the specialized, low-level constraints of various hardware architectures. This function is declared as a weak symbol placeholder (__weak), and its default baseline implementation acts as a simple empty shell function that instantly returns 0. It is defined within the source file git/kernel/softirq.c (historically or alternatively in git/kernel/irq/irqdesc.c depending on the kernel version tree) as follows:
int __init __weak early_irq_init(void)
{
return 0;
}
On certain hardware architectures, it is mandatory to pre-allocate specific blocks of memory or initialize unique hardware control registers prior to carving out individual interrupt tracks; under these constraints, the architecture-specific code overrides this baseline implementation. Because the default function is compiled as a weak symbol, whenever the linker encounters a platform-specific function sharing an identical name, the toolchain automatically prioritizes and links the architecture-specific override variant. Conversely, if a specific CPU architecture has no specialized early interrupt initialization demands, it seamlessly falls back to leverage this default weak placeholder behavior without triggering a linker failure anomaly. This decoupled design pattern elegantly reflects the foundational Linux engineering philosophy of a "unified generic framework paired with discrete architecture variances."
If the kernel image is compiled with sparse interrupt support enabled via the configuration flag CONFIG_SPARSE_IRQ, the system overrides and provides a comprehensive implementation of the early_irq_init() routine. This specific variant is hosted within the source file git/kernel/irq/irqdesc.c and is structured as follows:
int __init early_irq_init(void)
{
int i, initcnt, node = first_online_node;
struct irq_desc *desc;
init_irq_default_affinity();
initcnt = arch_probe_nr_irqs();
printk(KERN_INFO "NR_IRQS: %d, nr_irqs: %d, preallocated irqs: %d\n",
NR_IRQS, nr_irqs, initcnt);
if (WARN_ON(nr_irqs > IRQ_BITMAP_BITS))
nr_irqs = IRQ_BITMAP_BITS;
if (WARN_ON(initcnt > IRQ_BITMAP_BITS))
initcnt = IRQ_BITMAP_BITS;
if (initcnt > nr_irqs)
nr_irqs = initcnt;
for (i = 0; i < initcnt; i++) {
desc = alloc_desc(i, node, 0, NULL, NULL);
set_bit(i, allocated_irqs);
irq_insert_desc(i, desc);
}
return arch_early_irq_init();
}
Within the context of the Linux kernel interrupt subsystem, this version of early_irq_init serves as the core initialization logic for managing Sparse IRQ Descriptors. Its primary technical task is to establish the underlying database data structures for interrupt tracking and execute the transition from a static, compile-time configuration to a dynamic runtime tracking environment.
The function first invokes init_irq_default_affinity() to initialize the default CPU affinity bitmask assigned to the interrupt lines. In multi-core symmetric multiprocessing (SMP) architectures, this mask dictates which explicit CPU cores are authorized to respond to an incoming interrupt if no specialized routing constraints have been applied by user space, typically defaulting to the full set of all online processor cores.
Following this, it evaluates arch_probe_nr_irqs() to poll the total number of pre-allocated interrupt vectors natively demanded by the underlying hardware platform. It subsequently enforces hard boundaries over the system's aggregate interrupt limit (nr_irqs) and the pre-allocated vector count (initcnt) via the constraint variable IRQ_BITMAP_BITS (which is typically derived mathematically from the static build property NR_CPUS or NR_IRQS). This configuration safeguard guarantees that the administrative tracking bitmaps used to audit interrupt allocation states will never suffer an out-of-bounds memory access violation.
When CONFIG_SPARSE_IRQ is active, the system completely abandons the legacy architecture of maintaining a massive, statically compiled array of interrupt descriptors in memory. Instead, it transitions to manage these elements sparsely via a high-performance radix tree index. Utilizing the routine alloc_desc(), the allocator dynamic carves out a chunk of memory on the designated NUMA node to house a fresh struct irq_desc container for each pre-allocated vector index. It simultaneously triggers set_bit() to tag the matching interrupt slot inside the global allocation bitmap allocated_irqs as occupied, preventing subsequent dynamic runtime allocation requests from inducing an ID collision.
Once the descriptor structure is initialized, the system calls irq_insert_desc() to insert the allocated irq_desc instance directly into the global radix tree index repository. The radix tree engine supplies a highly efficient logarithmic lookup algorithm to resolve a target descriptor pointer (Value) from a raw logical software interrupt number (Key). When orchestrating massive, enterprise-grade hardware topologies that handle tens of thousands of concurrent interrupt sources, this sparse indexing layout delivers a substantial performance edge and significantly higher memory utilization efficiency compared to a linear array layout.
At its conclusion, the function dispatches arch_early_irq_init(). This interface acts as an architecture-dependent hardware hook (routinely overridden on platforms like x86 to execute early mapping initialization across hardware components); for ARM-based Linux distributions, this architecture hook resolves to a standard empty default function.