安装 libpam-systemd 后出现 sched_setscheduler 错误 (EPERM)

jar*_*729 3 linux pam ubuntu-15.04

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

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

STRACE:

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;
}
Run Code Online (Sandbox Code Playgroud)

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

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

root   soft   rtprio       99    
root   hard   rtprio       99
Run Code Online (Sandbox Code Playgroud)

来自 KENREL 配置文件

#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
Run Code Online (Sandbox Code Playgroud)

更新 文件中内核代码错误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
Run Code Online (Sandbox Code Playgroud)

PASS CASE:如果没有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 
Run Code Online (Sandbox Code Playgroud)

失败案例:使用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
Run Code Online (Sandbox Code Playgroud)

问题:为什么 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
Run Code Online (Sandbox Code Playgroud)

非常感谢任何帮助。

gra*_*ity 5

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
Run Code Online (Sandbox Code Playgroud)