Linux中断处理 [英] Linux Interrupt Handling

查看:81
本文介绍了Linux中断处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解Linux中断处理机制.我尝试了一下谷歌搜索,但找不到答案.有人可以向我解释为什么handle_IRQ_event最后需要调用local_irq_disable吗?此后,控件将返回到do_irq,最终它将返回到入口点.然后谁将使中断返回.这是中断处理程序的责任吗?如果是这样,为什么会这样?

I am trying to understand the Linux interrupt handling mechanism. I tried googling a bit but couldn't find an answer to this one. Can someone please explain it to me why the handle_IRQ_event needs to call local_irq_disable at the end? After this the control goes back to do_irq which eventually will go back to the entry point. Then who will enable the interrupts back.? It is the responsibility of the interrupt handler? If so why is that so?

参考代码

asmlinkage int handle_IRQ_event(unsigned int irq, struct pt_regs *regs, struct irqaction *action) 
{ 
    int status = 1; 
    int retval = 0; 

    if (!(action->flags & SA_INTERRUPT)) 
        local_irq_enable(); 
    do 
    { 
       status |= action->flags; 
       retval |= action->handler(irq, action->dev_id, regs); 
       action = action->next; 
    } 
    while (action); 

    if (status & SA_SAMPLE_RANDOM) 
        add_interrupt_randomness(irq);

    local_irq_disable(); 

    return retval; 
}

推荐答案

来自LDD3的handle_IRQ_event版本似乎来自2.6.8内核,甚至可能更早.假设我们正在使用x86,处理器将在调用中断处理程序之前清除EFLAGS寄存器中的中断标志(IF). iret指令将恢复旧的EFLAGS寄存器.

The version of handle_IRQ_event from LDD3 appears to come from the 2.6.8 kernel, or possibly earlier. Assuming we're dealing with x86, the processor clears the interrupt flag (IF) in the EFLAGS register before it calls the interrupt handler. The old EFLAGS register will be restored by the iret instruction.

Linux的SA_INTERRUPT IRQ处理程序标志(现已过时)确定中断处理程序中是否允许更高优先级的中断.为快速"中断处理程序设置了SA_INTERRUPT标志,该处理程序使中断保持禁用状态.没有为重新启用中断的慢速"中断处理程序设置SA_INTERRUPT标志.

Linux's SA_INTERRUPT IRQ handler flag (now obsolete) determines whether higher priority interrupts are allowed in the interrupt handler. The SA_INTERRUPT flag is set for "fast" interrupt handlers that left interrupts disabled. The SA_INTERRUPT flag is not set for "slow" interrupt handlers that re-enable interrupts.

无论SA_INTERRUPT标志如何,do_IRQ本身都会在禁用中断的情况下运行,并且在调用handle_IRQ_event时仍将其禁用.由于handle_IRQ_event可以启用中断,因此最后调用local_irq_disable可以确保在返回do_IRQ时再次将其禁用.

Regardless of the SA_INTERRUPT flag, do_IRQ itself runs with interrupts disabled and they are still disabled when handle_IRQ_event is called. Since handle_IRQ_event can enable interrupts, the call to local_irq_disable at the end ensures they are disabled again on return to do_IRQ.

用于i386体系结构的2.6.8内核中的相关源代码文件是arch/i386/kernel/entry.Sarch/i386/kernel/irq.c.

The relevant source code files in the 2.6.8 kernel for i386 architecture are arch/i386/kernel/entry.S, and arch/i386/kernel/irq.c.

这篇关于Linux中断处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆