调度员如何工作? [英] how dispatcher works?

查看:72
本文介绍了调度员如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始了我的操作系统课程.据我所知,调度程序的工作是保存当前进程的上下文并加载下一步要运行的进程的上下文.但是,它是如何做到的呢?当一个进程被抢占时,调度程序将被加载并执行(因为它也是一个程序),因此寄存器,PSW等中先前进程的上下文将立即丢失.在加载自身之前如何保存上下文?

I have recently started my OS course. As far as i know the work of dispatcher is to save the context of current process and load context of process to be run next. But how does it do that? When a process is preempted then as soon as dispatcher will be loaded and executed ( as it is also a program ) the context of previous process in registers, PSW etc will be lost. How is it going to save the context before loading itself ?

推荐答案

简单的答案是,现代处理器提供了体系结构扩展,提供了可以在硬件中交换的几组寄存器,因此最多X个任务可以保留其全部内容.套寄存器.

The simple answer is that modern processors offer architectural extensions providing for several banks of registers that can be swapped in hardware, so up to X tasks get to retain their full set of registers.

更复杂的答案是,调度程序在被中断触发时会接收中断时正在运行的程序的完整寄存器集(程序计数器除外,该计数器可能通过相互传播) -同意使用易失性"寄存器或其他类似方法.因此,在调度程序被触发时,必须仔细编写调度程序以存储寄存器组的当前状态,作为其第一个操作.简而言之,调度程序本身没有即时上下文,因此不会遇到相同的问题.

The more complex answer is that the dispatcher, when triggered by an interrupt, receives the full register set of the program that was running at the time of interrupt (with the exception of the program counter, which is presumably propagated through a mutually-agreed-upon 'volatile' register or some such). Thus, the dispatcher must be carefully written to store the current state of register banks as its first operation upon being triggered. In short, the dispatcher itself has no immediate context and thus doesn't suffer from the same problem.

这里是对调度程序调用过程中发生的情况的简单描述:

Here is an attempt at a simple description of what goes on during the dispatcher call:

  1. 当前具有上下文的程序正在处理器上运行.寄存器,程序计数器,标志,堆栈基等均适用于此程序;除了操作系统本地的保留寄存器"或类似的东西外,对该程序的任何知识都不了解调度程序.
  2. 调度程序功能的定时中断已触发.此时(在普通体系结构的情况下)唯一发生的事情是程序计数器立即跳到BIOS中断中列出的PC地址.这开始执行调度程序的"dispatch"子例程;其他所有内容都保持不变,因此调度程序可以查看先前正在执行的程序的寄存器,堆栈等.
  3. 调度程序(像所有程序一样)具有一组对当前寄存器集进行操作的指令.这些指令的编写方式使他们知道先前执行的应用程序已将其所有状态都抛在了后面.调度程序中的前几条指令会将这种状态存储在内存中的某个地方.
  4. 调度程序确定应该使cpu的下一个程序是什么,获取其先前存储的所有状态,并用它填充寄存器.
  5. 调度程序跳到任务中列出的适当的PC计数器,该任务现在已在cpu上建立了完整的上下文.

总结(简化);调度程序不需要寄存器,它要做的就是将当前的CPU状态写入预定的内存位置,从预定的内存位置加载另一个进程的CPU状态,然后跳转到该进程停止的地方.

To (over)simplify in summary; the dispatcher doesn't need registers, all it does is write the current cpu state to a predetermined memory location, load another processes' cpu state from a predetermined memory location, and jumps to where that process left off.

这使它更清晰吗?

这篇关于调度员如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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