linux内核2.4.27中'niceness'和'goodness'之间的区别 [英] Difference between 'Niceness' and 'Goodness' in linux kernel 2.4.27

查看:176
本文介绍了linux内核2.4.27中'niceness'和'goodness'之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解任务调度程序的linux内核代码. 我无法弄清楚什么是善良值,与善良值有何不同? 另外,它们每个人如何有助于调度?

I am trying to understand linux kernel code for task scheduler. I am not able to figure out what is goodness value and how it differs from niceness? Also, how each of them contribute to scheduling?

推荐答案

AFAIK:在运行队列中为每个进程分配一个" goodness "值,该值确定一个进程的运行状况.该值由 goodness()函数计算.

AFAIK: Each process in the run queue is assigned a "goodness" value which determines how good a process is for running. This value is calculated by the goodness() function.

具有较高优势的过程将是下一个要运行的过程.如果没有进程可运行,则操作系统将选择一个特殊的空闲任务.

The process with higher goodness will be the next process to run. If no process is available for running, then the operating system selects a special idle task.

好" 的第一近似值是根据过程量子中剩余的滴答声数量计算得出的.这意味着流程的优劣程度会随着时间的推移而降低,直到任务的时间量到期时它变为零为止.

A first-approximation of "goodness" is calculated according to the number of ticks left in the process quantum. This means that the goodness of a process decreases with time, until it becomes zero when the time quantum of the task expires.

最终优劣是根据过程的优劣来计算的. 因此,从根本上说,一个流程的好处是将时间片左逻辑与不错的值结合在一起.

The final goodness is calculated in function of the niceness of the process. So basically goodness of a process is a combination of the Time slice left logic and nice value.

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;
}

了解和记住美好的价值:记住这一点.

TO UNDERSTAND and REMEMBER NICE value: remember this.

Nice值的词源学是,更精细"的进程为其他进程提供了更多的运行时间,因此,较低的nice值将转化为较高的优先级.

The etymology of Nice value is that a "nicer" process allows for more time for other processes to run, hence lower nice value translates to higher priority.

所以

Higher the goodness value -> More likely to Run
    Higher the nice value  -> Less likely to run.

良善度"值是使用尼斯值

Also Goodness value is calculated using the nice value as

20 - p->nice

好的值的范围是 -20(最高优先级)到19(最低优先级)

lets assume a nice value of -20 ( EXTREMELY NOT NICE). hence 20 - (-20) = 40

这意味着善良值增加了,因此将选择此过程.

Which means the goodness value has increased, hence this process will be chosen.

这篇关于linux内核2.4.27中'niceness'和'goodness'之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆