linux 内核 2.4.27 中 'Niceness' 和 'Goodness' 的区别
Difference between 'Niceness' and 'Goodness' in linux kernel 2.4.27
我正在尝试理解 linux 任务调度程序的内核代码。
我无法弄清楚什么是善良价值以及它与善良有何不同?
另外,他们每个人如何为日程安排做出贡献?
AFAIK:运行 队列中的每个进程都分配了一个“goodness”值,该值决定了进程对 运行ning 的好坏程度。该值由 goodness() 函数计算得出。
具有更高优度的进程将是 运行 的下一个进程。如果 运行ning 没有进程可用,则操作系统选择一个特殊的 空闲任务。
"goodness"的一阶近似值是根据进程量程中剩余的滴答数计算的。这意味着进程的优度随着时间的推移而降低,直到任务的时间片到期时它变为零。
最终的优度是根据过程的优度计算的。 所以基本上一个过程的优点是时间片左逻辑和 nice 值的组合。
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 值的词源是 "nicer" 进程允许其他进程有更多时间 运行,因此较低的 nice 值转化为较高的优先级。
所以,
Higher the goodness value -> More likely to Run
Higher the nice value -> Less likely to run.
Goodness 值也是使用 nice 值计算的
20 - p->nice
因为 nice 值的范围从 -20(最高优先级)到 19(最低优先级)
lets assume a nice value of -20 ( EXTREMELY NOT NICE). hence 20 - (-20) = 40
表示goodness值增加了,所以会选择这个流程
我正在尝试理解 linux 任务调度程序的内核代码。 我无法弄清楚什么是善良价值以及它与善良有何不同? 另外,他们每个人如何为日程安排做出贡献?
AFAIK:运行 队列中的每个进程都分配了一个“goodness”值,该值决定了进程对 运行ning 的好坏程度。该值由 goodness() 函数计算得出。
具有更高优度的进程将是 运行 的下一个进程。如果 运行ning 没有进程可用,则操作系统选择一个特殊的 空闲任务。
"goodness"的一阶近似值是根据进程量程中剩余的滴答数计算的。这意味着进程的优度随着时间的推移而降低,直到任务的时间片到期时它变为零。
最终的优度是根据过程的优度计算的。 所以基本上一个过程的优点是时间片左逻辑和 nice 值的组合。
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 值的词源是 "nicer" 进程允许其他进程有更多时间 运行,因此较低的 nice 值转化为较高的优先级。
所以,
Higher the goodness value -> More likely to Run
Higher the nice value -> Less likely to run.
Goodness 值也是使用 nice 值计算的
20 - p->nice
因为 nice 值的范围从 -20(最高优先级)到 19(最低优先级)
lets assume a nice value of -20 ( EXTREMELY NOT NICE). hence 20 - (-20) = 40
表示goodness值增加了,所以会选择这个流程