更改线程实时调度策略失败:config_rt_group_sched = y



如果我在这里发布它而不是超级用户,我的歉意。

我试图在实时组中运行Docker,并且遇到了启用CGroups-CONFIG_RT_GROUP_SCHED在内核中运行实时Docker应用程序(这里:https://docs.docker.com/config/config/containers/containers/resource_constraints/#configure-default-cfs-scheduler(

我配置了我的内核来启用FIFO/RR标志并进行了验证(可在以下:如何启用ubuntu中的config_rt_group_sched以使其成为RT(

我相信我的系统现在已经适当安排了,因为我能够在此系统上运行有限的资源docker,该系统可以使用以下命令访问cgroups:

$ docker run -it --cpu-rt-runtime=950000 
                      --ulimit rtprio=99 
                      --cap-add=sys_nice 
                      debian:jessie

我继续尝试探索RT系统的更多功能。我拥有此CPP代码将RT优先级调度分配给线程。该代码基本上试图将SCHED_FIFO优先级设置为线程,并打印内核是否允许其设置优先级。

#include <iostream>
#include <pthread.h>
#include <sched.h>
using namespace std;
void set_realtime_priority() {
     int ret;
     // We'll operate on the currently running thread.
     pthread_t this_thread = pthread_self();
     // struct sched_param is used to store the scheduling priority
     struct sched_param params;
     // We'll set the priority to the maximum.
     params.sched_priority = sched_get_priority_max(SCHED_FIFO);
     std::cout << "Trying to set thread realtime prio = " << params.sched_priority << std::endl;
     // Attempt to set thread real-time priority to the SCHED_FIFO policy
     ret = pthread_setschedparam(this_thread, SCHED_FIFO, &params);
     if (ret != 0) {
         // Print the error
         std::cout << "Unsuccessful in setting thread realtime prio" << std::endl;
         return;     
     }
     // Now verify the change in thread priority
     int policy = 0;
     ret = pthread_getschedparam(this_thread, &policy, &params);
     if (ret != 0) {
         std::cout << "Couldn't retrieve real-time scheduling paramers" << std::endl;
         return;
     }
     // Check the correct policy was applied
     if(policy != SCHED_FIFO) {
         std::cout << "Scheduling is NOT SCHED_FIFO!" << std::endl;
     } else {
         std::cout << "SCHED_FIFO OK" << std::endl;
     }
     // Print thread scheduling priority
     std::cout << "Thread priority is " << params.sched_priority << std::endl; 
}
int main(){
set_realtime_priority();
return 0;
}

我已经在通用的Ubuntu/Fedora和RT修补的CentOS系统上验证了此代码。所有这些系统允许代码设置优先级。令人惊讶的是,它的CONFIG_RT_GROUP_SCHED=y配置了内核,这不允许我设置优先级策略。同样,它也不允许cyclictest运行

//install cyclictest by following
$ sudo apt-get install rt-tests
$ sudo cyclictest

我不了解这种异常行为。启用config_rt_group_sched是否可以阻止我更改调度策略?

我不确定您是否已修复它,但昨天我遇到了同样的问题,这是我的解决方案。

当config_rt_group_sched = y时,您应该允许将(某些(RT线程(S(运行到您的cgroup。可以通过为" rt_runtime_us"节点提供适当的价值来完成。

1(找到一个cyclictest的cgroup

如果由Shell Command午餐,它将遵循CGROUP进行外壳过程。请输入下面的命令,以查找Cyclictest或SH Process的cgroup

] ps -o cgroup

2(为您的cgroup

分配适当的时间表。

在我的情况下,'sh'过程都进入了" system.slice/system-serial-blabla" cgroup中。因此,我给了这些Cgroup层次结构的Max Timeslot,并已修复。

] echo 950000>/sys/fs/cgroup/cpu/system.slice/cpu.rt_runtime_us

] echo 950000>/sys/fs/cgroup/cpu/system.slice/system-serial-blabla/cpu.rt_runtime_us_us

祝你好运!

正如Yongho Shin所指出的那样,您仍然必须为运行cyclictest的对照组分配一个适当的时间插槽 - 无论您是从Docker内部还是外部运行它它 - 否则将向您显示错误消息Unable to change scheduling policy! either run as root or join realtime group。正如错误消息本身已经指出的那样,您必须在实时cgroup中运行该过程:

首先让我们安装 cgexec 来自cgroup-tools

$ sudo apt-get install cgroup-tools

然后为cgroup (在以下示例950000中(分配时间切片,该过程应通过修改相应的配置文件,例如:

来进行操作。
$ sudo echo 950000 > /sys/fs/cgroup/cpu/system.slice/cpu.rt_runtime_us

最后,您可以cgroup 内启动一个过程,并使用

之类的东西
$ sudo cgexec -g subsystems:path_to_cgroup command arguments

在我们的cyclictest中,我们的命令看起来像:

$ sudo cgexec -g cpu:system.slice cyclictest -m -sp99 -d0

最新更新