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.

Dependency Surface

Detected Declarations

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

Implementation Notes