Linux 内核中的 setscheduler()
大家,我在 static int setscheduler(pid_t pid, int policy, struct sched_param *param)
中找到了这个:
p->policy = policy;
if (policy != SCHED_OTHER) p->prio = MAX_USER_RT_PRIO-1 - p->rt_priority;
p 是指向具有当前 pid 的任务描述符的指针(上面的参数) 所以如果它的策略不是 SCHED_OHTER (它意味着 SCHED_FIFO 或 SCHED_RR),但为什么我们要这样改变 p->prio 呢? rt_priority 到底是什么意思?提前致谢
everyone, I found this inside static int setscheduler(pid_t pid, int policy, struct sched_param *param)
:
p->policy = policy;
if (policy != SCHED_OTHER) p->prio = MAX_USER_RT_PRIO-1 - p->rt_priority;
p is a pointer to the task descriptor with current pid (parameter above)
so if it's policy is not SCHED_OHTER (it means SCHED_FIFO or SCHED_RR) but why do we change p->prio such way? what exactly does it mean rt_priority? thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短回答:
rt_priority
表示实时优先级,对于SCHED_RR
和SCHED_FIFO
,它决定进程需要多长时间得到。长答案
首先,Linux 实现了
实时进程调度
(SCHED_RR
和SCHED_FIFO
)。在这些策略下运行的进程始终优先于其他进程。Linux 提供 99 个实时优先级,编号为 1(最低)到 99(最高)。
在内核中,如果我没记错的话“较小的数字意味着更好的优先级” - 较小的
p->prio
意味着更好的优先级。这是
sched_setscheduler
的样子:和
sched_param
整数
sched_priority
,用于SCHED_RR
或SCHED_FIFO
的策略意味着“实时优先级”,我假设是rt_priority
。因此内核做了正确的事情:Short answer:
rt_priority
means real-time priority and forSCHED_RR
andSCHED_FIFO
it decides how much time the process will get.Long answer
First of all Linux implements something called
Realtime Process Scheduling
(SCHED_RR
andSCHED_FIFO
). Processes operating under these policies always have priority over other processes.Linux provides 99 realtime priority levels, numbered 1 (lowest) to 99 (highest).
In the kernel, if I recall correctly "smaller numbers mean better preference" - smaller
p->prio
means better priority.Here us what
sched_setscheduler
looks like:And
sched_param
The integer
sched_priority
, for a policy ofSCHED_RR
orSCHED_FIFO
means "realtime priority" which I assume isrt_priority
. So the kernel does the right thing