2

只是尝试使用SCHED_FIFO策略将 sched 优先级设置为最大。安装 libpam-systemd 后,此代码开始抛出错误。

编辑:归结为以下两个问题,尽可能清楚地说明它们。

斯特拉斯:

sched_setscheduler(564, SCHED_FIFO, { 99 }) = -1 EPERM(不允许操作)

param.sched_priority = sched_get_priority_max(SCHED_FIFO);
printf("priority %d \n", param.sched_priority);

ret1 = sched_setscheduler(getpid(), SCHED_FIFO, &param);
printf("sched_setscheduler ret %d \n", ret1);
if(ret1 == -1){
    perror("sched_setscheduler");
    goto fail;
}

问题:为什么 root 用户应该获得 EPERM?

还尝试在/etc/security/limits.conf没有任何运气的情况下设置在下面。

root   soft   rtprio       99    
root   hard   rtprio       99

来自犬舍配置文件

#CONFIG_SCHED_AUTOGROUP is not set
CONFIG_CGROUP_SCHED=y
CONFIG_FAIR_GROUP_SCHED=y
CONFIG_CFS_BANDWIDTH=y
CONFIG_RT_GROUP_SCHED=y
CONFIG_GENERIC_SCHED_CLOCK=y
CONFIG_CGROUPS=y
CONFIG_CGROUP_DEBUG=y
CONFIG_CGROUP_FREEZER=y

更新 文件中的内核代码错误linux/kernel/sched/core.c

#ifdef CONFIG_RT_GROUP_SCHED
    /*
     * Do not allow realtime tasks into groups that have no runtime
     * assigned.
     */
    if (rt_bandwidth_enabled() && rt_policy(policy) &&
            task_group(p)->rt_bandwidth.rt_runtime == 0 &&
            !task_group_is_autogroup(task_group(p))) {
        task_rq_unlock(rq, p, &flags);
        return -EPERM;
    }
#endif

通过案例:没有libpam-systemd,我得到以下值

[   36.278241] rt_bandwidth_enabled(): 1 
[   36.281977] rt_policy(policy) : 1 
[   36.285367] task_group_is_autogroup(task_group(p)) : 0 
[   36.289883] task_group(p)->rt_bandwidth.rt_runtime : 950000000 

失败案例:使用libpam-systemd,我得到以下值

[ 2096.713855] rt_bandwidth_enabled(): 1 
[ 2096.717871] rt_policy(policy) : 1 
[ 2096.721408] task_group_is_autogroup(task_group(p)) : 0 
[ 2096.726180] task_group(p)->rt_bandwidth.rt_runtime: 0

问题:为什么 libpam-systemd 应该为 root 用户修改 rt 运行时带宽?

调度程序 RT 运行时值来自proc

root@jarvis:/home/jarvis# cat /proc/sys/kernel/sched_rt_runtime_us 
950000
root@jarvis:/home/jarvis# cat /proc/sys/kernel/sched_rt_period_us
1000000

任何帮助高度赞赏。

4

1 回答 1

4

systemd为每个用户和每个服务创建一个单独的cgroup 。检查/proc/self/cgroup以查看差异。请注意,RT 调度存在已知问题:

    We recommend to turn off Real-Time group scheduling in the
    kernel when using systemd. RT group scheduling effectively
    makes RT scheduling unavailable for most userspace, since it
    requires explicit assignment of RT budgets to each unit whose
    processes making use of RT. As there's no sensible way to
    assign these budgets automatically this cannot really be
    fixed, and it's best to disable group scheduling hence.
       CONFIG_RT_GROUP_SCHED=n
于 2016-01-29T07:27:34.487 回答