Linux kernel function set_user_nice
<p>I have an homework assignment, we need to add some features to Linux kernel, and we're working on red hat 2.4.18.
I looked in sched.c, function set_user_nice:</p>

<pre><code>void set_user_nice(task_t *p, long nice)
{
    unsigned long flags;
    prio_array_t *array;
    runqueue_t *rq;

    if (TASK_NICE(p) == nice || nice &lt; -20 || nice &gt; 19)
        return;
    /*
     * We have to be careful, if called from sys_setpriority(),
     * the task might be in the middle of scheduling on another CPU.
     */
    rq = task_rq_lock(p, &amp;flags);
    if (rt_task(p)) {
        p-&gt;static_prio = NICE_TO_PRIO(nice);
        goto out_unlock;
    }
    array = p-&gt;array;
    if (array)
        dequeue_task(p, array);
    p-&gt;static_prio = NICE_TO_PRIO(nice);
    p-&gt;prio = NICE_TO_PRIO(nice);
    if (array) {
        enqueue_task(p, array);
        /*
         * If the task is running and lowered its priority,
         * or increased its priority then reschedule its CPU:
         */
        if ((NICE_TO_PRIO(nice) &lt; p-&gt;static_prio) || (p == rq-&gt;curr))
            resched_task(rq-&gt;curr);
    }
out_unlock:
    task_rq_unlock(rq, &amp;flags);
}
</code></pre>

<p>I don't understand what exactly the code checks in the last if statement,
because few lines above it, we have this line:</p>

<pre><code>p-&gt;static_prio = NICE_TO_PRIO(nice);
</code></pre>

<p>and then, in the if statement we check:</p>

<pre><code>(NICE_TO_PRIO(nice) &lt; p-&gt;static_prio)
</code></pre>

<p>Am I missing something?
Thanks</p>