operating-system - 上下文切换开启时间中断

标签 operating-system context-switch

引用操作系统中的以下段落:三个简单的部分,

Note that there are two types of register saves/restores that happen during this protocol. The first is when the timer interrupt occurs; in this case, the user registers of the running process are implicitly saved by the hardware, using the kernel stack of that process. The second is when the OS decides to switch from A to B; in this case, the kernel registers are explicitly saved by the software (i.e., the OS), but this time into memory in the process structure of the process.



阅读有关上下文切换的其他文献我知道定时器中断将 cpu 抛出到内核模式,然后将进程上下文保存到内核堆栈中。

为什么作者在谈论多上下文保存时强调硬件/软件?

最佳答案

作者强调硬件/软件一部分是因为基本上是它的 上下文保存 正在完成,有时由 硬件 有时通过 软件 .

当定时器 interrupt发生时,user registershardware 保存(意思是由 CPU 本身保存)在 kernel stack 上那个过程。当interrupt handler代码写完了,user registers将使用 kernel stack 恢复那个过程,从而恢复user stack并且进程成功返回user mode来自 kernel mode .

如果是 context switch来自进程A处理 B ,非常kernel stacks两个进程的AB被切换,在 kernel 里面,间接表示 kernel registers 的保存和恢复.术语 软件 使用是因为 scheduler选择下一个运行哪个进程后的进程调用 function(thats why software) , 这就是 kernel stacks 的切换. context switch代码不用担心user register值 - 这些值已经安全地保存在 kernel stack 中到那时。

关于operating-system - 上下文切换开启时间中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41697642/

相关文章:

x86 - (写内核)如何修改中断描述符表?

linux - 调度器的工作

operating-system - 您想在操作系统中拥有哪些功能?

multithreading - 如何衡量一个非常大的程序的上下文切换开销?

java - 非同步i++是否重叠?

在 Linux 上,同一进程的线程之间的上下文切换成本

database - 您将如何构建数据库文件系统 (DBFS)?

c++ - 内存分配是系统调用吗?

.net - 是否有其他操作系统使用 PE 文件或至少将来有机会使用它?

java - Java程序的vmstat pidstat结果分析