gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 12:48:53 27 4
gpt4 key购买 nike

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

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com