简体   繁体   English

在上下文切换中将CPU分配给另一个进程到底意味着什么?

[英]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,即上下文切换,它将执行以下操作:

  1. Store Process 1 's data into PCB 1 过程1的数据存储到PCB 1中
  2. Load Process 2 's data, namely PCB 2 into the kernel 进程2的数据(即PCB 2)加载到内核中
  3. Update all register values from PCB 2 ( Includes PC ) 更新PCB 2中的所有寄存器值( 包括PC
  4. So then PC's address is updated to another text section. 因此,PC的地址将更新为另一个文本部分。 The diagram below shows my thought. 下图显示了我的想法。

上下文切换

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.

相关问题 究竟什么是“过程上下文”,它与“中断上下文”有什么关系? - What is “process context” exactly, and how does it relates to “interrupt context”? 什么时候开始“执行过程”? 它在 cpu/memory 的哪个阶段? - When does exactly “execution of process” starts ? At what stage it is in cpu / memory? 在本书的上下文中,所谓的“细粒度并行”到底是什么意思? - What does the so-called "Fine-Grained Parallelism" exactly mean in the context of this book? 上下文切换到内核的顺序是什么 - In what order does a context switch to the kernel occur 测量进程上下文切换 - Measuring a process context switch 上下文切换期间进程的物理内存内容发生了什么 - What happens to the physical memory contents of a process during context switch 32对64位......或者,'处理信息'究竟是什么意思 - 32 vs 64 bit…or, what exactly does 'processing information' mean “ CPU生成逻辑地址”是什么意思? - What does the phrase 'CPU generates the logical address' mean? 如何避免僵尸进程? 在这种情况下,确切的初始化过程是什么? - How to avoid zombie processes? and what exactly init process does in this situation? 进程的上下文切换和内存更改 - Context switch of a process and memory changes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM