gpt4 book ai didi

linux - 安装 libpam-systemd 后的 sched_setscheduler 错误 (EPERM)

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:50:07 25 4
gpt4 key购买 nike

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

编辑:归结为下面的两个问题,尽可能把它们说清楚。

追踪:

sched_setscheduler(564, SCHED_FIFO, { 99 }) = -1 EPERM (Operation not permitted)

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

来自 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

更新文件 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 运行时带宽?

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

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

非常感谢任何帮助。

最佳答案

systemd 创建一个单独的 cgroup对于每个用户和每项服务。检查 /proc/self/cgroup 以查看差异。注意这里有 known problems使用 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

关于linux - 安装 libpam-systemd 后的 sched_setscheduler 错误 (EPERM),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34018956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com