kernel/irq/handle.c
Source file repositories/reference/linux-study-clean/kernel/irq/handle.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/irq/handle.c- Extension
.c- Size
- 7929 bytes
- Lines
- 296
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/irq.hlinux/random.hlinux/sched.hlinux/interrupt.hlinux/kernel_stat.hasm/irq_regs.htrace/events/irq.hinternals.h
Detected Declarations
function handle_bad_irqfunction no_actionfunction warn_no_threadfunction __irq_wake_threadfunction irqhandler_duration_check_setupfunction irqhandler_duration_checkfunction __handle_irq_event_percpufunction for_each_action_of_descfunction handle_irq_event_percpufunction handle_irq_eventfunction set_handle_irqfunction generic_handle_arch_irqexport handle_bad_irqexport no_action
Annotated Snippet
* if (desc->state & IRQS_INPROGRESS) {
* spin_unlock(desc->lock);
* while(desc->state & IRQS_INPROGRESS)
* cpu_relax();
* goto again;
* }
* if (!test_bit(IRQTF_RUNTHREAD, &action->thread_flags))
* desc->threads_oneshot &= ~mask;
* spin_unlock(desc->lock);
*
* So either the thread waits for us to clear IRQS_INPROGRESS
* or we are waiting in the flow handler for desc->lock to be
* released before we reach this point. The thread also checks
* IRQTF_RUNTHREAD under desc->lock. If set it leaves
* threads_oneshot untouched and runs the thread another time.
*/
desc->threads_oneshot |= action->thread_mask;
/*
* We increment the threads_active counter in case we wake up
* the irq thread. The irq thread decrements the counter when
* it returns from the handler or in the exit path and wakes
* up waiters which are stuck in synchronize_irq() when the
* active count becomes zero. synchronize_irq() is serialized
* against this code (hard irq handler) via IRQS_INPROGRESS
* like the finalize_oneshot() code. See comment above.
*/
atomic_inc(&desc->threads_active);
/*
* This might be a premature wakeup before the thread reached the
* thread function and set the IRQTF_READY bit. It's waiting in
* kthread code with state UNINTERRUPTIBLE. Once it reaches the
* thread function it waits with INTERRUPTIBLE. The wakeup is not
* lost in that case because the thread is guaranteed to observe
* the RUN flag before it goes to sleep in wait_for_interrupt().
*/
wake_up_state(action->thread, TASK_INTERRUPTIBLE);
}
static DEFINE_STATIC_KEY_FALSE(irqhandler_duration_check_enabled);
static u64 irqhandler_duration_threshold_ns __ro_after_init;
static int __init irqhandler_duration_check_setup(char *arg)
{
unsigned long val;
int ret;
ret = kstrtoul(arg, 0, &val);
if (ret) {
pr_err("Unable to parse irqhandler.duration_warn_us setting: ret=%d\n", ret);
return 0;
}
if (!val) {
pr_err("Invalid irqhandler.duration_warn_us setting, must be > 0\n");
return 0;
}
irqhandler_duration_threshold_ns = val * 1000;
static_branch_enable(&irqhandler_duration_check_enabled);
return 1;
}
__setup("irqhandler.duration_warn_us=", irqhandler_duration_check_setup);
static inline void irqhandler_duration_check(u64 ts_start, unsigned int irq,
const struct irqaction *action)
{
u64 delta_ns = local_clock() - ts_start;
if (unlikely(delta_ns > irqhandler_duration_threshold_ns)) {
pr_warn_ratelimited("[CPU%u] long duration of IRQ[%u:%ps], took: %llu us\n",
smp_processor_id(), irq, action->handler,
div_u64(delta_ns, NSEC_PER_USEC));
}
}
irqreturn_t __handle_irq_event_percpu(struct irq_desc *desc)
{
irqreturn_t retval = IRQ_NONE;
unsigned int irq = desc->irq_data.irq;
struct irqaction *action;
for_each_action_of_desc(desc, action) {
irqreturn_t res;
/*
* If this IRQ would be threaded under force_irqthreads, mark it so.
*/
Annotation
- Immediate include surface: `linux/irq.h`, `linux/random.h`, `linux/sched.h`, `linux/interrupt.h`, `linux/kernel_stat.h`, `asm/irq_regs.h`, `trace/events/irq.h`, `internals.h`.
- Detected declarations: `function handle_bad_irq`, `function no_action`, `function warn_no_thread`, `function __irq_wake_thread`, `function irqhandler_duration_check_setup`, `function irqhandler_duration_check`, `function __handle_irq_event_percpu`, `function for_each_action_of_desc`, `function handle_irq_event_percpu`, `function handle_irq_event`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.