是否必须有模式切换才能有资格作为上下文切换?

发布于 2024-12-07 22:27:58 字数 45 浏览 0 评论 0原文

是否必须有一个模式开关,即。从用户模式到内核模式以便将该操作称为上下文切换?

Does there have to be a mode switch ie. from user to kernel mode in order for the action to be called a context switch?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

肥爪爪 2024-12-14 22:27:58

不。并非所有处理器都具有权限级别

上下文切换通常意味着从进程控制块恢复执行状态。然而,上下文的概念是实现定义的。来自维基百科

上下文的构成是由处理器和操作系统决定的。

...
当操作系统需要在用户态和内核态之间转换时,
不需要上下文切换;模式转换本身并不是上下文切换。但是,根据操作系统的不同,此时也可能会发生上下文切换

No. Not all processors even have privilege levels.

A context switch usually means restoring an execution state from a Process Control Block. However, the notion of a context is implementation-defined. From Wikipedia:

What constitutes the context is determined by the processor and the operating system.

...
When a transition between user mode and kernel mode is required in an operating system, a
context switch is not necessary; a mode transition is not by itself a context switch. However, depending on the operating system, a context switch may also take place at this time.

乱了心跳 2024-12-14 22:27:58

上下文切换仅发生在内核模式下。如果两个用户模式进程之间发生上下文切换,首先CPU必须切换到内核模式,执行上下文切换,然后返回到用户模式等等。
因此必须有一个与上下文切换相关联的模式切换。

context switch happens only in kernel mode. If context switching happens between two user mode processes, first cpu has to change to kernel mode, perform context switch, return back to user mode and so on.
So there has to be a mode switch associated with a context switch.

很糊涂小朋友 2024-12-14 22:27:58

模式切换 - 当单个进程模式从用户级切换到内核级或反之亦然时。它通过系统调用发生。当进程调用系统调用时,进程模式将更改为内核模式,并且内核将开始代表用户进程执行操作。一旦系统调用返回,进程模式将从内核模式更改为用户模式。 “模式”是与进程相关联的属性。所以,模式切换是单个进程模式的切换。

上下文切换 - 当正在运行的进程当前状态存储在某个位置并且选择新进程运行并将其已存储的状态加载到 CPU 寄存器中时。现在新进程开始运行。整个“上下文切换”过程是由“进程调度程序”完成的。

Mode Switch - When a single process mode is switched from user-level to kernel-level or the other way around. It happens through the system calls. When a process call the system call, the process mode will change to kernel-mode and the kernel will start acting on behalf of the user process. And once the system call returns the process mode will change from kernel-mode to user-mode. "Mode" is a property associated with the process. So, a mode switch is switch of the mode of a single process.

Context Switch - It is when the running process current state is stored some place and a new process is chosen for running and its already stored state is loaded in the CPU registers. And now the new process starts running. This whole "context switch" procedure is done by the "Process Scheduler".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文