21.4 Establishing the Timer Framework
Following the RCU callback offloading sequence, the next task executed by start_kernel() is to establish the software interrupt framework for system timers via the function init_timers(). The primary responsibility of init_timers() is to build the Timer Wheel management infrastructure and hook the explicit timer execution routines onto the softirq core framework. Acting as the definitive initialization entry point for the Linux kernel's low-resolution timer subsystem, its principal function is to assemble the baseline architecture required to handle deferred timing tasks. The function is declared within the source file git/kernel/time/timer.c, and its definition is implemented as follows:
void __init init_timers(void)
{
init_timer_cpus();
posix_cputimers_init_work();
open_softirq(TIMER_SOFTIRQ, run_timer_softirq);
}
This initialization routine executes three sequential steps internally:
-
Initializing Per-CPU Local Timer Bases: It invokes the sub-routine init_timer_cpus() to initialize the private, localized timer vector matrices assigned to each individual CPU core. Every CPU core manages its own private timer_base structures, with each base instantiating its own structural lock (base->lock) and initializing the integrated "wheel sectors" utilized to group and bucket timers based on their respective expiration distances. This decentralized architecture minimizes cross-core lock contention during high-frequency timer registration passes.
-
Bootstrapping POSIX CPU Timer Work Tasks: The function executes posix_cputimers_init_work() to initialize the deferred bottom-half execution workloads utilized to process POSIX CPU timers (timers whose expiration thresholds scale relative to process or thread execution CPU time metrics). Because the callback logic of these timers is prohibited from executing directly within a hard interrupt context, the routine initializes a task_work structure or a deferred processing task to guarantee they are evaluated safely right before a process returns to user-space execution.
-
Registering the Timer Softirq Vector: The routine calls open_softirq() to register the TIMER_SOFTIRQ vector within the kernel's global software interrupt allocation table, binding its execution target to the flow handler run_timer_softirq. Whenever a hardware clock interrupt (Tick) fires, if the system discovers that a registered timer has crossed its expiration boundary, the kernel raises the TIMER_SOFTIRQ vector. Subsequently, the scheduler dispatches run_timer_softirq at an appropriate checkpoint to drain the queue and execute the callback functions of the expired timers.
This function serves as the definitive starting pipeline for the kernel's time-driven event mechanisms. It establishes a clean execution bridge routing control from low-level "hardware interrupts" up into high-level "software interrupt flow processing."