Linux中的实时调度 [英] real time scheduling in Linux

查看:270
本文介绍了Linux中的实时调度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天早上,我读到了有关Linux实时调度的信息.根据《罗伯特·洛夫的Linux系统编程》一书,那里有两个主要的安排.一个是SCHED_FIFO(FIFO),第二个是SCHED_RR(循环).而且我了解了fifo和rr算法的工作原理.但是,有了系统调用,

This morning I read about Linux real time scheduling. As per the book 'Linux system programming by Robert Love', there are two main scheduling there. One is SCHED_FIFO, fifo and the second is SCHED_RR, the round robin. And I understood how a fifo and a rr algorithm works. But as we have the system call,

sched_setscheduler (pid_t pid, int policy, const struct sched_parem *sp)

我们可以为我们的流程显式设置调度策略.因此,在某些情况下,两个由root运行的进程可以具有不同的调度策略.作为一个具有SCHED_FIFO的进程,另一个具有SCHED_RR且具有相同优先级的进程.在这种情况下,将首先选择哪个过程? FIFO分类过程还是RR分类过程?为什么?

we can explicitly set the scheduling policy for our process. So in some case, two process running by root, can have different scheduling policy. As one process having SCHED_FIFO and another having SCHED_RR and with same priority. In that case, which process will be selected first? the FIFO classed process or the RR classed process? Why?

考虑这种情况.共有三个过程A,B,C.所有这些都具有相同的优先级. A和B是RR分类的过程,C是FIFO分类的过程. A和B是可运行的(因此两者在一段时间内交替运行).目前,A正在运行.现在,C成为可运行的.在这种情况下,是否

Consider this case. There are three process A,B,C. All are having same priority. A and B are RR classed processes and C is FIFO classed one. A and B are runnable (so both are running alternatively in some time intervel). And currently A is running. Now C becomes runnable. In this case, whether

1. A will preempt for C, or
2. A will run until its timeslice goes zero and let C run. Or
3. A will run until its timeslice goes zero and let B run.
   a) here after B runs till its timeslice becomes zero and let C run or
   b) after B runs till its timeslice becomes zero and let A run again (then C will starve untill A and B finishes)

推荐答案

在实时调度中,FIFO和RR的含义与非实时调度中的含义并不完全相同.始终以FIFO方式选择进程,但是,与SCHED_RR的时间量不同,SCHED_FIFO的时间量不受限制.

In realtime scheduling, FIFO and RR do not have exactly the same meaning they have in non-realtime scheduling. Processes are always selected in a FIFO- manner, however, the time quantum for SCHED_FIFO is not limited unlike the time quantum for SCHED_RR.

SCHED_FIFO进程不会抢占相同优先级的SCHED_RR进程.

SCHED_FIFO processes do not preempt SCHED_RR processes of the same priority.

sched_setscheduler(2)-Linux手册页

sched_setscheduler(2) - Linux man page

...

"进程的调度策略确定将其插入具有相同静态优先级的进程列表中的位置以及如何在列表中移动.所有调度都是抢先的:如果具有较高静态优先级的进程已准备好运行,当前运行的进程将被抢占并返回其静态优先级的等待列表.调度策略仅确定静态优先级相等的可运行进程列表中的顺序."

"A process's scheduling policy determines where it will be inserted into the list of processes with equal static priority and how it will move inside this list. All scheduling is preemptive: if a process with a higher static priority becomes ready to run, the currently running process will be preempted and returned to the wait list for its static priority level. The scheduling policy only determines the ordering within the list of runnable processes with equal static priority."

...

"SCHED_FIFO进程一直运行,直到被I/O请求阻止,被更高优先级的进程抢占或调用sched_yield(2)."

"A SCHED_FIFO process runs until either it is blocked by an I/O request, it is preempted by a higher priority process, or it calls sched_yield(2)."

...

当SCHED_FIFO进程变得可运行时,将根据优先级将其插入列表的末尾."

"When a SCHED_FIFO process becomes runnable, it will be inserted at the end of the list for its priority."

...

"SCHED_RR:循环调度

"SCHED_RR: Round Robin scheduling

SCHED_RR是SCHED_FIFO的简单增强.上面针对SCHED_FIFO所述的所有内容也适用于SCHED_RR,不同之处在于每个进程仅允许运行最大时间范围.如果SCHED_RR进程已经运行了等于或大于时间量的时间段,则将其放在优先级列表的末尾. SCHED_RR进程已被更高优先级的进程抢占,然后在运行进程中恢复执行,将完成其循环时间范围的未到期部分."

SCHED_RR is a simple enhancement of SCHED_FIFO. Everything described above for SCHED_FIFO also applies to SCHED_RR, except that each process is only allowed to run for a maximum time quantum. If a SCHED_RR process has been running for a time period equal to or longer than the time quantum, it will be put at the end of the list for its priority. A SCHED_RR process that has been preempted by a higher priority process and subsequently resumes execution as a running process will complete the unexpired portion of its round robin time quantum."

这篇关于Linux中的实时调度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆