中断处理程序中的上下文切换 [英] Context switch in Interrupt handlers

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

问题描述

为什么在执行中断处理程序时无法进行上下文切换?更具体地说,在linux内核中,中断处理程序在被中断的进程的上下文中运行.为什么无法在中断处理程序中进行上下文切换来安排另一个进程?

Why can't a context switch happen when an interrupt handler is executing ? More specifically, in the linux kernel, interrupt handlers run in the context of the process that was interrupted. Why is it not possible to do a context switch in the interrupt handler to schedule another process ?

推荐答案

在多处理器上,执行中断处理程序时肯定会发生上下文切换.实际上,将很难预防.

On a multiprocessor, a context switch can certainly happen while an interrupt handler is executing. In fact, it would be difficult to prevent.

在单CPU机器上,根据定义,它一次只能运行一个控制线程.它只有一个寄存器集,一个ALU,等等.因此,如果中断处理程序正在运行,则根本没有资源可用于执行上下文切换.

On a single-CPU machine, by definition it can only be running one thread of control at a time. It only has one register set, one ALU, etc. So if the interrupt handler is running there simply are no resources with which to execute a context switch.

现在,如果您要说的话,中断处理程序可以实际调用上下文切换代码,并且 make 一次发生吗,好吧,我想在可以使它们工作的某些系统上.但是对于大多数人来说,这没有太大价值,而且很难安排. CPU以更高的优先级运行,并且无法降低此优先级,或者中断级别之间的同步丢失. OS中的关键部分已经在与中断执行同步,这会带来复杂性.此外,上下文切换是通过更改堆栈来进行的,就像在线程用户模式程序中一样,因此很难想象当需要中断堆栈来从中断返回时会如何发生.

Now, if you mean, can the interrupt handler actually call the context switch code and make one happen, well, I suppose on some systems that could be made to work. But for most, this wouldn't have much value and would be difficult to arrange. The CPU is running at elevated priority, and this priority cannot be lowered or synchronization between interrupt levels is lost. Critical sections in the OS are already synchronizing against interrupt execution and this would introduce complexities. Furthermore, a context switch happens by changing stacks, much like in a threaded user mode program, so it's hard to imagine how this might happen when the interrupt stack is needed for a return from the interrupt.

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

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