What is voluntary preemption?

佐手、 提交于 2020-01-01 05:25:29

问题


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


回答1:


It depends a little bit on the OS.


In some RTOS, 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).



来源:https://stackoverflow.com/questions/5174955/what-is-voluntary-preemption

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!