什么是自愿抢占?

发布于 2024-10-20 07:28:59 字数 30 浏览 10 评论 0原文

什么是自愿抢占?我只知道这是调度中的一个概念。

What is voluntary preemption? I only know that it's a concept in scheduling.

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

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

发布评论

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

评论(1

凉城 2024-10-27 07:28:59

这在一定程度上取决于操作系统。


在某些 RTOS(实时操作系统)中,自愿抢占意味着正在运行的进程声明它可以被抢占的点(否则它将运行直到完成)。考虑此变体的另一种方式是协程中的yield。这与大多数由内核决定抢占的桌面操作系统形成鲜明对比。请记住,某些 RTOS 没有“用户模式”的概念。


在 Linux 中(至少),“自愿抢占”有点用词不当:

传统上(没有强制抢占),当用户进程进行系统调用时(在内核模式),它将阻塞直到完成。只有用户模式代码可以被抢占。

抢占式内核是指内核代码本身可以被抢占。这听起来有些多余,但值得注意的是,我们的意思是内核是可抢占的,而不是“内核支持抢占”。强制/非自愿抢占意味着即使在服务系统调用时,高优先级用户进程的中断也可以“强制”内核进行上下文切换,以便它现在可以运行(从技术上讲,它并不是真正的上下文切换,但它具有相同的功能)影响)。这减少了用户进程“看到”硬件状态变化的延迟。

自愿抢占是内核定期检查是否应该“在执行内核操作时”重新调度进程的情况。也就是说,它不是仅在抢占点调度/重新调度用户进程,而是在处理 I/O 等事务时定期执行此操作。因此,通常情况下,高优先级用户进程可能仍然需要等待低优先级进程完成其切片,而高优先级进程现在可能会“提前”运行,因为内核会更频繁地检查它是否要运行。这减少了用户进程从挂起状态转移到运行状态的延迟(以整体系统吞吐量为代价)。

It depends a little bit on the OS.


In some RTOS (real time operatiing system), voluntary preemption means that the running process declares points where it can be preempted (where otherwise it would run until completion). Another way to think of this variant is that of a yield in a coroutine. This is in contrast to most desktop OS where the kernel determines preemption. Keep in mind that some RTOS do not have the concept of a "user mode".


In Linux (at least), "voluntary preemption" is a bit of a misnomer:

Traditionally (no forced preemption), when a user process was making a system call (in kernel mode), it would block until completion. Only user mode code could be preempted.

The preemptive kernel is such that kernel code itself can be preempted. That sounds redundant but it's worth noting that we mean the kernel is preemptible, not that "the kernel supports preemption". Forced/involuntary preemption means that even while servicing a system call, an interrupt for a high priority user process can "force" the kernel to context switch so that it will now run (technically it's not really a context switch, but it has the same effect). This decreases the latency of a user process "seeing" a change in hardware state.

Voluntary preemption is where the kernel periodically checks to see if it should reschedule processes "while doing kernel things". That is, instead of only scheduling/rescheduling user processes at preemption points, it does it periodically while handling things such as I/O. So, where normally a high priority user process might still have to wait for a low priority process to finish its slice, the high prioirty process might now get run "early" as the kernel is checking more frequently if it's to run. This decreases the latency of a user process moving from a suspended state to a running state (at the expense of overall system throughput).

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