免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1017 | 回复: 0

Interrupts and Exceptions(二) [复制链接]

论坛徽章:
0
发表于 2008-05-08 00:39 |显示全部楼层

The Role of Interrupt Signals
As the name suggests, interrupt signals provide a way to divert the processor to code outside the normal flow of control. When an interrupt signal arrives, the CPU must stop what it's currently doing and switch to a new activity; it does this by saving the current value of the program counter (i.e., the content of the eip and cs registers) in the Kernel Mode stack and by placing an address related to the interrupt type into the program counter.
中断信号提供了一种改变处理器的执行顺序到正常控制序列外的代码的方法。当中断信号到达时,CPU必须停下它正在做的事,切换到一个新的活动;它通过将程序计数器的内容(eip和cs寄存器的值)保存在内核栈中,并用与中断类型对应的代码地址替换到程序计数器中,来完成这一改变。
There are some things in this chapter that will remind you of the context switch described in the previous chapter, carried out when a kernel substitutes one process for another. But there is a key difference between interrupt handling and process switching: the code executed by an interrupt or by an exception handler is not a process. Rather, it is a kernel control path that runs at the expense of the same process that was running when the interrupt occurred (see the later section "Nested Execution of Exception and Interrupt Handlers"). As a kernel control path, the interrupt handler is lighter than a process (it has less context and requires less time to set up or tear down).
这一章的一些内容将让你回想起上一章描述的,在内核用一个进程代替另一个进程时进行的上下文切换。然而在中断处理和进程切换之间有一个关键的区别:由中断或异常处理执行的代码不在进程中。相反,它只是一条内核控制路径,在那个中断发生时正在运行的进程的开销上运行。作为一条内核控制路径,中断处理比进程要轻得多(它拥有更少的上下文和需要更少的时间来启动和结束)。
Interrupt handling is one of the most sensitive tasks performed by the kernel, because it must satisfy the following constraints:
中断处理是内核进行的最敏感的任务之一,因为它必须满足下列约束:
·         Interrupts can come anytime, when the kernel may want to finish something else it was trying to do. The kernel's goal is therefore to get the interrupt out of the way as soon as possible and defer as much processing as it can. For instance, suppose a block of data has arrived on a network line. When the hardware interrupts the kernel, it could simply mark the presence of data, give the processor back to whatever was running before, and do the rest of the processing later (such as moving the data into a buffer where its recipient process can find it, and then restarting the process). The activities that the kernel needs to perform in response to an interrupt are thus divided into a critical urgent part that the kernel executes right away and a deferrable part that is left for later.
中断可以在任意时刻到来,这时内核可能希望结束它正在做的某件其他事情。因此,内核的目标是尽可能地结束中断,并尽可能地推迟大多数过程。比如,假设一块数据到达了网络设备。当硬件中断内核时,它可能简单地标记数据的存在,然后让处理器回去它之前做的事,稍后再做剩下的处理(比如将数据移到缓冲区,这里它的接收进程可以找到这些数据,并重新启动这个进程)。内核需要执行的响应中断的动作,因此被分为了一个相当紧急的部分,需要内核立刻执行,和一个可以推迟的部分,可以留在稍后处理。
·         Because interrupts can come anytime, the kernel might be handling one of them while another one (of a different type) occurs. This should be allowed as much as possible, because it keeps the I/O devices busy (see the later section "Nested Execution of Exception and Interrupt Handlers"). As a result, the interrupt handlers must be coded so that the corresponding kernel control paths can be executed in a nested manner. When the last kernel control path terminates, the kernel must be able to resume execution of the interrupted process or switch to another process if the interrupt signal has caused a rescheduling activity.
因为中断可以在任意时刻到来,内核可能在处理某个中断时,另外一个中断(不同类型)发生了。这应该被尽可能地容许,因为这样让I/O设备保持了繁忙。结果,中断处理程序必须这样编码,使得对应的内核控制路径可以以一种嵌套的方式执行。当最后的内核控制路径结束时,内核必须能恢复被中断的进程的执行,或者如果中断信号引发了重新调度的动作,切换到另外一个进程。
·         Although the kernel may accept a new interrupt signal while handling a previous one, some critical regions exist inside the kernel code where interrupts must be disabled. Such critical regions must be limited as much as possible because, according to the previous requirement, the kernel, and particularly the interrupt handlers, should run most of the time with the interrupts enabled.
尽管内核可以在执行一个中断时,接收一个新的中断信号,内核代码中存在一些临界区域,这里中断必须关闭。这种临界区域必须尽可能地限制,因为根据上面的需求,内核尤其是中断处理程序,大多数时间应该在中断开启的情况下运行。


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/65228/showart_680617.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP