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

问题描述 投票:1回答:1

如果我在这里而不是超级用户发帖,我深表歉意。

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

我将内核配置为启用FIFO / RR标志并对其进行了验证(在此处可用:How to enable CONFIG_RT_GROUP_SCHED in Ubuntu to make it RT

我相信我的系统现在已正确调度,因为我能够在该系统上运行资源受限的docker,该系统使用以下命令访问cgroup:

$ 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是否会以某种方式阻止我更改调度策略?

c++ docker linux-kernel real-time cgroups
1个回答
0
投票

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

[当CONFIG_RT_GROUP_SCHED = y时,您应授予对cgroup运行(某些)RT线程的权限。可以通过为“ rt_runtime_us”节点提供适当的值来完成此操作。

1)为循环测试找到一个cgroup如果通过shell命令进行午餐,它将遵循cgroup进行shell进程。请输入以下命令以找到用于循环测试或sh进程的cgroup] ps -O cgroup

2)为rt计划分配适当的时隙给您的cgroup在我的情况下,“ sh”进程进入了“ system.slice / system-serial-blabla” cgroup。因此,我将最大时隙分配给了这些cgroup层次结构,该问题已得到解决。] 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

祝你好运!

© www.soinside.com 2019 - 2024. All rights reserved.