[英]What exactly does that mean to allocate the CPU to another process in a Context Switch?
I'm studying both Computer Organization and Operating System. 我正在研究计算机组织和操作系统。 One confusing me a lot is What exactly does that mean to allocate a CPU to a process in a Context Switch? 一个让我感到困惑的是,在上下文切换中为进程分配CPU的确切含义是什么?
The term ' allocate CPU ' is not according to what I imagine about a Context Switch. 术语“ 分配CPU ”并不符合我对上下文切换的想象。
So I want to make sure If I'm right, according to my view: 因此,根据我的观点,我想确定如果我是对的:
Stored-program architecture stores instructions into the main memory, those instructions are as in the text section of a Process. 存储程序体系结构将指令存储到主存储器中,这些指令与流程的文本部分相同。
From computer organization's perspective, only Program Counter decides which instruction to execute. 从计算机组织的角度来看, 只有程序计数器才能确定要执行的指令。
If the kernel decides to switch the allocation from Process 1 to Process 2, namely context switch, it does: 如果内核决定将分配从进程1切换到进程2,即上下文切换,它将执行以下操作:
So, can I say that what kernel actually does to execute another Process, is it does a context switch and basically just changes the Program Counter's address to another process's text section address? 那么,我可以说内核实际上是执行另一个进程的,它是进行上下文切换,并且基本上只是将程序计数器的地址更改为另一个进程的文本段地址吗?
"Changing the program counter" is the low-level hardware view of what's going on. “更改程序计数器”是正在发生的底层硬件视图。
"Allocating the CPU" is the operating-system view of whatever it needs to do to keep track of system resources, which of course involves loading the program counter for the code now to be executed. “分配CPU”是操作系统的视图,它需要采取什么措施来跟踪系统资源,这当然包括为现在要执行的代码加载程序计数器。
A process is defined by its register values. 进程由其寄存器值定义。 Some of those will be general registers that any application can change and other will be system registers that can only be changed in kernel mode. 其中一些将是任何应用程序都可以更改的通用寄存器,而另一些将是只能在内核模式下更改的系统寄存器。
Most processors define a structure that is often called a Process Context Block. 大多数处理器定义一种结构,通常称为过程上下文块。 The PBC defines where each register defining the process state is stored. PBC定义了每个定义过程状态的寄存器的存储位置。 Some processor require multiple PCB-like structures as the my save floating point and other types of registers separately. 某些处理器需要多个类似PCB的结构作为我的保存浮点数和其他类型的寄存器。
Most processors have Load Process Context and Save Process Context instructions (or their equivalent. There is usually just a single operand to these instructions: the address of the PCB. 大多数处理器具有“加载过程上下文”和“保存过程上下文”指令(或等效指令)。这些指令通常只有一个操作数:PCB的地址。
A process change then looks like: 流程更改如下所示:
SAVEPCTX address_of_pcb_for_current_process
LOADPCT address_of_pcb_for_next_process ; after this, in a new process.
REI ; Return to user mode.
On some poorly design processors, these steps are more complicated. 在某些设计不佳的处理器上,这些步骤更加复杂。
The term 'allocate CPU' is not according to what I imagine about a Context Switch. 术语“分配CPU”并不符合我对上下文切换的想象。
It all depends upon how you think about it. 这完全取决于您如何看待它。 The processor always needs to be running something (unless you have some processor designed for mobile that can easily be turned off). 处理器始终需要运行某种东西(除非您有一些专门针对移动设备设计的可以轻松关闭的处理器)。 So is a context switch allocating a processor to a process or is it a process being assigned to a CPU? 那么,上下文切换是将处理器分配给进程还是将进程分配给CPU?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.