优先级为99的SCHED_FIFO进程被抢占了吗? [英] SCHED_FIFO process with priority of 99 gets preempted?
问题描述
这来自sched_setscheduler(2)-Linux手册页:
根据一种实时策略(SCHED_FIFO,SCHED_RR)调度的进程的sched_priority值在1(低)到99(高)之间."
"SCHED_FIFO进程一直运行,直到被I/O请求阻止,被更高优先级的进程抢占或调用sched_yield(2)."
我有以下代码:
struct sched_param sp;
memset( &sp, 0, sizeof(sp) );
sp.sched_priority = 99;
sched_setscheduler( 0, SCHED_FIFO, &sp );
现在,该进程应该在尽可能高的优先级下运行(99) 并且永远不应被抢占.
因此,当它开始运行以下循环时:
while ( 1 ) ;
它应该永远运行,并且不允许其他进程运行.
尽管如此,当我启动这样的过程时,我也可以使用其他过程.其他进程的运行速度要慢得多,但它们确实可以运行.
我的处理器有2个核心,因此我开始了该过程的两个副本. 两个内核的使用率跃升至97%-100%.这两个进程都在运行它们的无限循环.
我仍然可以在shell中键入命令并查看其输出.我也可以使用GUI程序.
那怎么办呢?因为永远不应该抢占优先级为99的SCHED_FIFO进程?
如果您尚未更改任何其他策略设置,则可能会受到限制.有关几年前添加到调度程序中的实时限制,请参见此信息文章. >
其要点是:非特权用户可以使用SCHED_FIFO
并尝试浸泡CPU,但是RT限制代码无论如何都会强制使用SCHED_OTHER
一点,这样您就不会楔入系统.摘自文章:
从2.6.25开始发布的内核已将rt_bandwidth值设置为 默认组是每1.0秒0.95.换句话说, 默认情况下,将组调度程序配置为保留5%的CPU 用于非SCHED_FIFO任务.
this is from sched_setscheduler(2) - Linux man page:
"Processes scheduled under one of the real-time policies (SCHED_FIFO, SCHED_RR) have a sched_priority value in the range 1 (low) to 99 (high)."
"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)."
I have the following code:
struct sched_param sp;
memset( &sp, 0, sizeof(sp) );
sp.sched_priority = 99;
sched_setscheduler( 0, SCHED_FIFO, &sp );
Now the process should be running under the highest possible priority (99) and should never be preempted.
So, when it starts running the following loop:
while ( 1 ) ;
it should be running forever and no other process should be allowed to run.
In spite of this, when I start such a process, I can use other processes too. Other processes run much slower, but they DO run.
My processor has 2 cores, so I started two copies of the process. Usage of both cores jumped to 97%-100%. Both processes were running their infinite loop.
I could still type commands in a shell and watch their output. I could use GUI programs as well.
How's that possible since a SCHED_FIFO process with a priority of 99 should never be preempted?
If you haven't changed any other policy settings, then you're likely getting throttled. See this informative article on the real-time limits added to the scheduler a few years back.
The gist of it is: Unprivileged users can use SCHED_FIFO
and try to soak the CPU, but the RT limits code will force a little bit of SCHED_OTHER
in anyway so you don't wedge the system. From the article:
Kernels shipped since 2.6.25 have set the rt_bandwidth value for the default group to be 0.95 out of every 1.0 seconds. In other words, the group scheduler is configured, by default, to reserve 5% of the CPU for non-SCHED_FIFO tasks.
这篇关于优先级为99的SCHED_FIFO进程被抢占了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!