Ich habe eine Hausaufgabe, müssen wir einige Funktionen zum Linux-Kernel hinzufügen, und wir arbeiten an Red Hat 2.4.18. Ich sehe in sched.c, Funktion set_user_nice:Linux-Kernel-Funktion set_user_nice
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 < -20 || nice > 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, &flags);
if (rt_task(p)) {
p->static_prio = NICE_TO_PRIO(nice);
goto out_unlock;
}
array = p->array;
if (array)
dequeue_task(p, array);
p->static_prio = NICE_TO_PRIO(nice);
p->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) < p->static_prio) || (p == rq->curr))
resched_task(rq->curr);
}
out_unlock:
task_rq_unlock(rq, &flags);
}
Ich verstehe nicht, was genau den Code überprüft, in dem letzten if-Anweisung, weil einige Zeilen darüber, haben wir diese Linie:
p->static_prio = NICE_TO_PRIO(nice);
und dann, in der if-Anweisung überprüfen wir:
(NICE_TO_PRIO(nice) < p->static_prio)
Bin ich etwas fehlt? Danke
Ich denke, das war nicht der Fall. Es scheint mir ein Fehler zu sein. Ich habe den neueren Quellcode dieses Teils in meine Antwort eingefügt –