引用操作系统中的以下段落:三个简单的部分,
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 registers
由 hardware
保存(意思是由 CPU
本身保存)在 kernel stack
上那个过程。当interrupt handler
代码写完了,user registers
将使用 kernel stack
恢复那个过程,从而恢复user stack
并且进程成功返回user mode
来自 kernel mode
.
如果是 context switch
来自进程A
处理 B
,非常kernel stacks
两个进程的A
和 B
被切换,在 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/