Linux等待中断 [英] Linux wait in interrupt

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

问题描述

大家好吧,



i是Linux设备驱动程序编程的新手,我有一个疑问为什么我们不打算等待中断,任何人都可以告诉我





谢谢,

shan



删除了SHOUTING - OriginalGriff [/ edit]

hi all,

i am new to linux device driver programming, i have one doubt why we don''t use wait in interrupt, can any one tell me


Thanks,
shan

[edit]SHOUTING removed - OriginalGriff[/edit]

推荐答案

为什么不等待linux设备驱动程序中的中断?出于同样的原因,你不能在 任何 中断处理程序中等待,无论操作系统,处理器或任务如何。因为这是一件非常非常愚蠢的事情。



想一想:什么是中断?

回答它是一个信号(通常是硬件生成的)发生的事情需要快速处理。不久,不是当处理器不忙,而是现在。因为如果不是,数据就会丢失。并且一次只能处理一个中断(通常 - 有异常)。如果您的中断处理程序例程运行时间太长,则其他中断无法在需要时执行,或者可能发生第二个事件,在您的中断仍在处理时再次发出一个中断信号,然后堆栈开始填满一个令人震惊的速度,整个系统都会崩溃并死亡。



将中断想象成电话铃声:你停止正在做的事情,接听电话进行对话,并结束通话。然后你会在电话响起之前回到你正在做的事情。如果您在打电话时门铃响了,会发生什么?如果您在回答门之前完成了通话,那么当您到达那里时,访客可能已离开。或者,如果您还在处理第一部电话时第二部电话响了?你暂停通话,然后接听另一部电话吗?如果是这样,如果第一个来电者无聊等待并试图在第三部手机上给你回铃,会发生什么? (我假设你这里有一张大桌子,但如果没有,你的个人堆栈会溢出,你的房子会崩溃。)



让你的中断处理程序保持一个绝对最低限度简短,快速,高效。并尽快摆脱它们。
Why do you not wait in an interrupt in a linux device driver? for the same reason you don''t wait in any interrupt handler, regardless of OS, processor or task. Because it is a very, very silly thing to do.

Think about it: what is an interrupt?
Answer it is a signal (normally hardware generated) that something has occurred that needs to be dealt with, quickly. Not soon, not when the processor isn''t busy, but now. Because if it isn''t, data will be lost. And only one interrupt can (normally - there are exceptions) be handled at any one time. If your interrupt handler routine takes too long to run, then other interrupts cannot execute when they need to, or a second event may happen which signals one of your interrupts again while your interrupt is still processing, and then the stack starts to fill up at an alarming rate and the whole system falls over and dies.

Think of an interrupt as a phone ringing: you stop what you are doing, answer the phone have a conversation, and end the call. You then go back to what you were doing before the phone rang. What happens if the doorbell rings while you are on the phone? If you finish your call before you answer the door, the visitor may have left by the time you get there. Or if a second phone rings while you are still dealing with the first? Do you pause the call you are on, and answer the other phone? If so, what happens if the first caller gets bored waiting and tried to ring you back on a third phone? (I''m assuming you have a large desk here, but if not, your personal stack overflows, and your house crashes.)

Keep your interrupt handlers to an absolute minimum. Short, fast, efficient. And get out of them as soon as possible.


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

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