I'm writing a a very small daemon that must remain responsive even when a system is under severe stress. I'm looking at the differences between SCHED_FIFO and SCHED_RR in regards to scheduling, as well as trying to determine a sensible priority.
我正在写一个非常小的守护进程,即使系统处于严重的压力下也必须保持响应。我正在研究SCHED_FIFO和SCHED_RR之间在调度方面的差异,以及尝试确定合理的优先级。
Which scheduler would be appropriate for a small but critical monitoring daemon, what priority would be reasonably safe? I'm still coming up a little fuzzy when trying to understand the differences between the two.
哪个调度程序适用于小型但关键的监视守护程序,哪个优先级相当安全?在试图理解两者之间的差异时,我仍然有点模糊。
My program is allocating under 3k (and uses mlockall()), it writes about 600 bytes to xenbus then sleeps, but its impossible for me to tell how much time (in ms) it will take to actually write the data.. since what is written depends on a configuration file.
我的程序在3k以下分配(并使用mlockall()),它向xenbus写入大约600个字节然后休眠,但我不可能告诉实际写入数据需要多少时间(以ms为单位)..因为什么编写取决于配置文件。
Thanks in advance for any suggestions / explanations.
提前感谢任何建议/解释。
4 个解决方案
#1
10
The infamous pchdtvr
program, which captures digital TV signals, uses SCHED_FIFO
to make sure that the TV packets are written to disk no matter what. It can capture 4 shows at once while playing Doom on an old computer.
臭名昭着的pchdtvr程序捕获数字电视信号,使用SCHED_FIFO确保无论如何都将电视数据包写入磁盘。它可以在旧计算机上播放Doom时一次捕获4个节目。
The program is infamous because it was released under GPL and the author tried to revoke the GPL retroactively. This act provoked a minor firestorm. Anyway, you can find a recent version to study at http://frequal.com/pmn/pchdtvr.html.
该程序臭名昭着,因为它是根据GPL发布的,作者试图追溯撤销GPL。这一举动引发了一场小小的风暴。无论如何,您可以在http://frequal.com/pmn/pchdtvr.html找到最新版本。
#2
6
SCHED_FIFO can't be preempted (context switched to another process) unless another process of higher priority shows up in the execution queue.
除非在执行队列中显示另一个具有更高优先级的进程,否则不能抢占SCHED_FIFO(上下文切换到另一个进程)。
SCHED_RR can be preempted by a time quantum (delay given to a process to execute).
SCHED_RR可以被时间量子(给予执行的进程的延迟)抢占。
They are both "real-time" priorities of linux based schedulers.
它们都是基于Linux的调度程序的“实时”优先级。
#3
2
I'm not an expert for scheduling schemes, but have a look at
我不是调度方案的专家,但请看一下
man sched_setscheduler
it details what the difference between the different scheduling algorithms are, and provide links to other scheduling functions. SCHED_FIFO actually sounds pretty dangerous, but is described as the most aggressive scheduling:
它详细说明了不同调度算法之间的区别,并提供了与其他调度功能的链接。 SCHED_FIFO实际上听起来很危险,但被描述为最积极的调度:
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进程一直运行,直到它被I / O请求阻塞,被优先级更高的进程抢占,或者调用sched_yield(2)。
Beware not to lock up your system. I would personally do some empirical tests to see what priority fits the best and how they behave exactly.
请注意不要锁定系统。我个人会做一些实证测试,看看哪个优先级最适合它们以及它们的行为如何。
#4
2
If all your other tasks use the standard scheduler, it makes no difference; SCHED_FIFO and SCHED_RR only affect the scheduling of these tasks with each other.
如果您的所有其他任务都使用标准调度程序,则没有任何区别; SCHED_FIFO和SCHED_RR仅影响这些任务的相互调度。
So on a normal system it makes no difference. FIFO is easiest to understand, so use that I guess.
所以在正常的系统上它没有任何区别。 FIFO是最容易理解的,所以使用我猜。
If you have several tasks of different priorities, only the higher one will be run if they are all ready to be run (and there is only one CPU core)
如果你有几个不同优先级的任务,只要它们都准备好运行(并且只有一个CPU核心),只会运行更高的任务。
#1
10
The infamous pchdtvr
program, which captures digital TV signals, uses SCHED_FIFO
to make sure that the TV packets are written to disk no matter what. It can capture 4 shows at once while playing Doom on an old computer.
臭名昭着的pchdtvr程序捕获数字电视信号,使用SCHED_FIFO确保无论如何都将电视数据包写入磁盘。它可以在旧计算机上播放Doom时一次捕获4个节目。
The program is infamous because it was released under GPL and the author tried to revoke the GPL retroactively. This act provoked a minor firestorm. Anyway, you can find a recent version to study at http://frequal.com/pmn/pchdtvr.html.
该程序臭名昭着,因为它是根据GPL发布的,作者试图追溯撤销GPL。这一举动引发了一场小小的风暴。无论如何,您可以在http://frequal.com/pmn/pchdtvr.html找到最新版本。
#2
6
SCHED_FIFO can't be preempted (context switched to another process) unless another process of higher priority shows up in the execution queue.
除非在执行队列中显示另一个具有更高优先级的进程,否则不能抢占SCHED_FIFO(上下文切换到另一个进程)。
SCHED_RR can be preempted by a time quantum (delay given to a process to execute).
SCHED_RR可以被时间量子(给予执行的进程的延迟)抢占。
They are both "real-time" priorities of linux based schedulers.
它们都是基于Linux的调度程序的“实时”优先级。
#3
2
I'm not an expert for scheduling schemes, but have a look at
我不是调度方案的专家,但请看一下
man sched_setscheduler
it details what the difference between the different scheduling algorithms are, and provide links to other scheduling functions. SCHED_FIFO actually sounds pretty dangerous, but is described as the most aggressive scheduling:
它详细说明了不同调度算法之间的区别,并提供了与其他调度功能的链接。 SCHED_FIFO实际上听起来很危险,但被描述为最积极的调度:
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进程一直运行,直到它被I / O请求阻塞,被优先级更高的进程抢占,或者调用sched_yield(2)。
Beware not to lock up your system. I would personally do some empirical tests to see what priority fits the best and how they behave exactly.
请注意不要锁定系统。我个人会做一些实证测试,看看哪个优先级最适合它们以及它们的行为如何。
#4
2
If all your other tasks use the standard scheduler, it makes no difference; SCHED_FIFO and SCHED_RR only affect the scheduling of these tasks with each other.
如果您的所有其他任务都使用标准调度程序,则没有任何区别; SCHED_FIFO和SCHED_RR仅影响这些任务的相互调度。
So on a normal system it makes no difference. FIFO is easiest to understand, so use that I guess.
所以在正常的系统上它没有任何区别。 FIFO是最容易理解的,所以使用我猜。
If you have several tasks of different priorities, only the higher one will be run if they are all ready to be run (and there is only one CPU core)
如果你有几个不同优先级的任务,只要它们都准备好运行(并且只有一个CPU核心),只会运行更高的任务。