【问题标题】:Difference between 'Niceness' and 'Goodness' in linux kernel 2.4.27Linux 内核 2.4.27 中“Niceness”和“Goodness”之间的区别
【发布时间】:2016-01-23 15:17:18
【问题描述】:

我正在尝试了解任务调度程序的 linux 内核代码。 我无法弄清楚什么是善良价值以及它与善良有何不同? 另外,它们各自对调度有何贡献?

【问题讨论】:

    标签: linux linux-kernel kernel scheduled-tasks scheduler


    【解决方案1】:

    AFAIK:运行队列中的每个进程都被分配了一个“goodness”值,该值决定了进程运行的好坏程度。该值由 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.
    

    Goodness 值也是使用 nice 值计算的

    20 - p->nice
    

    因为 nice 值的范围从 -20(最高优先级)到 19(最低优先级)

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

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

    【讨论】:

    • 谢谢!真的很有用:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-20
    • 2012-02-29
    • 2020-11-16
    • 2013-07-20
    • 2020-04-23
    • 2014-04-06
    相关资源
    最近更新 更多