我正在尝试了解任务调度程序的linux内核代码。 我无法弄清楚什么是善良价值以及它与善意的区别? 另外,他们每个人如何参与调度?
答案 0 :(得分:3)
AFAIK:为运行队列中的每个进程分配一个“ goodness ”值,该值确定进程运行的好坏程度。该值由 goodness()函数计算。
具有更高优势的流程将成为下一个运行流程。如果没有可用于运行的进程,则操作系统会选择一个特殊的空闲任务。
根据过程量子中剩余的滴答数计算“善”的第一近似值。这意味着进程的优点会随着时间的推移而减少,直到任务的时间量到期时它变为零。
最终的善良是根据过程的优点来计算的。 所以基本上一个过程的优点是时间片左逻辑和好价值的组合。
static inline int goodness(struct task_struct * p, int this_cpu, struct mm_struct *this_mm)
{
int weight;
/*
* select the current process after every other
* runnable process, but before the idle thread.
* Also, dont trigger a counter recalculation.
*/
weight = -1;
if (p->policy & SCHED_YIELD)
goto out;
if (p->policy == SCHED_OTHER) {
/*
* Give the process a first-approximation goodness value
* according to the number of clock-ticks it has left.
*
* Don't do any other calculations if the time slice is
* over..
*/
weight = p->counter;
if (!weight)
goto out;
...
weight += 20 - p->nice;
goto out;
}
/* code for real-time processes goes here */
out:
return weight;
}
理解并记住NICE的价值:记住这一点。
Nice值的词源是“更好”的过程允许更多时间运行其他进程,因此较低的nice值转换为更高的优先级。
所以,
Higher the goodness value -> More likely to Run
Higher the nice value -> Less likely to run.
此外,使用nice值
计算Goodness值20 - p->nice
好的值范围从 -20(最高优先级)到19(最低优先级)
lets assume a nice value of -20 ( EXTREMELY NOT NICE). hence 20 - (-20) = 40
这意味着善意值增加,因此将选择此过程。