在__do_IRQ()的处理函数中,handle_IRQ_event (irq/handle.c)主要负责调用不同的中断信号所注册的函数。
- /**
- * handle_IRQ_event - irq action chain handler
- * @irq: the interrupt number
- * @regs: pointer to a register structure
- * @action: the interrupt action chain for this irq
- *
- * Handles the action chain of an irq event
- */
- irqreturn_t handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
- struct irqaction *action)
- {
- irqreturn_t ret, retval = IRQ_NONE;
- unsigned int status = 0;
- handle_dynamic_tick(action);
- if (!(action->flags & IRQF_DISABLED))
- local_irq_enable_in_hardirq();
- do {
- ret = action->handler(irq, action->dev_id, regs);
- if (ret == IRQ_HANDLED)
- status |= action->flags;
- retval |= ret;
- action = action->next;
- } while (action);
- if (status & IRQF_SAMPLE_RANDOM)
- add_interrupt_randomness(irq);
- local_irq_disable();
- return retval;
- }
我们在来看看时间中断里所注册的处理函数,x86_64/kernel/time.c
- static struct irqaction irq0 = {
- timer_interrupt, IRQF_DISABLED, CPU_MASK_NONE, "timer", NULL, NULL
- };
timer_interrupt 函数
- static irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
- {
- if (apic_runs_main_timer > 1)
- return IRQ_HANDLED;
- main_timer_handler(regs);
- #ifdef CONFIG_X86_LOCAL_APIC
- if (using_apic_timer)
- smp_send_timer_broadcast_ipi();
- #endif
- return IRQ_HANDLED;
- }
- #ifndef CONFIG_SMP
- update_process_times(user_mode(regs));
- #endif
- /*
- * Called from the timer interrupt handler to charge one tick to the current
- * process. user_tick is 1 if the tick is user time, 0 for system.
- */
- void update_process_times(int user_tick)
- {
- struct task_struct *p = current;
- int cpu = smp_processor_id();
- /* Note: this timer irq context must be accounted for as well. */
- if (user_tick)
- account_user_time(p, jiffies_to_cputime(1));
- else
- account_system_time(p, HARDIRQ_OFFSET, jiffies_to_cputime(1));
- run_local_timers();
- if (rcu_pending(cpu))
- rcu_check_callbacks(cpu, user_tick);
- scheduler_tick();
- run_posix_cpu_timers(p);
- }
